Piicodev TMP117 could not communicate

Hello,
I’m trying to connect a Piicodev TMP117 to a Pimoroni Automation 2040 W board. I am following your instructions at: PiicoDev Precision Temperature Sensor TMP117 - Raspberry Pi Pico Guide - Tutorial Australia . This includes copying the noted files and then running your main.py script.

When running main.py I get the error message “Piicodev could not communicate with module at address 0x48, check wiring. nan C”. The TMP117 green light is on. I’ve tried it using two different Qwiic cables (supplied by Core), plugging into either Qwicc jack on the A2040W and on the Piicodev. Also, when I run main.py the A2040W relay #1 switches on, it’s “NO” LED lights up and it’s “NC” LED blinks very briefly and rapidly.

ASW DIP switch 1 is on,all others off. Also, switched off all switches, then switch 1 on again.

The board is flashed with Pimoroni’s pimoroni-picow-v1.19.9-micropython.uf2. (I’ve run numerous Pimoroni script (blink, wireless, relays operation,etc. - with all working OK). Have also tried running your main.py after flashing the board with rp2-pico-20220618-v1.19.1.uf2. Get the same error message.

What should I do next?

2 Likes

Hi Pete,

Could you please post a link to the exact devbaord you are using?

It sounds like your board uses different pins to the default piicodev pins

When initialising the sensor use the following:

from machine import Pin
sda = Pin(4,Pin.OUT)
scl = Pin(5,Pin.OUT)
... = PiicoDev_TMP117(0,sda=sda, scl=scl)

There might be a couple of errors as I’m writing on this on my phone😁

3 Likes

Here ya go. Thanks.

1 Like

automation2040w_schematic.pdf (199.0 KB)

1 Like

To reinforce @Liam120347’s recommendation - the problem is due to default pin use.

When we designed PiicoDev we selected default I2C pins (sda=8, sck=9) based on the Pico datasheet.
The Pimoroni Automation 2040 W uses (sda=4, scl=5) and so these must be prescribed explicitly when initialising the temperature sensor.

Best of luck with your project! That looks like a great dev board for home automation projects :smiley: We’d love to see what you come up with

3 Likes

OK.
So in PiicoDev_Unified.py, line 51 change
self.i2c = I2C(0, scl=Pin(9), sda=Pin(8), freq=100000)
To
self.i2c = I2C(0, scl=Pin(5), sda=Pin(4), freq=100000)

Is that correct?
Is there any other lines of code / values that need to be changed in this file or the other two files (main.py or PiicoDev_TMP117.py)?

3 Likes

Hi Pete,

You shouldn’t need to modify the Piicodev Unified compatibility layer, simply declare the pins and put them in as arguments as suggested by Liam above:

from machine import Pin
sda = Pin(4,Pin.OUT)
scl = Pin(5,Pin.OUT)
tempSensor = PiicoDev_TMP117(0,sda=sda, scl=scl)

Please let us know if this doesn’t work, and we’ll test it out on the bench. I’ve used PiicoDev libraries with custom boards and different RP2040 pins with the code above, so this should be fine.
-James

1 Like

I’m still getting the error. This is what I have in main.py:

# PiicoDev TMP117 minimal example code
# This program reads the temperature from the PiicoDev TMP117 precision temperature sensor
# and displays the result in Degrees Celsius, Farenheit and Kelvin

from machine import Pin # added by Core Elec for Automation 2040 W pins
from PiicoDev_TMP117 import PiicoDev_TMP117
from PiicoDev_Unified import sleep_ms # cross-platform compatible sleep function


sda = Pin(4,Pin.OUT) # added by Core Elec for Automation 2040 W pins
scl = Pin(5,Pin.OUT) # added by Core Elec for Automation 2040 W pins
tempSensor = PiicoDev_TMP117(0,sda=sda, scl=scl) # added by Core Elec for compat with Automation 2040 W board
tempSensor = PiicoDev_TMP117() # initialise the sensor

while True:
    # Read and print the temperature in various units
    tempC = tempSensor.readTempC() # Celsius
    tempF = tempSensor.readTempF() # Farenheit
    tempK = tempSensor.readTempK() # Kelvin
    
    # Convert temperature into a string and print the data
    print(str(tempC) + " °C")
    
    sleep_ms(1000) # delay 1 second
1 Like

Hi Pete,

If you remove the line
tempSensor = PiicoDev_TMP117() # initialise the sensor it should work - if it doesn’t could you please send through a screenshot of the error and your code?

Here it is.

Interesting! Thanks for following us down the rabbit-hole @Pete56180

Time for a sanity-check!
Does the device respond on the I2C bus outside of any PiicoDev compatibility layers:
The following 3-line script is my go-to for checking for signs of life. It just uses native MicroPython.

Ensure only the temperature sensor is connected and run the following:

from machine import Pin, I2C
i2c = I2C(0, sda=Pin(5), scl=Pin(4), freq=100000) # initialise bus0, pins 5 & 4
print( i2c.scan() ) # scan for *any* i2c device.

the output in the shell should simply be the (decimal formatted) addresses of any connected I2C devices:

[72]

72 (decimal) is 0x48 (hex)

If it isn’t or there is no response at all we have other problems.

5 Likes

Got this:
Traceback (most recent call last):
File “”, line 2, in
ValueError: bad SCL pin

Aw shucks…

2 Likes

2 Likes

Gents,

I’ve tried your i2c scan code on another brand new / never used Automation 2040 W, Piicodev TMP117, and Qwiic cable.

Following Pimoroni’s instructions…
Powered up board w/ 12vdc power sup., power light comes on.
Flashed it with pimoroni-picow-v1.19.9-micropython.uf2
Did the pimoroni LED blink test. OK

Connected another new/unused PiicoDev TMP117 with new Qwiic cable.
Ran the Core Elec i2c scan code and got the error message:
“bad SCL pin”

1 Like

Hi Pete,

You’ve got SDA/SCL flipped:
Correct
image

Flipped
image

-James

2 Likes

I just saw that - it was what you sent over. Hey, I’ve made the same mistake many times…

After switching the pin numbers, Thonny does not return any value or text when I run it.

1 Like

I’ve been running that command set in the REPL and the behaviour is slightly different when run in a script (the REPL shows what is returned without a print() )

It seems that when run in script form, line 3 must instead be

print( i2c.scan() )

I’ve updated my previous reply to suit.

Here’s my printout for some other devices -

when no device is connected I see this

3 Likes

[72] on both boards.

1 Like

Just checked again. Same errors.

1 Like

I’ve just run an exhaustive test with a Pico W - running the Pico W port of micropython
Everything works as expected. I connected a temperature sensor in turn to every I2C bus option and was able to read data. Between each test I did find I had to power cycle my Pico, for it to work on the new pins - it seems that the hardware perihperials aren’t reset when the interpreter is restarted. Perhaps we can roll a deinitialise feature into PiicoDev in future though this is a bit of an edge case.

My test code

# PiicoDev TMP117 minimal example code
# This program reads the temperature from the PiicoDev TMP117 precision temperature sensor
# and displays the result in Degrees Celsius, Farenheit and Kelvin

from PiicoDev_TMP117 import PiicoDev_TMP117
from PiicoDev_Unified import sleep_ms # cross-platform compatible sleep function
from machine import Pin

### BUS 1
# tempSensor = PiicoDev_TMP117(1,sda=Pin(26), scl=Pin(27), freq=100000) # works

# tempSensor = PiicoDev_TMP117(1,sda=Pin(18), scl=Pin(19), freq=100000) # works

# tempSensor = PiicoDev_TMP117(1,sda=Pin(14), scl=Pin(15), freq=100000) # works

# tempSensor = PiicoDev_TMP117(1,sda=Pin(10), scl=Pin(11), freq=100000) # works

# tempSensor = PiicoDev_TMP117(1,sda=Pin(6), scl=Pin(7), freq=100000) # works

# tempSensor = PiicoDev_TMP117(1,sda=Pin(2), scl=Pin(3), freq=100000) # works


### BUS 0

# tempSensor = PiicoDev_TMP117(0,sda=Pin(8), scl=Pin(9), freq=100000) # works

tempSensor = PiicoDev_TMP117(0,sda=Pin(4), scl=Pin(5), freq=100000) # works

# tempSensor = PiicoDev_TMP117(0,sda=Pin(12), scl=Pin(13), freq=100000) # works

# tempSensor = PiicoDev_TMP117(0,sda=Pin(20), scl=Pin(21), freq=100000) # works

# tempSensor = PiicoDev_TMP117(0,sda=Pin(16), scl=Pin(17), freq=100000) # works


while True:
    # Read and print the temperature in various units
    tempC = tempSensor.readTempC() # Celsius

    
    # Convert temperature into a string and print the data
    print(str(tempC) + " °C")
    
    sleep_ms(1000) # delay 1 second

The question now is whether the Automation 2040 W Port of MicroPython deals with I2C in a different way. Since it’s a different port of MicroPython, it may well need special consideration in the compatibility layer PiicoDev_Unified.py.

This is getting into the heavy-lifting end of code development. You may find more success using vanilla MicroPython for this project, depending on your needs.

4 Likes