#include <Wire.h>
#include "SparkFunMPL3115A2.h"
//Create an instance of the object
MPL3115A2 myPressure;
void setup()
{
Wire.begin(); // Join i2c bus
Serial.begin(9600); // Start serial for output
myPressure.begin(); // Get sensor online
//Configure the sensor
myPressure.setModeAltimeter(); // Measure altitude above sea level in meters
//myPressure.setModeBarometer(); // Measure pressure in Pascals from 20 to 110 kPa
myPressure.setOversampleRate(7); // Set Oversample to the recommended 128
myPressure.enableEventFlags(); // Enable all three pressure and temp event flags
}
void loop()
{
float altitude = myPressure.readAltitude();
Serial.print(" Altitude(M):");
Serial.print(altitude, 2);
float temperature = myPressure.readTemp();
Serial.print(" Temp(c):");
Serial.print(temperature, 2);
Serial.println();
delay(200);
}
As soon as I run the code, I end up getting only -999 readings (see picture)
Please use logic level converter.
Arduino Uno operate 5V.
So 5V will be applied to MPL3115A2 from SDA and SDL in your condition.
Many electronic components are sensitive and will break down if a voltage higher than the operating voltage is applied.
Hi, I have tried it out and it doesn't work which, I think, is either due to the sensor being damaged or as it says on the File you sent:
"-999 indicates that I2C timed out (512ms max). Check your
connections."
Could it just be a connection error or is the connection error due to the board being damaged?
Thanks for your help so far
Hi @hijiy .
Within a few minutes after using the MPL3115a2 on 3.3v successfully, it went back to -999 readings. I had tinkered around a bit and checked the connection using the I2C bus scanner. In the beginning, it said not connection found but after I soldered the pins and used 1k ohm resistors, it is not saying it is not connecting. Is this progress and what else can I do? Thanks again
In addition to this, while the new MPL3115A2 was working, I connected the old one and it worked too. This seems very weird to me.
SOLUTION:
An UNO (or any other board) does not output a (5V) signal. I2c works in tri-state connections. To send a 0-bit, it will pull the SCL or SDA line to GND, to send a 1-bit it will leave the line floating. Hence you always need pullup resistors to bring the line high. I have checked the schematics and these pull-up resistors (1k) are already on the MPL3115A2 board and connect the VCC ( 3v3).
Try to connect the board GND- GND, VCC -3V3, SCL to SCL, SDA to SDA ( NO resistors needed).
Thanks to paulvha from the Sparkfun Forum for helping!