Pages: [1]   Go Down
Author Topic: SD Card logging  (Read 1191 times)
0 Members and 1 Guest are viewing this topic.
Israel
Offline Offline
Jr. Member
**
Karma: 0
Posts: 84
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hello,
I wrote a small code to collect values from some sensors and to write on SD card in csv format.
It does the work but only when I have serial monitor open. Writing on SD card stops after the moment I close serial monitor.
I want the process to keep going on until the time I turn off Arduino since this sensor unit will be working standalone without any connection with a computer.

Thanks a lot.

Regards,
Z

ps. I am using Arduino Mega and official Arduino Ethernet Shield.
« Last Edit: April 09, 2012, 05:50:44 pm by zeus2kx » Logged

Israel
Offline Offline
Jr. Member
**
Karma: 0
Posts: 84
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Someone?
Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 65
Posts: 3638
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What does it do it you never open the serial monitor?
Logged

Phillipsburg, NJ
Offline Offline
Full Member
***
Karma: 6
Posts: 184
Author: Matrix Keypad Library
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Everytime you are writing to the SD card you are trying to send dataString over a serial connection that doesn't exist.  I would suggest adding a flag, that you can control from your pc, to this bit of code at the end of your loop():
Code:
  if (logFile)
  {
    logFile.println(dataString);
    logFile.close();
    if (serial_avail == true)
        Serial.println(dataString);
    end
  }

And...
Code:
boolean serial_avail = false;

void setup(){
.
.
.
}

Then, write a small function that will allow you to send a command to change the value of serial_avail when you connect to the serial port.

Just don't forget to set it back to false before disconnecting the serial port. smiley-wink
Logged

Offline Offline
Jr. Member
**
Karma: 1
Posts: 54
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Could you also use
Code:
if(Serial.available() >0) { Serial.println(dataString); }
?
Logged

Phillipsburg, NJ
Offline Offline
Full Member
***
Karma: 6
Posts: 184
Author: Matrix Keypad Library
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Could you also use
Code:
if(Serial.available() >0) { Serial.println(dataString); }
?
I thought the same thing at first but I figured since Serial.available() only checks for incoming data what happens if he never sends any data from his pc even if the Arduino serial port is open? That would mean he would have to constantly send requests from the pc before the Arduino would send any logging info.

Unless I'm completely missing how Serial.available() works which is a distinct possibility.
Logged

Israel
Offline Offline
Jr. Member
**
Karma: 0
Posts: 84
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What does it do it you never open the serial monitor?
It doesn't even create a csv file on SD card.  smiley-roll-sweat
Logged

Israel
Offline Offline
Jr. Member
**
Karma: 0
Posts: 84
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

mstanley and
Could you also use
Code:
if(Serial.available() >0) { Serial.println(dataString); }
?

I am trying make the code work for me..
Do you guys have a better data logger code?

Thanks.

Z
Logged

Offline Offline
Jr. Member
**
Karma: 1
Posts: 54
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Could you also use
Code:
if(Serial.available() >0) { Serial.println(dataString); }
?
I thought the same thing at first but I figured since Serial.available() only checks for incoming data what happens if he never sends any data from his pc even if the Arduino serial port is open? That would mean he would have to constantly send requests from the pc before the Arduino would send any logging info.

Unless I'm completely missing how Serial.available() works which is a distinct possibility.
Ah, I see.

Don't use that then, Z!  smiley-razz
Logged

Israel
Offline Offline
Jr. Member
**
Karma: 0
Posts: 84
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No, it worked after I applied at two different places in code.
Now a csv file is created and written even I don't turn on serial monitor first or I turn on in the middle.
Kindly comment how is it possible to make this code more efficient.

Thanks.

Z
« Last Edit: April 09, 2012, 05:51:18 pm by zeus2kx » Logged

Israel
Offline Offline
Jr. Member
**
Karma: 0
Posts: 84
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

...not really.
It doesn't work if USB is not connected. There is also no file present on SD card.
Please post a solution.

Thanks.

Z
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What does the debug output show?
Logged

Israel
Offline Offline
Jr. Member
**
Karma: 0
Posts: 84
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What does the debug output show?
I am testing the code without serial monitor (USB unplugged). If not (with USB), code creates a csv file and logs data. Without USB (Serial monitor), this code is even unable to create a file on SD.
I want Arduino to work standalone without a computer/no serial communication/no USB attached, only powered by AC adopter.

Thanks.

Z
Logged

Phillipsburg, NJ
Offline Offline
Full Member
***
Karma: 6
Posts: 184
Author: Matrix Keypad Library
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

...not really.
It doesn't work if USB is not connected. There is also no file present on SD card.
Please post a solution.
Go back to my first post and try using the boolean flag like I showed you.  When the USB is disconnected you need to avoid calling any Serial functions.  By using the flag it will prevent those calls unless the USB is connected AND you tell your sketch it's OK to use the serial port.
Logged

Israel
Offline Offline
Jr. Member
**
Karma: 0
Posts: 84
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

mstanley
Thanks, problem solved.
There wasn't any problem with code but the way I was using it.
After everytime I unplug USB cable, I need to turn off and on Arduino for working.

Z
Logged

Pages: [1]   Go Up
Jump to: