Posts: 23
Joined: Thu Mar 15, 2018 10:22 pm

Getting i2c to work on 3 B+

Sun Mar 18, 2018 2:26 am

Hi there,

following on from my previous post about which communication method to use for arduino (slave) to pi (master), i've decided to go with i2c.

I tried connecting my arduino to the pi using sample code from however, after going through the tutorials below, i could not get the pi to detect the arduino. So i decided to try with a simple accelerometer (mma7660), yet i still can't get anything to be detected. any changes from the B to the B+? all pins the same etc? I bought the pi 3 days ago so i am as big a begginer to pi's as can be, but not so much to programming and electronics.

many thanks


Posts: 5294
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Getting i2c to work on 3 B+

Sun Mar 18, 2018 12:13 pm

The pin outs are exactly the same for the 3B and the 3B+ did you enable the i2c interface on your pi ?
as all interfaces are disabled by default , enabling can be done via raspi-config under interfacing options.
Remember we want information no help
The use of crystal balls & mind reading is not supported

Posts: 23
Joined: Thu Mar 15, 2018 10:22 pm

Re: Getting i2c to work on 3 B+

Sun Mar 18, 2018 5:39 pm

Hi there

Yes, i went into raspi-config, enabled i2c and spi, used i2cdetect -y 1 and nothing comes up with either the arduino or the accelerometer. As i said, i followed the tutorials and changed the last few lines in the config.txt file. what else is needed?

Posts: 23
Joined: Thu Mar 15, 2018 10:22 pm

Re: Getting i2c to work on 3 B+

Tue Mar 20, 2018 12:55 pm

Ok, so i've managed to get an error message which hopefully someone will understand. I followed this tutorial;

where an arduino uno is configured as a slave device, and you send data from the pi to the arduino via i2c

i get all the way to the final part of sending data, but when i click eneter, the following error message shows up;

Code: Select all

Enter the data to be sent : 2
Traceback (most recent call last):
  File "", line 38, in <module>
  File "", line 22, in writeNumber
    bus.write_byte(address, value)
IOError: [Errno 121] Remote I/O error
does this indicate to anyone what i'm doing wrong? Thanks

Posts: 217
Joined: Wed Jun 20, 2012 2:51 pm
Location: Southampton, England

Re: Getting i2c to work on 3 B+

Mon Mar 26, 2018 2:55 pm

If you cannot see anything via i2cdetect then there is little chance of you getting any code working. Start by checking the hardware.
You will need four connections: ground, power, and the two I2C lines (SDA and SCL). The power to the I2C device might need to be 3.3V or 5V, so check which, and make sure it is the right level. Regardless of whether the power supply comes from a 3.3V GPIO pin or 5V GPIO pin on the Pi, or from a separate source, the ground will need to be linked with the Pi, so if you are using a separate power supply for the device then the grounds will need to be linked. Then check the SDA and SCL lines are connected the right way round. This is probably the easiest mistake to make.

The next stage is to check what voltage the I2C device considers logic high. If it is powered by 3.3V then logic high will also be 3.3V and connecting directly to the GPIO pins will work. However, if it is a 5V device then the minimum voltage for high will vary depending on exactly which technology is used (CMOS, TTL, etc). There is some variation between different devices, but generally 5V TTL devices consider anything above 2V to be high, but 5V CMOS devices might need 4V for high. You might need to use a logic level shifter if the threshold voltage is above 3.3V.

Although the accelerometer datasheet ( describes it as a low voltage device which would be perfectly OK at 3.3V supply and logic, it may be mounted on some kind of carrier board which expects a 5V supply. If you can get the arduino to see the accelerometer, then this is the case, as that is what the arduino uses.

User avatar
Posts: 13769
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Getting i2c to work on 3 B+

Mon Mar 26, 2018 3:26 pm

Does i2cdetect show your device?

If so there is probably an error in your code which we would need to see.

Return to “Interfacing (DSI, CSI, I2C, etc.)”