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.
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.
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)?
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:
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
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
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?
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:
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”
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
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.