Show Posts
Pages: [1] 2 3 ... 8
1  Using Arduino / Programming Questions / Software Reset Arduino from a webpage on: July 06, 2013, 05:21:57 pm
Is it possible to do a software reset to the arduino from a webpage using ethernetshield?? How?

Thanks in advance!
2  Using Arduino / Programming Questions / Re: delete sd card files every year on: May 25, 2013, 06:09:02 pm
Can you give me an example or something to read about it? i thought about compare the date and time to see if it is: 31-12   and 23:59 the program dele the files, but it will cause the program to everytime it logs a value to compare the date and time and i thought that maybe could be some better options
3  Using Arduino / Programming Questions / delete sd card files every year on: May 25, 2013, 05:30:40 pm
hello, i've been thinking what is the best way to delete files every year.
i use a RTC to get date and time and save it to a log file with some variables.

Code:
Log = file.open(&root, LogFile, O_WRITE | O_APPEND);

  if (Log) {
    Date_Time();
   
    file.print(dayMonth, DEC);
    file.print(" ");
    file.print(Month);
    file.print(" ");
    file.print("20");
    if (year < 10) {
      file.print("0");
    }
    file.print(year, DEC);
    file.print(" , ");
    if (hour < 10) {
      file.print("0");
    }
    file.print(hour, DEC);
    file.print(":");
    if (minute < 10) {
      file.print("0");
    }
    file.print(minute, DEC);
    file.print(":");
    if (second < 10) {
      file.print("0");
    }
    file.print(seconf, DEC);   
    file.print(" , ");
    file.print(data1, 1);
    file.print(" , ");
    file.println(data2);
    file.close();
    Log = false;
  }
  else {
    Serial.println(F("ERROR"));
thanks in advance
4  Using Arduino / Programming Questions / Re: RTC causing program problems on: May 14, 2013, 01:19:43 pm
I'm using arduino mega. it is not ram problem because i've already do a lots of debugg and it only happens when i "turn on" rtc. It could be some variable overload but i'm using everything lalmost like it is on the rtc page i've posted. If there is any better library to use please tell me
5  Using Arduino / Programming Questions / RTC causing program problems on: May 14, 2013, 12:56:48 pm
I'm experiencing some program running problem when i uncomment the RTC function to read date and time for program save it with data to a log file. I'm getting the data by RF with virtualwire and if program runs with RTC uncomment i can't even get the data it shows in serial monitor something like "ggggggggggggggggggggggggggggggg..." and keeps going for eternity.
I i comment in everithing works just fine.

Code:
#include <SPI.h>
#include <avr/pgmspace.h>
#include <Ethernet.h>
#include <VirtualWire.h>
#include <Wire.h>
#include "SdFatUtil.h"

#define DS1307_I2C_Endereco 0x68  //SCL<--> Analog Input 5  SDA<--> Analog Input 4
#define I2C_Write Wire.write
#define I2C_Read Wire.read

prog_char noMes_0[] PROGMEM = "";
prog_char noMes_1[] PROGMEM = "Jan";
prog_char noMes_2[] PROGMEM = "Fev";
prog_char noMes_3[] PROGMEM = "Mar";
prog_char noMes_4[] PROGMEM = "Abr";
prog_char noMes_5[] PROGMEM = "Mai";
prog_char noMes_6[] PROGMEM = "Jun";
prog_char noMes_7[] PROGMEM = "Jul";
prog_char noMes_8[] PROGMEM = "Ago";
prog_char noMes_9[] PROGMEM = "Set";
prog_char noMes_10[] PROGMEM = "Out";
prog_char noMes_11[] PROGMEM = "Nov";
prog_char noMes_12[] PROGMEM = "Dez";
PROGMEM const char* noMes[] = {
  noMes_0, noMes_1, noMes_2, noMes_3, noMes_4, noMes_5, noMes_6, noMes_7, noMes_8, noMes_9, noMes_10,
  noMes_11, noMes_12};

byte segundo, minuto, hora, diaSemana, diaMes, mes, ano;
char nomeMes[10];
char ficheiroLer[10];
char mensagem[30];
unsigned int dadosAgua = 0;
float dadosBat = 0.0;
float percentagem = 0.0;
unsigned long litros = 0;

void setup() {

  Serial.begin(9600);
  delay(100);

  //DEFINE OS PINOS DE ENTRADA E DE SAÍDA
  pinMode(ledInfo, OUTPUT);
  pinMode(ledRececao, OUTPUT);
  pinMode(10, OUTPUT);

  //INICIA A COMUNICAÇÃO I2C
  Wire.begin();

  //LIGA E DESLIGA OS 2 LEDS PARA INDICAR QUE ESTÃO OPERACIONAIS
  digitalWrite(ledInfo, HIGH);
  digitalWrite(ledRececao, HIGH);
  digitalWrite(10, HIGH);
  delay(1000);
  digitalWrite(ledInfo, LOW);
  digitalWrite(ledRececao, LOW);
Ethernet.begin(mac, ip);
  server.begin();
  delay(100);

  //CONFIGURA E INICIA O RECEPTOR
  vw_set_tx_pin(6);
  vw_set_rx_pin(8);
  vw_set_ptt_pin(5);
  vw_setup(2000);
  vw_rx_start();

void loop() {

  //actDataHora();
  rececaoRF();
  clienteLigado();
  
}

void actDataHora() {

  //FAZ O STACK POINTER IR PARA O INÍCIO
  Wire.beginTransmission(DS1307_I2C_Endereco);
  I2C_Write(0x00);
  Wire.endTransmission();
  Wire.requestFrom(DS1307_I2C_Endereco, 7);

  segundo  = bcdToDec(I2C_Read() & 0x7f); //MASCARA PQ É BIT DE CONTROLE
  minuto   = bcdToDec(I2C_Read());
  hora     = bcdToDec(I2C_Read() & 0x3f); //MÁSCARA PQ É BIT DE CONTROLE
  diaSemana= bcdToDec(I2C_Read());
  diaMes   = bcdToDec(I2C_Read());
  mes      = bcdToDec(I2C_Read());
  ano      = bcdToDec(I2C_Read());
}

//CONVERSÃO DOS DADOS DE BCD PARA DECIMAL - RTC
byte bcdToDec(byte val)
{
  return ((val/16*10) + (val%16));
}

//RECEPÇÃO DOS DADOS POR RF 433MHz
void rececaoRF() {

  byte buf[VW_MAX_MESSAGE_LEN];
  byte buflen = VW_MAX_MESSAGE_LEN;
 
  if (vw_get_message(buf, &buflen)) {
    digitalWrite(ledRececao, HIGH);
    for (int j = 0; j<buflen; j++) {
      mensagem[j] = char(buf[j]);
    }
    mensagem[buflen] = '\0';

    if (mensagem[0] == 'R') {
      dadosAgua = atoi(&mensagem[1]);
      if (dadosAgua > 0 && dadosAgua <= 465) {
        calcAgua();
        //Serial.println(dadosAgua);
      }
    }
    else if (mensagem[0] == 'B') {
      dadosBat = atof(&mensagem[1]);
      if (dadosBat > 0.00 && dadosBat <= 9.99) {
        gravarDados();
        //Serial.println(dadosBat);
      }
    }
    Serial.println(mensagem);
    memset(&buf, 0, sizeof(buf));
    memset(&mensagem, 0, sizeof(mensagem));
    digitalWrite(ledRececao, LOW);
  }
}


void gravarDados() {

  char ficheiroLog[10];
  strcpy_P(nomeMes, (char*)pgm_read_word(&(noMes[mes])));
  sprintf(ficheiroLog,"%s.csv", nomeMes);
  boolean Log = false;
  Serial.println(ficheiroLog);
  Log = file.open(&root, ficheiroLog, O_WRITE | O_APPEND);

  if (Log) {
    actDataHora();
    //DATA E HORA
    file.print(diaMes, DEC);
    file.print(" ");
    file.print(nomeMes);
    file.print(" ");
    file.print("20");
    if (ano < 10) {
      file.print("0");
    }
    file.print(ano, DEC);
    file.print(" , ");
    if (hora < 10) {
      file.print("0");
    }
    file.print(hora, DEC);
    file.print(":");
    if (minuto < 10) {
      file.print("0");
    }
    file.print(minuto, DEC);
    file.print(":");
    if (segundo < 10) {
      file.print("0");
    }
    file.print(segundo, DEC);
    //DADOS    
    file.print(" , ");
    file.print(percentagem, 1);
    file.print(" , ");
    file.println(litros);
    file.close();
    Log = false;
  }
  else {
    Serial.println(F("ERRO grav LOG!"));
    for (int i = 0; i<5; i++) {
      digitalWrite(ledRececao, HIGH);
      delay(250);
      digitalWrite(ledRececao, LOW);
      delay(250);
    }
  }
  memset(&ficheiroLog, 0, sizeof(ficheiroLog));
}
I haven't posted the whole code because it is a little big, but i think that i've posted the most important parts.
I'm using RTC library from http://combustory.com/wiki/index.php/RTC1307_-_Real_Time_Clock
Thanks in advance for your help!
6  Using Arduino / Programming Questions / Re: Doubt about IF statement on: May 13, 2013, 06:23:07 pm
i got it! many thanks for your help!

Cheers
7  Using Arduino / Programming Questions / Re: Doubt about IF statement on: May 13, 2013, 05:23:21 pm
Sorry but i couldn't understand
8  Using Arduino / Programming Questions / Doubt about IF statement [SOLVED] on: May 13, 2013, 04:40:07 pm
Is there any difference between
Code:
if (main condition) {
if (1st condition) {
do something...
} else if (2nd condition) {
do something...
}
}
and this:
Code:
if (main condition) {
if (1st condition) {
do something...
}
if (2nd condition) {
do something...
}
}
between using only if's or if and if else's..

Thanks in adance!
9  Using Arduino / Programming Questions / Re: Question about char array on: May 01, 2013, 04:36:16 pm
And the last one... what does the & before char array means? Like &Str1
10  Using Arduino / Programming Questions / Re: Question about char array on: May 01, 2013, 04:23:55 pm
So which is the best way to use undefined lenght strings?

EDIT: Functions like sprintf, and others that are used to make strings in char arrays, add the NULL character automatically i just need to declare a char array with enough space?

11  Using Arduino / Programming Questions / Re: Question about char array on: May 01, 2013, 04:19:33 pm
So, a char array Str1 will always need 16 bytes even if i do something like
Code:
memset(&Str1, 0, sizeof(Str1));
and this "cleaning" it's unnecessary?
12  Using Arduino / Programming Questions / Question about char array on: May 01, 2013, 04:10:35 pm
Hello, if i have a char array for example
Code:
char Str0[6] = "hello";
char Str1[16] = "hellototheworld";
and in the middle of the program i do something like
Code:
sprintf(Str1,"%s.txt", Str0);
Str1 will be
Code:
hello.txt\0
which is 9 bytes plus NULL character. What happens to the bytes that was after this position in the first declaration of Str1?
13  Using Arduino / Programming Questions / Re: Program Compiles but doesn't run at 100% on: April 30, 2013, 07:15:38 pm
Thanks a lot!  I'll test what you told me to do and see what happens. I'll post feedback.
Thanks to all for your attention!
14  Using Arduino / Programming Questions / Re: Program Compiles but doesn't run at 100% on: April 30, 2013, 07:00:18 pm
Sorry  smiley-red my mistake.  Yes the ELSE func. is for everything less that 6 bytes will go to the if statement of vw_get_message.

If, for some reason i have to go to an arduino mega this code will be just upload to it or do i have to make some changes?
15  Using Arduino / Programming Questions / Re: Program Compiles but doesn't run at 100% on: April 30, 2013, 06:48:44 pm
hmmm.... something like this?
Code:
char mensagem[6];
  byte buf[VW_MAX_MESSAGE_LEN];
  byte buflen = VW_MAX_MESSAGE_LEN;

if (sizeof(buflen) > 5) { Serial.print(F("BUFFER OVERFLOW"));}

  if (vw_get_message(buf, &buflen)) {
    digitalWrite(ledRececao, HIGH);
Pages: [1] 2 3 ... 8