About Us Knowledge Base Community Forum Electronics Toolbox FAQ Shipping & Delivery

Community Forum

Share your projects and post your questions

Search
Register or Sign In
Forum

Fuel cell data logger . Unable to import and operate libraries . Beginner.

1557 Views - Created 12/06/2016

12/06/2016

Posted by:
janoska

Users Avatar

Location:
Hungary

 HI folks i have taken the plunge. I am attempting to make a data logger for a fuel cell upto 100 channels. Off the shelf items are stupid expensive.  I am a beginner. House electrician.

I have rigged up the ADC differential pi with a Raspberry pi 3 . The ADC is connected to 1.5 volt on channel 1 . Activated I2c,SPI, python symbus. Downloaded the Abe electronic python libraries. All seen in the Terminal as present.   I followed the git hub tutorial AB Electronics UK ADC Differential Pi Python Library. Activated the python path and Attempted to import the libraries to activate the read function on the ADC connected to the PI but no joy. Unable to import the library.  Here is a posting of the terminal  . The abe libraries are installed.

pi@raspberrypi:~ $ ls
ABElectronics_Python_Libraries  Downloads     Pictures   python_games  Videos
Desktop                         Music         Public     Scratch

Here is the import...

pi@raspberrypi:~/ABElectronics_Python_Libraries $ Desktop                         Music         Public     Scratch
-bash: Desktop: command not found
pi@raspberrypi:~/ABElectronics_Python_Libraries $ from ABE_ADCDifferentialPi import ADCDifferentialPi
from: can't read /var/mail/ABE_ADCDifferentialPi
pi@raspberrypi:~/ABElectronics_Python_Libraries

Forgive my stupidity... If i get it goin i will post a morons guide for house electricians and analog dinosaurs.

An yhelp appreciated. Thanks all.

 

 

 

Analogdude struggling

12/06/2016

Posted by:
andrew

Users Avatar

Location:
United Kingdom

Users Twitter  Users Website  

Hi

The easiest way to get started with the library in python would be to copy the ABE_ADCDifferentialPi.py and ABE_helpers.py files from ABElectronics_Python_Libraries/ADCDifferentialPi into the same folder as your python project.  You can then import the library into your code by putting the following at the top of your python script.

from ABE_ADCDifferentialPi import ADCDifferentialPi
from ABE_helpers import ABEHelpers

AB Electronics UK Tech Support

02/07/2016

Posted by:
janoska

Users Avatar

Location:
Hungary

Hello again,  i have been labouring at the Rasperry pi. My operating file is Fuelcell_Datalogger.python. I have copied  both the  ABE_ADCDifferentialPi.py and ABE_helpers.py files into the data logger file and inserted the above text at the top, saved and exited.

from ABE_ADCDifferentialPi import ADCDifferentialPi
from ABE_helpers import ABEHelpers

I have returned to python and ran the import function, here is the text with no errors

>> from ABE_helpers import ABEHelpers
>>> from ABE_ADCDifferentialPi import ADCDifferentialPi
>>> from ABE_helpers import ABEHelpers
>>>


Can you inform me what is the next step or direct me to a tutorial. The hardware is connected. Sorry for being a nuisance,i spend most of my time wiring houses. Regards and thanks .

 

Analogdude struggling

03/07/2016

Posted by:
andrew

Users Avatar

Location:
United Kingdom

Users Twitter  Users Website  

We have a demonstration file called demo-readvoltage.py in the same folder as the ABE_ADCDifferentialPi.py library which shows the basics of how to set up the ADC Differential Pi and read a voltage from the channels.

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.

AB Electronics UK Tech Support

19/07/2016

Posted by:
janoska

Users Avatar

Location:
Hungary

Hi Folks thanks, for the reply. I am trying to keep things simple as possible.

I navigated down to the demo-readvoltage.py library and ran it in python. 8 channel Data logger works in real time.  Excellent. See

