mawmaw
Posts: 5
Joined: Mon Oct 08, 2018 11:37 am

Cannot detect sensor with i2c-gpio (i2cdetect -y 3)

Mon Oct 08, 2018 12:31 pm

Hi. I'm using a sensor (SCD30) that requires clock-stretching. Therefore I have followed the advice in this answer: https://raspberrypi.stackexchange.com/q ... spberry-pi, in order to activate the i2c-gpio.

Unfortunately, i2cdetect -y 3 does not detect anything, while i2cdetect -y 1 shows the address on 61. The pins that are used are SDA=3, SCL=5.

When reading the output of gpio readall after rebooting the PI, the SDA and SCL are set to ALT0. After using the i2cdetect -y 3, the SCL is set to IN, and neither i2cdetect -y 1 nor 3 detects anything.

I suspect SCL being set to IN instead of ALT0 could be the issue here, but the SCL keeps getting set to IN for some reason.

Does anyone have any idea how to fix this?

mawmaw
Posts: 5
Joined: Mon Oct 08, 2018 11:37 am

Re: Cannot detect sensor with i2c-gpio (i2cdetect -y 3)

Tue Oct 09, 2018 7:51 am

I got it working after realizing I had to use pin 23/24 on the PI.

Now i2cdetect -y 3 finds the correct address.

Unfortunately, after few minutes something happens, and suddenly i2cdetect -y 3 is 1 second slow when searching for addresses.

And then it no longer finds the address. Any advice?

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5822
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Cannot detect sensor with i2c-gpio (i2cdetect -y 3)

Tue Oct 09, 2018 8:55 am

mawmaw wrote:
Tue Oct 09, 2018 7:51 am
I got it working after realizing I had to use pin 23/24 on the PI.

Now i2cdetect -y 3 finds the correct address.

Unfortunately, after few minutes something happens, and suddenly i2cdetect -y 3 is 1 second slow when searching for addresses.

And then it no longer finds the address. Any advice?
That sounds like it has started clock stretching and timing out. Have you got the required pull up resistors on SDA and SCL?
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

mawmaw
Posts: 5
Joined: Mon Oct 08, 2018 11:37 am

Re: Cannot detect sensor with i2c-gpio (i2cdetect -y 3)

Tue Oct 09, 2018 9:19 am

6by9 wrote:
Tue Oct 09, 2018 8:55 am
mawmaw wrote:
Tue Oct 09, 2018 7:51 am
I got it working after realizing I had to use pin 23/24 on the PI.

Now i2cdetect -y 3 finds the correct address.

Unfortunately, after few minutes something happens, and suddenly i2cdetect -y 3 is 1 second slow when searching for addresses.

And then it no longer finds the address. Any advice?
That sounds like it has started clock stretching and timing out. Have you got the required pull up resistors on SDA and SCL?
I read the following thread https://raspberrypi.stackexchange.com/q ... 1-slc1-pin where joan recommended using 'sudo pigpiod; pigs pud 19 u pud 21 u' (I of course used 23 and 24 instead) in order to use those as pull-ups, but it hasnt made any difference as far as I can tell.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5822
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Cannot detect sensor with i2c-gpio (i2cdetect -y 3)

Tue Oct 09, 2018 9:37 am

mawmaw wrote:
Tue Oct 09, 2018 9:19 am
I read the following thread https://raspberrypi.stackexchange.com/q ... 1-slc1-pin where joan recommended using 'sudo pigpiod; pigs pud 19 u pud 21 u' (I of course used 23 and 24 instead) in order to use those as pull-ups, but it hasnt made any difference as far as I can tell.
The internal pull ups are ~50kohms. The normal I2C pull ups are around 1k8-4k7 in value.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

mawmaw
Posts: 5
Joined: Mon Oct 08, 2018 11:37 am

Re: Cannot detect sensor with i2c-gpio (i2cdetect -y 3)

Wed Oct 10, 2018 7:20 am

