Trouble

Can't read I2C bus in raspbian

9 12559
Post Last Edited by ylgaoyifan at 2014-7-7 11:32

Post Last Edited by ylgaoyifan at 2014-7-7 11:14

I followed the https://projects.drogon.net/raspberry-pi/wiringpi/i2c-library/
But when I run:
$ sudo gpio load i2c
FATAL: Module i2c_bcm2708 not found.
gpio: Unable to load i2c_bcm2708

Then I try to comment out the following lines:
blacklist spi-bcm2708
blacklist i2c-bcm2708

in the  /etc/modprobe.d/raspi-blacklist.conf ,but still get the same error.

edit modules in  /etc/modules does no help.

$ gpio readall
+----------+-Rev2-+------+--------+------+-------+
| wiringPi | GPIO | Phys | Name   | Mode | Value |
+----------+------+------+--------+------+-------+
|      0   |  17  |  11  | GPIO 0 | IN   | Low   |
|      1   |  18  |  12  | GPIO 1 | IN   | Low   |
|      2   |  27  |  13  | GPIO 2 | IN   | Low   |
|      3   |  22  |  15  | GPIO 3 | IN   | Low   |
|      4   |  23  |  16  | GPIO 4 | IN   | Low   |
|      5   |  24  |  18  | GPIO 5 | IN   | Low   |
|      6   |  25  |  22  | GPIO 6 | IN   | Low   |
|      7   |   4  |   7  | GPIO 7 | IN   | Low   |
|      8   |   2  |   3  | SDA    | IN   | Low   |
|      9   |   3  |   5  | SCL    | IN   | Low   |
|     10   |   8  |  24  | CE0    | IN   | Low   |
|     11   |   7  |  26  | CE1    | IN   | Low   |
|     12   |  10  |  19  | MOSI   | IN   | Low   |
|     13   |   9  |  21  | MISO   | IN   | Low   |
|     14   |  11  |  23  | SCLK   | IN   | Low   |
|     15   |  14  |   8  | TxD    | IN   | Low   |
|     16   |  15  |  10  | RxD    | IN   | Low   |
|     17   |  28  |  53  | GPIO 8 | IN   | Low   |
|     18   |  29  |  54  | GPIO 9 | IN   | Low   |
|     19   |  30  |  55  | GPIO10 | IN   | Low   |
|     20   |  31  |  56  | GPIO11 | IN   | Low   |
+----------+------+------+--------+------+-------+

Anyone who have a solution ?
Do not use gpio load i2c... The i2c has been load in the boot. You can use it directly

Banana Pi is not Raspberry Pi. The i2c driver is i2c-sunxi and i2c-dev. We have build it into kernel not modules.

Post Last Edited by ylgaoyifan at 2014-7-7 21:01

Reply 3# tony_zhang

Is there a simple solution to read I2C in C/C++ (like wiringPi)?

Reply 4# ylgaoyifan

You can directly use the i2c function in wiringPi to read data. It is ok. Just notice that the i2c in Banana Pi is i2c-2

Post Last Edited by tony_zhang at 2014-7-7 22:13

Reply 4# ylgaoyifan

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <errno.h>
  4. #include<wiringPi.h>
  5. #include<wiringPiI2C.h>
  6. int devid = 0x20;   //you can use "i2cdetect" to find this devidint fd;        
  7. int main()
  8. {
  9.     if ((fd=wiringPiI2CSetup(devid)) < 0)
  10.     {   
  11.          fprintf (stderr, "Unable to open I2C device: %s\n", strerror (errno)) ;   
  12.          return 1 ;
  13.     }
  14.     if ((wiringPiI2CWrite(fd,0x00)) < 0)
  15.     {   
  16.          fprintf (stderr, "write badly %s\n", strerror (errno)) ;   
  17.          return 1 ;
  18.     }
  19.     delay(500);
  20.      printf("read from I2C: %d\n",wiringPiI2CRead(fd));
  21. }
Copy the Code
I use this program to test pcf8574. It works well

Reply 6# tony_zhang

Thanks a lot

coto  
Well, I only have one i2c device after reboot and can add a second using the gpio tool. But the important device /dev/i2c-2 is still missing.

I did an update/upgrade/dist-upgrade recently. I do have installed WiringBPi dated 2014-10-11.

How can I access sensors and other devices sitting on the GPIO ports using the i2c bus?


pi@bananapi ~ $ uname -a
Linux bananapi 3.4.90 #1 SMP PREEMPT Mon May 26 20:19:17 CST 2014 armv7l GNU/Linux
pi@bananapi ~ $ ll /dev/i2c*
crw-rw---T 1 root i2c 89, 1 Oct 11 20:44 /dev/i2c-1
pi@bananapi ~ $ uptime
20:45:20 up 1 min,  1 user,  load average: 0.69, 0.22, 0.08
pi@bananapi ~ $ sudo gpio load i2c
gpio: Warning: File not present: /dev/i2c-2
gpio: Warning: File not present: /dev/i2c-2
pi@bananapi ~ $ ll /dev/i2c*
crw-rw---T 1 root i2c 89, 0 Oct 11 20:45 /dev/i2c-0
crw-rw---T 1 root i2c 89, 1 Oct 11 20:44 /dev/i2c-1
pi@bananapi ~ $ sudo i2cdetect -y 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- UU -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --                        
pi@bananapi ~ $ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --                        
pi@bananapi ~ $ sudo i2cdetect -y 2
Error: Could not open file `/dev/i2c-2' or `/dev/i2c/2': No such file or directory

coto  
Thank you!
I thought, a dist-upgrade would solve that... so I'll fetch another SD card and try that.

You have to log in before you can reply Login | Sign Up

Points Rules