I’m at wit’s end trying to get my TCT40 sensors to function. I’m able to get them to initialize through the sparkfun multiplexer just fine (I have the buzzer, oled, tof devices working this way already) but when i try to read from them the function just hangs. I’ve tried both with additional power to the board and just powering via USB to watch via serial monitor.
I’m using Arduino Nano Wifi 1010, a Sparkfun Multiplexer, and two TCT40 sensors. Of course I’m wiring via I2C Qwiic and everything else seems to be working fine in the I2C bus. Just the whole sketch freezes up when I try to read. I’m going to try to run trigger/echo later today and remove the mux from the equation, but since I’m fully within the sparkfun world I expected this to work like all the other sensors I’ve had success with.
What else can I try here?
It sounds like you might be using some ‘blocking’ code (where one sensor’s read or write blocks the other from functioning)
Share your code and maybe that’ll shed some light on what might be going on (but my guess is you just need to isolate those reads)
Does one TCT40 work fine by itself?
Thanks, yes I was using blocking code, but the problem seems to be that these sensors don’t give a reading back. I have actually reverted back to just using the arduino examples which come with the library. Neither Example3_Trigger_Echo.ino nor Example1_BasicReadings.ino work at all.
I have also generated code that works low level just using Wire, and no matter what I do, I can’t get a distance reading from either of these sensors. I have also changed out the I2C wiring, switched from the I2C board connector in the arduino to the SCL/SDA pins directly. I even changed out the arduino board to see if it was a board problem.
I can hear the sensor “clicking” as it triggers, I just can’t get a reading back. I don’t see how it could be possible I got two bad sensors from Sparkfun, but I honestly don’t know what else I would even try at this point. I have a few HC-SR04s coming to see if it’s a sensor issue.
Also yes I have taken the multiplexer out of the loop and I am directly connecting a single sensor either via trigger/echo pads or i2c… and/or both.
1 Like
Ok and now the HC-SR04s arrived. Worked out of the box immediately. What is going on with these Sparkfun TCT40s?
Because of the freezing behavior you’re seeing, I wonder if the TCT40 is doing an infinite clock stretch. Could you try the following:
- Run example 1 again and wait for it to freeze. When it does, unplug the TCT40. Does it stay frozen, or continue running?
2. If it stays frozen, then there could be a bug in the library or something else.
3. If it continues running, then that’s evidence for clock stretching.
- Do you have a logic analyzer or oscilloscope you can connect to probe the I2C lines when it attempts to read? A trace would be helpful. If not, another thing to try would be measuring the voltage on the SDA and SCL pins when it freezes (another way to check for clock stretching.
1 Like
- Yes, if I unplug the code continues running and the library returns NA. It’s the same behavior as if I go low level to Wire… nothing comes back when I try to read.
- No I don’t have either of those tools at the moment.
Lets assume it’s clock stretching, what would I even do?
Sounds like an infinite clock stretch.
I suppose another option would be to use another Arduino board to measure the voltage with analog pin, though I’m pretty confident you’ll just measure 0V on SCL and 3.3V on SDA.
I would guess that your sensor is just defective, but the fact you have 2 exhibiting the same behavior would make that hypothesis unlikely (though not impossible).
Is the HC-SR04 a suitable replacement for the TCT40 for your project? If so, I would suggest using that instead, and RMA the TCT40s. Then we can take a deeper look at them to try and diagnose why they’re behaving like that.
@TS-Russell Can you please get an RMA set up for these 2 TCT40 sensors? @raceconditions I believe we’ll need your order number to get the RMA underway.
1 Like
Thanks for the help. I see the RMA as it looks like you found my order number. I’ll ship them back - I still really like the Sparkfun ecosystem and if you figure out what’s going on I’d be interested in them down the line. The HC-SR04s are functional enough, so I can do what I need, but was really excited for the TCT40 and the simplicity of the I2C wiring (wire management is important for my project).
1 Like
Great! Once we get them, we’ll do our best to figure out why they’re misbehaving 
1 Like