Multiple 1 Wire Bus on Digital Pin .... | Arduino | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
Multiple 1 Wire Bus on Digital Pin ....
No permission to create posts
June 30, 2016
2:38 am
Avatar
Smitty
New Member
Members
Forum Posts: 1
Member Since:
June 29, 2016
sp_UserOfflineSmall Offline

How best to achieve this ...

Not getting a successful compile from the below sketch ....

Very much a newb with ThingSpeak and Arduino ... 

/* Arduino Mega 2560 WiFi Weather Station

* July 2016 By John D Smith ZL4CO
* */

 

#include <Ethernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <ThingSpeak.h>

byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
// assign an IP address for the controller:
IPAddress ip(0.0.0.0);

// Initialize Arduino Ethernet Client
EthernetClient client;

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

// ThingSpeak Settings
unsigned long myChannelNumber = secret;
const char * myWriteAPIKey = "";

// There are currently 2 x Trial DS18B20 "1-Wire" digital Temperature sensors.

// 1 Wire Data wire is plugged into Digital pin 12 on the Arduino
#define ONE_WIRE_BUS 12

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

// Assign the addresses of the 1-Wire temp sensors.

DeviceAddress Temp1 = { 0x28, 0xFF, 0x7F, 0x71, 0x2C, 0x04, 0x00, 0x79 };
DeviceAddress Temp2 = { 0x28, 0xEC, 0xAB, 0x1E, 0x00, 0x00, 0x80, 0xA8 };

void setup(void)

{
// start serial port
Serial.begin(9600);
// Start up the library
sensors.begin();
// set the resolution to 10 bit (good enough?)
sensors.setResolution(Temp1, 10);
sensors.setResolution(Temp2, 10);

ThingSpeak.begin(client);
}

void printTemperature(DeviceAddress deviceAddress)
{

float tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00) {
Serial.print("Error getting temperature");
} else {
Serial.print("C: ");
Serial.print(tempC);
Serial.print(" F: ");
Serial.print(DallasTemperature::toFahrenheit(tempC));
}
}

