Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: openenergy project with 2 or 3 led pulses? (seeeduino stalker) on: February 21, 2011, 03:06:00 pm
attachInterrupt(gaslogInterrupt, gasinterruptHandler, FALLING);

When i add the line above, i get a error writing SD card.

It seems that the scetch has a problem with mij void gasinterruptHandler.
When i change it in elektrainterruptHandler, there is no problem.

Who can help me?

I add the full sketch below this line.

#include <Fat16.h> // the SD Card library - http://code.google.com/p/fat16lib/
#include <Wire.h> 
#include <Time.h> 
#include <DS1307RTC.h> // a basic DS1307 library - http://www.arduino.cc/playground/Code/Time


const long logInterval = 10; // De intervaltijd tussen elke log

// LED pins
const int  elektraLedPin     =  4;  // LED indicatie elektra puls gesignaleerd
const int  schrijfLedPin     =  5;  // LED indicatie dat er data naar de SD kaart wordt weggeschreven
const int  errorLedPin       =  6;  // LED indicatie error met SD kaart
const int  gasLedPin         =  7;  // LED indicatie gas puls gesignaleerd

const char *fileName = "logdata.csv";  // De naam van de logfile

const int elektralogInterrupt = 1; // ATmega 168 and 328 - interrupt 0 = pin 2, 1 = pin 3
const int elektrainterruptPin = 3; // Elektra pulsen input

const int gaslogInterrupt = 0;     // ATmega 168 and 328 - interrupt 0 = pin 2, 1 = pin 3
const int gasinterruptPin = 2;     // Gas pulsen input

SdCard card;
Fat16 LogFile;

volatile unsigned long wattSensor = 0;  // Telt elektra pulsen in interrupt, 1 pulse = 1 watt
volatile unsigned long gasSensor  = 0;  // Telt gas pulsen in interrupt, 1 pulse = 1 watt

volatile byte          dataState  = 0;  // Gebruikt om de elektraLedPin te blinken in geval van data update
unsigned long totalWatts = 0;           // Totaal elektra pulsen sinds de sketch is gestart

time_t nextTrigger;


void setup(void)
{
  setSyncProvider(RTC.get);   // Deze fuctie geeft de tijd van de RTC
//setTime(21,30,0,19,2,11);   // set tijd en datum op 17:05:00  1 Mar 2010
//RTC.set(now());             // set de RTC met de tijd zoals in voorgande regeld ingesteld is.

  pinMode(elektraLedPin, OUTPUT);    // LED interrupt indicator initialization
  pinMode(gasLedPin, OUTPUT);
  pinMode(schrijfLedPin, OUTPUT);     
  pinMode(errorLedPin, OUTPUT); 

  pinMode(elektrainterruptPin, INPUT);     
  digitalWrite(elektrainterruptPin, HIGH);
 
  pinMode(gasinterruptPin, INPUT);     
  digitalWrite(gasinterruptPin, HIGH);
 
  attachInterrupt(elektralogInterrupt, elektrainterruptHandler, FALLING);
 
  attachInterrupt(gaslogInterrupt, gasinterruptHandler, FALLING);
 
  nextTrigger = now() + logInterval; // schedule the logging time
 
  // initialize the SD card
  if (!card.init())
     error(1);
 
  // initialize a FAT16 volume
  if (!Fat16::init(&card))
      error(2);

  // open file for append, create if it doesn't exist 
  if (!LogFile.open(fileName, O_CREAT | O_APPEND | O_WRITE))
      error(3);
 
  // clear write error
  LogFile.writeError = false;
  LogFile.println("Start");
}

void loop(void)

  time_t timeStamp = now(); 
  if( timeStamp >= nextTrigger)
  {
     digitalWrite(schrijfLedPin, HIGH);
     printDateTime(timeStamp);
     MeterPulseLog();
     LogFile.println();
    // write the data to the card at the end of every line
     if (!LogFile.sync())
        error(4);
       
     nextTrigger += logInterval;// schedule the next log time       
     digitalWrite(schrijfLedPin, LOW);
  }
 
  // blink the LED to show meter pulses
 
  if( digitalRead(elektrainterruptPin)== LOW ) // Led oplichten als de PIN 3 low is.
  {
    digitalWrite(elektraLedPin, HIGH);   
    delay(100);  // Led oplichten voor 100 ms
  }
  else
     digitalWrite(elektraLedPin, LOW); 

  if( digitalRead(gasinterruptPin)== LOW )     // Led oplichten als de PIN 2 low is.
  {
    digitalWrite(gasLedPin, HIGH);   
    delay(100);  // Led oplichten voor 100 ms
  }
  else
     digitalWrite(gasLedPin, LOW); 
}

