Support Forum

Share your projects and post your questions

Register   or   Sign In
The Forum

Failed to import ADCPi from python system path

2213 Views - Created 19/11/2018

19/11/2018

Posted by:
albertju

albertju Avatar

When I try to run the code from ADCPi, demo_readvoltage.py, I get the following error:

Failed to import ADCPi from python system path
Importing from parent folder instead
Traceback (most recent call last):
File "demo_readvoltage.py", line 61, in <module>
main()
File "demo_readvoltage.py", line 40, in main
adc = ADCPi(0x68, 0x69, 12)
File "../ADCPi.py", line 128, in __init__
self.__bus = self.__get_smbus()
File "../ADCPi.py", line 84, in __get_smbus
raise IOError('Could not open the i2c bus')
IOError: Could not open the i2c bus


Does anyone know what could causing this error and how i can fix it?

19/11/2018

Posted by:
albertju

albertju Avatar

Here is the code from demo_readvoltage.py,



#!/usr/bin/env python
"""
================================================
ABElectronics ADC Pi 8-Channel ADC demo

Requires python smbus to be installed
run with: python demo_readvoltage.py
================================================

Initialise the ADC device using the default addresses and sample rate,
change this value if you have changed the address selection jumpers

Sample rate can be 12,14, 16 or 18
"""

from __future__ import absolute_import, division, print_function, \
unicode_literals
import time
import os

try:
from ABElectronics_Python_Libraries import ADCPi
except ImportError:
print("Failed to import ADCPi from python system path")
print("Importing from parent folder instead")
try:
import sys
sys.path.append('..')
from ADCPi import ADCPi
except ImportError:
raise ImportError(
"Failed to import library from parent folder")


def main():
'''
Main program function
'''

adc = ADCPi(0x68, 0x69, 12)

while True:

# clear the console
os.system('clear')

# read from adc channels and print to screen
print("Channel 1: %02f" % adc.read_voltage(1))
print("Channel 2: %02f" % adc.read_voltage(2))
print("Channel 3: %02f" % adc.read_voltage(3))
print("Channel 4: %02f" % adc.read_voltage(4))
print("Channel 5: %02f" % adc.read_voltage(5))
print("Channel 6: %02f" % adc.read_voltage(6))
print("Channel 7: %02f" % adc.read_voltage(7))
print("Channel 8: %02f" % adc.read_voltage(8))

# wait 0.2 seconds before reading the pins again
time.sleep(0.2)

if __name__ == "__main__":
main()

20/11/2018

Posted by:
andrew

andrew Avatar

Location:
United Kingdom

andrew Twitter  andrew Website  

Hi

The error you are getting normally means the I2C bus is not configured correctly. Can you try going through our I2C tutorial to set up the I2C bus on the Raspberry Pi?

Once you have gone through the tutorial try running the command "sudo i2cdetect -y 1". It should list all of the I2C devices that are visible to the Raspberry Pi, the ADC Pi should be on 0x68 and 0x69. If it is showing up then you should be able to use the ADC Pi with our software libraries. If it is not showing up then check the solder joints on the 40-pin GPIO connector and the address header to make sure there are no dry joints or solder bridges.

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.