Hi, with the project "enerduino" downloaded from the web I have to be able to control the consumption of electricity meter via a photoresistor me count the pulses of the LED of the meter itself, and through the module RTC, and the SD Shield, I memorize the data on the card. The problem is that in verifying the sketch gives me the following error:
FileLogger :: append ("data.log", buffer, length-1);
Enerduino: 185: error: can not convert 'bytes *' to 'int *' for argument '2' to 'int FileLogger :: append (const char *, int *, unsigned long int)'
Can you tell me how to fix it?
Below the sketch used:
//
// Enerduino
//
// version 0.2
//
// Internal revision: $Id: Enerduino.pde,v 0.22 2009/11/28 16:30:16 cesare Exp cesare $
//
// written by Cesare Pizzi
//
// This simple Arduino application allow to monitor power consumpion by checking the flashing
// light of the power meter.
// There are 2 lights on italian ENEL power meters: RA (active) and RR (reactive).
// Only RA led is computed for home contracts
// One flash should be 1 w/h
//
//
#include <stdlib.h>
// Include files for Filelogger library
#include <Spi.h>
#include <mmc.h>
#include <nanofat.h>
#include <FileLogger.h>
// Include files for clock DS1307 library
#include <WProgram.h>
#include <Wire.h>
#include <DS1307.h>
// Include files for MsTimer2 library
#include <MsTimer2.h>
/// The PIN to power the SD card shield
#define MEM_PW 9
// Analog input for photoresistor
#define PHOTO_IN 0
unsigned long timer=3600000; // Log file is written every 60 minutes (3600000) FIXME
unsigned long flash=0;
int threshold=450; // If photoresistor read more than this value, it count a flash
int writeLog=0;
// Arduino setup routine
void setup(void)
{
// This is to power on the SD shield
pinMode(MEM_PW, OUTPUT);
digitalWrite(MEM_PW, HIGH);
// Setup for photoresistor
pinMode(PHOTO_IN,INPUT);
// Initialize timer
MsTimer2::set(timer, flushCounter);
MsTimer2::start();
// Serial.begin(9600); // FIXME
// Enable to set up external clock
// setClock(0,38,17,6,14,11,9);
}
// Main
void loop(void)
{
// Serial.println(analogRead(PHOTO_IN)); // FIXME
// Read the photo sensor value
if (analogRead(PHOTO_IN) > threshold)
{
while (analogRead(PHOTO_IN) > threshold)
{
// Just wait the flash to turn off (to avoid multiple counts)
}
flash++;
// Serial.println("Flash"); // FIXME
}
// Write the log file if interrupt has been called
if (writeLog==1)
{
char time[10];
char date[15];
char logStr[50];
char buffer[5];
// Write flashes to log file
strcpy(logStr,getDate(time));
strcat(logStr," ");
strcat(logStr,getClock(date));
strcat(logStr,"\t");
itoa(flash,buffer,10);
strcat(logStr,buffer);
strcat(logStr,"\n");
write_log(logStr);
writeLog=0;
flash=0;
}
delay(10);
}
/////////////////
// Subroutines //
/////////////////
// Setup the external clock
void setClock(int seconds, int minutes, int hour, int dow,
int day, int month, int year)
{
RTC.stop();
RTC.set(DS1307_SEC,seconds); //set the seconds
RTC.set(DS1307_MIN,minutes); //set the minutes
RTC.set(DS1307_HR,hour); //set the hours
RTC.set(DS1307_DOW,dow); //set the day of the week
RTC.set(DS1307_DATE,day); //set the date
RTC.set(DS1307_MTH,month); //set the month
RTC.set(DS1307_YR,year); //set the year
RTC.start();
}
// Get the time from the external clock
char* getClock(char *timeStr)
{
char buffer[5]=" ";
itoa(RTC.get(DS1307_HR,true),buffer,10);
strcpy(timeStr,buffer);
strcat(timeStr,":");
itoa(RTC.get(DS1307_MIN,false),buffer,10);
// Add 0 if a single digit minute has been returned
if (strlen(buffer)==1)
{
strcat(timeStr,"0");
}
strcat(timeStr,buffer);
// Seconds are not useful at this time. Commented out
// strcat(timeStr,":");
// itoa(RTC.get(DS1307_SEC,false),buffer,10);
// strcat(timeStr,buffer);
return timeStr;
}
// Get the date from extrenal clock
char* getDate(char *dateStr)
{
char buffer[5]=" ";
itoa(RTC.get(DS1307_DATE,true),buffer,10);
strcpy(dateStr,buffer);
strcat(dateStr,"/");
itoa(RTC.get(DS1307_MTH,false),buffer,10);
strcat(dateStr,buffer);
strcat(dateStr,"/");
itoa(RTC.get(DS1307_YR,false),buffer,10);
strcat(dateStr,buffer);
return dateStr;
}
// Write data to log file named data.log
void write_log(char msg[])
{
int i;
unsigned int length = (strlen(msg)+1);
byte buffer[length];
for(i=0; i<length;i++)
{
buffer[i] = msg[i];
}
FileLogger::append("data.log", buffer, length-1);
// We should check for errors here....we'll do it...
}
// Routine executed by the timer interrupt. This flush the
// data to the log file
void flushCounter(void)
{
writeLog=1;
}