Questions with regards to ESP8266 Basic and hardware interfacing and control via Basic commands

Moderator: Mmiscool

User avatar
By livetv
#48417 A little homework helps. I'm using the DS18B20 and currently operating under the latest Branch 2. Going through the datasheet answers some questions but brings up more questions about how the temp() function is written.

I could not get the DS18B20 to work in parasite mode which suggests that perhaps the temp() function is not written to do the strong pull-up needed in parasite mode. I am using the recommended 470k ohm resistor as a pull-up on the data line but an explicit strong pull-up is also needed during temperature conversion while in parasite mode. By powering the sensor, I got an 85 return value (instead of the -127 you get when the unit isn't working). Obviously this was not room temperature! 85 is the startup contents of the temperature buffer in the DS18B20 so I'm led to believe that the sensor logic is working and sending back data (I tried two of them with the same results). It seems that no temperature conversion is being done. This is supposed to be initiated by a command from the temp() function.

Unless I'm missing something in the documentation, the temp() function is the only onewire command or function. This suggests that the first time it is called (and possibly every time) it does a discovery to see how many devices are connected, gets their unique ROM codes, and builds a look-up table to associate them as devices 0 - n. It may or may not address each device by ROM code, initiate a temperature conversion, then read the temperature data.

My theories as to why this is not working are : 1. The sensors need configuration bytes sent and this is not happening. 2. The temperature conversion command is either not being sent or it is being sent using the wrong ROM code (this would be a bug). 3. As there doesn't seem to be a way to configure each OW device, it could be that the DS18B20 is configured differently than the temp function in expecting.

Has anybody gotten this to work?
Last edited by livetv on Wed Jun 01, 2016 11:35 pm, edited 1 time in total.
User avatar
By forlotto
#48430 Temperature Conversion like this?

Code: Select allT(°F) = T(°C) × 1.8 + 32


There are lots of examples and info in this thread:
viewtopic.php?f=41&t=6422

just remember po pwo etc... are used like so now:
Code: Select allio(po,0,2)

So if you are using old code for a framework it may not function as plain po 0 2 doesn't work anymore.

We surely need more in depth materials on temp sensors this I can agree on some good temp sensor documentation would be great.
I will try and do some reading as I get time this was my first spare minute tonight have a few more emails to check then bed for me but there is a good chance you may have an epiphany before I can get to the bottom of it and if you do it would be great to see a contribution in the way of good documentation for temp sensors if you have the free time.

In the mean time:

Calling all temp sensor guys
Please help this fella out got a good head on his shoulders just needs a little direction!

After looking another fella has had similar issues I think if I understand you correctly with temp sensor viewtopic.php?f=42&t=9742&p=48431#p48431

Dunno if this is something that may need to be fixed with an update possibly things are kinda messy right now the transition to 3.0 is going to provide a lot of solutions in the long run but their will be problems to iron out this may be one of them I am not sure to be honest. But rest assured we have a great community of folks in may take a while but I am almost certain a solution is likely on the horizon.

Have you tried the following:
Code: Select alllet cura=0
temp 0 cura
let curb=0
temp 1 curb
wprint cura
wprint curb


This fella seemed to have gotten things going fairly well it was a fairly newer version as well when I attempted to help him out.
viewtopic.php?f=45&t=9898#sthash.BcG6KHPl.dpuf
User avatar
By livetv
#48438 I figured it out! There's a bug in the temp() function.

When I use tmp = temp(0) I get either 85 or -127 depending on whether or not the 18B20 is connected right. The 85 means it is. However, when I use temp 0 tmp I get good temperature readings. The Branch 2 documentation claims the function equivalent works, but I think it is broken.

forlotto wrote:Temperature Conversion like this?

Code: Select allT(°F) = T(°C) × 1.8 + 32



No, by conversion, I was referring to the ADC conversion done in the 18B20. The whole transaction happens in a few steps (which varies a little depending on the number of devices connected) but I'll try to describe it as I think the temp command does it:

1. Query the devices on the onewire chain to get their ROM code (unique IDs) and build a 0-n device table. Not sure this happens, but as I connect and disconnect devices as the program runs, the table is updated, so it must be this way.
2. Send "reset" pulse.
3. Wait for any device to respond.
4. Send a "match ROM" command (55h) followed by ROM code of sensor to address (only it will respond).
5. Send "convert temperature" command (44h) to initiate ADC conversion in the sensor.
6. Send reset pulse.
7. Wait for any device to respond.
8. Send a "match ROM" command (55h) followed by ROM code of sensor to address.
9. Send a "read scratchpad" command (BEh).
10. Receive and decode data from sensor.

It appears that the temp() function is missing step 5 but I think an examination of the code will reveal the problem. My suggestion is to fix this in Branch 2 or at least document that it does not work and to check Branch 3 for the same error. Hopefully I'll be flashing a new ESP-12F with Branch 3 soon and I'll check it if nobody does before me.

About the hardware experiments:

1. I cannot get parasite mode to work so it looks like we get to run 3.3v to each sensor. Frankly, I like this better.
2. I tried 1, 2, and 3 sensors on the same data line. All work.
3. No pull-up resistor is needed for powered mode. Not even with 3 sensors.
4. I tried another sensor that is not a DS18B20 but claims to be compatible. It works.

Hookup is simple. Between the ESP and the DS18B20, run GND to GND, GPIO2 to DQ, and 3.3v to Vdd (these are pins 1 ,2, and 3 respectively on the DS18B20, left to right as you look at the flat side, pins down). To add more sensors, just run them in parallel. These sensors have very low current draw so you can add quite a few. I'd estimate you're ok for a couple dozen.

One last thing: I think it is problematic to have the sensors addressed by number (0-n) and not by ROM code. Although the numeric addressing seems to be consistent between reboots, in a remote setting where a sensor might be disabled (rat chews through a wire, etc) you could no longer count on the numbers matching the expected devices anymore. Having a function that returns a ROM code or a list of ROM codes would be helpful. That way, we could at least know the codes of the sensors we are using and address them positively that way. If a sensor disappears, it's no trouble. If a sensor needs to be changed out, the new one could be queried and registered in a flash variable so that the program does not have to change.
User avatar
By forlotto
#48597 hrmmm yes interesting indeed how does the address get set 0-n I almost wonder if the rom code may not have something to do with it if not then I estimate it is set on which sensor responds to reset the quickest possibly?

This could lead to a conflict if you have a couple of sensors the same length wire maybe?

Are you certain that the number it is addressed does not stay the same even if one were to drop out?

Interesting notes thanks for sharing!