Skip to content

Instantly share code, notes, and snippets.

@benalb
Created February 14, 2021 17:54
Show Gist options
  • Save benalb/0ef9ca3cb15fbb6b960f6e2358f496b7 to your computer and use it in GitHub Desktop.
Save benalb/0ef9ca3cb15fbb6b960f6e2358f496b7 to your computer and use it in GitHub Desktop.
poor man's weather station with rpi pico.
from machine import Pin, SPI, ADC
import ssd1306
import utime
spi = SPI(0,100_000,polarity=1,phase=1)
dc = Pin(4, Pin.OUT)
res = Pin(3, Pin.OUT)
cs = Pin(5, Pin.OUT)
oled = ssd1306.SSD1306_SPI(128,64,spi,dc,res,cs,False)
sensor_temp = ADC(4)
conversion_factor = 3.3/(65535)
while True:
reading = sensor_temp.read_u16()*conversion_factor
temperature = 27-(reading-0.706)/0.001721
oled.fill(0)
oled.show()
utime.sleep(0.5)
oled.text(str(int(temperature))+" C", 0, 0)
oled.show()
utime.sleep(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment