I am using some PCF8951 board like this:

enter image description here

I remove all the jumper, like this:

enter image description here

This is every thing:

enter image description here

Then I plug two senor board to this board. Everything plugs into AIN0 will get the correct value. But each of them plugs into AIN1 (or AIN2, AIN3) will not get the correct value.

My codes are written in Python. Using the code from https://github.com/ShuDiamonds/PCF8591. Code like this:

def analogRead0(self):
    self.i2c.writeReg8(self.dev, 0x48,0x40)
    self.i2c.readReg8(self.dev,0x48)    #read dummy
    return self.i2c.readReg8(self.dev,0x48)

def analogRead1(self):
    self.i2c.writeReg8(self.dev, 0x48,0x41)
    self.i2c.readReg8(self.dev,0x48)    #read dummy
    return self.i2c.readReg8(self.dev,0x48)

def analogRead2(self):
    self.i2c.writeReg8(self.dev, 0x48,0x42)
    self.i2c.readReg8(self.dev,0x48)    #read dummy
    return self.i2c.readReg8(self.dev,0x48)

def analogRead3(self):
    self.i2c.writeReg8(self.dev, 0x48,0x43)
    self.i2c.readReg8(self.dev,0x48)    #read dummy
    return self.i2c.readReg8(self.dev,0x48)

My question is how I know there is something wrong in the hardware? Or in my code?

I know my senors are good, I used my multimeter to measure the voltage between AO and GND, they are all good.

  • 1
    Can we have a photo showing how you are connecting to the inputs? – joan Jun 16 '19 at 9:45
  • Your analogRead methods look OK. I would suggest not to use any sensors, but just use 1.5V or 3.0V DC batteries. This just narrow down the troubleshooting area. Or rename AnalogRead0 to AnalogRead7, AnalogRead 1 to AndlogRead9 etc, just to catch any careless typos. And if you once applies high voltages to the AIN1 to AIN3 inputs, you might have fried them. – tlfong01 Jun 16 '19 at 9:53
  • @joan Thanks. I edited the post. Add a photo. I have a raindrop detector and a temperature sensor. They both can get the correct value when they plug in AIN0 separately. – Tinyfool Jun 16 '19 at 9:53
  • @tlfong01 Thanks. I will try your method first. – Tinyfool Jun 16 '19 at 9:54
  • I see that you have 3 PCF8591 modules. If you swap them for troubleshooting, you can easily catch the bad guy. Good luck! Ah sorry, you have only one PCF8591. My apologies. In that case, buy one or two more to do swap, compare and contrast testing. Those modules are so dirt cheap, so it worth your money to get spares for troubleshooting or maintenance later. – tlfong01 Jun 16 '19 at 9:56

I don't why, and I buy three same components and still get the same problem. So I switch this code https://github.com/sunfounder/SunFounder_SensorKit_for_RPi2/blob/master/Python/PCF8591.py

And everything now is ok.

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.