1-Wire Bus Question, Regarding Multiple Devices Code from Tutorial

Edit – I spent the day making sure I have the DS18b20 circuit right. Pretty sure I have it. Have used these before. This is a log report from the April reading 2 thermistors (sense pins 2/8 and anything present on UART57), device #/count on UART57 varies as I plug/unplug individual maxim chips from the 1-wire bus (breadboard)…but device log always lists all UART devices as all same temp and serial number, yet with differing “device id”. I would post the code for reading the ds18b20’s but, to spare you, it’s the same code as in the tutorial (“multiple devices” code, see link in post below). I did add the sleep every minute part, and some code to send to xively by device id, but that’s about it.

2014-05-10 23:50:02 UTC-4 [Device] -----START of Code----------------------------------------------------
2014-05-10 23:50:02 UTC-4 [Device] SSID:netgear432 MAC Address:0c2a69000a72 BSSID:d850e6af798c
2014-05-10 23:50:02 UTC-4 [Device] Power Save:true Wake Interval:1(mins) Unique ID:23625f4cead3dbee
2014-05-10 23:50:02 UTC-4 [Device] Signal Strength: -72dBm (4 bars - Comment: Wow, Not Bad at All)
2014-05-10 23:50:02 UTC-4 [Device] firmware: af0f28a - release-27.10 - Fri Dec 13 11:08:38 2013
2014-05-10 23:50:03 UTC-4 [Device] UART57 Device: 01 Family: 28 Serial: 000005440bf0 Temp: 72.95
2014-05-10 23:50:03 UTC-4 [Device] UART57 Device: 02 Family: 28 Serial: 000005440bf0 Temp: 72.95
2014-05-10 23:50:03 UTC-4 [Device] UART57 Device: 03 Family: 28 Serial: 000005440bf0 Temp: 72.95
2014-05-10 23:50:03 UTC-4 [Device] UART57 Device: 04 Family: 28 Serial: 000005440bf0 Temp: 72.95
2014-05-10 23:50:03 UTC-4 [Device] Thermistor (Sense Pin 2) Temp (F):73.62
2014-05-10 23:50:03 UTC-4 [Device] Thermistor (Sense Pin 8) Temp (F):73.25
2014-05-10 23:50:03 UTC-4 [Device] sleeping until 1399780261000
2014-05-10 23:50:03 UTC-4 [Status] Device disconnected; 1600 bytes sent, 0 received, 1600 total
2014-05-10 23:50:03 UTC-4 [Agent] maximtemp_0 Posted to Xively:72.95, return code:200, msg:
2014-05-10 23:50:04 UTC-4 [Agent] maximtemp_1 Posted to Xively:72.95, return code:200, msg:
2014-05-10 23:50:04 UTC-4 [Agent] maximtemp_2 Posted to Xively:72.95, return code:200, msg:
2014-05-10 23:50:05 UTC-4 [Agent] maximtemp_3 Posted to Xively:72.95, return code:200, msg:
2014-05-10 23:50:05 UTC-4 [Agent] Thermistor_Pin2 Posted to Xively:73.62, return code:200, msg:
2014-05-10 23:50:05 UTC-4 [Agent] Thermistor_Pin8 Posted to Xively:73.25, return code:200, msg:

I want to thank @smittytone @theo and anyone else responsible for the recent 1-wire tutorial placed at the Dev Center.

I was up and reading DS18B20’s in no time. It was amazing.

However, I’m having trouble with the “Multiple Devices” code. I think the BUS recognizes when I have multiple devices plugged-in, but posts them in the log as the same serial number and temp. See attached picture. Could it be I’m not understanding how to wire multiple devices on the breadboard? I can post how I’m wiring this if it helps?

Anyway, I guess my question is if any one else has had luck with the multiple devices code (and reading multiple DS18B20’s) in the tutorial? If so, that would confirm that the problem is on my end…and that I need to think a little harder about this circuit (and understand it better).

Hi, @solarishot. I think the error lies in my code: instead of writing x IDs to the array, it’s writing the same one four times. I’ll take a look.

In the meantime, you might want to try @theo’s code here (just over half way down the page). My code gets all the IDs, saves them and accesses them later; @theo’s code gets the IDs fresh each time it takes the temperature. It’d be interesting to compare what you with his code and what you get from mine.

Edit–How many 1-Wire devices do you have on the bus, and are these separate from what you have on uart57?

@ smittytone - thanks! I will give the other code a try. I started reading the thread you pointed to so it has time to sink in. If you happen to make a change to your code soon, could you drop a note on this thread to make sure I catch it?

I’m not sure how to answer your “edit” question. The log report I included above was from when I had 4 maxim sensors in the breadboard at the time. If I take one out, 3 devices are shown in the log. If I remove another, 2. And so on. I think you are right that multiple devices are recognized by your code, but not individually listed.

No, the maxim devices (all 4) are not separate from UART57. All are on the same two pins, 5 and 7. Was that your question?

On different pins I have thermistors. I have been working on a custom pcb with screw terminals for thermistors, but when I saw your tutorial I decided to put a screw terminal block on the board for a 1-wire bus, too.

Thanks for the update, @solarishot. What was worrying me was that two devices were being each read twice, but it’s good to see that four devices are being correctly detected, but only one is being recorded.

As a test, you may want to try the following code in place of the current one_wire_search() function:

`function one_wire_slaves()
id <- [0,0,0,0,0,0,0,0];
next_device <- 65;

    next_device = one_wire_search(next_device);
    slaves.push(clone(id));   // THIS IS THE ONLY CHANGE


I haven’t yet tried this myself, but I think it will ensure all the device IDs are added to the slaves array, not just the first or last.

And yes, just as soon as we have a solution, I’ll post it here.




I only had a minute to try this before work, but it looks to have solved the problem. I now have 4 maxim chips in log, each have different ID’s now and different (varying) temps.

Just to be sure, I will test better when home later tonight.

For now, Thanks!!! More soon.

That’s good to hear. Thanks for trying it out.

I can confirm my tweak works for me too. I’ll revise the code for the article. Thanks for spotting the error, @solarishot.

No problem @smittytone, it’s me who should be thanking you. The work people like you do to support people like me is amazing. I can’t say enough good things about the electric imp team and the dedicated followers.

Thanks again!

The tutorial is great. I may switch from using thermistors to the ruggedized DS18b20 for our applications. The sample circuit shows a 1n5815 Schottky diode. I’m having a bit of a problem locating those (at least in small qty). Is a 1n5817 a suitable substitute or do you recommend something else? I’m guessing I would attempt the DS2482 in the near future to enable me to have longer wire runs without issues. It appears that should be an easy implementation–right?

Thanks for a great tutorial and all the support!

Hmm, the 1n5815 seems a bit rare (and, huge looking at the few datasheets I could see). @smittytone was this really the one you used?

The main thing here is it being a shottky, or ~0.4v forward voltage drop at low current vs 0.7v on a normal diode. Details beyond that are mostly immaterial.

I have been using this without problem.

Specs say its a 1n5817, 1n5818 or 1n5819.

@Hugo, @ctmorrisonhvacsp - I use this one, which on closer inspection is the SparkFun product that @solarishot mentioned: http://proto-pic.co.uk/schottky-diode/

I don’t have it in front of me now, but IIRC it was the 1n5819. To my eyes (I’m not an electronics engineer), there’s not much difference between the 17, 18 and 19 for this application.