How to do it...

  1. Create a script called log_adc.py:
#!/usr/bin/python3 #log_adc.c import time import datetime import data_adc as dataDevice DEBUG=True FILE=True VAL0=0;VAL1=1;VAL2=2;VAL3=3 #Set data order FORMATHEADER = "t%st%st%st%st%s" FORMATBODY = "%dt%st%ft%ft%ft%f" if(FILE):f = open("data.log",'w') def timestamp(): ts = time.time() return datetime.datetime.fromtimestamp(ts).strftime( '%Y-%m-%d %H:%M:%S') def main(): counter=0 myData = dataDevice.device() myDataNames = myData.getName() header = (FORMATHEADER%("Time", myDataNames[VAL0],myDataNames[VAL1], myDataNames[VAL2],myDataNames[VAL3])) if(DEBUG):print (header) if(FILE):f.write(header+"n") while(1): data = myData.getNew() counter+=1 body = (FORMATBODY%(counter,timestamp(), data[0],data[1],data[2],data[3])) ...

Get Raspberry Pi 3 Cookbook for Python Programmers - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.