Cart 0

CheeseBoard: Adding I2C Sensors

Posted by Matthew Little on

The next step for my environment monitor is to add some I2C sensors.

Temperature and Humidity

There are loads of I2C sensors available. The first one I'm looking at is the "Grove - Temperature&Humidity Sensor (High-Accuracy &Mini) v1.0" from Seeed Studio. This has a TH02 sensor for temperature and humidity readings.

I added the TH02 library to Arduino IDE via the library manager (search for TH02 and use the library from Seeed Studio).

When I connected up to the I2C bus then I got errors on my OLED screen - there is some confusion between the TH02 and the OLED commands. The issue here is that the hardware I2C on the ESP8266 is wired to:

  • GPIO 5 (D1): SCL
  • GPIO 4 (D2): SDA

The CheeseBoard has the OLED wired to SDA =  D5 and SCLK = D4. The u8g2 library connects to the OLED with the I2C pins I have specified.

I then note in the u8g2 FAQ:

Q: Why does my xxx_SW_I2C() device not work with my other I2C devices?

A: SW_I2C emulates I2C with digitalWrite(), which will have a conflict with otherI2C devices at the same pins. There are two options: (A) use xxx_HW_I2C() or (B) use different pins with xxx_SW_I2C()

As I already have my I2C as a software (SW) I2C on those pins, maybe I should try using the hardware (HW) I2C of D1 and D2? This is also my software serial, so that could mess things up as well! and yes - it didn't work....

After a bit of messing about I added the I2C SDA and SCK to the same pins as the Encoder A and B pins. So I have it wired with SDA on D7 and SCK on D6. Lets see if that works.... it did! Whoop!

You need to create another instance of Wire.begin(SW_SDA,SW_SCK) where SW_SDA is the software SDA and SW_SCK is the software SCK for the additional I2C bus.

This worked pretty well and will only give errors if the encoder is twisted at exactly the same time as the sensor is being read. This might happen, but is OK for now. (This will probably come back to bite me!).

Pressure and Altitude

I had a BMP180 sensor (breakout board from an unknown source!). This is an I2C barometric pressure/temperature/altitude sensor made by Bosch. This sensor is available as a breakout board from Sparkfun and Adafruit and other suppliers.

So I thought I'd hook that up as well! Starting to get the hang of adding sensors to my environment monitor unit now...

 As usual, someone had already made an Arduino library for the BMP180 sensor. I searched for BMP180 and installed the main library, then included it within my project. It works perfectly on the same I2C bus as the TH02 sensor.

So now I've got a PM2.5 and PM10 dust sensor, temperature (x2), humidity, barometric pressure all being monitored and uploaded to my Adafruit IO.

If you want to see the data feed of whats going on in my workshop then the public feed is here:

Share this post

← Older Post Newer Post →