I originally tried to have the sensor on the same pins as the OLED but that didn't work the sensor never showed up on a I2C buss scan.
Any Help would be appreciated.
Mike
#include <Wire.h>
#include <SparkFunMPL3115A2.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 16
Adafruit_SSD1306 display(OLED_RESET);
#if (SSD1306_LCDHEIGHT != 32)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
//Create an instance of the object
MPL3115A2 myPressure;
float altitude;
float agl;
int start = 1;
int resetPin = 12;
void setup() {
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32)
display.clearDisplay();
display.setTextSize(4);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.print("HELLO");
display.display();
Wire.begin(12,13);
myPressure.begin(); // Get sensor online
myPressure.setModeAltimeter(); // Measure altitude above sea level in meters
myPressure.setOversampleRate(7); // Set Oversample to the recommended 128
myPressure.enableEventFlags(); // Enable all three pressure and temp event flags
agl = myPressure.readAltitudeFt();
}
void loop() {
// put your main code here, to run repeatedly:
if (start = 1) {
int average = 0;
for (int i=0; i <= 1000; i++){
average = average + (agl = myPressure.readAltitudeFt());
delay(2);
}
agl = average/1000;
Serial.println(round(agl));
start = 0;
}
mystart:
altitude = myPressure.readAltitudeFt();
Serial.println(round(agl));
Serial.println(round(altitude));
Serial.println(round(altitude-agl));
int mymins = ((millis()/1000)/(60));
Serial.println(mymins);
display.clearDisplay();
display.setCursor(0,0);
display.print(round(altitude-agl));
display.display();
if (round(altitude-agl) >= 10) {
Serial.println("WTF");
Serial.println("Going into deep sleep for 20 seconds");
ESP.deepSleep(5); // 20e6 is 20 microseconds
}
delay(500);
goto mystart;
}