PCF8591 board only reads 128, 0x80 - Raspberry Pi Forums


i have pcf8591 board. same pictured in link:

http://blog.chrysocome.net/2012/12/i2c- ... erter.html

have trouble communicating , looking advice.

i'll upfront wired incorrectly 5v instead of 3.3, have tried on pi on 3.3 , same problem.

shows fine @ address 48 sudo i2cdetect -y 1.

when sudo i2cget -y 1 0x48,
0x80 response.

if again 0x80.

no matter on channel 0x80 response.

when try grumpy mikes code 128's on channels:

http://www.raspberrypi.org/phpbb3/viewt ... it=pcf8591

have ideas? jumpers on, meaning should connected on board sensors. perhaps bad board, wanted check here before considering damaged.

of discussion on forum relates working chip itself, not type of board.

thank help.

try c code. it's not mine, adapted code found on web. if remember source i'll post link.

code: select all

#include <stdio.h> #include <fcntl.h> #include <unistd.h> #include <sys/ioctl.h> #include <linux/i2c-dev.h> #include <ncurses.h> /* sudo apt-get install libncurses5-dev */  int main( int argc, char **argv ) {    int i;    int r;    int fd;    int aout;    unsigned char command[2];    unsigned char value[4];    unsigned char str[8];    useconds_t delay = 5000;     char *dev = "/dev/i2c-1";    int addr = 0x48;     int j;    int key;     initscr();    noecho();    cbreak();    nodelay(stdscr, true);    curs_set(0);    printw("pcf8591");     mvaddstr(10, 0, "brightness");    mvaddstr(12, 0, "temperature");    mvaddstr(14, 0, "?");    mvaddstr(16, 0, "resistor");    refresh();    fd = open(dev, o_rdwr );    if(fd < 0)    {       perror("opening i2c device node\n");       return 1;    }     r = ioctl(fd, i2c_slave, addr);    if(r < 0)    {       perror("selecting i2c device\n");    }     command[1] = 0;    aout = 0;    while(1)    {       for(i = 0; < 4; i++)       {          command[1]=aout++;          command[0] = 0x40 | ((i + 1) & 0x03); // output enable | read input          r = write(fd, &command, 2);          usleep(delay);          // read 1 step behind selected input          r = read(fd, &value[i], 1);          if(r != 1)          {             perror("reading i2c device\n");          }          usleep(delay);           sprintf(str, "%3d", value[i]);          mvaddstr(10+i+i, 12, str);          value[i] = value[i] / 4;          move(10 + + i, 16);           for(j = 0; j < 64; j++)          {             if(j < value[i])             {                addch('*');             }             else             {                addch(' ');             }          }       }       refresh();        key = getch();       if(key == 43)       {          command[1]++;       }       else if(key == 45)       {          command[1]--;       }       else if(key > -1)       {          break;       }    }     endwin();    close(fd);    printf("%d\n", key);    return(0); } 
you'll need curses.

sudo apt-get install libncurses5-dev

compile use

gcc -o yl-40 yl-40.c -lcurses

edited add: original source code http://blog.chrysocome.net/2013/04/grap ... f8591.html


raspberrypi



Comments

Popular posts from this blog

Thread: PKI Client 5.00 install (for eToken Pro)

ATmega2560-Arduino Pin Mapping

Crossfader Arduino Tutorial