Moe
Posts: 230
Joined: Sun Jan 25, 2015 2:44 pm

Short range I2C woes

Fri Jan 13, 2017 7:58 pm

Apologies for the rant, but I'm at my wit's end and on the verge of abandoning my entire hobby. Please feel free to skip the rant and just tell me your experiences with getting I2C to work.

Situation is - I have a model B Pi with I2C expander hat (AB Electronics Expander Pi) sitting on top. The expander presents 5V I2C pins to the outside world. This works fine.
I also have a servo controller (AB Electronics Servo Pi) mounted about 1 inch away from the Pi. If I connect this to the expander 5V I2C pins with 20cm jumper wires it also works fine. Both modules have their own internal pullups.

I planned to use bus extenders to attach others things to the bus, 2-3m away. But I can't even get the bus to reach as far as the extender chip. I made a little veroboard for four extenders, mounted it next to the Pi, and attached the 5V bus wires from the expander to the veroboard, then to the servo controller . The bus failed. So I made a smaller board for just one extender chip, cut the SDA/SCL tracks as small as possible and soldered the wires directly into it. Total wire length, including veroboard tracks, is about 12cm, with all connections soldered. Still doesn't work. Sometimes I2cdetect gives the correct addresses, but my program always crashes out.

It all buzzes out fine, I've played with smaller pullups, run it off a clean battery supply, separated the wires from everything else; nothing works. Basically, a point-to-point jumper wire between two devices works, anything more complicated doesn't. I don't have a 'scope and my meter isn't nearly precise enough to measure 400pF.

As this is derailing the entire project, I almost decided to replace all the boards with clean new ones and just stack them - but of course they're for a model B and you can't buy them any more! So then I thought I'd use my Pi 3 instead with new boards, but they don't make those yet, and I'm a bit reluctant to start again with a different manufacturer's python libraries etc.

From everything I've read, I2C should easily work over these distances.
Anyone had this much trouble before? Help, please!

Failing that, any recommendations for Pi 3 expansion that is known to work? (I need a lot of I/O, 8 ADCs, 12 servos, and referably RTC).
Submarine communication systems engineer and amateur robot enthusiast.

User avatar
Gavinmc42
Posts: 4508
Joined: Wed Aug 28, 2013 3:31 am

Re: Short range I2C woes

Fri Jan 13, 2017 11:48 pm

You don't indicate which board you are using.
Is it an expander or multiplexer?
I am assuming the "expander" can do 3v3 i2c for the Pi and 5V i2c for the rest?

I use i2c-tools for testing.
Does i2cdetect -y 1 come back with any addresses? This is the first thing I do for testing.

I have done lots of i2c stuff, 5m cables or more can be done if you lower the bus clock speed.
What is your clock rate?

Pi B and Pi 3? i2c-0 and i2c-1
Are you using the right i2c?
Any expander for a B should work on a B+, 2B, 3B apart from mechanical clearances.

Putting 5V into a 3V3 won't help, you could damage the i2c IO pins, this is just guessing.
Have you tried another B?

I have done lots of i2c, done just about everything wrong :lol:
It will be obvious after you figure it out :oops:

Do you have a scope to look at the clock/data lines? This will help if everything else fails.
If you change the i2c clock to 10-20khz you can use the sound card inputs on a PC as a low speed scope.
This one is useful https://www.zeitnitz.eu/scope_en
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

Moe
Posts: 230
Joined: Sun Jan 25, 2015 2:44 pm

Re: Short range I2C woes

Sat Jan 14, 2017 1:08 pm

Is it an expander or multiplexer?
I am assuming the "expander" can do 3v3 i2c for the Pi and 5V i2c for the rest?
AB Electronics ExpanderPi, and yes it plugs into the Pi and provides a 5V bus externally.
Does i2cdetect -y 1 come back with any addresses? This is the first thing I do for testing.
Yes but not consistently. Most often, it comes back with the correct addresses but my program bombs out (even though it works when the devices are connected directly).
What is your clock rate?
Default, 100kHz I think.
Putting 5V into a 3V3 won't help, you could damage the i2c IO pins, this is just guessing.
Have you tried another B?
No I don't have another one but it all seems to work fine when directly connected. There are no 5V lines going to the Pi.
Do you have a scope to look at the clock/data lines?
Unfortunately not, and I don't want to buy one just for this when it might not even solve my problem :( .

Tried playing with another device, a MaxSonar I2C, with exactly the same results. Works fine when plugged into the expander 5V I2C pins with a 30cm jumper wire. If I use two 10cm wires with a a chocolcate block or veroboard in the middle, it fails every time :?

