from machine import Pin, ADC
from utime import sleep
import onewire
import ds18x20
import network
import urequests
import ujson
from math import log
redLed = Pin(15, Pin.OUT)
greenLed = Pin(18, Pin.OUT)
def adc_to_cel(x):
BETA = 3950
KELVIN = 273.15
print(x / 4095 * 3.3)
return (1/ (log(1/(4095/x - 1)) / BETA + 1/298.15) - KELVIN)
def send_temperature():
ds_pin = ADC(Pin(35, Pin.IN))
ds_pin.atten(ADC.ATTN_11DB)
while True:
print(adc_to_cel(ds_pin.read()))
sleep(0.1)
def do_connect():
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
redLed.off()
greenLed.off()
if not wlan.isconnected():
print('connecting to network...')
wlan.connect('Wokwi-GUEST', '')
while not wlan.isconnected():
redLed.on()
sleep(0.5)
redLed.off()
sleep(0.5)
pass
redLed.off()
greenLed.on()
print('network config:', wlan.ifconfig())
send_temperature()
do_connect()