Friday, February 3, 2023

Raspberry Pico and I2C Communication Oled Display SSD1306 and sensor BME280

Raspberry Pi Pico project demo I2C serial communication.

Oled display SSD1306 128x64 and sensor BME280 in same bus.
Thonny micropython code and bus scan address command on the shell.

SCL (Serial Clock Line) and SDA (Serial Data Line) are two of the most important signals used in the Inter-Integrated Circuit (I2C) communication protocol.
I2C is a popular communication protocol used for short-distance communication between microcontrollers, sensors, and other peripherals in embedded systems.

Thonny sample code: from machine import Pin, I2C from time import sleep from ssd1306 import SSD1306_I2C import BME280 i2c = I2C(0,sda=Pin(0), scl=Pin(1), freq=400000) oled = SSD1306_I2C(128,64,i2c) ## Oled Display pixel size 128x64 oled.fill(0) while True: bme = BME280.BME280(i2c=i2c) temp = bme.temperature ## hum = bme.humidity No humidity in BMP280 pres = bme.pressure ## tempf temperature in Fahrenheit tempf = (bme.read_temperature()/100) * (9/5) + 32 tempf = str(round(tempf, 2)) + 'F' ##print('Temperature:', temp ,tempf, ' Pressure: ',pres) ##print('Humidity: ', hum) oled.fill(0) oled.text("TEMPERATURE",20,0) oled.text(temp, 20,15) ### tempf Farenheit oled.text("PRESSURE",20,35) oled.text(pres, 20,50) oled.show() sleep(0.3)

No comments:

Post a Comment