![]() ![]() ![]() All you would need to add, aside from closing the port when you're done ), is import time and then use: import serial, timeser = serial.Serial('/dev/ttyACM0', 9600)while 1:serialline = ser.readlineprint(serialline) # If using Python 2.x use: print serialline# Do some other work on the datatime.sleep(300) # sleep 5 minutes# Loop restarts once the sleep is finishedser.close # Only executes once the loop exitsI don't know if pySerial is buffered (data sent while sleeping is stored or simply dropped), but I usually prefer to use a generator, if you don't explicitly need to wait. ![]() After that period of time, the port closes and the received data will be analysed.After a pause of several minutes, the port will reopen and the RPi will read data from it again.This continues in a loop.Any help is much appreciated. I would like to read from the USB serial port from time to time in a loop.I can open the port and read data with:import serialser = serial.Serial('/dev/ttyACM0', 9600)while 1:ser.readlineAn Arduino Uno is connected to the USB port of the RPi.The Arduino acts as a sensor and it will constantly produce readings.I need some help in adding timing features to the above code.I want to open the port and read from it for a certain period of time.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
June 2023
Categories |