Fuel cell data logger . Unable to import and operate libraries . Beginner.
The ADC Differential Pi is an Analogue to Digital converter for the Raspberry Pi
12/06/2016
Posted by:
janoska
12/06/2016
Posted by:
andrew
02/07/2016
Posted by:
janoska
03/07/2016
Posted by:
andrew
We also have two tutorials in our knowledge base which go into more details on how to use the ADC Differential Pi. The projects they cover are different to yours but hopefully you can use those tutorials to get an idea about how to read voltages from the ADC Differential Pi.
19/07/2016
Posted by:
janoska
19/07/2016
Posted by:
andrew
I have uploaded a demo file to the python library which shows how to save the voltage readings to a text file.
demo_logvoltage.py
The demo saves each entry on a new line but it would be easy to modify it to output in CSV format by replacing the spaces and \n new line characters with commas. By default, it saves the log file into the same directory as the python script but you can change that by modifying the line f = open('adclog.txt', 'a') and adding a file path before adclog.txt.
22/08/2016
Posted by:
janoska
22/08/2016
Posted by:
andrew
24/08/2016
Posted by:
janoska
24/08/2016
Posted by:
andrew
i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()
adc1 = ADCDifferentialPi(bus, 0x68,0x69,14)
adc2 = ADCDifferentialPi(bus, 0x6A,0x6B,14)
while (True):
# clear the console
os.system('clear')
# read from ADC channels and print to screen
print ("Channel 1: %02f" % adc1.read_voltage(1))
print ("Channel 2: %02f" % adc1.read_voltage(2))
print ("Channel 3: %02f" % adc1.read_voltage(3))
print ("Channel 4: %02f" % adc1.read_voltage(4))
print ("Channel 5: %02f" % adc1.read_voltage(5))
print ("Channel 6: %02f" % adc1.read_voltage(6))
print ("Channel 7: %02f" % adc1.read_voltage(7))
print ("Channel 8: %02f" % adc1.read_voltage(8))
print ("Channel 9: %02f" % adc2.read_voltage(1))
print ("Channel 10: %02f" % adc2.read_voltage(2))
print ("Channel 11: %02f" % adc2.read_voltage(3))
print ("Channel 12: %02f" % adc2.read_voltage(4))
print ("Channel 13: %02f" % adc2.read_voltage(5))
print ("Channel 14: %02f" % adc2.read_voltage(6))
print ("Channel 15: %02f" % adc2.read_voltage(7))
print ("Channel 16: %02f" % adc2.read_voltage(8))
27/08/2016
Posted by:
janoska
19/09/2016
Posted by:
janoska
20/09/2016
Posted by:
andrew
If you are writing to a CSV file then the best way to format the date would be to create a separate DateTime object and then format it in ISO date format which removes any spaces and adds a T between the date and time. Below is an updated version of your writetofile function which outputs the data in with commas separating the date and other values. I also added a new line character to the end so the text file will be easier to read.
def writetofile(texttowrtite):
current_time = datetime.datetime.now()
f = open('/media/pi/25DD-E8DF1/adclog.txt', 'a')
f.write(texttowrtite + "," + current_time.isoformat() + "\n")
f.closed
29/09/2016
Posted by:
janoska
30/09/2016
Posted by:
andrew
You can update your writetofile function to print to the screen as well as write to a file. You just need to add a print() command with the same content as the f.write command as shown below.
def writetofile(texttowrtite):
current_time = datetime.datetime.now()
f = open('adclog.txt', 'a')
f.write(texttowrtite + "," + current_time.isoformat() + "\n")
print(texttowrtite + "," + current_time.isoformat() + "\n")
f.closed
30/09/2016
Posted by:
janoska
01/10/2016
Posted by:
andrew
The two config variables in the ABE_ADCDifferentialPi library control the two chips on each board with Config1 controlling the first four channels and Config2 controlling channels 5 to 8. Both of the variables are local to the library itself so they shouldn't have any effect on reading from more than one ADC board.
I noticed that there is a spelling mistake in the code you posted, the third instance of ADCDifferentialPi has an uppercase I instead of a lowercase one. That may be causing the problem as it would fail when it tries to initialise adc3.
Note: documents in Portable Document Format (PDF) require Adobe Acrobat Reader 5.0 or higher to view.
Download Adobe Acrobat Reader or other PDF reading software for your computer or mobile device.