Thanks for your help.
Submarine communication systems engineer and amateur robot enthusiast.

User avatar
Gavinmc42
Posts: 4508
Joined: Wed Aug 28, 2013 3:31 am

Re: Short range I2C woes

Sat Jan 14, 2017 1:45 pm

https://www.abelectronics.co.uk/
Which one is it?

Any PC with microphone input can be turned into a low freq scope.
http://homediyelectronics.com/projects/ ... illoscope/
http://makezine.com/projects/sound-card-oscilloscope/
http://www.ledametrix.com/oscope/
http://ladyada.net/library/equipt/diyaudioprobe.html

100KHz should not have problems over a few cm.
But by lowering the freq you can use the soundcard scope to see what is actually happening.
A multimeter with frequency settings can sort of be used to see if the SCL is clocking.
It can be hard unless you have software sending continuously.

I have not used it but piscope is a like a logic analyzer on the Pi
http://abyz.co.uk/rpi/pigpio/piscope.html
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

Moe
Posts: 230
Joined: Sun Jan 25, 2015 2:44 pm

Re: Short range I2C woes

Sat Jan 14, 2017 11:37 pm

This one https://www.abelectronics.co.uk/kb/arti ... xpander-pi They don't make it any more.
Submarine communication systems engineer and amateur robot enthusiast.

User avatar
Gavinmc42
Posts: 4508
Joined: Wed Aug 28, 2013 3:31 am

Re: Short range I2C woes

Sun Jan 15, 2017 8:04 am

Ok, the TXS0108B is doing the level translation.
Never used that one, but on the schematic there is no pullups on the 5v side.
Ok, found the data sheet, there is internal pullups.
http://www.ti.com/lit/ds/symlink/txs0108e.pdf

Hmm, smart chip might be too smart? Can it do i2c?
Without looking at the waveform it will be hard to see what is going on.
2 x 5V i2c and 2 x SPI parts on it.

I would be scoping the i2c pin, both sides because you now have two sets of pull-ups on the 3V3 Pi side.
You can lower the baud rate in the config.txt file, it could be rise time issues.

You have got to the stage of trying to debug without knowing what is going on.
Without a waveform image everything is guessing now.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

stevend
Posts: 262
Joined: Fri Oct 11, 2013 12:28 pm

Re: Short range I2C woes

Sun Jan 15, 2017 9:54 am

I'm not convinced that the TI converter does a 'proper' job of buffering the I2C bus, even though it clearly works with just one expander.
I've used the PCA9512 successfully for years; there are others in the family with subtly different control pins and functions.
Silicon Labs also do an isolated level translator - good for analog

Having said that, 2-3m is pushing it for reliable I2C communication using standard level translators. There are circuits around for expanding over these distances - start by looking at the application notes on the NXP web site.

skipfire
Posts: 29
Joined: Fri Dec 30, 2016 1:27 pm
Location: Indiana, USA

Re: Short range I2C woes

Sun Jan 15, 2017 10:18 pm

Can you try not connecting the power line (just the 3.3v or 5v wire) and powering it locally on both ends instead? You will still need a connected ground so that there is a common reference for the clock and signal.

Moe
Posts: 230
Joined: Sun Jan 25, 2015 2:44 pm

Re: Short range I2C woes

Mon Jan 16, 2017 10:28 pm

Without a waveform image everything is guessing now.
I'm not convinced that the TI converter does a 'proper' job of buffering the I2C bus, even though it clearly works with just one expander.
Hmm, so the choice is persevering and investing in a 'scope I don't really need, or replacing the expander hat. Given that everyone thinks I should be getting far greater distances, and it certainly seems to be the common cause, this might be the way to go. Sigh.
Can you try not connecting the power line (just the 3.3v or 5v wire) and powering it locally on both ends instead?
Everything is powered from the same source but through a distribution block, i.e. not from the Pi. I've tried it with a 3A 5V wall wart, the robot's own 24V to 5V DC converter, and a USB power bank, all with the same results.
Having said that, 2-3m is pushing it for reliable I2C communication using standard level translators.
My plan was to use P82B715 extenders for the longer stretches, problem is I can't get to unbuffered bus to reach the extender!

Thanks for all your help.
Submarine communication systems engineer and amateur robot enthusiast.

skipfire
Posts: 29
Joined: Fri Dec 30, 2016 1:27 pm
Location: Indiana, USA

Re: Short range I2C woes

Mon Jan 16, 2017 11:11 pm

Keep in mind that voltage drops over distance, so since you are using a single supply you may have too much voltage drop on some devices. 

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

Re: Short range I2C woes

Mon Jan 16, 2017 11:20 pm

http://abyz.co.uk/rpi/pigpio/piscope.html will show you the I2C activity.

I suggest you start the daemon with sudo pigpiod -s2 if using a 100kbps bus.

User avatar
Gavinmc42
Posts: 4508
Joined: Wed Aug 28, 2013 3:31 am

Re: Short range I2C woes

Tue Jan 17, 2017 1:59 am

Hmm, so the choice is persevering and investing in a 'scope I don't really need,
Debugging i2c? or any serial type comms, very hard without a scope or waveform display.
Sometimes it is very easy but even with a scope it can get hard.

Invest the time in the other options first before getting a real scope.

Have not tried these but if you have a smart phone all you needs is 3.5mm plug resistor and soldering skills
https://play.google.com/store/apps/deta ... cope&hl=en
https://retronics.wordpress.com/2012/07 ... illoscope/

Minimum investment in a real cro? this one even works on the Pi
http://www.bitscope.com/product/BS05/

https://www.kickstarter.com/projects/75 ... cilloscope
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

Moe
Posts: 230
Joined: Sun Jan 25, 2015 2:44 pm

Re: Short range I2C woes

Fri Feb 17, 2017 4:33 pm

Right then. Refusing to be defeated, I bought myself a BitScope (nice little gadget!)

It's not helping. Everywhere I stick the probes, the signal looks fine. This is running a basic program that tries to write a random byte to a random address (clock yellow, data green)
1.jpg
1.jpg (49.39 KiB) Viewed 4109 times
. And yet, i2cdetect only finds the attached devices sporadically, and the main program always bombs out with a IO error.

And it has uncovered a second problem. When I try to insert the P82B715 extender chip, with nothing attached to the buffered side of the bus, this happens:
2.jpg
2.jpg (50.69 KiB) Viewed 4109 times
Submarine communication systems engineer and amateur robot enthusiast.

User avatar
Gavinmc42
Posts: 4508
Joined: Wed Aug 28, 2013 3:31 am

Re: Short range I2C woes

Sat Feb 18, 2017 1:29 am

That looks a little like power supply ringing.
Do you have any capacitors across the chip supplies?
At least a 0.1uF X7R ceramic?
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

Moe
Posts: 230
Joined: Sun Jan 25, 2015 2:44 pm

Re: Short range I2C woes

Sun Feb 19, 2017 12:22 pm

I do at the supply end, yes. Also note the signal level has dropped to ~1V. I would've thought the chip would be high impedance on the unbuffered side so as to NOT affect the signal on the rest of the bus.
Submarine communication systems engineer and amateur robot enthusiast.

Moe
Posts: 230
Joined: Sun Jan 25, 2015 2:44 pm

Re: Short range I2C woes

Sun Feb 19, 2017 3:12 pm

OK, took the baudrate down to 50k then 10k, no difference. Same symptoms - direct connection via simple jumper wire: works; longer run or via veroboard: doesn't work. Tried with two different i2cdevices with completely different code, same results. Signal in all cases looks absolutely fine. :? :cry:
Submarine communication systems engineer and amateur robot enthusiast.

User avatar
Gavinmc42
Posts: 4508
Joined: Wed Aug 28, 2013 3:31 am

Re: Short range I2C woes

Mon Feb 20, 2017 2:47 am

Bypass or decoupling caps should be across the supply at the chip not at the supply end.
https://en.wikipedia.org/wiki/Decoupling_capacitor.

That waveform shows ringing on the supply, it will be worse for longer wires due to inductance.
You must have power supply filtering capacitors at the digital chip/sensor and on every digital chip.
Depending on the type of chip you need at least a 0.1uF X7R per chip and as close at possible to the gnd and supply pins.

You can also get waveforms like that due to the cro probe impedance mismatch.
And/or Ground loops.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

Bruce_Pi
Posts: 20
Joined: Tue Feb 21, 2017 5:09 pm

Re: Short range I2C woes

Tue Feb 21, 2017 10:53 pm

NXP makes a chip called P82B715TD. it can extend your i2c cable length up to 100 feet.
its a very simple chip and you will install one chip on the raspberry pi side and another one on the device side.
the max I2C freq supported by this P82B715TD is 400K.

if you are looking a before a breakout board with this chip. you can find over here
https://shop.controleverything.com/coll ... s-extender
I hope this helps.
Thanks

Moe
Posts: 230
Joined: Sun Jan 25, 2015 2:44 pm

Re: Short range I2C woes

Sat Feb 25, 2017 2:24 pm

OK, for clarity and completeness, here is the bus seen at the input to the extender board, with no chip fitted. As you can see, it is a healthy 5V signal with no discernable supply switching noise. Despite this, actual bus operation is sketchy.
1.jpg
1.jpg (49.39 KiB) Viewed 3692 times
Here it is with chip fitted:
2.jpg
2.jpg (50.69 KiB) Viewed 3692 times
And here is the clock with capacitor across the supply at the chip end:
w cap.png
w cap.png (18.81 KiB) Viewed 3692 times
Cap may have cleaned up the noise a little, but obviously makes no difference to the volt drop. Bus doesn't work at all with chip fitted. Remove chip and signal goes back to normal. All traces measured at the same point, with same scope. All 0V lines are connected in a star arrangement, isolated from ground.
Submarine communication systems engineer and amateur robot enthusiast.

Moe
Posts: 230
Joined: Sun Jan 25, 2015 2:44 pm

Re: Short range I2C woes

Sat Feb 25, 2017 5:02 pm

Right, think I've sussed the extender chip issue. According to the manufacturer of the expansion board, the level shifters will stop working if the overall bus pullup is less than 5k. The P82B715 on its own contributes about 700ohms, which would explain the volt drop. Unfortunately, it also means what I'm trying to do is impossible... :cry:

Think I'm looking at alternative expansion hardware.
Submarine communication systems engineer and amateur robot enthusiast.

User avatar
Gavinmc42
Posts: 4508
Joined: Wed Aug 28, 2013 3:31 am

Re: Short range I2C woes

Mon Feb 27, 2017 9:02 am

You have measured the 3V3 and 5V rails?
That voltage drops seems excessive, I had just assumed it was a different scale.
That is only about a 1V signal.

And 5K is nominal, I usually use 4K7 for 5V and 3k3 for 3V3 pull-ups.
Capacitor is helping but there must be impedance somewhere or no power on one side?
The P82B715 alone does not support voltage level translation
Are you using this chip?
It is NOT a level translator it assumes 5V in signals?
because the device output levels are always held within 100 mV of input drive levels,
If you hook it to the 3V3 SDA/SCL on the Pi and power with 5V strange things will happen?
You need a level converter buffer or power it with 3V3?
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

Moe
Posts: 230
Joined: Sun Jan 25, 2015 2:44 pm

Re: Short range I2C woes

Tue Feb 28, 2017 12:03 am

Sorry, some confusion here. All this is happening at 5V. My expansion HAT does the shifting. I am trying to connect the 5V I2C to an little board with an extender chip to make the bus go ~2m. The bus is unreliable even when connecting to the board.with no chip (open circuit, very high impedance). Insert the chip in its DIL socket (measured 700ish ohms between signal and 5V line), with everything exactly the same, I get the 1V pk-pk mess shown above.

I think I now know what is causing the 1V mess, bit still cannot understand why I can't get the bus to work reliably over more than about 15cm when signal looks fine on the scope, wherever I measure it.
Submarine communication systems engineer and amateur robot enthusiast.

Moe
Posts: 230
Joined: Sun Jan 25, 2015 2:44 pm

Re: Short range I2C woes

Thu Mar 23, 2017 9:45 pm

Problem solved. Upgraded to Pi3 and changed all the hardware, now using straightforward level shifters I can understand and pullup values under my control. Three months delay and a 'scope I don't need, but live and learn! :lol:
Submarine communication systems engineer and amateur robot enthusiast.

User avatar
Gavinmc42
Posts: 4508
Joined: Wed Aug 28, 2013 3:31 am

Re: Short range I2C woes

Fri Mar 24, 2017 2:17 am

Hang on to that scope.
If you do more i2c or SPI or i2s or PWM or PCM it will come in handy.

Not sure why changing to a Pi3 would make any difference.
If it works on that is should work on others.
Unless 5Volts got into the i2c 3V3 pins on the original Pi.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

Moe
Posts: 230
Joined: Sun Jan 25, 2015 2:44 pm

Re: Short range I2C woes

Sun Mar 26, 2017 8:02 pm

Yes, I must admit, now I have the scope I'm using it for all sorts of things. Gives a much clearer view of stuff than a meter.

I don't think it was the Pi itself, more the expander I was using to externalise the 5V bus, and it's weird 'smart' resistors and level shifter. As it was for an original model B you cant buy then any more and the Pi 3 versions are much more straightforward - everything local now runs straight off the 3.3V bus, and I've added my own level shifter for the 5V devices.
Submarine communication systems engineer and amateur robot enthusiast.

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