Hello everyone,
I am experiencing the following issue:
I hooked two LPS331AP sensors over I2C, on an Arduino Uno R3. The sensors allow the last bit of its address to be changed - it is internally pulled-up. I wired it to GND to pull it down. The communication - once established, is fine.
But every time I power-on the Arduino it starts to read wrong data from the pulled-down sensor - pressure 760mbar, and the value never changes.
Here is the strange part - if I do the following:
- power-on Arduino - fails to read correct data;
- remove GND wire - so the two sensors now have the same address, the Arduino freezes;
- reboot Arduino (whitout powering it off) - fails to detect sensor;
- connect GND wire back;
- reboot Arduino (again no play with the power supply, only reboot from the button on the Arduino board);
and now the faulty sensor is detected and everything works fine...Until power-off.
Somewhere, I believe from Pololu support forum, I read that the value 760mbar is read when the I2C
wiring was not done properly. And I did see this early on while I was wiring the first time. But the case now is very different. Once I do the mentioned procedure after a fail-start everything works wonderfully!
The code that follows is the part of the setup() that relates to the sensors. It was largely copied from
an example from the <LPS.h> developers.
#include <Wire.h>
#include <LPS.h>
void setup() {
Serial.begin(9600);
Wire.begin();
if (!ps.init(LPS::device_331AP, LPS::sa0_low))
{
Serial.println("Failed to autodetect pressure sensor_In!");
}
if (!ps.init(LPS::device_331AP, LPS::sa0_high))
{
Serial.println("Failed to autodetect pressure sensor_Out!");
}
ps.enableDefault();
ps.init(LPS::device_331AP, LPS::sa0_low); //address sens_In; [sa0] is the last bit of the I2C address; here Im telling it to look for LPS331AP device with sa0_low;
ps.writeReg(LPS::RES_CONF, 0x7A); //sets high averg rate
ps.init(LPS::device_331AP, LPS::sa0_high); //address sens_Out
ps.writeReg(LPS::RES_CONF, 0x7A); //sets high averg rate
}
The hole code is rather large, but I wont post it all unless requiered. I believe the problem lies in the beginning somewhere. Once the Arduino powers up and boots up with the two sensors properly recognized everything works fine!
If someone had expirience with these sensors please respond.
Any reply will be appreciated and thank you very much! You may not know it but
you already helped a lot with this project! ![]()