I am trying to use a MS5837 pressure sensor, but continue to get the message that the sensor cannot initialize. The library was intended for use with Arduino, but a friend told me that if I changed all of the instances of D1/D2 to P1/P2 it should work. The SCL goes to D1 and the SDA goes to D0. I personally don’t understand how to port Arduino libraries (or really just use libraries) and am rather new to Particle, so I would appreciate any help. The error message I am receiving is in the setup function for the .ino file
I see where you did this in the library and I’m not sure how this would “port” the library. All this does is change the name of a variable which has no effect on the actual code.
Pull-up resistors keep the signal at a “high” voltage when the source of the signal is not applying an voltage to them. The “Wire” library that your MS5837 library uses is a wrapper for the I2C module on the electron. I2C uses an “open-drain” output so it only pulls the signal low, and doesn’t drive it high. There are lots of resources on I2C that for more information like:
Actually this does matter in this case. Since D1 & D2 in the Particle world are defined as the pin designators having these used as variable names too will create problems. So renaming them is a crucial part in “porting” the library.
However, since 0.6.3 not a lot has to be done in order to port Arduino libraries that don’t rely on the AVR hardware specifics.
10k is a good place to start. You can go higher (100k or 1M) if you have really low power requirements but the trade-off is the current/voltage response time and thus the bandwidth. If power draw doesn’t matter, and you want really fast speeds or have really long wires you could drop the resistance to 5k or even 1k.
Thanks! The resistors did the trick, but that fickleness is coming into play - the readings for the sensor are dropping by 2-10 every time it logs to the serial monitor. Do you know what the cause/fix for this could be?
As mentioned in the PM - this is now the second time (first about the fact about needed pull-ups and then the sensor drift) that the same question was posted here and via PM simultaneously - that’s not appreciated.