kinku
February 18, 2019, 7:11pm
1
I am trying to figure out what this means
essentially trying to reset DS18b20
#include <DHT.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// DS18B20 Data wire is plugged into pin 10 on the Arduino
#define ONE_WIRE_BUS 10
#define Relay 3 // Pin to Activate relay
#define LED 13 // Pin to show relay is on (blue)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);//https://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html
void setup() {
float getTemp(OneWire sensor) {
byte data[12];
byte addr[8];
if ( !sensor.search(addr)) {
sensor.reset_search();
return -1000;
}
if ( OneWire::crc8( addr, 7) != addr[7]) {
Serial.println("Bad CRC!");
return -1000;
}
if ( addr[0] != 0x10 && addr[0] != 0x28) {
Serial.print("Unknown device!");
return -1000;
}
sensor.reset();
sensor.select(addr);
sensor.write(0x44, 1);
byte present = sensor.reset();
sensor.select(addr);
sensor.write(0xBE);
for (int i = 0; i < 9; i++) {
data[i] = sensor.read();
}
sensor.reset_search();
byte MSB = data[1];
byte LSB = data[0];
float tempRead = ((MSB << 8) | LSB);
float TemperatureSum = tempRead / 16;
return TemperatureSum;
}
}
void loop() {
// put your main code here, to run repeatedly:
}
system
February 18, 2019, 7:15pm
2
I am trying to figure out what this means
What what means?
float getTemp;
void setup() {
float getTemp(OneWire sensor) {
You can't have a function (getTemp()) inside another function (setup()). You shouldn't have a function and a variable with the same name.
kinku
February 18, 2019, 7:31pm
3
Thanks Paul. Can you help me fix it?
I removed the float getTemp as it is a function.
But not sure about the second fix!
system
February 18, 2019, 8:09pm
4
But not sure about the second fix!
If you can't put a function inside another function, your ONLY choice is to define the function OUTSIDE of any other function.
It is critical that you recognize when a function starts, and when it ends.
Look at the blink example, for instance. Where can you define a function, blinker() that returns nothing? Show us where you think you can, by posting your best attempt.
kinku
February 18, 2019, 8:57pm
5
Like this
float getTemp(OneWire sensor) {
byte data[12];
byte addr[8];
}
void setup() {
if ( !sensor.search(addr)) {
sensor.reset_search();
return -1000;
}
if ( OneWire::crc8( addr, 7) != addr[7]) {
Serial.println("Bad CRC!");
return -1000;
}
if ( addr[0] != 0x10 && addr[0] != 0x28) {
Serial.print("Unknown device!");
return -1000;
}
sensor.reset();
sensor.select(addr);
sensor.write(0x44, 1);
byte present = sensor.reset();
sensor.select(addr);
sensor.write(0xBE);
for (int i = 0; i < 9; i++) {
data[i] = sensor.read();
}
sensor.reset_search();
byte MSB = data[1];
byte LSB = data[0];
float tempRead = ((MSB << 8) | LSB);
float TemperatureSum = tempRead / 16;
return TemperatureSum;
}
}
void loop() {
// put your main code here, to run repeatedly:
}
.Now it says 'sensor' was not declared in this scope . :o
Now it says 'sensor' was not declared in this scope
Well, it is telling the truth.
Where is sensor declared in your code ?
Shouldn't there be at least one library #included in your code ?
kinku
February 18, 2019, 9:13pm
7
Helibob ,please check the first code sequences.All sensors are defined there.
Now wondering sensor vs sensors make a difference.
but sensor.reset_search(); is not a valid one either
Now wondering sensor vs sensors make a difference.
Well, as sensor is not declared in the code but sensors is then do you think referring to an object named sensor is going to work ?
kinku
February 18, 2019, 10:30pm
9
Sensor is not working either.
Sensor is not working either.
Do you mean Sensor or sensor ?
Let's see some code
cherk
February 18, 2019, 10:33pm
11
kinku:
Helibob ,please check the first code sequences.All sensors are defined there.
Now wondering sensor vs sensors make a difference.
but sensor.reset_search(); is not a valid one either
DallasTemperature sensors(&oneWire); !! sensors.
kinku
February 18, 2019, 11:12pm
12
sensor helibob.
Cherk please explain a bit more!!!
Please post your code as it is now