Hi , i need some help in python script :
Im receiveing data from USB0 of my Raspberry Pi and for now , with my python script i can print all data . What i need now is only when i receive numerics values of light greater than 50 print "Atencion!!!" and smaller than 50 print "LOW"
if (whatireceive) > 50 print (ATENCION!!!) else print (LOW!!!)
#####################################################
PI incoming from USB0: I already receive this in my USB0 port
pi@lima-raspberrypi:~ $ python receive_seria_data_from_usb0.py
12 lx, level: 1 , quality: toolow
Light: 12 lx
12 lx, level: 1 , quality: toolow
Light: 15 lx
15 lx, level: 1 , quality: toolow
Light: 34 lx
34 lx, level: 2 , quality: low
Light: 28 lx
28 lx, level: 2 , quality: low
Light: 67 lx
67 lx, level: 3 , quality: ideal
Light: 88 lx
88 lx, level: 3 , quality: ideal
Light: 582 lx
582 lx, level: 5 , quality: toohigh
Light: 664 lx
664 lx, level: 5 , quality: toohigh
Light: 28 lx
28 lx, level: 2 , quality: low
Light: 12 lx
12 lx, level: 1 , quality: toolow
^
pi@lima-raspberrypi:~ $
###########################################################
Python Script:
#!/usr/bin/env python3
import serial
if __name__ == '__main__':
ser = serial.Serial('/dev/ttyUSB0', 115200, timeout=1)
ser.flush()
while True:
if ser.in_waiting > 0:
line = ser.readline().decode('utf-8').rstrip()
print(line)
############################################################
Someone can help?
Im receiveing data from USB0 of my Raspberry Pi and for now , with my python script i can print all data . What i need now is only when i receive numerics values of light greater than 50 print "Atencion!!!" and smaller than 50 print "LOW"
if (whatireceive) > 50 print (ATENCION!!!) else print (LOW!!!)
#####################################################
PI incoming from USB0: I already receive this in my USB0 port
pi@lima-raspberrypi:~ $ python receive_seria_data_from_usb0.py
12 lx, level: 1 , quality: toolow
Light: 12 lx
12 lx, level: 1 , quality: toolow
Light: 15 lx
15 lx, level: 1 , quality: toolow
Light: 34 lx
34 lx, level: 2 , quality: low
Light: 28 lx
28 lx, level: 2 , quality: low
Light: 67 lx
67 lx, level: 3 , quality: ideal
Light: 88 lx
88 lx, level: 3 , quality: ideal
Light: 582 lx
582 lx, level: 5 , quality: toohigh
Light: 664 lx
664 lx, level: 5 , quality: toohigh
Light: 28 lx
28 lx, level: 2 , quality: low
Light: 12 lx
12 lx, level: 1 , quality: toolow
^
pi@lima-raspberrypi:~ $
###########################################################
Python Script:
#!/usr/bin/env python3
import serial
if __name__ == '__main__':
ser = serial.Serial('/dev/ttyUSB0', 115200, timeout=1)
ser.flush()
while True:
if ser.in_waiting > 0:
line = ser.readline().decode('utf-8').rstrip()
print(line)
############################################################
Someone can help?
buran write Jan-22-2021, 05:55 PM:
Please, use proper tags when post code, traceback, output, etc.
See BBcode help for more info.
Please, use proper tags when post code, traceback, output, etc.
See BBcode help for more info.