Hi,
I'm trying to get consumption information from my electricity meter and to store it on the SD card embedded on the Ethernet shield.
I managed to get consumption information from my electricity meter and to display it through serial monitor adding the UTC timestamp.
The problem happens when I include SD.h library. I just manage to display the end of the consumption frame.
Could you help me?
Here is my source code :
//include Téléinformation
#include <SoftwareSerial.h>
//include RTC
#include <Wire.h>
#include "RTClib.h"
//include SD
//#include <SD.h>
#include <SPI.h>
//Variable globale pour le module RTC
RTC_DS1307 RTC;
//Variable de récupération du compteur1
SoftwareSerial cptSerial_1(2, 3);
/*
//Variable SD
Sd2Card card;
SdVolume volume;
SdFile root;
File myfile;
*/
/******************************* Setup *******************************/
//Setup Global
void setup() {
setupRTC();
//setupSD();
Serial.begin(1200); // opens serial port, sets data rate to 1200 bps
cptSerial_1.begin(1200);
}
//Setup RTC module
void setupRTC()
{
Wire.begin();
RTC.begin();
if (! RTC.isrunning())
{
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
// RTC.adjust(DateTime(__DATE__, __TIME__));
}
}
/******************************* Main *******************************/
void loop() {
Serial.println(getTeleInfo(cptSerial_1));
}
String getTeleInfo(SoftwareSerial &cptSerial)
{
char tmp=' ';
String ReturnValue = String("");
//Attendre la fin de la trame en cours
while (tmp!=char(2))
{
if (cptSerial.available())
{
tmp=cptSerial.read() & 0x7F;
}
}
//une fois char(2) passé, attendre char(10)
while (tmp!=char(10))
{
if (cptSerial.available())
{
tmp=cptSerial.read() & 0x7F;
}
}
//Récupérer la Trame en remplaçant les char(10) par des ';'
while (tmp!=char(2))
{
//Attendre le prochain caractère
while (!cptSerial.available())
{}
if(cptSerial.available())
{
tmp=cptSerial.read() & 0x7F;
}
//Remplacer les Char(10) par ";"
if(tmp==char(10))
{
ReturnValue = ReturnValue + ';';
}
else
{
//Eliminer les caractères inutiles
if(tmp > 31) // and tmp < 127)
{
ReturnValue = ReturnValue + tmp;
}
}
}
//Intégrer la date à la sortie
ReturnValue = ReturnValue + ";" + RTC.now().unixtime() + " UTC";
return ReturnValue;
}
Here is the result without including SD.h
ADCO 031128380698 H;OPTARIF HC.. <;ISOUSC 45 ?;HCHC 000000000 F;HCHP 000000000 S;PTEC HP.. ;IINST 000 W;IMAX 000 ?;PAPP 00000 !;HHPHC A ,;MOTDETAT 000000 B;1353536567 UTC
ADCO 031128380698 H;OPTARIF HC.. <;ISOUSC 45 ?;HCHC 000000000 F;HCHP 000000000 S;PTEC HP.. ;IINST 000 W;IMAX 000 ?;PAPP 00000 !;HHPHC A ,;MOTDETAT 000000 B;1353536570 UTC
ADCO 031128380698 H;OPTARIF HC.. <;ISOUSC 45 ?;HCHC 000000000 F;HCHP 000000000 S;PTEC HP.. ;IINST 000 W;IMAX 000 ?;PAPP 00000 !;HHPHC A ,;MOTDETAT 000000 B;1353536574 UTC
And the result with SD.h includes
,;MOTDETAT 000000 B;1353536669 UTC
,;MOTDETAT 000000 B;1353536672 UTC
,;MOTDETAT 000000 B;1353536675 UTC
I'm using the assembly that is described here (in french) : blog.cquad.eu/2012/02/02/recuperer-la-teleinformation-avec-un-arduino/
Adrien