Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making it simpler to use multiple OneWire buses with an arduino array #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion OneWire.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
/*
Copyright (c) 2007, Jim Studt (original old version - many contributors since)

Modifications by Prashant : An extra no arguments constructor to simplify
multiple OneWire buse use, allowing for easier construction of arrays of OneWire buses,
in the limited environment provided by Arduino.
See the Multibus_simple example illustrating a use-case of the extension.
Use in conjunction with my modification of the DallasTemperature library.

Version 2.3: Modifications by Norbert Truchsess, January 2013
add search_alarms() to find only devices in alarmed state.

Expand Down Expand Up @@ -122,7 +128,8 @@ sample code bearing this copyright.
#include "OneWire.h"


OneWire::OneWire(uint8_t pin)
OneWire::OneWire() {}
void OneWire::setPin(uint8_t pin)
{
pinMode(pin, INPUT);
bitmask = PIN_TO_BITMASK(pin);
Expand All @@ -132,6 +139,11 @@ OneWire::OneWire(uint8_t pin)
#endif
}

OneWire::OneWire(uint8_t pin)
{
setPin(pin);
}


// Perform the onewire reset function. We will wait up to 250uS for
// the bus to come high, if it doesn't then it is broken or shorted
Expand Down
2 changes: 2 additions & 0 deletions OneWire.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ class OneWire
#endif

public:
OneWire();
void setPin(uint8_t pin);
OneWire( uint8_t pin);

// Perform a 1-Wire reset cycle. Returns 1 if a device responds
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
Copyright (c) 2007, Jim Studt (original old version - many contributors since)

Modifications by Prashant : An extra no arguments constructor to simplify
multiple OneWire buse use, allowing for easier construction of arrays of OneWire buses,
in the limited environment provided by Arduino.
See the Multibus_simple example illustrating a use-case of the extension.
Use in conjunction with my modification of the DallasTemperature library.

Version 2.3: Modifications by Norbert Truchsess, January 2013
add search_alarms() to find only devices in alarmed state.

Expand Down
48 changes: 48 additions & 0 deletions examples/Multibus_simple/Multibus_simple.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include <OneWire.h>
#include <DallasTemperature.h>

int oneWirePins[]={3,7};//OneWire DS18x20 temperature sensors on these wires
const int oneWirePinsCount=sizeof(oneWirePins)/sizeof(int);

OneWire ds18x20[oneWirePinsCount];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line gives me this error:

Multibus_simple:8: error: no matching function for call to 'OneWire::OneWire()'
 OneWire ds18x20[oneWirePinsCount];
                                 ^

I guess because there is no constructor that takes an array as argument?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait, I got a bit confused there... This example is for the DallasTemperature.h lib... And is already merged there... However, since this change was never merged into this library, that example won't work with the official version of this library.

Another error I'm getting:

Multibus_simple:23: error: 'class OneWire' has no member named 'setPin'
     ds18x20[i].setPin(oneWirePins[i]);
                ^

DallasTemperature sensor[oneWirePinsCount];


void setup(void) {
// start serial port
Serial.begin(9600);
Serial.println("Dallas Temperature Multiple Bus Control Library Simple Demo");
Serial.print("============Ready with ");
Serial.print(oneWirePinsCount);
Serial.println(" Sensors================");

// Start up the library on all defined bus-wires
DeviceAddress deviceAddress;
for (int i=0; i<oneWirePinsCount; i++) {;
ds18x20[i].setPin(oneWirePins[i]);
sensor[i].setOneWire(&ds18x20[i]);
sensor[i].begin();
if (sensor[i].getAddress(deviceAddress, 0)) sensor[i].setResolution(deviceAddress, 12);
}

}

void loop(void) {
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
Serial.print("Requesting temperatures...");
for (int i=0; i<oneWirePinsCount; i++) {
sensor[i].requestTemperatures();
}
Serial.println("DONE");

delay(1000);
for (int i=0; i<oneWirePinsCount; i++) {
float temperature=sensor[i].getTempCByIndex(0);
Serial.print("Temperature for the sensor ");
Serial.print(i);
Serial.print(" is ");
Serial.println(temperature);
}
Serial.println();
}