pi@raspberrypi:~/ABElectronics_Python_Libraries/ADCDifferentialPi $ sudo nano demo-readvoltage.py

 

I now need to log the data to a USB stick and eventually to a CSV format text file. I have searched the forums , most of them deal with web server storage, cloud etc. I want to keep it simple and robust. Any pointers on adding a text file to your demo-readvoltage.py with storage to USB stick.Many thanks for your patience. 

Analogdude struggling

19/07/2016

Posted by:
andrew

Users Avatar

Location:
United Kingdom

Users Twitter  Users Website  

Hi

I have uploaded a demo file to the python library which shows how to save the voltage readings to a text file.

https://github.com/abelectronicsuk/ABElectronics_Python_Libraries/blob/master/ADCDifferentialPi/demos/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 add a file path before adclog.txt.

AB Electronics UK Tech Support

22/08/2016

Posted by:
janoska

Users Avatar

Location:
Hungary

Hi Folks, making progress. Everything works fine channel 1 to 8.  I am unable to get the second stacked ADC board to read voltages, i.e channel 8 to 16.

I have modified the I2c jumpers to config 2 ,Analogue Channels 1-4 = I2C Address: 0x6A and Analogue Channels 5-8 = I2C Address: 0x6B.I also adjusted the read rate to midway 14.

I have also modified the script in the demo read voltage library, inserting the new I2C addresses ,0x6A and 0x6B. Run python  and the following error

Traceback (most recent call last):
  File "demo-readvoltage.py", line 25, in <module>
    adc = ADCDifferentialPi(bus, 0x68,0x69,0x6A,0x6B,14)
TypeError: __init__() takes at most 5 arguments (7 given)


Any pointers or insight. Many thanks for your patience .

Analogdude struggling

22/08/2016

Posted by:
andrew

Users Avatar

Location:
United Kingdom

Users Twitter  Users Website  

Hi

To read from two ADC boards you will need to create two instances of the ADCDifferentialPi class.  If you create two adc objects as shown in the code below then you can use adc1 to access the first board and adc2 to access the second.

adc1 = ADCDifferentialPi(bus, 0x68,0x69,14)
adc2 = ADCDifferentialPi(bus, 0x6A,0x6B,14)

AB Electronics UK Tech Support

24/08/2016

Posted by:
janoska

Users Avatar

Location:
Hungary

Hi I have modified the code in the demo-readvoltage .py library to incude ADC 1 and ADC2 classes. 16 channels. Here is the code

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(9))
    print ("Channel 10: %02f" % adc2.read_voltage(10))
    print ("Channel 11: %02f" % adc2.read_voltage(11))
    print ("Channel 12: %02f" % adc2.read_voltage(12))
    print ("Channel 13: %02f" % adc2.read_voltage(13))
    print ("Channel 14: %02f" % adc2.read_voltage(14))
    print ("Channel 15: %02f" % adc2.read_voltage(15))
    print ("Channel 16: %02f" % adc2.read_voltage(16))

    # wait 0.5 seconds before reading the pins again

I run the python demo-readvoltage.py and i get 16 channels however the ADC 2 card will not read voltages on the channel 9 to 16.  Channels 1 to 8 reads voltage fine. Its not the ADC cards or connections  because i have transposed the cards between card 1 and card 2 . I have put a 1.5 battery on channel 1 to display... here is the output

Channel 1: 1.566500
Channel 2: 0.009000
Channel 3: 0.013750
Channel 4: 0.017250
Channel 5: -0.000250
Channel 6: -0.000250
Channel 7: -0.000250
Channel 8: 0.000750
Channel 9: -0.000500
Channel 10: -0.000500
Channel 11: -0.000500
Channel 12: -0.000500
Channel 13: -0.000500
Channel 14: -0.000500
Channel 15: -0.000500
Channel 16: -0.000500

It must be the software in the imported libraries maybe? I dare not modify. Any pointers would be appreciated.Regards and thank you for your time.