void MeterPulseLog()
{
    unsigned long wattSensorCount;   //number of watts during this logging interval
    uint8_t oldSREG = SREG;          // save interrupt register
    cli();                          // prevent interrupts while accessing the count   
    wattSensorCount = wattSensor;    //get the count from the interrupt handler
    wattSensor = 0;                //reset the watts count
    SREG = oldSREG;                 // restore interrupts

    totalWatts = totalWatts + wattSensorCount; //total watts counter
    LogFile.print(',');   // print comma to seprate from previous data
    LogFile.print(wattSensorCount);
    LogFile.print(',');
    LogFile.print(totalWatts);       
}

// routine handle file errors
void error(int err)
{
  // blink forever
 while(1)
 {
   digitalWrite(errorLedPin, HIGH);
   delay(err * 200);
   digitalWrite(errorLedPin, LOW);
   delay(200); 
 }     
}

void printDateTime(time_t t)
{
  printDigits(hour(t),':' );
  printDigits(minute(t),':' );
  printDigits(second(t),',' );  // uncomment this to print seconds (and replace the comma above with colon)
  // print a space here if you need it
  printDigits(day(t),'//' ); 
  printDigits(month(t),'//' );   
//  LogFile.print(year(t));  // prints year using 4 digits
  LogFile.print(year(t)-2000);  // prints year using 2 digits
  LogFile.print(',');
}

void printDigits(int digits, char seperator)
{
  // utility function time with leading 0
  if(digits < 10)
    LogFile.print('0');
  LogFile.print(digits);
  LogFile.print(seperator); 
}

void elektrainterruptHandler() // routine called when external interrupt is triggered
{
  wattSensor = wattSensor + 1;  //Update number of pulses, 1 pulse = 1 watt
}

void gasinterruptHandler() // routine called when external interrupt is triggered
{
gasSensor = gasSensor + 1;  //Update number of pulses, 1 pulse = 0,01 m3
}
2  Using Arduino / Programming Questions / openenergy project with 2 or 3 led pulses? (seeeduino stalker) on: February 20, 2011, 02:46:56 pm
http://www.airsensor.co.uk/component/zoo/item/energy-monitor.html

I made this project and works perfect.
now i want to add my gas meter as well ( also with a led puls for every 0,01 M3)

I try to add this in the sketch, but it seems that i have not enough knowledge about C.

Does sombody allready made a sketch for 2 or 3 input? and do you wan to share it with me?
I will be very pleased with it.

3  Using Arduino / Storage / Re: Reading microSD card directly from USB serial port on: February 16, 2011, 02:40:07 pm
http://www.ladyada.net/learn/arduino/ethfiles.html

It seems thats it is possible, but i realise i have to learn more first, before i start this project......
4  Using Arduino / Storage / Re: Reading microSD card directly from USB serial port on: February 11, 2011, 06:01:20 am
mmm, so the only possibility is to remove the SD card and put in my PC?
Thats too bad....
5  Using Arduino / Storage / Re: Reading microSD card directly from USB serial port on: February 10, 2011, 01:43:25 am
Thats not what i want to hear, but i have to live whit this fact.

There is also a serial connection on the board. Does somebody know if its possible to dowlaod the lof file on the SD card by using de serial connection?
6  Using Arduino / Storage / Re: Reading microSD card directly from USB serial port on: February 07, 2011, 04:25:01 pm
Sounds easy, but not for a newbee smiley-cool
Is is possible with a ethetnet shield?
I have an Seeeduino stalker and i want to copy the log file from the SD card to my pc once a while.
Does anyone know how i can do this easy?
Pages: [1]