0
votes

Currently, I'm hooking up sensors to an Arduino Mega and printing the readings through serial to a Beaglebone Black. I need the data to have timestamps in such a manner as seen in the Arduino's serial monitor. For instance: arduino serial monitor.

For testing purposes, I'm simply telling the Arduino to continue printing the right column to the tx pin (but not the timestamp.) The beaglebone then receives that data through it's UART1 pins. What I've told the beaglebone to do is print a timestamp in milliseconds and then what it receives from the Arduino. What I get is this: Beaglebone's output file.

Obviously, something is very wrong here. I'm getting values that should definitely not be anything other than 1, and the timestamps are not okay.

The relevant parts of the code I wrote:

    z = 0
    millis = lambda: int(float(time.time()))
    sensorValue = 0
    header = 'Sensor 1 output'
    data.write(str(header))
    data.write(str('\n'))

while z==0:
    sensorValue = ser.read() #add more for more pins
    data.write(str(float(time.clock()*1000)))
    data.write('\t')
    data.write(sensorValue) # tosses what's coming in at pin to our file
    data.write('\n')

I'm pretty sure the time.time() function isn't right to use. What I'm looking for is something that starts a timer of sorts and outputs the milliseconds that have elapsed since the start of the program and the receipt of data from the RX pin.

My question is does that even exist in Python? All I've been able to find is time.time() or time.clock() but those don't seem to work. The Arduino-IDE has a function called millis() that does exactly that, but it doesn't seem Python has an equivalent in terms of functionality.

1

1 Answers

0
votes

What I'm looking for is something that starts a timer of sorts and outputs the milliseconds that have elapsed since the start of the program

#!/usr/bin/env python
from time import time as timer

start = timer() 
...
elapsed_seconds = timer() - start
elapsed_milliseconds = elapsed_seconds * 1000

If you have access to Python 3 then use:

from time import monotonic as timer

time.monotonic() is not affected by system clock updates.