Skip to content

Commit c5b0ff9

Browse files
committed
RP Pico examples tested
1 parent fc726e8 commit c5b0ff9

12 files changed

Lines changed: 947 additions & 10 deletions

File tree

examples/03-i2c-sensor/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import sys
2525

2626
# Create I2C peripheral at frequency of 100 kHz
27-
i2c = I2C(0, scl=Pin(22), sda=Pin(21), freq=100_000)
27+
i2c = I2C(0, sda=Pin(21), scl=Pin(22), freq=100_000)
2828

2929
# Scan for peripherals, returning a list of 7-bit addresses
3030
# between 0x08 and 0x77 inclusive

examples/81-techday-iot/02-temperature-display.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from sh1106 import SH1106_I2C
2525

2626
# Init DHT12 sensor
27-
i2c = I2C(0, scl=Pin(22), sda=Pin(21), freq=100_000)
27+
i2c = I2C(0, sda=Pin(4), scl=Pin(5), freq=100_000)
2828
sensor = DHT12(i2c) # 1st variant
2929
# sensor = BME280(i2c) # 2nd variant
3030

examples/81-techday-iot/02-temperature-simple.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@
2222
from dht12 import DHT12
2323
from bme280 import BME280
2424

25-
# Init DHT12 sensor
26-
i2c = I2C(0, scl=Pin(22), sda=Pin(21), freq=100_000)
27-
# sensor = DHT12(i2c) # 1st variant
28-
sensor = BME280(i2c) # 2nd variant
25+
# Init sensor
26+
i2c = I2C(0, sda=Pin(4), scl=Pin(5), freq=100_000)
27+
sensor = DHT12(i2c) # 1st variant
28+
# sensor = BME280(i2c) # 2nd variant
2929

3030
print()
3131
print("Press `Ctrl+C` to stop")
3232
print()
3333

3434
try:
3535
while True:
36-
# temp, humid = sensor.read_values() # 1st variant
37-
temp, humid, P, A = sensor.read_values() # 2nd variant
36+
temp, humid = sensor.read_values() # 1st variant
37+
# temp, humid, P, A = sensor.read_values() # 2nd variant
3838
print(f"T={temp:.1f}°C, H={humid:.1f}%")
39-
print(P, A)
39+
# print(P, A)
4040

4141
sleep(10)
4242

examples/92-pico_w/02-i2c_scan.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from machine import I2C, Pin
1717

1818
# On Raspberry Pi Pico, I2C using pins GP21 & GP20 (default I2C0 pins)
19-
i2c = I2C(0, scl=Pin(21), sda=Pin(20), freq=100_000)
19+
i2c = I2C(0, scl=Pin(5), sda=Pin(4), freq=100_000)
2020

2121
print("Scanning I2C... ", end="")
2222
addrs = i2c.scan()
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
"""
2+
I2C OLED display SH1106 + DHT12 sensor
3+
4+
MicroPython script for reading data from DHT12 I2C sensor
5+
and displaying on an OLED with the SH1106 controller. The
6+
script requires SH1106 and DHT12 modules, stored in ESP32 device.
7+
8+
Authors:
9+
- Robert Hammelrath, https://github.com/robert-hh/SH1106
10+
- Martin Fitzpatrick, https://blog.martinfitzpatrick.com/oled-displays-i2c-micropython/
11+
- Tomas Fryza
12+
13+
Creation date: 2023-10-27
14+
Last modified: 2026-09-01
15+
"""
16+
17+
# MicroPython builtin modules
18+
from machine import I2C, Pin, I2C
19+
from time import sleep
20+
21+
# External modules
22+
from dht12 import DHT12
23+
from bme280 import BME280
24+
from sh1106 import SH1106_I2C
25+
26+
# Init DHT12 sensor
27+
i2c = I2C(0, sda=Pin(4), scl=Pin(5), freq=100_000)
28+
sensor = DHT12(i2c) # 1st variant
29+
# sensor = BME280(i2c) # 2nd variant
30+
31+
# Init OLED display
32+
display = SH1106_I2C(i2c)
33+
display.text("Temp. [C]:", 0, 40)
34+
display.text("Humid.[%]:", 0, 52)
35+
36+
led = Pin(2, Pin.OUT)
37+
38+
print("Read temperature and humidity every 10 secs.")
39+
print()
40+
print("Press `Ctrl+C` to stop")
41+
print()
42+
43+
try:
44+
while True:
45+
led.on()
46+
temp, humid = sensor.read_values() # 1st variant
47+
# temp, humid, P, A = sensor.read_values() # 2nd variant
48+
print(f"T={temp:.1f}°C, H={humid:.1f}%")
49+
50+
display.fill_rect(85, 38, 120, 50, 0)
51+
display.text(f"{temp:.1f}", 85, 40)
52+
display.text(f"{humid:.1f}", 85, 52)
53+
display.show()
54+
led.off()
55+
56+
sleep(10)
57+
58+
except KeyboardInterrupt:
59+
print()
60+
print("Program stopped. Exiting...")
61+
62+
# Optional cleanup code
63+
display.poweroff()
64+
led.off()
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""
2+
I2C DHT12 sensor
3+
4+
MicroPython script for reading data from DHT12 I2C sensor
5+
and printing to shell. The script requires DHT12 module, stored
6+
in ESP32 device.
7+
8+
Authors:
9+
- Robert Hammelrath, https://github.com/robert-hh/SH1106
10+
- Martin Fitzpatrick, https://blog.martinfitzpatrick.com/oled-displays-i2c-micropython/
11+
- Tomas Fryza
12+
13+
Creation date: 2023-10-27
14+
Last modified: 2026-09-01
15+
"""
16+
17+
# MicroPython builtin modules
18+
from machine import Pin, I2C
19+
from time import sleep
20+
21+
# External module(s)
22+
from dht12 import DHT12
23+
from bme280 import BME280
24+
25+
# Init sensor
26+
i2c = I2C(0, sda=Pin(4), scl=Pin(5), freq=100_000)
27+
sensor = DHT12(i2c) # 1st variant
28+
# sensor = BME280(i2c) # 2nd variant
29+
30+
print()
31+
print("Press `Ctrl+C` to stop")
32+
print()
33+
34+
try:
35+
while True:
36+
temp, humid = sensor.read_values() # 1st variant
37+
# temp, humid, P, A = sensor.read_values() # 2nd variant
38+
print(f"T={temp:.1f}°C, H={humid:.1f}%")
39+
# print(P, A)
40+
41+
sleep(10)
42+
43+
except KeyboardInterrupt:
44+
print()
45+
print("Program stopped. Exiting...")

0 commit comments

Comments
 (0)