nodemcu, esp8266, ds18s20 #5265
Replies: 1 comment
-
Posted at 2015-11-05 by @gfwilliams @Kolban does OneWire work on ESP8266? I thought I'd seen that someone had got it working? Have you tried a different pin? GPIO0 could be one of the pins that is used for something else. Posted at 2015-11-05 by hygy Yes. I tried other pins too. Posted at 2015-11-05 by hygy @Kolban there is no OneWire support yet in esp8266? Posted at 2015-11-05 by Ollie I had Onewire working fine on ESP8266 last week though I needed to add
before my code. I believe this is only while the ESP8266 port is in development, when complete this will be set off by default. Posted at 2015-11-05 by hygy Wow, i2c started to work. I can list the devices. But the values are wrong with ds18s20. Its always writes the same value: 10.6875 and it is not changing. :( How do I know when I can remove this line from the code? Posted at 2015-11-05 by Ollie
That's one for @Kolban I don't know - though I don't imagine leaving the code in will do any harm even when the default is set to false. Re your readings I got good readings on the ESP8266-1. Maybe try another temperature probe - I note you say DS18S20? I used the DS18B20. One thing I found useful was to mirror or replicate the setup on a Pico - especially since the DS18B20 wire colour coding seems to vary! Once I sussed the wiring on a Pico, I then knew what to expect on the ESP8266. Posted at 2015-11-05 by hygy The ds18b20 and s20 are differs for reading mode as I know. The wiring is good, couse I can read the onewire device id (if I connect more then one, then all the readings). Posted at 2015-11-05 by Kolban It is time to change the debugging to a default of "off". Sorry about that guys ... next set of builds will have debug off by default. Posted at 2015-11-05 by hygy @Kolban thanks. Can U check the ds18s20 problem too? Posted at 2015-11-05 by Kolban I'll be delighted to .... however it might be a few days (weekend likely) before I can get to it. Do you use the gitter stream in case I need to ask you some live questions? Posted at 2015-11-05 by hygy @Kolban If U give me a documentation where can U found this gitter stream, I use it then to help you. Its like google hangouts? Posted at 2015-11-05 by Ollie Espruino Gitter room here https://gitter.im/espruino/Espruino Posted at 2015-11-05 by hygy Thanks! I connected. Posted at 2015-11-06 by tve You may need a smaller pull-up resistor, maybe 2.2K. I tried a ds18b20 two days ago and it didn't work and I don't understand why, but it was working a couple of weeks ago. Maybe the logging is the issue, I didn't check that. Posted at 2015-11-06 by tve Forgot to add, looking at the DS18B20 module, the code does not wait for the temperature conversion to complete, so I think you will always get the old conversion. It's not a very good module, IMHO... Posted at 2015-11-06 by tve I made some fixes to the built-in OneWire module to support parasitically powered one-wire devices. The old code wasn't providing enough power to perform temperature conversions: a DS18B20 uses 1mA-1.5mA during conversion and that's not going to come through a 2.2K or 4.7KOhm pull-up resistor. This change would have no effect on powered 1-wire devices. There's also a bug in the DS18B20 JS module in that it doesn't wait for the conversion to finish. I'm pretty sure that the effect is that one gets the result of the previous conversion, which may be why people have not noticed. WRT the DS18S20 the temperature format is slightly different from the DS18B20, so some adaptation of the code is necessary. I believe that multiplying the result by 8 will so the trick, but I'm not sure. If anyone has trouble with parasitically powered DS18B20's and wants to try my esp8266-12 firmware let me know. I'll create a pull request for master in a few days as there are a few more improvements I'd like to make to the code. Posted at 2015-11-07 by @gfwilliams It'd be great if the OneWire changes could help with parasitically-powered devices... I did try at some point in the past and couldn't get it working... Do you have a Pico and/or original board you could test the changes out with? I guess it should be the same on your EMW port though. Yes, the DS18B20 module isn't great... Any idea how long the conversion takes? If it's anywhere near 1ms it should probably use a callback though. Posted at 2015-11-09 by hygy At the weekend I changed a little bit the ds18b20 code: Now it works for me with ds18s20 too, and it waits for 1 sec to a conversation and then calls a given callback. It's based on @tve modification.
Posted at 2015-11-09 by HubieKimber I want to know that if OneWire work with the ESP8266? As per my observation someone had got it working? Posted at 2016-01-14 by petrynchyn Here's my modified @hygy code. I set Timeout depending on Thermometer Resolution and Max Conversion Time. Tested on DS18B20 and ESP-12q. Can someone check and update code DS18B20.js ?
Posted at 2016-03-02 by Wilberforce Is there a way of making this backward compatible with the existing library? So instead of:
Will this work with older code:
So if the callback is missing, it will wait and return? Which leads to this question.. There is no versioning in modules, so if the library code was updated there is no easy way to tell if an update has been made. Would a simple 1.2 type version number in the module header suffice? Posted at 2016-03-02 by @gfwilliams Maybe... Busy-waiting is a really bad idea in Espruino though. The best bet would be to return the last temp reading if no callback was supplied (the current behaviour), and if there was a callback, to kick off a new reading, wait and return that. The code above waits 1 second for the callback - seems pretty extreme? I doubt many people would be happy with that. I'm still a bit confused here - does the existing DS18B20 library not work with ESP8266? My understanding was just that the current one was fine, but it just returned the previous reading (which means the first one returns 85 or something like that).
Well, there's GitHub's versioning? Each version of each module has a unique Git hash. I guess that could be added to each module in Then if you want to go back to a certain version, pull it straight off GitHub, eg:
Maybe. What do you expect to do with it though? Most people won't look at the module number until something goes wrong, and then it's too late. How would you then work back to find the older version? Posted at 2016-03-02 by hygy I modifed this code originally, couse the original is doesnot work with ds18s20 just with 18b20. Posted at 2016-03-02 by Wilberforce @gfwilliams
a. Yes - the code works on the ESP8266 b. Add support ds18s20 as well as ds18s20
c. Callback
The time it takes for a conversion depends on the resolution and if parasitic mode mode is in use. d. One of the issues with the original code is that the initial reading is bogus. The device returns all 111111's, and this turns out to be a value of 85c. For the next call, the real value is in place as the conversion is done. There is no way of knowing if this is a 'real' 85c or the bogus first value One solution would be to return e. The original code has So existing code that use getTemp with verify used would fails as the first param is now a callback. f. versioning Posted at 2016-03-02 by Ollie
Ignore first reading since it's always 85C, and report from the next? Assuming you're capturing at intervals a counter var is all needed. Workaround, but works fine for me. Posted at 2016-03-03 by @gfwilliams I think the DS18B20 module is used a lot, so I'd be against changing something that broke it. Having said that, I doubt many people are using 'verify' so I'm not convinced about returning To help with that, kicking off a conversion in the constructor sounds like a good plan though.
The comment in them would have to show the git hash of the repo at the commit they were made I think.
Yeah, it makes sense - I think in Espruino's case there's not as much need for it as in something like NPM though. Generally modules are relatively simple and don't change that much once they're written. The current solution is definitely not perfect, but adding NPM style version control (and A bit off topic, but my personal gripe with NPM/Node.js is that because there is a good versioning system, it seems to give people an excuse to make changes to the API all the time. As a result, if you don't have a Posted at 2016-03-03 by @gfwilliams I'm looking at this now... Does anyone actually use I'd imagine that if the device got removed there would be some OneWire error anyway, which could be dealt with. Posted at 2016-03-03 by @gfwilliams Ok, I've just updated the module. Please could someone try:
And see if it works on DS18S20 as well? I hopefully tidied it up a lot so it uses OneWire a bit more efficiently. It also checks the CRC now, so Personally I'd be tempted to remove Posted at 2016-03-03 by Wilberforce works for me with DS18B20 devices - had to add for the esp8266: or my case change to D5: ( wired to different pin)
I'll test the callback soon, and have some questions on how this will work multiple sensors. Can we start a conversion on all sensors, and then have a callback with all temps? I'm not sure if the current callback identifies the device, I'll set up some test cases. Posted at 2016-03-04 by Wilberforce The callback needs some sort of identifier, as you can't assume the order of the readings in the callbacks. I have two sensors connected:
There are a couple of options:
or probably most flexible:
Posted at 2016-03-04 by Wilberforce
This could be done automagically in the constructor here:
Posted at 2016-03-04 by Wilberforce or not ;-( After re-powering the board, the sensors reverted to the 85C state:
I guess if you executed other code before the first actual call to getTemp() this would work out ok.... By setting the mode to 9 bit so the conversion is shorter:
Posted at 2016-03-04 by @gfwilliams @wilberforce I think it's best not to worry about the initial value - people have been using this DS18B20 module for years and are happy to just put up with it. Producing a good first value half the time is worse than never doing it :)
I don't think so... It's another request over OneWire and more calculation that will never be used most of the time...
I don't think so - you can easily re-write your code:
And there are plenty of other ways to do this that don't require changes in the module. Posted at 2016-03-04 by Wilberforce Thanks Gordon. Here is the code modified to save the results to an array, updating every 1/2 sec and displaying every sec:
Posted at 2016-03-07 by Artyom Messing around with this sketch and nodemcu amica board. Spent a lot of time on debug and finally got the issue, nodemcu pinout didn't match esp8266 mounted on it (for example D2(esp) => D4(amica)). Posted at 2016-03-07 by @gfwilliams Try using Posted at 2016-03-07 by Artyom @gfwilliams thank you! It works. I'm so happy I found espruino, I really like it! Thank you! Is there any way to store short data counters using inner memory? Posted at 2016-03-07 by @gfwilliams Yes, ESP8266 should now be in the main repo - @tve is probably still doing some development in his, but he generally syncs everything up with the main repo. FlashEEPROM does work, but you have to manually specify an address for it. You should be able to use: http://www.espruino.com/Reference#l_ESP8266_getFreeFlash to find one. It's something that'll hopefully change soon - we'll add a function to get free flash pages that works on all platforms. Posted at 2016-03-07 by Artyom @gfwilliams getFreeFlash() will calculate a next free address or returns user flash area of specific platform? I'm trying to get if it returns same results on each run or increasing address depending on usage? Sorry for lame questions I'm noob here. Posted at 2016-03-07 by @gfwilliams It just returns the addresses of unused areas of flash memory - they're the same each time, so you can just do Posted at 2016-03-08 by Artyom @gfwilliams it works but property called area not addr, and it bricked nodemcu with [0], won't boot on the next run and after reflashing. I've manage to fix it by flashing blank512kb.bin twice. Posted at 2016-03-08 by @gfwilliams Wow, that's not good. @tve? Maybe we could put the pages in a different order? I noticed yesterday about the odd naming - it didn't match the docs either. I've now fixed it though, so 1v86 will be better when it is released (and FlashEEPROM should work automatically) Posted at 2016-03-08 by Wilberforce The areas [0] and [1] are tiny from memory. I have used the area[2] but I think that is only 3 pages of 4096 bytes long. Posted at 2016-03-08 by Wilberforce There is a 16kb block here if you have > 512 kb device - There is some conversation around this on gitter |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2015-11-05 by hygy
Hi,
I'm trying to wire up a nodemcu with ds18s20, but it is not found the sensor. DS18S20 is connected to 3.3V and GND between the 3.3V and DATA line I connected a 4k7 resistor. Data line connected to ~D3 port (pin0).
What i'm doing wrong?
I'm getting null for sensor.getTemp();
thanks,
HyGy
Beta Was this translation helpful? Give feedback.
All reactions