I am writing a little "oscilloscope" program in c++ using /dev/fbx. I am reading in analog values via a pcf8591 connected to the I2C bus. Every thing works well if I only read 1 channel of analog data. But if I add in a 2nd channel the data gets messed up. There are a lot of extraneous 0 and 255 as well as data from one channel showing in the read from the other channel.

Here is a sample of what I am doing:

... part of an infinite loop ..

    wiringPiI2CWrite(fd, 0x40 );
    sig2 = wiringPiI2CRead(fd) - 100;
    sig2 = wiringPiI2CRead(fd) - 100;

    sig3 = (x & 0xff) / 2;

 commented out---
    wiringPiI2CWrite(fd, 0x43 );
    sig3 = wiringPiI2CRead(fd) - 100;
    sig3 = wiringPiI2CRead(fd) - 100;
commented out--


This code works perfectly with channel 0... But when I uncomment the 3 lines for channel 3 the data gets messed up..

I've tried using the auto-increment function but the same problem. I does not matter what channel I use - only if I use more than 1 channel. I've also tried using long delays after each read and write but to no avail.

Any ideas out there??

  • Why did you read both sig2 and sig3 twice? – NomadMaker Jan 24 at 19:09

Interpreted from the datasheet. Your module may have differences.

Connect Pi 3V3 - VCC, Pi Ground - Ground, Pi SDA - SDA, Pi SCL - SCL.

I2C address 0x48

P4 The thermister voltage is provided at AIN 1.
P5 The photocell voltage is provided at AIN 0.
P6 The single turn 10K ohm trim pot voltage is provided at AIN 3.

7 6 5 4 3 2 1 0
0 X X X 0 X X X
  | | |   | | |
  A B B   C D D

0 1 0 0 0 1 0 0

A 0 D/A inactive
  1 D/A active

B 00 single ended inputs
  01 differential inputs
  10 single ended and differential
  11 two differential inputs

C 0 no auto inc
  1 auto inc

D 00 select channel 0
  01 select channel 1
  10 select channel 2
  11 select channel 3

I give several examples of reading the PCF8591.

Non-pigpio C + Python

pigpio C

pigpio Python

| improve this answer | |
  • Thanks for taking the time to answer. I'm using an Orange Pi so the library won't work for me. My code using the wiringOP library does essentially the same thing as yours. I did notice that you were using a long (20000) delay so I tried it in my code but no joy. In the mean time I tried adapting my code for use with an ADS1115 4 ch A/D and got it working great. It does poll the chip before reading data - need to see if the PCF8591 offers anything like that. My problem is reading multiple channels - one channel alone works great. – Art Sayler Jul 19 '18 at 20:10

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.