Analogdude struggling

24/08/2016

Posted by:
andrew

Users Avatar

Location:
United Kingdom

Users Twitter  Users Website  

When reading from the second ADC you will need to use channels 1 to 8 like on the first one.  Try changing your code to the following.

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))

AB Electronics UK Tech Support

27/08/2016

Posted by:
janoska

Users Avatar

Location:
Hungary

Hello again, Script modified, 16 channel voltage reading  works fine now. I will eventually take it upto 32 channels. Many thanks for your patience and help.

Analogdude struggling

19/09/2016

Posted by:
janoska

Users Avatar

Location:
Hungary

Hi good evening,making progress, bit dyslexic. I am writing the 16 channel data to a USB drive which is mounted and records data. For the CSV data to be exported to a spread sheet you need commas to de lineate the information. I have inserted commas in the script. Require " channel, voltage, date time ".  The  date and time wont accept commas . Here is the basic output in the USB text file...  How do i insert commas in the date time recording?

Channel 1, 1.5477502016-09-19 20:16:20.679996

 

Here is the python script  channel  1 ...

def writetofile(texttowrtite):
    f = open('/media/pi/25DD-E8DF1/adclog.txt', 'a')
    f.write(str(datetime. datetime.now ()) + " " + texttowrtite)
    f.closed

 

while (True):

 

    # read from adc channels and save to identified usb storage with CSV format
    writetofile ("Channel 1, %02f" % adc1.read_voltage(1))

 Perhaps you can be of help. Many thanks.

Analogdude struggling

20/09/2016

Posted by:
andrew

Users Avatar

Location:
United Kingdom

Users Twitter  Users Website  

Hi

If you are writing to a csv file then the best way to format the date would be to create a seperate 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 seperating the date and other values.  I also added a new line charater 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

AB Electronics UK Tech Support

29/09/2016

Posted by:
janoska

Users Avatar

Location:
Hungary

Hello Good evening. I have connected the 32 channel ADC to a Hydrogen fuel cell, logging voltages on a USB with CSV script. Many thanks. There is no voltage logging appearing on the laptop screen.

Would it be possible to simultaneously store the CSV on  USB and PRINT to screen.

I could use the syst.stdout function but a simple print statement would be easier..

Any pointers would be appreciated...

I will post all the script when it all works, a plonkers guide!

Thanks

Analogdude struggling

30/09/2016

Posted by:
andrew

Users Avatar

Location:
United Kingdom

Users Twitter  Users Website  

Hi

You can update your writetofile function to print to the screen as well as writing 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

AB Electronics UK Tech Support

30/09/2016

Posted by:
janoska

Users Avatar

Location:
Hungary

Hello again. I have modified the script to bring it up to read 32 channels. Ran the script, it only reads 16 channels. i2c detect shows buses active, jumpers correctly installed, config 1 to config 4. .... see below

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- 68 69 6a 6b 6c 6d 6e 6f


The classes have been modified to include  AD1 to ADC 4...  see

i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()
adc1 = ADCDifferentialPi(bus, 0x68,0x69,14)
adc2 = ADCDifferentialPi(bus, 0x6A,0x6B,14)
adc3 = ADCDifferentialPI(bus, 0x6C,0x6D,14)
adc4 = ADCDifferentialPi(bus, 0X6E,0x6F,14)

I went into the ABE_ADCDifferentialPi library, it seems only config 1 and config 2 are enabled(16 channels). I think the config 3 and config 4 need to be  included to make it read 32 channels.Perhaps you can take a look when you get time. Thanks

   

 

 

Analogdude struggling

01/10/2016

Posted by:
andrew

Users Avatar

Location:
United Kingdom

Users Twitter  Users Website  

Hi

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 lower case one.  That may be causing the problem as it would fail when it tries to initialise adc3.

AB Electronics UK Tech Support

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.