-
I'd like to read the temperature from my LoPy using a DS18B20 sensor. My problem is that this is a digital sensor using the 1-wire protocol, and as far as I can tell, there's no 1-wire library on the LoPy? Looking at the Micro Python documentation (https://docs.micropython.org/en/latest/esp8266/esp8266/tutorial/onewire.html) I see that they've got a onewire module, they've even got a ds18x20 module, but that's not available on my LoPy I think. I've been searching the Internet looking for a suitable 1-wire library, but so far without any luck. I can find some that require libusb or the like, but that won't work I assume.
Does anyone know how I should go about reading from a 1-wire sensor on a LoPy?
Best regards,
Mads -
Hi!
Following library:
https://forum.micropython.org/viewtopic.php?f=11&t=1000&hilit=onewire&start=10#p6255
works on Wipy 1.0, but only when you use a firmware without multithreading support:
https://forum.micropython.org/viewtopic.php?f=11&t=1000&start=30#p15187You could try to use the same library on Lopy. If it fails, let me know and I will try it on my Wipy 2.0 too.
Michal
-
Thanks for your answer.
I assume using that firmware will break the LoRa functionality? I also need LoRa ;-)
Best regards,
Mads -
@madsdk
I apologize if my previous post was confusing for you. The notice about firmware was just a warning, that later versions of Wipy 1.0 firmware don't work with onewire library. So I am not sure, whether this library will work on Lopy and Wipy 2.0 since their stock firmware has multithreading enabled from the beginning.Firmware for Wipy 1.0 is not compatible with Lopy or Wipy 2.0 (different MCU: CC33200 vs ESP32).
Michal
-
@michal Ah, ok. Thanks. I've just tested it on my LoPy and sadly it doesn't seem to work.
-
Hi all,
I'm connecting this probe on my WiPy 1.0, it's working with the official firmware, with multithreading support activated.
First I was also loading the not multhreaded firmware, but this morning I wanted to test the 1.8.6 firmware and with the onewire lib and this probe, it just works.
I was suprised, but it's cool :)
My connexions :
probe + on 3V3 pin
probe ground on ground pin
probe data on pin 10 -
@madsdk
I have tested the library on Wipy 2.0 and it works with stock firmware too. So it has to work on Lopy.My setup:
Wipy Sensor
3V3 -> red (VCC)
P23 -> yellow (DATA)
GND -> black (GND)
Pull-up resistor 4k7 is connected between VCC and DATA.
Sample code:>>> import onewire >>> from machine import Pin >>> ds = onewire.DS18X20(onewire.OneWire(Pin('P23'))) >>> print('devices:', ds.roms) devices: [bytearray(b'(\xff\xae8\x90\x15\x03T')] >>> print('temperatures:', ds.read_temps()) temperatures: [2525]Michal
-
@michal I have WiPy 2.0 and just upgraded firmware to release 0.9.5.b1. 'import onewire' does not work.
-
Never mind. Uploaded onewire.py to the WiPy 2.0. First got error about the last line that runs test. Commented that out and hooked two sensors up on P23. ds.roms call showed both. ds.read_temps also showed reasonable temps.
Nice!
-
@michal Thanks a lot for your answer. I just tried it once more. I have the same setup, except that I had connected the data line to pin 19, which didn't work. When I connect it to pin 23, like you've done, I suddenly get some data from the sensor. I don't think the data I get is correct, but at least I get some data :)
>>> test('P23') devices: [bytearray(b'(\xc5?6\x07\x00\x00\xba')] temperatures: [8500]Why does it work on pin 23 but not on pin 19? I'm fairly new to messing around with hardware on this level :-)
Best regards,
Mads -
Did anyone get it to work and where can i find the related modules? It seems that i need "onewire", "ds18x20" and "pyb". As pyb seem to be more common i can not find a version compatible to LoPy anywhere?
-
I have 3 DS18B20 sensors working with the WiPy 2.0 using the onewire.py module. I'm not sure of the differences between WiPy and LoPy, but it comes down to precision timing, on the order of 6 usec. The WiPy 2.0 (and 1.0) correctly detects the 3 sensors on a single GPIO port.
-
@acheesehead can you provide a link to the onewire, ds18x20 and pyb.py files?
-
While I've had success porting the prior micropython bitbanging onewire code (it was mostly changing the IO mode to open drain, and replacing pyb with machine), I just managed to wake up the RMT peripheral. It could conceivably run onewire with extremely precise timing without requiring much CPU. It should only require two RMT channels (one input, one output) mapped on the same GPIO, set to open drain. 6µs should be no problem at all considering I did 0.05µs for the WS2812 :)
The micropython onewire example code is at https://github.com/micropython/micropython/tree/master/drivers/onewire and my initial RMT access code is at https://github.com/lonetech/LoPy
By the way, I suspect the issue with P19 was the bug when accessing GPIO>=31. P19 is GPIO 32.
-
@LoneTech Would you mind sharing your port of the MicroPython library on the Lopy?It's too bad that this library is not portable across different MicroPython board...
Once I've confirmed that my DS18B20 works fine on the Lopy, I'll try to use the RMT instead of this bitbanging library :) -
@JF002 Sure. The patch and modules are in http://donkey.vernier.se/~yann/onewire.zip - sorry for taking so long.
-
@LoneTech have you got a working example with the Lopy/Wipy?
When I try to get it working on a Lopy I get a 'OneWire pin didn't go high' error when I run this piece of coded=DS18X20(Pin('G5')) -
I got it working now.
from machine import Pin from ds18x20 import DS18X20 d=DS18X20(Pin('G17', mode=Pin.OUT)) result=d.read_temps() print(result) -
@LoneTech Thank you! I'll give it a try as soon as I have time :)
-
@michal The temperature output(2525 = 25.25 degrees celsius) is as 4 digits output. The strange fact is that If I read the same sensor with raspberry pi or on Arduino I got the value as 5 digits. (eq 25437)
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login