Code: Select all
from machine import Pin, Timer
import machine
led1 = Pin(15, Pin.OUT)
led2 = Pin(13, Pin.OUT)
led3 = Pin(25, Pin.OUT)
tim = Timer()
sensor_temp = machine.ADC(4)
conversion_factor = 3.3 / (65535)
def tick(timer):
global led1
global led2
global led3
global uart
led3.toggle()
reading = sensor_temp.read_u16() * conversion_factor
temperature = 27 - (reading - 0.706)/0.001721
print("{}".format(temperature))
if temperature > 15:
led1.value(1)
led2.value(0)
elif temperature < 15:
led1.value(0)
led2.value(1)
tim.init(freq=1, mode=Timer.PERIODIC, callback=tick)
However on reading /dev/ttyACM0 I just get a few temperature sensor readings and then a bunch of exceptions (the LEDS keep on blinking so the program is running!)
Code: Select all
~|▶ cat /dev/ttyACM0
17.68152
17.68152
17.68152
>>>
>>> 17.68152
17.68152
>>>
>>> 17.68152
17.68152
>>>
>>> >>>
Traceback (most recent call last):
File "<stdin>", line 1
SyntaxError: invalid syntax
>>>
>>> >7.2
Traceback (most recent call last):
File "<stdin>", line 1
SyntaxError: invalid syntax
>>> 17.685
17.685
>>>
>>> >