pythonbeagleboneblackadafruit

How to print out time for every output data


I am trying to retrive my data from a sensor through BeagleBone Black. I got reading and volts, but since I allready use time for time.sleep(). time.sleep() gets syntax error when I try to incorporate start_time.

start_time = time.time()
seconds = (time.time() -start_time)
print('%f\t%f\%s' % (reading, volts, seconds)

This is the code block I try to write.

import Adafruit_BBIO.ADC as ADC
import time

sensor_pin = 'P9_40'

    ADC.setup()
    
    print('Reading\t\tVolts')
    
    while True:
        reading = ADC.read(sensor_pin)
        volts = reading * 1.800
        print('%f\t%f' % (reading, volts)
        time.sleep(0.5)

Why do I get syntax error and is there a better way to add time in seconds? Syntax Error:

File "pulse.py", line 15
    time.sleep(0.5)
       ^
SyntaxError: invalid syntax

Solution

  • Your issue here is that you haven't closed the parentheses () on the line above the time.sleep.

    It should read as below

    print('%f\t%f' % (reading, volts))

    You have the same issue in the print statement you used when calculating the time difference