Closed unique1o1 closed 6 years ago
I have the same issue. The type comes up as <type 'NoneType'> and I struggle to cast it to anything.
@unique1o1 I suspect the error is thrown on the if x>20:
line?
Use if x and x > 20:
instead. read()
can return None
in the beginning when there aren't any reads yet.
Try print(x) after x=board.analog[0].read()
I had the same problem and that is how a solved it.
from pyfirmata import ArduinoMega, util, pyfirmata import time
LED = 3 arduino = ArduinoMega("COM3")
it = util.Iterator(arduino) it.start() time.sleep(0.05) arduino.analog[7].enable_reporting() i=0 while(True): sensor=arduino.analog[7].read() print(sensor) if i>100 and sensor > 0.500: arduino.digital[LED].write(1) else: arduino.digital[LED].write(0) i=i+1
i'm trying to turn OFF and ON an LED according to the data from a LDR using this code:
and it gives me this error
TypeError: unorderable types: NoneType() > int()
whereas using the
board.analog[0].read()
in a python shell give a float. What am i doing wrong here?