Support Forum

Share your projects and post your questions

Register   or   Sign In
The Forum

demo code for ADC does not run

3861 Views - Created 05/10/2015

21/07/2015

Posted by:
Peter Thejll

Peter Thejll Avatar

Hi, just received my ADC Pi Plus, and can't get the demo codes to run. I assume it is something really simple, and would appreciate a pointer or two.
I have plugged the board into the RPi 2's GPIO bus.
I did the pip install spidev thing
I have done the git clone thing, assuming python 2.X (and it does show 2.7.3 when I start python, so...)
I have gone to the resulting directory ~/ABElectronics_Python_Libraries/ADCDACPi
and there done the export PYTHONPATH thing
I then try to run the demo code, and this happens:
~/ABElectronics_Python_Libraries/ADCDACPi $ python demo-adcread.pyTraceback (most recent call last):File "demo-adcread.py", line 3, in from ABE_ADCDACPi import ADCDACPiFile "/home/pi/ABElectronics_Python_Libraries/ADCDACPi/ADCDACPi.py", line 17, in class ADCDACPi:File "/home/pi/ABElectronics_Python_Libraries/ADCDACPi/ADCDACPi.py", line 24, in ADCDACPispiADC.open(0, 0)IOError: [Errno 2] No such file or directory
Any ideas on what's wrong?

21/07/2015

Posted by:
andrew

andrew Avatar

Location:
United Kingdom

andrew Twitter  andrew Website  

Hi Peter

It appears that you are trying to use the wrong library with the ADC Pi Plus board. The ADCDACPi library is designed for our ADC DAC Pi board, the library you need can be downloaded from https://github.com/abelectronicsuk/ABElectronics_Python_Libraries/tree/master/ADCPi

You will also need to enable the I2C bus first before using the board which you can do by following the tutorial at https://www.abelectronics.co.uk/kb/article/1/i2c-part-2---enabling-i-c-on-the-raspberry-pi

21/07/2015

Posted by:
Peter Thejll

Peter Thejll Avatar

Hi

It appears that you are trying to use the wrong library with the ADC Pi Plus board.

Hmmm - not sure I understand - I did those things. Perplexingly, I can get the board to run if I go into the DeltaSIgmaPi directory ... not sure what this means?

21/07/2015

Posted by:
andrew

andrew Avatar

Location:
United Kingdom

andrew Twitter  andrew Website  

The library you are trying to run is in the /ABElectronics_Python_Libraries/ADCDACPi folder. You need to use the /ABElectronics_Python_Libraries/ADCPi library instead. Try running the demo-readvoltage.py script in the ADCPi folder and see if that works with your board.

21/07/2015

Posted by:
Peter Thejll

Peter Thejll Avatar

The library you are trying to run is in the /ABElectronics_Python_Libraries/ADCDACPi folder. You need to use the /ABElectronics_Python_Libraries/ADCPi library instead. Try running the demo-readvoltage.py script in the ADCPi folder and see if that works with your board.
Thanks. I see what I did - I do not have an ADC-DAC - just the ADC. Fine.
I tried the above advice and that code runs - but returns 0.000000 on all 8 channels despite having a light sensor attached to channel 1's inputs. The similarly-named code over in DeltaSigmaPi/ runs there (as explained earlier) and returns numbers that do seem to vary with the light level on the sensor.
I guess I have started out trying to jump in too fast, but was also a bit mystified by documentation that did seem to assume that various things had already been installed. If I were to 'start all over' which is the most complete set of howto instructions to follow for the ADC Pi Plus?

21/07/2015

Posted by:
andrew

andrew Avatar

Location:
United Kingdom

andrew Twitter  andrew Website  

The best way to start is to follow the instructions on abelectronics.co.uk/kb/article/1090/i2c-part-1---introducing-i2c which installs the I2C bus and the python drivers. Once that is installed you can download the ABElectronics_Python_Libraries from GitHub and the demonstration scripts should run.

If the ADC is reading 0.00 when you connect a sensor try checking that the polarity of the sensor is connected the correct way around as negative values on the ADC Pi always return as 0.

21/07/2015

Posted by:
Peter Thejll

Peter Thejll Avatar

If the ADC is reading 0.00 when you connect a sensor try checking that the polarity of the sensor is connected the correct way around as negative values on the ADC Pi always return as 0.

Yes! That was it! Thanks!
I see the point about the scale starting at 0. Is there a nice reason why, running (mistakenly) under the DeltaSigmaPi/ directory I can read signals with plus and minus signs?

21/07/2015

Posted by:
andrew

andrew Avatar

Location:
United Kingdom

andrew Twitter  andrew Website  

The Delta Sigma Pi measures differential inputs where the voltage can be between -2.048V and +2.048V so the library was written to return negative values as well as positive ones.

With the ADC Pi, the ADC is configured in the single-ended mode so it can only measure between 0V and 5V. As the voltage should never go below 0V any readings below that value are normally noise within the ADC chip so we made the library display those values as 0.

Sign in to post your reply

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.