Ceci est une ancienne révision du document !
It’s hard to believe that it’s been a year since I started this series of articles. It only seems right to go back to the beginning with the Raspberry Pi Pico and do something new with it, since we’ve spent so many months on the ESP series microcontrollers. This time, we will work with the RPi Pico and use a si7021 Temperature and Humidity sensor along with a ssd1306 OLED display. The wiring is basically the same as any RPi Pico with the ssd1306, but we’ll extend I2C to work with the si7021. I got my si7021 from Adafruit for less than $10 USD. https://www.adafruit.com/product/3251 You can find a driver for the si7021 that I modified to work successfully on the RPi Pico at https://github.com/gregwa1953/SI7021-MicroPython-RPi-Pico. You’ll need to copy this driver to the RPi Pico. You’ll also need to have the ssd1306 driver that we have used multiple times on the Pico as well.
Here is the wiring diagram: I always run the i2cscan.py utility to verify my wiring and that all my I2C devices are working properly. When you run it, you should see a response of: 0x3c 0x40 Of course, the 0x3c is the display and the 0x40 is the Temp/Humidity sensor. Now, on to the code. I took the si7021 test file that I created for the driver and modified it to support the addition of the OLED display. Here (top right) is the import section. Once we have all the hardware stuff set up, we can do a small test to verify the OLED is working. We’ll sleep for 5 seconds to let the user see it. If you want, you can leave this block out altogether: oled.fill(0) oled.show() oled.text(“Raspberry Pi”,5,5) oled.text(“Pico”,5,15) # Finally update the oled display so the text is displayed oled.show() time.sleep(5)
Now we need to start querying the si7021. The si7021 seems to be a bit odd: to get the proper temperature readings, you have to query the humidity first. It’s part of the chip firmware. We also use this time to get the dew point (not really needed, but why not?), the serial number, and revision. I’ve never gotten the revision to show correctly, but that’s ok, because the chip runs just fine. humidity = si7021.humidity() temperature = si7021.temperature() print('Temperature: {0}C'.format(temperature)) print('Temperature: {0}F'.format(temperature*9/5+32)) humidity = si7021.humidity() print('Humidity: {0}'.format(humidity)) dew_point = si7021.dew_point() print('Dew Point: {0}'.format(dew_point)) serial = si7021.serialnumber print(serial) revision = si7021.revision print(revision)
This is what should be displayed in the IDE REPL: Temperature: 25.17976C Temperature: 77.32357F Humidity: 41.80579 Dew Point: 11.29874 bytearray(b'\x0c\xfe\x854\x15\xff\xff\xff') b' ' Now we can finally get down to the business of reading and displaying the Temp/Humidity on the display (top right). As you can see, we go into a “forever loop” and clear the display (oled.fill(0), oled.show()). Then we pull the temperature, humidity and dew point. As I’ve stated many times, I can’t think in metric anything, so I convert the temperature to Fahrenheit so I can understand it.
I print to the REPL, then create two strings to send to the OLED, one for temperature that starts a column 5, row 5, and one for the humidity that shows at column 5, row 15. Again, we call the oled.show() method to push the data to the display, and sleep for 5 seconds. Feel free to change the sleep time up or down. That’s it. An easy project for a good and solid Temp/Humidity sensor. My si7021 from Adafruit is the one that comes with the STEMMA/QT female connectors on each end. I got a 150mm STEMMA/QT to Male Pin cable for less than $1.00 which allows me to quickly plug into the breadboard. I’ve put the code, drivers and the wiring diagram on my repository at https://github.com/gregwa1953/FCM-178_MicroThisMicroThat.
Until next time, as always; stay safe, healthy, positive and creative!