I recently purchased a stack (literally 15 or so) of I2C (Inter-Integrated Circuit) sensors from Lady Adafruit (editorial note – huge fan, she does great work!) for about $10 apiece. Seven are of the temperature / humidity / pressure variety, and eight are of the n-DOF (degrees of freedom, typically 6 or 9) variety. (Almost) all of the items I purchased had a miniature 4-pin socket (SparkFun’s STEMMA QT / Qwiic) on both ends. This makes serial I2C connections a breeze when testing out new parts (which is exactly what I was doing).

They also offer a number of short cables (150 mm to 200 mm) with a variety of connector options (STEMMA QT/Qwiic plugs on both ends, STEMMA QT/Qwiic plug on one end and pins or sockets on the other, etc.) I stocked up on the double-ended so I could test out more than one at a time. I also purchased a few of the pin and socket varieties – to simplify the soldering when I made a patch cord to connect to my PLCs.

You may also solder on pins or wires – essential if you’re going the SPI (Serial Peripheral Interface) route.

LPS25 with STEMMA QT/Qwiic Connectors and Patch Panel Plugs

Adafruit Libraries and Test Software on Arduino-based PLCs

Testing these on the Arduino-based PLCs is relatively painless. Assuming you have your PLC up and running, simply click on the Tools | Manage Libraries… option from the drop-down menu, and wait. To be fair, I’m running on a Raspberry Pi 4, but once you have all the libraries needed for the sensors loaded, it seems to get bogged down. Once all the installed libraries have been scanned, you can search for your new sensor, and install the Adafruit library. For example, if you search for “LPS25”, you should find a half-dozen or so options from Adafruit, Pololu, SparkFun, etc. Select the Adafruit option (the install button should appear in the lower right corner when you hover on the Adafruit option; you may be given an option to select a particular version. The same task that took 10 minutes on the RPi4 took 10 seconds on a Dell i7.

Patch Panel with Two Sensors and a Variety of PLCs and a Power Supply

Connect the Sensors and Load the Test Software

Next, connect the sensor to your PLC. Red goes to 5V or 3V, black goes to GND, yellow goes to SCL, and green goes to SDA. Click on File | Examples | Adafruit LPS2X | adafruit_lps25_test to open the basic example sketch. Load the sketch and open the Serial Monitor (at 115200 baud). I ran my test in sunny Arizona, with my window open, and a balmy 88°F (31°C). The local barometric pressure is reported 29.8 in Hg (1010 hPa). The LPS25 reports the temperature is -10°C (-25°F) and 972 hPa (28.7 in Hg). Now, in the big picture, the temperature is off by 12% (~304 Kelvin) and pressure is off by 4% – not too encouraging.

So, I hooked up a BME280 sensor, loaded the test software, set the Serial Monitor to 9600 baud, and was pleasantly surprised. The temperature reads 30°C, pressure 965 hPa, and humidity 24% (reported locally as 20%). Just to be sure, I checked out the pressure with another pressure-only sensor, the BMP280 cousin of the BME280. It turns out that the I2C address of the BMP280 is the same as the BME280, so only one can be in the series at a time. Not surprisingly, the pressure, temperature, and approximate altitude (reported locally as 370 m, is 389 m) are similar to the BME280. As a final check, I connected an LPS35HW; likewise, it seems to share the same I2C address with the LPS25, but the temperature and pressure reported are consistent with the BME280 and BMP280: 34°C and 969 hPa.

LPS35HW Sensor Test Code and Serial Monitor Updates Temperature and Pressure Every Second

Each I2C sensor (client) has an address, and each of the Adafruit sensors has a fixed address. As I discovered above, this may mean you can’t connect two clients to the same server (PLC), even if they’re different sensors. Both the LPS25 and the LPS35HW address is 0x5D, but both (or just one) can be changed to 0x5C with a jumper from SDO to GND.

Don’t forget to use the resources available at the Adafruit site – they have lots of information available for every sensor. For the LPS25 sensor, the Adafruit pdf is available here. Every sensor has one like this. Be sure to support Adafruit – they put a lot of effort into developing this material.

Last updated: 2021 May 21