void loop (void)
{
delay(10000);*/
Serial.print("Getting temperatures...

");
sensors.requestTemperatures();

Serial.print("Temp 1 is: ");
printTemperature(Temp1);
Serial.print("

");
Serial.print("Temp 2 is: ");
printTemperature(Temp2);
Serial.print("

");

Serial.print("

");

delay(200);
}

Cry
//Update the ThingSpeak Channel

float pinVoltage = sensors.(Temp1) ;
ThingSpeak.setField(1,pinVoltage);
pinVoltage = sensors.(Temp2)
ThingSpeak.setField(2,pinVoltage);

// Write the fields that you've set all at once.
ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);

Serial.print("Temperatures Uploaded to Cloud...

");
delay(80000);

It is in this part here I am not sure how to Access my Temp1 and Temp2 values for ThingSpeak

June 30, 2016
8:58 pm
Avatar
rw950431

Top
Members
Forum Posts: 262
Member Since:
January 30, 2014
sp_UserOfflineSmall Offline

For a start the Thingspeak section is outside the loop() so probably wont compile. Use the arduino IDE Tools->Format menu to nicely indent your code so its easy to pick these things up.

 

I suggest you work through some of the Examples that come with the Thingspeak library and go from there.

July 6, 2016
5:18 pm
Avatar
HydroponicsMAC

Silver
Members
Forum Posts: 8
Member Since:
June 26, 2016
sp_UserOfflineSmall Offline

Here's the code I'm using which is doing something similar.

#include "ThingSpeak.h"
unsigned long myChannelNumber = 123456789;
const char * myWriteAPIKey = "ABCDEFGHIJK";

#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; //DE:AD:BE:EF:FE:ED, Internal static IP is 192.168.0.52
EthernetClient client;

#include <OneWire.h>
#include <DallasTemperature.h>
OneWire oneWire(3);
DallasTemperature OneWire_Sensors(&oneWire);

#include "DHT.h"
#define PLANT_DHTPIN 2
#define DHTTYPE DHT11
DHT Plant_dht(PLANT_DHTPIN, DHTTYPE);

#define RAIN_SENSOR_DIGITAL 4

float fltEnviromentTemp = 0, fltPlantTemp = 0, fltReservoirTemp = 0;
int i, intPlantHumidity = 0, intSensorAlarm = 0, intRainAlarm = 0;
boolean blnRainAlarmNotified = false;

void setup() {
Serial.begin(9600);

pinMode(RAIN_SENSOR_DIGITAL, INPUT);

Serial.println(F("v." __DATE__ ", " __TIME__ "
"));

Serial.print(F("Starting network"));
Ethernet.begin(mac);

Serial.print(F(", ThingSpeak"));
ThingSpeak.begin(client);

Serial.println(F(" and sensors."));
OneWire_Sensors.begin();
Plant_dht.begin();
}

void loop() {
Serial.println(F("
Reading sensors"));

// Rain sensor
if (!(digitalRead(RAIN_SENSOR_DIGITAL))) {
Serial.println(F("WARNING: Rain detected, ALARM activated"));
intRainAlarm = 1;
blnRainAlarmNotified = true;
} else {
intRainAlarm = 0;
blnRainAlarmNotified = false;
}

//Onewire sensors
OneWire_Sensors.requestTemperatures();
fltEnviromentTemp = OneWire_Sensors.getTempCByIndex(0);
fltPlantTemp = OneWire_Sensors.getTempCByIndex(1);
fltReservoirTemp = OneWire_Sensors.getTempCByIndex(2);

//DHT11 sensor
intPlantHumidity = Plant_dht.readHumidity();

Serial.print(F("Environment = "));
Serial.print(fltEnviromentTemp);
Serial.println(F("*C"));
Serial.print(F("Plant = "));
Serial.print(fltPlantTemp);
Serial.println(F("*C"));
Serial.print(F("PlantHumidity="));
Serial.print(intPlantHumidity);
Serial.println(F("%"));
Serial.print(F("Reservoir = "));
Serial.print(fltReservoirTemp);
Serial.println(F("*C"));
Serial.print(F("RainAlarm = "));
Serial.println(intRainAlarm);

if ((fltEnviromentTemp == -127.00) || (fltPlantTemp == -127.00) || (fltReservoirTemp == -127.00) || isnan(intPlantHumidity) || (intPlantHumidity == 0))
{
Serial.println(F("WARNING: Sensor problem, ALARM activated"));
intSensorAlarm = 1;
} else {
Serial.println(F("Sensors are OK"));
intSensorAlarm = 0;
}

ThingSpeak.setField(1, fltEnviromentTemp);
ThingSpeak.setField(2, fltPlantTemp);
ThingSpeak.setField(3, intPlantHumidity);
ThingSpeak.setField(4, fltReservoirTemp);
ThingSpeak.setField(5, intRainAlarm);
ThingSpeak.setField(6, intSensorAlarm);

Serial.println(F("Updating ThingSpeak"));

ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey); // ThingSpeak only accept updates every 15 seconds

Serial.println(F("Finished updating"));

Serial.println(F("Sleeping for 15 minutes"));

for (i = 0; i < 45; i++) { //15 minutes = 45 * 20,000 = 900,000
delay(20000); //Wait 20 seconds
Serial.println(F("Checking for rain"));

if (!(digitalRead(RAIN_SENSOR_DIGITAL)))
{
Serial.println(F("WARNING: Rain detected, ALARM activated"));

if (blnRainAlarmNotified == false)
{
Serial.println(F("Updating ThingSpeak"));
ThingSpeak.writeField(myChannelNumber, 5, 1, myWriteAPIKey);
Serial.println(F("Finished updating"));

blnRainAlarmNotified = true;

} else {
Serial.println(F("Already updated ThingSpeak"));
}
}
}
}

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
18 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 261

Vinod: 196

piajola: 85

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

Newest Members:

MiguelWap, JamesdinnA, ScottTug, ThomasApesy, RicardoVeque, AlbertRop

Administrators: Hans: 387, lee: 457