#include <SPI.h>
#include "DHT.h"
#include <stdio.h>
#include <XBee.h>
#include <SoftwareSerial.h>
#define DHTTYPE DHT22
#define DHTPIN 5
// Define NewSoftSerial TX/RX pins
// Connect Arduino pin 8 to TX of usb-serial device
uint8_t ssRX = 1;
// Connect Arduino pin 9 to RX of usb-serial device
uint8_t ssTX = 0;
int sensorPin = A5;
int sensorValue = 0;
SoftwareSerial nss(ssRX, ssTX);
XBee xbee = XBee();
DHT dht(DHTPIN, DHTTYPE);
void setup(){
Serial.begin(9600);
xbee.setSerial(Serial);
dht.begin();
}
void loop() {
sensorValue = analogRead(sensorPin);
float h = dht.readHumidity();
float t = dht.readTemperature();
Serial.print(h);
Serial.print(" H ");
Serial.print(t);
Serial.print(" C ");
Serial.print(sensorValue);
Serial.print(" ppm ");
Serial.print("\n");
Serial.print("\r");
}
Questo è ciò che manda arduino uno al seriale del mega dove gira il programma che vi ho fatto vedere in precedenza.
E' corretto mandare i terminatori così in modo che poi il programma li interpreti come fine riga?
#include <SPI.h>
#include <Ethernet2.h>
#include <RCSwitch.h>
#include "DHT.h"
#include <stdio.h>
#define DHTTYPE DHT22
#define DHTPIN 5
RCSwitch mySwitch = RCSwitch();
DHT dht(DHTPIN, DHTTYPE);
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(192, 168, 1, 106);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
EthernetServer server(80);
//Sensori
char dato[255];
char d;
byte conta = 0;
const int value = mySwitch.getReceivedValue();
String readString; //stringhe
boolean ledon1 = false;
boolean ledon2 = false;
boolean ledon3 = false;
boolean ledon4 = false;
boolean ledon5 = false;
void setup() {
Serial.begin(9600);
Serial1.begin(9600);
dht.begin();
Ethernet.begin(mac, ip);
mySwitch.enableTransmit(31);
mySwitch.enableReceive(0);
}
void loop() {
if (Serial1.available()) {
while (Serial1.available())
{
d = Serial1.read();
Serial.write(d);
if ( d != '\n' ) {
if ( d != '\r' ) {
dato[conta] = d;
conta++;
}
}
}
}
Li dovrebbe ricevere quì giusto?