0

I have wired according to these instructions.

http://blog.chrysocome.net/2012/12/i2c-analog-to-digital-converter.html

I tried the methods of getting the value at the bottom of the page and it told me that there was a read error. naturally, i tried a different method, python

#Read a value from analogue input 0
#in A/D in the PCF8591P @ address 0x48
from smbus import SMBus

bus = SMBus(1)

print("Read the A/D")
print("Ctrl C to stop")
bus.write_byte(0x48, 0) # set control register to read channel 0
last_reading =-1

while(0 == 0): # do forever
    reading = bus.read_byte(0x48) # read A/D
    if(abs(last_reading - reading) > 2):
        print(reading)
        last_reading = reading

that threw an error saying it to couldn't read the input. After several google searches, I found a fix that was simply bad wiring. I have reattached everything. still no different result. Any thoughts on how to fix this?

migrated from electronics.stackexchange.com Apr 14 '16 at 2:25

This question came from our site for electronics and electrical engineering professionals, students, and enthusiasts.

1

Check with i2cdetect that your device is indeed being scanned. Also, the original Pis had the i2c bus as bus 0, not bus 1; maybe that's your problem?

Also, the proper way to do an infinite loop in Python is while True:

  • I did i2cdetect -y 1 and it showed up in 48. – Chris Hawley Apr 14 '16 at 15:29
  • what is the actual error? – JayEye Apr 14 '16 at 15:43
  • I2cget -y 1 0x48 – Chris Hawley Apr 14 '16 at 16:24
  • Error: Read Failed – Chris Hawley Apr 14 '16 at 16:24
  • I mean, what does errno contain? "read failed" is not what the OS returns. – JayEye Apr 14 '16 at 16:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.