ciao,
ho risolto con questo sketch:
*/
// TX---------------
#include <VirtualWire.h>
//________________Amp 1
#include "EmonLib.h" // Include Emon Library
EnergyMonitor emon1; // Create an instance
EnergyMonitor emon2; // Create an instance
EnergyMonitor emon3; // Create an instance
//_______________Amp 1
// LED's
const int ledPin = 13;
// Sensors
const int Sensor1Pin = A1;
const int Sensor2Pin = A2;
const int Sensor3Pin = A3;
int Sensor1Data;
int Sensor2Data;
int Sensor3Data;
char Sensor1CharMsg[4];
char Sensor2CharMsg[4];
char Sensor3CharMsg[4];
void setup() {
// PinModes
// LED
pinMode(ledPin,OUTPUT);
// Sensor(s)
pinMode(Sensor1Pin,INPUT);
pinMode(Sensor2Pin,INPUT);
pinMode(Sensor3Pin,INPUT);
//______________Amp 1
emon1.current(1, 111.1); // Current: input pin, calibration.
emon2.current(2, 111.1); // Current: input pin, calibration.
emon3.current(3, 111.1); // Current: input pin, calibration.
//______________Amp 1
// for debugging
Serial.begin(9600);
// VirtualWire setup
// Setup the transmitter
//------------------------------------------------------------
vw_set_tx_pin(6);
vw_setup(2000); // Bits per sec
}
void loop() {
{
//________________Amp 1
double IrmsL1 = emon1.calcIrms(1480); // Calculate Irms only
Serial.print(IrmsL1*230.0); // Apparent power
Serial.print(" ");
Serial.println(IrmsL1); // Irms
//_________________Amp 1
// Read and store Sensor 1 data
Sensor1Data = IrmsL1;
// Convert integer data to Char array directly
itoa(Sensor1Data,Sensor1CharMsg,10);
// DEBUG
Serial.print("Sensor1 Integer: ");
Serial.print(Sensor1Data);
Serial.print(" Sensor1 CharMsg: ");
Serial.print(Sensor1CharMsg);
Serial.println(" ");
delay(200);
// END DEBUG
digitalWrite(13, true); // Turn on a light to show transmitting
char buff[30]; //righe che mantengono i dati nelle stesse posizioni nell'LCD. Senza queste non sono mai allo stesso posto
sprintf(buff,"%c",255); //righe che mantengono i dati nelle stesse posizioni nell'LCD. Senza queste non sono mai allo stesso posto
const char *msg0 = buff; //righe che mantengono i dati nelle stesse posizioni nell'LCD. Senza queste non sono mai allo stesso posto
vw_send((uint8_t *)msg0, strlen(msg0)); // Send control character --- //righe che mantengono i dati nelle stesse posizioni nell'LCD. Senza queste non sono mai allo stesso posto
vw_wait_tx(); // Wait until the whole message is gone
vw_send((uint8_t *)Sensor1CharMsg, strlen(Sensor1CharMsg));
vw_wait_tx(); // Wait until the whole message is gone
sprintf(buff,"%c",223); // righe per simbolo Temperatura + uno spazio
const char *msg2 = buff; // righe per simbolo Temperatura + uno spazio
vw_send((uint8_t *)msg2, strlen(msg2)); // righe per simbolo Temperatura + uno spazio
vw_wait_tx(); // Wait until the whole message is gone
const char *msg5 = " "; // righe per simbolo %
vw_send((uint8_t *)msg5, strlen(msg5)); // righe per simbolo %
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13, false); // Turn off a light after transmission
delay(200);
} // END void loop 1...
{
//________________Amp 2
double IrmsL2 = emon2.calcIrms(1480); // Calculate Irms only
Serial.print(IrmsL2*230.0); // Apparent power
Serial.print(" ");
Serial.println(IrmsL2); // Irms
//_________________Amp 2
// Read and store Sensor 2 data
Sensor2Data = IrmsL2;
// Convert integer data to Char array directly
itoa(Sensor2Data,Sensor2CharMsg,10);
// DEBUG
Serial.print("Sensor2 Integer: ");
Serial.print(Sensor2Data);
Serial.print(" Sensor2 CharMsg: ");
Serial.print(Sensor2CharMsg);
Serial.println(" ");
delay(10);
// END DEBUG
digitalWrite(13, true); // Turn on a light to show transmitting
char buff[30]; //righe che mantengono i dati nelle stesse posizioni nell'LCD. Senza queste non sono mai allo stesso posto
sprintf(buff,"%c",223); //righe che mantengono i dati nelle stesse posizioni nell'LCD. Senza queste non sono mai allo stesso posto
const char *msg0 = buff; //righe che mantengono i dati nelle stesse posizioni nell'LCD. Senza queste non sono mai allo stesso posto
vw_send((uint8_t *)msg0, strlen(msg0)); // Send control character --- //righe che mantengono i dati nelle stesse posizioni nell'LCD. Senza queste non sono mai allo stesso posto
vw_wait_tx(); // Wait until the whole message is gone
vw_send((uint8_t *)Sensor2CharMsg, strlen(Sensor2CharMsg));
vw_wait_tx(); // Wait until the whole message is gone
sprintf(buff,"%c",223); // righe per simbolo Temperatura + uno spazio
const char *msg3 = buff; // righe per simbolo Temperatura + uno spazio
vw_send((uint8_t *)msg3, strlen(msg3)); // righe per simbolo Temperatura + uno spazio
vw_wait_tx(); // Wait until the whole message is gone
const char *msg5 = " "; // righe per simbolo %
vw_send((uint8_t *)msg5, strlen(msg5)); // righe per simbolo %
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13, false); // Turn off a light after transmission
delay(200);
} // END void loop 2...
{
//________________Amp 3
double IrmsL3 = emon3.calcIrms(1480); // Calculate Irms only
Serial.print(IrmsL3*230.0); // Apparent power
Serial.print(" ");
Serial.println(IrmsL3); // Irms
//_________________Amp 3
// Read and store Sensor 3 data
Sensor3Data = IrmsL3;
// Convert integer data to Char array directly
itoa(Sensor3Data,Sensor3CharMsg,10);
// DEBUG
Serial.print("Sensor3 Integer: ");
Serial.print(Sensor3Data);
Serial.print(" Sensor3 CharMsg: ");
Serial.print(Sensor3CharMsg);
Serial.println(" ");
delay(10);
// END DEBUG
digitalWrite(13, true); // Turn on a light to show transmitting
char buff[30]; //righe che mantengono i dati nelle stesse posizioni nell'LCD. Senza queste non sono mai allo stesso posto
sprintf(buff,"%c",223); //righe che mantengono i dati nelle stesse posizioni nell'LCD. Senza queste non sono mai allo stesso posto
const char *msg0 = buff; //righe che mantengono i dati nelle stesse posizioni nell'LCD. Senza queste non sono mai allo stesso posto
vw_send((uint8_t *)msg0, strlen(msg0)); // Send control character --- //righe che mantengono i dati nelle stesse posizioni nell'LCD. Senza queste non sono mai allo stesso posto
vw_wait_tx(); // Wait until the whole message is gone
vw_send((uint8_t *)Sensor3CharMsg, strlen(Sensor3CharMsg));
vw_wait_tx(); // Wait until the whole message is gone
sprintf(buff,"%c",223); // righe per simbolo Temperatura + uno spazio
const char *msg4 = buff; // righe per simbolo Temperatura + uno spazio
vw_send((uint8_t *)msg4, strlen(msg4)); // righe per simbolo Temperatura + uno spazio
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13, false); // Turn off a light after transmission
delay(200);
} // END void loop 3...
delay(1000);
}
// RX----------------------
#include <SerialLCD.h>
#include <SoftwareSerial.h>
SerialLCD slcd(9,10);
#include <VirtualWire.h>
#undef int
#undef abs
#undef double
#undef float
#undef round
void setup()
{
slcd.begin();
slcd.setCursor(0,0);
slcd.print(" L1 L2 L3");
Serial.begin(9600); // Debugging only
Serial.println("setup");
// Initialise the IO and ISR
vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000); // Bits per sec
vw_set_rx_pin(11);
vw_rx_start(); // Start the receiver PLL running
}
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) // Non-blocking
{ int i;
digitalWrite(13, true); // Flash a light to show received good message
Serial.print("Got: ");
// Message with a good checksum received, dump it.
for (i = 0; i < buflen; i++) {
if (buf[i]==255){ slcd.setCursor(0,1);
}
slcd.print(buf[i]);
}
}
}
L'unica cosa che non va molto bene è la visualizzazione nell'LCD in quanto prima e dopo i valori visualizzati, c'è il simbolo ° che non riesco ad eliminare. L'altro fastidio è che in base alle cifre visualizzate, i numeri cambiano un po' di posizione...
L1 L2 L3
xx° °xx° °xx°
Come posso fare per avere una visualizzazione più gradevole e stabile?
Penso che derivi dai vari:
sprintf(buff,"%c",255);
Ma che significa? come posso modificarlo?