6by9 wrote:
Tue Oct 09, 2018 9:37 am
mawmaw wrote:
Tue Oct 09, 2018 9:19 am
I read the following thread https://raspberrypi.stackexchange.com/q ... 1-slc1-pin where joan recommended using 'sudo pigpiod; pigs pud 19 u pud 21 u' (I of course used 23 and 24 instead) in order to use those as pull-ups, but it hasnt made any difference as far as I can tell.
The internal pull ups are ~50kohms. The normal I2C pull ups are around 1k8-4k7 in value.
To be honest I have no experience in this (that's probably already clear). Is it possible to use resistors on a direct sensor -> jumper wire -> RPI connection, or do I need a breadboard to be able to use resistors? All examples I have found uses a breadboard, but that's not really possible in my scenario. And can you guide my in how I can figure out which type of resistor to use? For this project I have been given plenty to choose from.

mawmaw
Posts: 5
Joined: Mon Oct 08, 2018 11:37 am

Re: Cannot detect sensor with i2c-gpio (i2cdetect -y 3)

Wed Oct 10, 2018 8:19 am

Otherwise, can you tell me if clock-stretching happens when the device is simply connected but not written to / read from? Or does it happen when actively 'used'?

lbdroidman
Posts: 13
Joined: Wed Oct 17, 2018 7:46 pm

Re: Cannot detect sensor with i2c-gpio (i2cdetect -y 3)

Thu Oct 18, 2018 7:08 pm

You don't *need* a breadboard, they're just nice for keeping your circuit organized, clean, and robust. You can certainly dangle components in a drunken spiderweb configuration, and it will still work if the connections are all correct.

What you will be looking for in a resistor, is a run of the mill "axial" resistor. This is the kind that is usually beige in color, has a wire lead sticking out both ends, and has multiple colored "bands" around it. A 4.7k resistor with 5% tolerance (means that the actual resistance will be within 5% of the nominal) will have stripes of these colors (in this and only this order): YELLOW, PURPLE, RED, GOLD
Yellow means "4" and in the 10's place
Purple means "7" and in the 1's place
(so YELLOW-PURPLE means "47")
Red means "x100"
Gold means 5%
There are color code calculators all over everywhere. Websites, applications on google play, etc.
Standard axial resistor will be 1/4 watt, it is way more than enough power for the job and is what I'd recommend. Bigger or smaller than that and the resistor body will also get bigger or smaller -- 1/4 watt resistors are an ideal physical size for hobbyist. Only go with 1/8 W if you are space constrained, and only go with 1/2+W if you need the higher power.

So you connect one of your resistors from 3V3 to SDA, and your second resistor from 3V3 to SCL. Then you connect your peripheral to all the same pins as you would have before, except that now you are driving some more current into the I2C pins.

Now about clock stretching... this is something done by the PERIPHERAL. Basically, if it needs to slow down the rate that data is being sent to it, it will hold the SCL pin at 0V until it is ready for more data. The consequence of this is, of course, that it makes that i2c bus inaccessible to ALL devices that are connected to it, which doesn't matter if there is only one device on the bus.

A very good device when you're running into issues with wire-level data, is a logic analyzer. Especially one with an ANALOG input capability. These will tell you what is *actually* going on, on the wires, so if you see the clock line being held LOW, you know that there is clock stretching going on (both lines will remain "high" while inactive). With analog capability, you will be able to see the *shape* of the curves, which will tell you if you need more or less pull-up current to match the bus. This would be *especially* useful for you, since you are using i2c-gpio instead of hardware i2c. That makes it especially important to know what is actually going on with the wire.

Unfortunately, I can't suggest what logic analyzer to get. I can tell you that Saleae makes *great* devices, but they're hella expensive -- $500 for their "entry level" unit now. I got a Logic 4 for $100, but they've since discontinued it.


Now looking at that module, there **IS AN ALTERNATIVE** to clock stretching i2c. And that alternative is using UART instead of i2c.

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