Im using 20x4 lcd wid my uno. I get 2 analog values from temp sensor and current transformer (virtually im giving input wid a pot) and also read accelerometer via I2C (lsm303) all these values need to be logged in a micro SD (SFE Shield).
i initi lcd as LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
problem are
- sometimes arduino resets randomly (rather i say its not entering loop()) this happens only when i run this prog
2.or i get a running(i donn how to say tis) like its printing too fast on 1st & 2nd line (its not the blacked out boxes)
please help i ran a eg program from lib and also some i wrote(that inclueds only lcd lib) they run w/o any probs ....
my guess is its conflicting wid sd or i2c
i also tried external power 12/700mA, thinking that reseting ll b due to insuffice power
#include <SD.h>
#include <Wire.h>
#include <LSM303.h>
#include <LiquidCrystal.h>LSM303 compass;
File myFile;const int chipSelect = 8;
static int h,m,s,ms;
int sensor,ct,ON_OFF=9;
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);void dc(float d=3)
{
delay(d*1000);
lcd.clear();
}void lp(String s , int x=0, int y=0)
{
lcd.setCursor(x,y);
lcd.print(s);
}void setup()
{lcd.begin(20, 4); // lcd init
lp("Initializing microSD",0,0);
pinMode(10, OUTPUT);
if (!SD.begin(chipSelect))
{
lp("Card not present...",0,1);
return;
}
lp("Card Initialized...",0,1);Wire.begin();
compass.init();
compass.enableDefault();
lp("Compass Initialized ",0,2);dc();//clr
if(SD.exists("data"))
{
lp("Data folder exists ",0,0);
}
else
{
lp("Data doesn't exists ",0,0);
lp("Creating data folder",0,1);
SD.mkdir("data");
// myFile = SD.open("data");
// myFile.close();
}if (SD.exists("data/log.lvm"))
{
lp("data/log.lvm exists.",0,2);
}
else
{
lp("log.lvm doesn't exist",0,2);
lp("Creating data/log.lvm",0,3);
myFile = SD.open("data/log.lvm", FILE_WRITE);
myFile.close();
}dc();
pinMode(ON_OFF,INPUT);}
void loop()
{if(digitalRead(ON_OFF))
{lp("Data Being Logged ",0,0);
lp("Temp: ",0,1);
lp("Iph:",7,1);
compass.read();ms = (millis()%1000)/100;
s = (millis()/1000)%60;
m = (millis()/60000)%60;
h = (millis()/3600000)%24;
String dataString = String(h)+':'+String(m)+':'+String(s)+'.'+String(ms);
// lp(dataString,0,2);for (ct = 0; ct < 3; ct++)
{
if(ct==0)
{
sensor = (int)compass.a.x;
}
else if(ct==1)
{
sensor = (int)compass.a.y;
}
else
{
sensor = (int)compass.a.z;
}dataString += ",";
dataString += String(sensor);
}File myfile = SD.open("data/log.lvm", FILE_WRITE);
if (myfile)
{
myfile.println(dataString);
myfile.close();
Serial.println(dataString);
}
else
{
dc();
lp(" Error opening file ",0,1);
dc(10);
return;
}delay(200);
}
else if(!digitalRead(ON_OFF))
{
myFile = SD.open("data");if(myFile)
{
if(SD.remove("data/log.lvm"))
{
dc();
lp("log.lvm removed... ");
return;
}
else
{
dc();
lp("File doesn't exists...");
return;
}
}
myFile.close();
delay(500);
}}
any help is appreciated...
json