Show Posts
|
|
Pages: [1] 2
|
|
1
|
Using Arduino / Project Guidance / Re: Is SD.begin a one-time thing??After removing card, it can't reinitialize...
|
on: March 09, 2013, 06:40:28 am
|
i'm sorry i forgot to edit some #include <LiquidCrystal.h> #include <SD.h>
LiquidCrystal lcd(7,6,5,4,3,2);
const int analogInPin = A3; const int lcdLed=13; const int runLed=24; const int chipSelect=53;
int ledState=LOW; File myFile; unsigned long number;
int i; int counter1=0; int counter2=0; int mmenu[10]; const int rxPin=10; const int txPin=11; const int byteSize=64;
bool startDataReceived=false; bool dataAvailable=false; bool sdInserted=false;
void setup(){ pinMode(lcdLed,OUTPUT); digitalWrite(lcdLed,HIGH); pinMode(runLed,OUTPUT); pinMode(chipSelect,OUTPUT); lcd.begin(16,2); Serial.begin(9600); mySerial.begin(9600); }
void insertCard(){ while(!SD.begin(chipSelect)){ lcd.setCursor(2,0); lcd.write("Please Insert"); lcd.setCursor(4,1); lcd.write("SD Card..."); delay(1000); lcd.clear(); } lcd.clear(); lcd.setCursor(1,0); lcd.print("Press Blinking"); lcd.setCursor(4,1); lcd.print("Button..."); while(ledState==LOW){ ledState=HIGH; digitalWrite(runLed,ledState); delay(500); ledState=LOW; digitalWrite(runLed,ledState); delay(500); Analogkeyinput(); delay(500); if((mmenu[0]<225&&mmenu[0]>205)){ ledState=HIGH; } } digitalWrite(runLed,LOW); lcd.clear(); lcd.setCursor(4,0); lcd.write("SD Card"); lcd.setCursor(2,1); lcd.write("Validating..."); delay(5000); myFile=SD.open("CARDID.txt"); if(myFile){ char fileStr[9]; int j; for(j=0;j<10;j++){ fileStr[j]=myFile.read(); } char result[9]; uint8_t k = 0; while (fileStr[k] != '\0' && k < sizeof(result) - 1){ result[k] = fileStr[k]; k++; } result[k] = '\0'; number = atol(result); digitalWrite(runLed,LOW); } if(number==18231801){ myFile.close(); lcd.clear(); delay(1000); lcd.setCursor(4,0); lcd.write("SD Card"); lcd.setCursor(4,1); lcd.write("Valid!"); delay(1000); } else{ digitalWrite(runLed,LOW); delay(1000); lcd.clear(); lcd.setCursor(4,0); lcd.write("SD Card"); lcd.setCursor(4,1); lcd.write("Invalid!"); myFile.close(); delay(500); } }
void Analogkeyinput(){ int Ak = analogRead(analogInPin); int Dk = map(Ak,0,1023,0,255); mmenu[0]=Dk; } void loop(){ insertCard(); }
|
|
|
|
|
2
|
Using Arduino / Project Guidance / Is SD.begin a one-time thing??After removing card, it can't reinitialize...
|
on: March 09, 2013, 06:31:26 am
|
this is the code #include <LiquidCrystal.h> #include <SD.h>
LiquidCrystal lcd(7,6,5,4,3,2);
const int analogInPin = A3; const int lcdLed=13; const int runLed=24; const int chipSelect=53;
int ledState=LOW; File myFile; unsigned long number;
int i; int counter1=0; int counter2=0; int mmenu[10]; const int rxPin=10; const int txPin=11; const int byteSize=64;
bool startDataReceived=false; bool dataAvailable=false; bool sdInserted=false;
void setup(){ pinMode(lcdLed,OUTPUT); digitalWrite(lcdLed,HIGH); pinMode(runLed,OUTPUT); pinMode(chipSelect,OUTPUT); lcd.begin(16,2); Serial.begin(9600); mySerial.begin(9600); insertCard(); }
void insertCard(){ while(!SD.begin(chipSelect)){ lcd.setCursor(2,0); lcd.write("Please Insert"); lcd.setCursor(4,1); lcd.write("SD Card..."); delay(1000); lcd.clear(); } lcd.clear(); lcd.setCursor(1,0); lcd.print("Press Blinking"); lcd.setCursor(4,1); lcd.print("Button..."); while(ledState==LOW){ ledState=HIGH; digitalWrite(runLed,ledState); delay(500); ledState=LOW; digitalWrite(runLed,ledState); delay(500); Analogkeyinput(); delay(500); if((mmenu[0]<225&&mmenu[0]>205)){ ledState=HIGH; } } digitalWrite(runLed,LOW); lcd.clear(); lcd.setCursor(4,0); lcd.write("SD Card"); lcd.setCursor(2,1); lcd.write("Validating..."); delay(5000); myFile=SD.open("CARDID.txt"); if(myFile){ char fileStr[9]; int j; for(j=0;j<10;j++){ fileStr[j]=myFile.read(); } char result[9]; uint8_t k = 0; while (fileStr[k] != '\0' && k < sizeof(result) - 1){ result[k] = fileStr[k]; k++; } result[k] = '\0'; number = atol(result); digitalWrite(runLed,LOW); } if(number==18231801){ myFile.close(); lcd.clear(); delay(1000); lcd.setCursor(4,0); lcd.write("SD Card"); lcd.setCursor(4,1); lcd.write("Valid!"); delay(1000); } else{ digitalWrite(runLed,LOW); delay(1000); lcd.clear(); lcd.setCursor(4,0); lcd.write("SD Card"); lcd.setCursor(4,1); lcd.write("Invalid!"); myFile.close(); delay(500); } }
void Analogkeyinput(){ int Ak = analogRead(analogInPin); int Dk = map(Ak,0,1023,0,255); mmenu[0]=Dk; } void loop(){ insertCard(); } problem is after i remove the card...i can get back to blinking please inserd card...but when i reinsert the card, the please insert the card won't blink and i get stuck with the permanent please insert card....i can't go back to rereading the file
|
|
|
|
|
5
|
Using Arduino / Project Guidance / Re: Serial buffer overflow
|
on: February 26, 2013, 01:13:06 pm
|
anyways here is the serial monitor output  Serial.println(wattSecond); //89.80 Serial.println(wattHour,4); //74.1634 Serial.println(counter1); //59, this is every 60 seconds Serial.println(counter2); //46,this is every 60 minutes Serial.println(kilowattHour,4); //0.0000
The numbers above correspond to the last values before serial.print hangs.... so....the serial.print hangs right after 46 minutes and 59 seconds.... and i did some other test too.... second attempt, it hangs at 1 hour and 29 minutes third attempt, it hangs at 33 minutes time here is obtained using counter
|
|
|
|
|
6
|
Using Arduino / Project Guidance / Re: Serial buffer overflow
|
on: February 26, 2013, 12:54:40 pm
|
|
yeah, i'm not really sure what to call it either...i mean the output....the printing of serial.print just hangs...
i'm not sure if it's an overflow, but judging from the comments answered by people here (considering that there should be at least characters that should be present but are just invalid, and not completely to a halt),i mean what really is the output is that after some time, SERIAL.PRINT HANGS....
anyways, i'm using 9600 baud rate as this is specifically required by the serial-outputting device i used (i used power analyzer that outputs csv format)
the DATA IS SENT TO ARDUINO....arduino just receives it.....
|
|
|
|
|
8
|
Using Arduino / Project Guidance / Re: Serial buffer overflow
|
on: February 26, 2013, 12:44:15 pm
|
#include <SoftwareSerial.h>
char incomingByte;
int i; int counter1=0; int counter2=0;
const int rxPin=10; const int txPin=11; const int byteSize=53;
char * range; char * watts; char * va; char * var; char * pf; char * volts; char * amps;
char buffer[53];
bool startDataReceived=false; bool dataAvailable=false;
SoftwareSerial mySerial(rxPin,txPin);
float wattHour,wattHour2,dummy,currentConsumption,kilowattHour; float wattHour1=0; float wattHour3=0; float wattSecond; float wattSecond1; float wattSecond2=0; float dummy1=0; float lastConsumption=0; float KWHInterval=1000;
void setup(){ pinMode(lcdLed,OUTPUT); digitalWrite(lcdLed,HIGH); pinMode(pulseLed,OUTPUT); digitalWrite(pulseLed,LOW); lcd.begin(16,2); Serial.begin(9600); mySerial.begin(9600); }
void displayData(){ lcd.setCursor(0,0); lcd.print(wattSecond,0); lcd.print("w "); lcd.setCursor(0,1); lcd.print(wattHour/1000, 2); lcd.print("kwh "); lcd.setCursor(8,0); lcd.print(wattHour, 2); lcd.print("wh "); }
void storeKwh(){ wattSecond=atof(watts); counter1=counter1+1; wattSecond1=wattSecond; if(wattSecond2==wattSecond) wattSecond=wattSecond; else{ wattSecond=(wattSecond-wattSecond2)+(wattSecond2); wattSecond2=wattSecond1; wattSecond=wattSecond; } if(wattSecond==0) wattHour3=wattHour1; else{ wattHour2=wattSecond/3600; wattHour=(wattHour3)+(wattHour2); wattHour1=wattHour; } if(counter1<=60&&wattSecond!=0){ dummy=wattHour; wattHour=(dummy1)+dummy; dummy1=wattHour; } else{ counter1=0; counter2=counter2+1; if(counter2<=60&&wattSecond!=0){ dummy=wattHour; wattHour=dummy1+dummy; dummy1=wattHour; } else counter2=0; currentConsumption=wattHour; if((currentConsumption-lastConsumption)>(KWHInterval)){ lastConsumption+=KWHInterval; kilowattHour=(lastConsumption/1000); } } }
void loop(){
if(mySerial.available()>0){ incomingByte=mySerial.read(); if(incomingByte=='I'){ startDataReceived=true; buffer[0]=incomingByte; } }
if((startDataReceived==true)&&(mySerial.available()>0)){ for(i=1;i<byteSize;i++){ while(mySerial.available()==0){ } buffer[i]=mySerial.read(); } startDataReceived=false; dataAvailable=true; }
if(dataAvailable==true){ range=strtok(buffer, ","); watts=strtok(NULL, ","); va=strtok(NULL, ","); var=strtok(NULL, ","); pf=strtok(NULL, ","); volts=strtok(NULL, ","); amps=strtok(NULL, ",");
storeKwh(); Serial.println(wattSecond); Serial.println(wattHour,4); Serial.println(counter1); Serial.println(counter2); Serial.println(kilowattHour,4);
memset(buffer,NULL,byteSize); dataAvailable=false; } }
|
|
|
|
|
9
|
Using Arduino / Project Guidance / Re: Serial buffer overflow
|
on: February 26, 2013, 12:28:36 pm
|
Here: #include <SoftwareSerial.h> #include <LiquidCrystal.h>
LiquidCrystal lcd(9,8,7,6,5,4);
const int lcdLed=13;
char incomingByte;
int i; int counter1=0; int counter2=0;
const int rxPin=10; const int txPin=11; const int byteSize=53;
char * range; char * watts; char * va; char * var; char * pf; char * volts; char * amps;
char buffer[53];
bool startDataReceived=false; bool dataAvailable=false;
SoftwareSerial mySerial(rxPin,txPin);
float wattHour,wattHour2,dummy,currentConsumption,kilowattHour; float wattHour1=0; float wattHour3=0; float wattSecond; float wattSecond1; float wattSecond2=0; float dummy1=0; float lastConsumption=0; float KWHInterval=1000;
void setup(){ pinMode(lcdLed,OUTPUT); digitalWrite(lcdLed,HIGH); pinMode(pulseLed,OUTPUT); digitalWrite(pulseLed,LOW); lcd.begin(16,2); Serial.begin(9600); mySerial.begin(9600);} void displayData(){ lcd.setCursor(0,0); lcd.print(wattSecond,0); lcd.print("w "); lcd.setCursor(0,1); lcd.print(wattHour/1000, 2); lcd.print("kwh "); lcd.setCursor(8,0); lcd.print(wattHour, 2); lcd.print("wh ");}
void storeKwh(){ wattSecond=atof(watts); counter1=counter1+1; wattSecond1=wattSecond; if(wattSecond2==wattSecond) wattSecond=wattSecond; else{ wattSecond=(wattSecond-wattSecond2)+(wattSecond2); wattSecond2=wattSecond1; wattSecond=wattSecond;} if(wattSecond==0) wattHour3=wattHour1; else{ wattHour2=wattSecond/3600; wattHour=(wattHour3)+(wattHour2); wattHour1=wattHour;} if(counter1<=60&&wattSecond!=0){ dummy=wattHour; wattHour=(dummy1)+dummy; dummy1=wattHour;} else{ counter1=0; counter2=counter2+1; if(counter2<=60&&wattSecond!=0){ dummy=wattHour; wattHour=dummy1+dummy; dummy1=wattHour;} else counter2=0; currentConsumption=wattHour; if((currentConsumption-lastConsumption)>(KWHInterval)){ lastConsumption+=KWHInterval; kilowattHour=(lastConsumption/1000); }}}
void loop(){ if(mySerial.available()>0){ incomingByte=mySerial.read(); if(incomingByte=='I'){ startDataReceived=true; buffer[0]=incomingByte;} } if((startDataReceived==true)&&(mySerial.available()>0)){ for(i=1;i<byteSize;i++){ while(mySerial.available()==0){} buffer[i]=mySerial.read();} startDataReceived=false; dataAvailable=true;} if(dataAvailable==true){ range=strtok(buffer, ","); watts=strtok(NULL, ","); va=strtok(NULL, ","); var=strtok(NULL, ","); pf=strtok(NULL, ","); volts=strtok(NULL, ","); amps=strtok(NULL, ","); storeKwh(); Serial.println(wattSecond); Serial.println(wattHour,4); Serial.println(counter1); Serial.println(counter2); Serial.println(kilowattHour,4);
memset(buffer,NULL,byteSize); dataAvailable=false;}}
|
|
|
|
|
10
|
Using Arduino / Project Guidance / Re: Serial buffer overflow
|
on: February 26, 2013, 11:53:04 am
|
|
i'm sorry but i think i don't get it that much
am i supposed to get some thing to do with tx at the arduino side (my system is only receiving data from serial device, this is not transmitting whatsoever to a serial device) ???
how am i going to somehow put a solution to this hanging of serial.print??
and what might cause it????
|
|
|
|
|
11
|
Using Arduino / Project Guidance / Re: Serial buffer overflow
|
on: February 26, 2013, 11:43:41 am
|
|
i'm not really sure with this thing that's going in my system....
at a long period of time after buffer is filled with an incoming byte...and then parsed....there are times at which sending of data from serial device gets halted....is this overflow??? or overflow just means there will still be data left but not valid ...or there are portions of the data that are being skipped and thus, continues to just shift the remaining characters just for the compliance that buffer is filled with same exact number of bytes?
what i'm trying to say is, overflow still has data to display (garbage or anything that is invalid)? it does not completely mean that serial device stops sending data and halts serial display?
|
|
|
|
|
12
|
Using Arduino / Project Guidance / Serial buffer overflow
|
on: February 26, 2013, 11:27:04 am
|
|
hello just want to ask, how can i detect a serial buffer overflow???
and if then my buffer is cleared or empty, how can i retrieve the dumped data ( am i right with my understanding here, that once buffer overflows, data are dumped to somewhere-i-don't-know in the serial device? if so can this data be retrieved? then, how am i going to re.initialize serial available command so as to continue the stopped portion of the data and get valid data again as arduino is receiving?)
i'm not really sure with this...i'm totally new to arduino...
i just want to achieve these things: 1. detect overflow 2.clear buffer 3.retrieve data from last (not really sure here) 4.get back to serial available command 5. start filling buffer again
anyways, main thing is i want to get a reliable serial communication ....and be able to recover once overflow happens.....
|
|
|
|
|
13
|
Using Arduino / Storage / Re: power down data saving
|
on: February 20, 2013, 02:23:01 am
|
|
if not, can i use an external eeprom then? if i;m going to use 12Vdc...what will be the value for my zener diode?and i couldn't find 100nF,can i replace it??
|
|
|
|
|
15
|
Using Arduino / Project Guidance / Display to LCD from Serial CSV out? Help...
|
on: January 25, 2013, 12:22:11 am
|
Hi...i'm planning to display CSV serial out to LCD....but it only display 0 watt and 0 kwh...no change at all...please do reply.... Here is the code: #include <SoftwareSerial.h> #include <LiquidCrystal.h>
LiquidCrystal lcd(9,8,7,6,5,4);
const int lcdLed=13; const int pulseLed=12;
char incomingByte;
int i;
const int rxPin=2; const int txPin=3; const int byteSize=53;
char * range; char * watts; char * va; char * var; char * pf; char * volts; char * amps;
char buffer[53];
bool startDataReceived=false; bool dataAvailable=false;
SoftwareSerial mySerial(rxPin,txPin);
float wattHour,currentConsumption,currentwattHour; float wattSecond=0; float lastConsumption=0; float KWHInterval=1000;
void setup(){ pinMode(lcdLed,OUTPUT); digitalWrite(lcdLed,HIGH); pinMode(pulseLed,OUTPUT); digitalWrite(pulseLed,LOW); lcd.begin(16,2); Serial.begin(9600); mySerial.begin(9600);} void extractData(){ if(mySerial.available()>0){ incomingByte=mySerial.read(); if(incomingByte=='I'){ startDataReceived=true; buffer[0]=incomingByte;}} if((startDataReceived==true)&&(mySerial.available()>0)){ for(i=1;i<byteSize;i++){ while(mySerial.available()==0){} buffer=mySerial.read();} startDataReceived=false; dataAvailable=true;} if(dataAvailable==true){ range=strtok(buffer, ","); watts=strtok(NULL, ","); va=strtok(NULL, ","); var=strtok(NULL, ","); pf=strtok(NULL, ","); volts=strtok(NULL, ","); amps=strtok(NULL, ",");
Serial.print("Watts: "); Serial.println(watts); Serial.print("Va: "); Serial.println(va); Serial.print("Var: "); Serial.println(var); Serial.print("Pf: "); Serial.println(pf); Serial.print("Volts: "); Serial.println(volts); Serial.print("Amps: "); Serial.println(amps); memset(buffer,NULL,byteSize); dataAvailable=false;}} void pulseOn(){ digitalWrite(pulseLed,HIGH); delay(5000); digitalWrite(pulseLed,LOW);} void displayData(){ lcd.setCursor(0,0); lcd.print(wattSecond,0); lcd.print("w "); lcd.setCursor(0,1); lcd.print(wattHour/1000, 4); lcd.print("kwh ");}
void loop(){ extractData(); wattSecond+=atof(watts); currentwattHour=wattSecond/3600; wattHour=wattSecond/3600; displayData(); currentConsumption=currentwattHour; if((currentConsumption-lastConsumption)>(KWHInterval)){ lastConsumption+=KWHInterval; pulseOn();}}
|
|
|
|
|