[Solved] How to read internal temperature sensor of RP2040 in circuitpython

According to the datasheet, an RP2040 has an internal temperature sensor, measuring the temperature of the chip. How can one read this sensor of the Nano RP2040 using circuitpython?

Hello ck3951. I also wanted to know about this for quite some time. It seems Arduino Nano RP2040 Connect has 2 onboard temperature sensors, one from RP2040 that you described, and one other from its ST LSM6DSOXTR 6-axis IMU.

I did not find a way to access those yet :frowning:

The following script shows how to read the temperature of the IMU (as well):

import time
import board
from adafruit_lsm6ds.lsm6dsox import LSM6DSOX

i2c= board.I2C()
sensor= LSM6DSOX( i2c )

for i in range(10):
  print( 'Acceleration:  X:{:6.3f}, Y:{:6.3f}, Z:{:6.3f} [m/s^2]'.format(*sensor.acceleration) )
  print( 'Gyro        :  X:{:6.3f}, Y:{:6.3f}, Z:{:6.3f} [radian/s]'.format(*sensor.gyro) )
  print( 'Temperature :                        {:6.3f} [C]'.format(sensor.temperature) )
  time.sleep( 1 )

Thank you ck3951! This looks good for circuit python.
For Arduino language, which i prefer to use, It seems that we still can't do it using the official Arduino library sadly :frowning:

Does anybody know if we can suggest change to the Arduino Team and if yes, how? I find the github repository for this library, and would like to suggest this new functionality in order to be able to get temperature from the onboard LSM6DSOX of the Nano Connect. I don't think i can ask for this in the issue category.

It might be possible to use Adafruit LSM6DS library, but i would prefer to use an Arduino one :grinning_face_with_smiling_eyes:

To go back to your initial request, i also would like to know if there is a way of getting temperature directly from RP2040, on the Pico we can get it from the internal RP2040 A4, but looking at Nano Connect schematics it seems we can't access this pin

It's true that there are specific appropriate uses of the issue trackers in Arduino's GitHub repositories. However, those appropriate uses are both bug reports and feature requests. So you are welcome to submit a feature request for this. Just make sure to do a search of the issue tracker for existing requests for the same feature so you don't submit a duplicate. Check both the open and closed issues.

You can see a similar request for the Arduino_LSM6DS3 library here:

That's a different library, so the same request for the Arduino_LSM6DSOX would not be considered a duplicate, but I mention the Arduino_LSM6DS3 request because it is somewhat related to this subject and so might be interesting to you.

1 Like

Page 137 in PDF document entitled 'CircuitPython Documentation Release 7.0.0-alpha.6' contains the answer to my question. It is demonstrated in the script below:

import microcontroller

for attr in dir(microcontroller.cpu):
    if attr.startswith('_'):  continue
    print( '{:12s} : {}'.format(attr,getattr(microcontroller.cpu,attr)) )

The output of this script is:

frequency    : 125000000
reset_reason : microcontroller.ResetReason.UNKNOWN
temperature  : 24.7977
uid          : bytearray(b'P1P376\x00\x01')
voltage      : 3.3

Thus the temperature can be retrieved in circuitpython using property microcontroller.cpu.temperature.

1 Like

Congrats ck3951, looks like you have everything now!
I don't want to use CircuitPython, so i will have to wait for an Arduino library update.

Thank you pert for the information, i created an enhancement query here
If this end up being done, we will be able to access the embedded temperature sensor of the ST LSM6DSOXTR, which will add yet another feature to this board!

I wonder if there is a way to also access the internal cpu temperature sensor with an Arduino library :thinking:

Thanks! Thanks also for taking the time to link to it from the discussion here. I think that can be very helpful for the people who are interested in this subject by allowing them to easily access any valuable information that might evolve from the GitHub issue, which is not an uncommon occurrence.

@pert : the library sources has been updated soon after my query and it is now possible to retrieve the temperature, which is amazing! But there have been no new release of the library. So unless you manually retrieve the sources, and only use the Arduino IDE manager to get it, you won't have the last modification that includes the temperature, and still use release v1.0.0 :thinking:

The reference page is also not updated

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.