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

demo code for ADC does not run

2171 Views - Created 05/10/2015

21/07/2015

Posted by:
Peter Thejll

Users 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.py
Traceback (most recent call last):
File "demo-adcread.py", line 3, in 
from ABE_ADCDACPi import ADCDACPi
File "/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 ADCDACPi
spiADC.open(0, 0)
IOError: [Errno 2] No such file or directory

Any ideas on what's wrong?

21/07/2015

Posted by:
andrew

Users Avatar

Location:
United Kingdom

Users Twitter  Users 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 ADCDAC 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/1076/i2c--smbus-and-raspbian-wheezy-linux

AB Electronics UK Tech Support

21/07/2015

Posted by:
Peter Thejll

Users 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

Users Avatar

Location:
United Kingdom

Users Twitter  Users 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.

AB Electronics UK Tech Support

21/07/2015

Posted by:
Peter Thejll

Users 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

Users Avatar

Location:
United Kingdom

Users Twitter  Users Website  

The best way to start is to follow the instructions on https://www.abelectronics.co.uk/kb/article/1076/i2c--smbus-and-raspbian-wheezy-linux 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.

AB Electronics UK Tech Support

21/07/2015

Posted by:
Peter Thejll

Users 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

Users Avatar

Location:
United Kingdom

Users Twitter  Users 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 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.

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.