Znam da je ovo otislo malo van teme, izvinjavam se ali,
odustao sam od dugackih kablova za DS18B20.
Prelazim na serijsku komunikaciju izmedju dva arduina.
Dve blize sonde ostaju kod prvog arduina, a ove dve dalje idu na drugi arduino (nano, ili micro)
risiver:
Code:
// Example 5 - Receive with start- and end-markers combined with parsing
const byte numChars = 32;
char receivedChars[numChars];
char tempChars[numChars]; // temporary array for use when parsing
// variables to hold the parsed data
char Informacija[numChars] = {0};
float SpavacaTemp = 0.0;
float DecijaTemp = 0.0;
//float HodnikTemp = 0.0;
boolean newData = false;
int led = A1;
int temperatura = 5;
//============
void setup() {
Serial.begin(9600);
Serial.println("This demo expects 3 pieces of data - text, an integer and a floating point value");
Serial.println("Enter data in this style <HelloWorld, 12, 24.7> ");
pinMode (led, OUTPUT);
Serial.println();
pinMode (12, OUTPUT);
digitalWrite(12, LOW);
}
//============
void loop() {
recvWithStartEndMarkers();
if (newData == true)
{
strcpy(tempChars, receivedChars);
// this temporary copy is necessary to protect the original data
// because strtok() used in parseData() replaces the commas with \0
parseData();
showParsedData();
newData = false;
}
}
//============
void recvWithStartEndMarkers() {
static boolean recvInProgress = false;
static byte ndx = 0;
char startMarker = '<';
char endMarker = '>';
char rc;
while (Serial.available() > 0 && newData == false) {
rc = Serial.read();
if (recvInProgress == true) {
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
recvInProgress = false;
ndx = 0;
newData = true;
}
}
else if (rc == startMarker) {
recvInProgress = true;
}
}
}
//============
void parseData() { // split the data into its parts
char * strtokIndx; // this is used by strtok() as an index
strtokIndx = strtok(tempChars,","); // get the first part - the string
strcpy(Informacija, strtokIndx); // copy it to Informacija
strtokIndx = strtok(NULL, ",");
SpavacaTemp = atof(strtokIndx); // convert this part to a float
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
DecijaTemp = atof(strtokIndx); // convert this part to an integer
// strtokIndx = strtok(NULL, ",");
// HodnikTemp = atof(strtokIndx); // convert this part to a float
}
//============
void showParsedData() {
{if ((SpavacaTemp <temperatura) || (SpavacaTemp <temperatura))
{digitalWrite(led,HIGH);}
//else{digitalWrite(led,LOW);}
}
/*
Serial.println("");
Serial.println("INFORMACIJE SA SERIAL PORTA");
Serial.print("Informacija ");
Serial.println(Informacija);
Serial.print("Spavaca ");
Serial.println(SpavacaTemp);
Serial.print("Decija ");
Serial.println(DecijaTemp);
//Serial.print("Hodnik ");
// Serial.println(HodnikTemp);
Serial.println("");
Serial.println("");
*/
}
sender:
Code:
/*
korisceni pinovi:
pin 13 -
pin 12 -
pin 11 -
pin 10 -
pin 9 - OneWire DS18b20 sonda siva
pin 8 -
pin 7 -
pin 6 -
pin 5 -
pin 4 -
pin 3 -
pin 2 -
pin A5 - SCL LiquidCrystal_I2C zuta
pin A4 - SDA LiquidCrystal_I2C plava
pin A3 -
pin A2 -
pin A1 -
pin A0 -
*/
//koriscene biblioteke
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// pin na koji ulaze senzori
#define ONE_WIRE_BUS 9
OneWire oneWire(ONE_WIRE_BUS);
// koriscenje dallas-a i oneWire
DallasTemperature sensors(&oneWire);
//podesavanje LCD-a 16 slova x2 reda
LiquidCrystal_I2C lcd(0x27,16,2);
//---------------------------------------------------------------
void setup() {
//startuj serial port
Serial.begin(9600);
// startuj onewire biblioteku
sensors.begin();
lcd.init(); // analiziraj LCD
// Stampaj na LCD-u
lcd.backlight();
lcd.setCursor (3,0);
lcd.print("by bobahru");
lcd.setCursor (1,1);
lcd.print("064/412-68-66");
delay(10000); //zadrzavanje poruke pri paljenju
lcd.clear(); //ocisti LCD
}
//citanje temperature sa senzora i pretvaranje u vrednost
float sensorValue (byte deviceAddress[])
{
float tempC = sensors.getTempC (deviceAddress);
float temp = (DallasTemperature::toFahrenheit(tempC));
return temp;
delay(10000);
}
void loop() {
//sve vrednosti senzora
sensors.requestTemperatures();
//0,1,2,3 je broj senzora, pretvoriti u ime
float SpavacaSoba = (sensors.getTempCByIndex(0));
float DecijaSoba = (sensors.getTempCByIndex(1));
//float Hodnik = (sensors.getTempCByIndex(2));
// Serial.print("0123456789");
Serial.print ("<");
Serial.print ("s");
Serial.print (",");
Serial.print (SpavacaSoba);
Serial.print (",");
Serial.print (DecijaSoba);
//Serial.print (",");
//Serial.print (Hodnik);
Serial.print (">");
lcd.setCursor (0,0); //prvi red
lcd.print(" Spavaca:");
lcd.setCursor (10,0);
lcd.print (SpavacaSoba);
lcd.setCursor (0,1); //drugi red
lcd.print(" Decija:");
lcd.setCursor (10,1);
lcd.print (DecijaSoba);
delay(500);
}
Sve ce to moj prijatelj Milan da ti objasni on je kolektor.
Lektor Ziko,lektor.