Skip to content

Instantly share code, notes, and snippets.

@sisomm
Created February 23, 2014 09:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sisomm/9168986 to your computer and use it in GitHub Desktop.
Save sisomm/9168986 to your computer and use it in GitHub Desktop.
The python/raspi side in arduino communication
## How it was with Serial
if(not commands.empty()):
command=commands.get()
if(args.verbosity>0):
print("DISPATCHER: sending to Arduino: "+command)
start=time.time()
arduino.write(command)
# wait until we get OK back
response=''
ack=False
while not ack:
response=arduino.readline()
if (len(response)>0):
ack=True
end=time.time()
print('Response to {} took {:G} millis'.format(response.strip(),(end-start)*1000))
## How it is with SoftSerial
while True:
if(not commands.empty()):
command=commands.get()
if(args.verbosity>0):
print("DISPATCHER: sending to Arduino: "+command)
start=time.time()
arduino.write(command+'|')
# wait until we get OK back
response=''
ack=False
while not ack:
response=arduino.readline()
if (len(response)>0):
ack=True
end=time.time()
print('Response {} to {} took {:G} millis'.format(response,command,(end-start)*1000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment