Can I use 1-Wire devices with Spark Core?

These interfaces are sensitive to timing, so it might require some porting work. Happy to help out!

Would the OneWire library written for the Teensy 3.0 work on the Core? I’m pretty sure they both use the same architecture.

Might require some modification, but perhaps an easier port than porting from the original Arduino.

I have been able to (poorly) port the one wire library from here and I’ve successfully got it to compile in the spark cloud. I’ve been able to get the spark core to read the serial number and get the temperature from a DS18B20.
Here is the example code for that.

to get the library running on the spark core all I had to do is create functions that correspond to the DIRECT_WRITE and DIRECT_MODE #defines and then replace all uses of those defines with the functions I created.
but I’m not a programmer so although it works i have no idea if there is any unintended consequences of what I’ve done so use at your own risk. I copied the code from the digitalWrite and pinMode functions but without the safety checks to increase the speed.

hopefully someone with a little more experienced can properly port it and make it available as a #include in the spark cloud but for now this might be helpful to get a OneWire device working if you need to.

3 Likes

I just wanted to post a follow-up that @tidwelltimj’s port works great for me! Thank you! Thank you! THANK YOU! :smile:

Also, I’ve seen mention that a lower value resistor might be recommended for 3v3 instead of the 4.7k that is commonly used with 5v. The DS18B20 that I had readily available already had the 4.7k resistor already soldered on, and it seems like the temperature it’s reading is a little high (maybe by 5 degrees or so?). Hopefully, I can solder up a lower resistor on my extra DS18B20 tonight and post a follow-up.

Next up, however, is a DHT22!

3 Likes

that’s great to hear! @wgbartley I’m using a 4.7k resistor on it and its within a half degree (19.8 C vs 19.5 C) of one i have running right next to it that’s connected to a 5V uno w/ Ethernet shield. Of course they could both be wrong since I don’t have another thermometer handy. Since its digital I don’t think the input voltage matters as far as accuracy but a lower value resistor could help with the pull-up. But if the one-wire protocol is working then the pull up is working since the point of the resistor is to pull up the line when the pin is set to floating input mode.

Good call on the resistor. Both my thermistor and DS18B20 seem to read higher than the actual temperature in the house. It’s also possible that the temperature is that much warmer in the house considering it was in the 70s (Fahrenheit) outside (the average temp for 12/21 here is 51). Maybe I’ll dig up one of my real thermometers and double-check.

I’m getting nearly 96F degrees off of my DS18B20 on my Spark. My off-the-shelf thermometer has me sitting at 76.5F. Maybe I’ll solder on the lower resistor to my other DS18B20 and try it. I know the one I have now worked fine when connected to my Raspberry Pi, but I haven’t really touched it in a few months. I’ll update again when I can break out the soldering kit.

wow that is quite off, I’m a bit out of ideas except the normal stuff, check the raw bytes, new resistor, different controller, different sensor etc.

In theory that resistor value should not affect the temp reading from the sensor in the slightest. Its just a pull-up. 4.7K normal for 5V, something a little lower for 3.3V would be ideal, but the fact that you are able to communicate with the sensor at all means that resistor is basically OK. Could the sensor have been damaged e.g. by incorrect connection or high temp from soldering iron at some point in the past?

I’ve been playing with it some more tonight and now i’m using the example code that comes with the library. Here is the Spark Core version of that. it tests all of the features of the library, read, write, search and CRC check and all appears to be working fine. This is the output I’m getting with two temperature probes connected. I can try to move this into .h and .cpp files if anyone is interested.

About DHT22 ENERGIA library from the link below works with multiple microcontrollers:
TivaC / Stellaris Launchpad, msp430g2553 and MSP430F5529 launchpad.

No specific hardware dependencies, in the library be used digitalWrite, digitalRead and Millis().
Read the posts to set the delay and the size of the counter.
You can try! :smile:

1 Like

tidwelltimj, I cannot get your code to work. All it prints is “no more addresses”. I put a pull-up on the data pin but still no luck. I even changed the input to D4, again without luck. Any thoughts?

that sounds like its not pulling up correctly or the DS18B20 is responding at all. Can you get it to work with any other micro controller?

Good question. I’ll scope it and try it on an a 3.3V arduino to be sure.

Oh garsh, I’m embarassed :stuck_out_tongue: I was using Serial as the output instead of Serial1 and I missed one of the suckers and it basically hung the code. As soon as I fixed it, everything worked superbly.

Thanks!

2 Likes

no worries, happy to hear its working!

I am relatively new to SparkCore/Arduino but have used One-Wire library in an arduino project.

I would like to use it with Spark but have no idea of how to change it to a library file .h .cpp, have you managed it yet?

gorstj, Yes, I have it split up for an 18B02 temperature sensor demo I have on my web IDE. If you’re interested, I can put it up on my github. :smile:

someone has already posted it to Github, its here.