geerlingguy / baby-safe-temp

Safe temperature monitor for baby's room. Made for Raspberry Pi Pico.
MIT License
74 stars 10 forks source link

Allow use of DS18B20 1-wire temperature sensor #1

Open geerlingguy opened 3 years ago

geerlingguy commented 3 years ago

In my initial design of this board, I wanted to use an external DS18B20 temperature sensor (either the little chip package or a waterproof probe) for more accuracy and better placement (the RP2040 chip is on the board, and could have temperature fluctuations based on the power supply and/or what's being processed).

However, when I tried to use the DS18B20 'hello world' micropython script as listed here (http://docs.micropython.org/en/v1.9.3/esp8266/esp8266/tutorial/onewire.html), I got the following error:

Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
ImportError: no module named 'onewire'

So it would be interesting to see what's required to get onewire support on the Pico; might be a missing feature for now.

geerlingguy commented 3 years ago

It looks like onewire support has been added to the official MicroPython firmware, so I should give it a try again...

kevinjwalters commented 3 years ago

BTW, where do your temperature constants come from in the celsius calculation?

https://github.com/geerlingguy/baby-safe-temp/blob/ff70a0fc5befbbd92d2d163fb4c7b2df1db9fe2f/main.py#L44-L45

Do those compensate for typical RP2040 self-heating to get an estimate of air temperature?

kevinjwalters commented 3 years ago

@tannewt has pointed out these come from the RP2040 datasheet. Section 4.9.4

gadjet commented 3 years ago

Just to let you know I got a DS18B20 working with the Pico by using the Circuitpython UF2 image instead of Myicrropython, Adafruit has lots of libraries for Circuitpython including Onewire and DS18X20 libraries that are copied onto the pico in the CIRCUIT/lib folder.

crzyhorse commented 3 years ago

BTW, where do your temperature constants come from in the celsius calculation?

https://github.com/geerlingguy/baby-safe-temp/blob/ff70a0fc5befbbd92d2d163fb4c7b2df1db9fe2f/main.py#L44-L45

Do those compensate for typical RP2040 self-heating to get an estimate of air temperature?

i would like to know this as well. did you calibrate this? i believe the pico would show higher than the room temp if you use the onboard temp sensor.

kevinjwalters commented 3 years ago

I never tried with RP2040 internal. I saw a few forum reports which suggest it varies, not sure if that is RP2040 variation or load (GPIO, both cores active??) related.

I've compared external sensors on Adafruit CLUE before: https://forums.adafruit.com/viewtopic.php?f=19&t=175494

There are lots of cheap options there that let you get away from thermal conduction on the board and you can place away from convection too. The analogue stuff requires a bit more finesse. I learnt the hard way that cheap jumper wires are sometimes not well made and high impedance outputs are a great and confusing way to highlight that!