I found the error.
I forget (in the fact I don´t know why is necessary) add two lines in void loop:
DateTime now = rtc.now();
printDate(now);
now works well: CT1-2-3, temperature and clock.
The complete code is:
/*
EmonTx Shield 4 x CT example
An example sketch for the emontx Arduino shield module for
CT only electricity monitoring.
Part of the openenergymonitor.org project
Licence: GNU GPL V3
Authors: Glyn Hudson, Trystan Lea
Builds upon JeeLabs RF12 library and Arduino
emonTx documentation: http://openenergymonitor.org/emon/modules/emontxshield/
emonTx firmware code explination: http://openenergymonitor.org/emon/modules/emontx/firmware
emonTx calibration instructions: http://openenergymonitor.org/emon/modules/emontx/firmware/calibration
THIS SKETCH REQUIRES:
Libraries in the standard arduino libraries folder:
- JeeLib https://github.com/jcw/jeelib
- EmonLib https://github.com/openenergymonitor/EmonLib.git
Other files in project directory (should appear in the arduino tabs above)
- emontx_lib.ino
*/
/*Recommended node ID allocation
------------------------------------------------------------------------------------------------------------
-ID- -Node Type-
0 - Special allocation in JeeLib RFM12 driver - reserved for OOK use
1-4 - Control nodes
5-10 - Energy monitoring nodes
11-14 --Un-assigned --
15-16 - Base Station & logging nodes
17-30 - Environmental sensing nodes (temperature humidity etc.)
31 - Special allocation in JeeLib RFM12 driver - Node31 can communicate with nodes on any network group
-------------------------------------------------------------------------------------------------------------
*/
#define FILTERSETTLETIME 5000 // Time (ms) to allow the filters to settle before sending data
const int CT1 = 1;
const int CT2 = 1; // Set to 0 to disable
const int CT3 = 1;
//const int CT4 = 0;
#define RF_freq RF12_433MHZ // Frequency of RF12B module can be RF12_433MHZ, RF12_868MHZ or RF12_915MHZ. You should use the one matching the module you have.
//const int nodeID = 6; // emonTx RFM12B node ID
const int nodeID = 17; // emonTx RFM12B node ID
const int networkGroup = 210; // emonTx RFM12B wireless network group - needs to be same as emonBase and emonGLCD
#define RF69_COMPAT 1 // set to 1 to use RFM69CW
#include <JeeLib.h> // make sure V12 (latest) is used if using RFM69CW
#include "EmonLib.h"
//EnergyMonitor ct1,ct2,ct3,ct4; // Create instances for each CT channel
EnergyMonitor ct1,ct2,ct3; // Create instances for each CT channel
typedef struct { int hora, CT1, CT2, CT3, TEMP1 ;} PayloadTX; // create structure - a neat way of packaging data for RF comms, nothing is added a a 5th integer to match data structure of voltage version
PayloadTX emontx;
const int LEDpin = 9; // On-board emonTx LED
boolean settled = false;
int x;
// TEMPERATURA
#include <OneWire.h>
#include <DallasTemperature.h>
OneWire oneWire(4); // Setup one-wire on digital input pin 4
DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature.
DeviceAddress address_T1 = { 0x28, 0xFD, 0xBE, 0xBC, 0x07, 0x00, 0x00, 0x32 };
// RTC
#include <Wire.h>
#include "RTClib.h"
RTC_DS3231 rtc;
String daysOfTheWeek[7] = { "Domingo", "Lunes", "Martes", "Miercoles", "Jueves", "Viernes", "Sabado" };
String monthsNames[12] = { "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre" };
int hour;
int minute;
void setup() {
// TEMP
sensors.begin();
// PERESENTACION
Serial.begin(9600);
Serial.println("emonTX Shield CT123");
Serial.print("Node: ");
Serial.print(nodeID);
Serial.print(" Freq: ");
if (RF_freq == RF12_433MHZ) Serial.print("433Mhz");
Serial.print(" Network: ");
Serial.println(networkGroup);
if (CT1) ct1.current(1, 60.606); // Setup emonTX CT channel (channel, calibration)
if (CT2) ct2.current(2, 60.606); // Calibration factor = CT ratio / burden resistance
if (CT3) ct3.current(3, 60.606);
// if (CT4) ct4.current(4, 60.606);
// emonTx Shield Calibration = (100A / 0.05A) / 33 Ohms
rf12_initialize(nodeID, RF_freq, networkGroup); // initialize RFM12B
rf12_sleep(RF12_SLEEP);
pinMode(LEDpin, OUTPUT); // Setup indicator LED
digitalWrite(LEDpin, HIGH);
// RTC
if (!rtc.begin()) {
Serial.println(F("Couldn't find RTC"));
while (1);
}
//rtc.adjust(DateTime(2018, 12, 18, 20, 52, 0)); // AAA: descomentar esta linea para poner en hora
}
// RTC
void printDate(DateTime date)
{
/*
Serial.print(date.year(), DEC);
Serial.print('/');
Serial.print(date.month(), DEC);
Serial.print('/');
Serial.print(date.day(), DEC);
Serial.print(" (");
Serial.print(daysOfTheWeek[date.dayOfTheWeek()]);
Serial.print(") ");
Serial.print(date.hour(), DEC);
Serial.print(':');
Serial.print(date.minute(), DEC);
Serial.print(':');
Serial.print(date.second(), DEC);
Serial.println();
*/
hour = (date.hour());
minute = (date.minute());
}
void loop() {
// RTC
DateTime now = rtc.now();
printDate(now);
emontx.hora = (hour * 100) + minute ; // se empaqueta la hora y el minuto para emviar a EMONCMS
Serial.print("emontx.hora= "); Serial.print(emontx.hora); Serial.print("\t");
// TEMP
sensors.requestTemperatures();
emontx.TEMP1 = sensors.getTempC(address_T1);
if (emontx.TEMP1 < 0) emontx.TEMP1 = 0; if (emontx.TEMP1 > 120) emontx.TEMP1 = 120;
Serial.print("emontx.TEMP1: ");Serial.print(emontx.TEMP1); Serial.print("\t");
// CT´S
if (CT1) {
emontx.CT1 = ct1.calcIrms(1480) * 240.0; //ct.calcIrms(number of wavelengths sample)*AC RMS voltage
if (emontx.CT1 < 100) emontx.CT1 = 0; if (emontx.CT1 > 6000) emontx.CT1 = 6000;
}
if (CT2) {
emontx.CT2 = ct2.calcIrms(1480) * 240.0;
if (emontx.CT2 < 100) emontx.CT2 = 0; if (emontx.CT2 > 6000) emontx.CT2 = 6000;
}
if (CT3) {
emontx.CT3 = ct3.calcIrms(1480) * 240.0;
if (emontx.CT3 < 100) emontx.CT3 = 0; if (emontx.CT3 > 6000) emontx.CT3 = 6000;
}
Serial.print("CT1= ");Serial.print(emontx.CT1);
Serial.print(" CT2= "); Serial.print(emontx.CT2);
Serial.print(" CT3= "); Serial.print(emontx.CT3);
Serial.println(); delay(1000);
// because millis() returns to zero after 50 days !
if (!settled && millis() > FILTERSETTLETIME) settled = true;
if (settled) // send data only after filters have settled
{
send_rf_data(); // *SEND RF DATA* - see emontx_lib
digitalWrite(LEDpin, HIGH); delay(2); digitalWrite(LEDpin, LOW); // flash LED
delay(3000); // delay between readings in ms
}
}
I focused my attention in the A4 y A5 signals and forget add the two lines from the RTC sketch.
Any question let me know.
Thanks for everybody for the support.