Will there be a 1-Wire library compatible with Spark Core?
I would like to connect one or more Dallas 18B20 temp sensors for example.
On Arduino, I have successfully used OneWire and DallasTemperature libraries.
Thanks,
Paul
Will there be a 1-Wire library compatible with Spark Core?
I would like to connect one or more Dallas 18B20 temp sensors for example.
On Arduino, I have successfully used OneWire and DallasTemperature libraries.
Thanks,
Paul
Hey @PaulRB - I’m not familiar with the OneWire and DallasTemperature libraries; they may need to be ported but they will probably work fine with the Spark Core with perhaps some minor adjustments to the code.
Hi @PaulRB
I’m a contributor to the brewpi project, currently built on arduino, using the OneWire And DallasTemperature libraries.
I too will be porting these to the spark once my units are shipped, so it would be great if we could collaborate on that.
I thought the spark could run Arduino sketches directly?
The Spark Core can run Arduino sketches out of the box. However, Arduino libraries are written to interface directly with the ATmega chip, and have to be ported over to the Core’s microcontroller (which is an STM32). We’re porting all of the standard Arduino libraries, but any third party libraries like OneWire would need to be ported as well.
Happy to colaberate, if I can!
Paul
I’ve just been looking at an alternative sensor, DHT11, a combined temp & humidity unit. It also has its own Arduino library.
Reading through the library code, the only functions it seems to use are pinMode (), digitalRead () and micros (). As long as those will all be available (and I think they will based on what Zach said) the library won’t need any porting effort at all. Hopefully many other libraries will be like that.
Yep those will all be available, so sounds like it should work right out of the box!
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.
I just wanted to post a follow-up that @tidwelltimj’s port works great for me! Thank you! Thank you! THANK YOU!
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!
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!