microbit-foundation / micropython-microbit-v2

Temporary home for MicroPython for micro:bit v2 as we stablise it before pushing upstream
MIT License
41 stars 22 forks source link

micro:bit v2 MICROPYTHON onewire DB18B20 waterproof temp sensor #162

Open burksfamly opened 7 months ago

burksfamly commented 7 months ago

I need micro:bit v2 micropython .py library files for the onewire protocol and DS18B20 driver for a waterproof temp sensor. Research has been frustrating. Has anyone ported this yet.

I took a look at PyCom. Looks good if I could get enough info on micro:bit v2 micropython implementation. For example need to deal with removing from machine import Pin with from microbit import pin1...and then deal wirh the equivalwnt OPEN_DRAIN pin mode using pin1...without a map of rhe micro:bit v2 micropython environment...this will be trial and error, and I am alreadg in too many rabbit holes on this project. I DO NOT want to go back to the TMP36 because it requires a constant reference voltage. If you use your battery or battery points, temp readings change as the battery drains, and adding constant refererence voltage circuit is battery expensive

Any sources for the afforementioned files?

Thank You

martinwork commented 7 months ago

Thanks to @rhubarbdog: https://github.com/rhubarbdog/microbit-ds18b20

rhubarbdog commented 7 months ago

The code doesn't work. It requires an oscilloscope to get the timings correct. The big number in the sleep sub routine (register 7) needs to be reduced and possibly also the number of register 0 needs to be reduced before calling the sleep sub routine

martinwork commented 7 months ago

Thanks for letting us know @rhubarbdog

dpgeorge commented 7 months ago

MicroPython does have a built-in onewire module and drivers for the ds18x20. But the onewire module is not enabled on the micro:bit and needs to be compiled into the firmware to work.

burksfamly commented 7 months ago

Damien, Thank you. Why was it 'turned off'? What would be required to get a micro:bit version of the micropython image onto the micro:bit. Will that cause problems with other services and hardware assumptions? Maybe you could help with the actual dilemma I am having. I need a reliable temperature sensor for the micro:bit for HVAC supply and return temperatures as well as a waterproof implementation for aquariums. This sensor must be used on a battery powered micro:bit using micropython. I had used the TMP36 sensor, but this requires a constant reference voltage, of which the micro:bit does not supply (without modification). So, when the TMP36 is used the temperature changes during battery drain based on the manner in which the analog reading is converted to temperature. This is why I was exploring the use of the DS18B20 waterproof temperature probe which uses the onewire protocol and the DS18X20 driver unavailable in micropython for micro:bit. So...I am in a catch 22. I either need a simple way to use the DS18B20 or a method to get a constant 3vdc reference voltage from the micro:bit to drive the TMP36 temperature sensor to get reasonably accurate temperature readings. Any thoughts on your experience with this would be greatly appreciated. I could use another micro:controller IF I could find one that is compatible with the micro:bit micropython radio communications protocol, of which I have not yet been able to find. In other words, I have not found another microcontroller configuration that will allow me to communicate via radio with the micro:bit v2 micropython environment. Best,Randy

On Sunday, November 12, 2023 at 10:24:55 PM EST, Damien George ***@***.***> wrote:  

MicroPython does have a built-in onewire module and drivers for the ds18x20. But the onewire module is not enabled on the micro:bit and needs to be compiled into the firmware to work.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

dpgeorge commented 6 months ago

Why was it 'turned off'?

Well, more so it was never turned on. Micro:bit v1 didn't have it and neither does v2.

To enable it and get the DS18x20 driver working requires a bit of work:

Then, the ds18x20.py driver in micropython-lib will work.

leomlr commented 4 months ago

Hi,

We look forward to being able to program the ds18b20 with micro:bit with either solution. While waiting for these updates, thank you Damien George and Phil Hal.

Best regards, Léo