Hi I am not new at this but do have problems interfacing sensors on displays. I’m trying the Piicodev family as a learning tool…I’ve looked at the examples but am having trouble how to interface the PiicoDev SSD1306 with other sensors in the PiicoDev family starting with BME 280.
Is your desired outcome to show temperature/humidity/pressure on the SSD1306 screen?
If that is the outcome, I would make sure I have used a cable to plug the SSD1306 and the BME280 piicodev boards to the pico piicodev carrier board.
Then I would look at the example for the BME280 and see it I can successfully read the temp/pressure/humudity and display that to the serial output.
Then I would load the example for the SSD1306 and make sure it displays something.
Then I would start with the SSD1306 example code and add the BME280 code to that file to store the BME280 data in a variable and then have the SSD1306 code take that variable and display it.
from PiicoDev_BME280 import PiicoDev_BME280 from PiicoDev_SSD1306 import create_PiicoDev_SSD1306 from PiicoDev_Unified import sleep_ms atmo = PiicoDev_BME280() oled = create_PiicoDev_SSD1306() oled.text('hello', 10,10) oled.show() sleep_ms(500) while True: try: oled.fill(0) tempC, presPa, humRH = atmo.values() # read all data from the sensor pres_hPa = presPa / 100 # convert air pressure Pascals -> hPa (or mbar, if you prefer) print(str(tempC)+" °C " + str(pres_hPa)+" hPa " + str(humRH)+" %RH") tempC = str(round(tempC,1)) pres_hPa = str(round(pres_hPa,2)) humRH = str(round(humRH)) oled.text('Weather Data', 1,0) oled.text(tempC + ' degC', 10,25) oled.text(pres_hPa + ' hPa', 10,35) oled.text(humRH + ' % humidity', 10,45) oled.show() except Exception as e: print(e) sleep_ms(1000)
Thanks Michael for the code. It works great and has helped me to modify the Air Quality sensor (ENS160) to be read on the OLED as well and given me confidence to have a look at other displays and sensors.