#import time import os import time from time import sleep from datetime import datetime # Import SPI library (for hardware SPI) and RAS library. import Adafruit_GPIO.SPI as SPI import RAS_ADS7952 # Hardware SPI configuration: SPI_PORT = 0 SPI_DEVICE = 0 mcp = RAS_ADS7952.ADS7952(spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE)) # Create a save file when software is initiated and stored in home/pi directory: file = open("/home/pi/RAS_data_log.csv", "a") i=0 if os.stat("/home/pi/RAS_data_log.csv").st_size == 0: file.write("Date and Time,Sensor1,Sensor2,Sensor3,Sensor4,Sensor5,Sensor6,Sensor7,Sensor8,Sensor9,Sensor10,Sensor11,Sensor12\n") print('Reading ADS7952 values, press Ctrl-C to quit...') # Print nice channel column headers. print('| Date and Time | {0:>4} | {1:>4} | {2:>4} | {3:>4} | {4:>4} | {5:>4} | {6:>4} | {7:>4} | {8:>4} | {9:>4} | {10:>4} | {11:>4} |'.format(*range(12))) print('-' * 57) # Main program loop. while True: # Read all the ADC channel values in a list. values = [0]*12 for i in range(12): # The read_adc function will get the value of the specified channel (0-11). values[i] = mcp.read_adc(i) now = datetime.now() # Print the ADC values. print('| {0:>4} | {1:>4} | {2:>4} | {3:>4} | {4:>4} | {5:>4} | {6:>4} | {7:>4} | {8:>4} | {9:>4} | {10:>4} | {11:>4} |'.format(*values)) file.write(str(now)+","+str(values)+"\n") file.flush() # Sample time in seconds... time.sleep(0.005)