gaute
New Member
Posts: 34
|
Post by gaute on May 11, 2016 22:19:44 GMT
Hi, I've been using computerist's code for quite some time now, and I'm very happy! One of the things that I've monitored is windows, doors, etc using a reed switch and a digital input on my arduino. It troubles me that I have to run one cabel for each window to a arduino, and it takes up so many ports. A few weeks ago I came across a onewire chip that might be a good solution. The chip is called DS2401, and it only sends out the ID, and no data. The idea is to connect it so the dataport goes into the reedswich, so when the reed is closed you send data, and when its open you do not. Much like this sketch docs.domogik.org/plugin/onewire/0.2/en/_images/ds2401.pngI'm using the Onewire libary from www.pjrc.com/teensy/td_libs_OneWire.html. To my question: As the Subject sais, I'm looking for a way to check if a sensor is present. If it is, I would like a boolean to be set to true, if not it should be false. I have tried different approaches, but no luck due to my poor programmingskills. Is there anyone who have a better skillset than me, that could help me with this? If so, I would be very happy! Thanks!
|
|
|
Post by rhyssman on May 12, 2016 5:39:05 GMT
Hi gaute I am currently using Onewire temperature sensors (DS18B20) on a bus to measure temperatures. I agree that the onewire system of programming is not straight forward for novices. I ended up using the Dallas temperature library which is linked from the guide you were reading. I found the functions easy to understand and interface with for novices like me. However at the expense of program memory. You may be able to use this library for your device either by butchering out what you need or only referencing the basics I currently use the isconnected function to search the bus for a known address which I have mapped in the initialisation code. This verifies the device is connected before I poll for a temperature. Have a look at the Multiple.ino example in the library. Are you expecting to have a large bus running around to multiple devices? I was a little worried about the bus length in my installation so I used Twisted Pair network cable with the data and ground on 1 pair and an external supply on another core. Hope you can have some success. Rhyssman
|
|
gaute
New Member
Posts: 34
|
Post by gaute on May 22, 2016 13:04:17 GMT
Thanks, Can you post an example of isConnected?
G
|
|
|
Post by rhyssman on May 23, 2016 6:39:27 GMT
Thanks, Can you post an example of isConnected? G Hi gaute See below example of how isConnected is used. #include <OneWire.h> #include <DallasTemperature.h>
#define ONE_WIRE_BUS 5
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) OneWire oneWire(ONE_WIRE_BUS); // Pass our oneWire reference to Dallas Temperature. DallasTemperature sensors(&oneWire);
// arrays to hold device addresses DeviceAddress Temp0 = { 0x28, 0x83, 0xDA, 0x1D, 0x7, 0x0, 0x0, 0xAD }; // Can be determined by plugging in sensor to one_wire_Address_finder example
void setup() { // Start up the library sensors.begin();
}
void loop() { // put your main code here, to run repeatedly: if (sensors.isConnected(Temp0)) { //Do your code here } delay(10000); } Regards Rhyssman
|
|
gaute
New Member
Posts: 34
|
Post by gaute on May 27, 2016 23:20:20 GMT
Hmm.. This does not solve the problem for me. Sadly the "isconnected" is only working for DallasTemperature supported sensors.
Does anyone else have any ideas?
G
|
|
redi
New Member
Posts: 3
|
Post by redi on May 28, 2016 4:40:37 GMT
Thank you for this post.
|
|