I wrote a system to exchange crc-checked struct data between an arduino nano and my python script. This is working pretty well but when i let the system run i get unexpected output on my python monitor (using pycharm)
print "Took ", (time.time() - timeout), " s" sometimes prints out Took 0.0 s. Usually it prints Took 0.0160000324249 s. Using win7-64bit professional.
From time doc : Return the time in seconds since the epoch as a floating point number. Note that even though the time is always returned as a floating point number, not all systems provide time with a better precision than 1 second.
I´m looking for something like millis() thats enough precision for my case
Code Python :
import serial
import time
import binascii
import struct
from ctypes import *
arduino = serial.Serial()
def receive_struct2():
start = 0x85
detected_start = False
arduino.baudrate = 57600
arduino.timeout = 0
arduino.port = 'COM8'
try:
arduino.open()
except serial.SerialException, e:
print e
while True:
if(arduino.inWaiting() >= 1 and detected_start == False):
data = ord(arduino.read())
if data == start:
print "Detected begin"
detected_start = True
else: print chr(data),
if arduino.inWaiting() >= 1 and detected_start == True:
message_length = ord(arduino.read())
#print "Got message length ", message_length
timeout = time.time()
while time.time() - timeout <= 0.3 and arduino.inWaiting() < message_length-1:pass
print "Took ", (time.time() - timeout), " s"
....