Israel
Offline
Jr. Member
Karma: 0
Posts: 84
|
 |
« on: April 07, 2012, 03:19:32 pm » |
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
Jr. Member
Karma: 0
Posts: 84
|
 |
« Reply #1 on: April 07, 2012, 07:28:09 pm » |
Someone?
|
|
|
|
|
Logged
|
|
|
|
|
New Jersey
Offline
Edison Member
Karma: 26
Posts: 2450
|
 |
« Reply #2 on: April 08, 2012, 07:48:19 am » |
What does it do it you never open the serial monitor?
|
|
|
|
|
Logged
|
|
|
|
|
Phillipsburg, NJ
Offline
Full Member
Karma: 6
Posts: 141
Author: Matrix Keypad Library
|
 |
« Reply #3 on: April 08, 2012, 09:13:52 am » |
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(): if (logFile) { logFile.println(dataString); logFile.close(); if (serial_avail == true) Serial.println(dataString); end }
And... 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. 
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 1
Posts: 54
|
 |
« Reply #4 on: April 08, 2012, 11:30:06 am » |
Could you also use if(Serial.available() >0) { Serial.println(dataString); } ?
|
|
|
|
|
Logged
|
|
|
|
|
Phillipsburg, NJ
Offline
Full Member
Karma: 6
Posts: 141
Author: Matrix Keypad Library
|
 |
« Reply #5 on: April 08, 2012, 03:11:42 pm » |
Could you also use 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
Jr. Member
Karma: 0
Posts: 84
|
 |
« Reply #6 on: April 08, 2012, 03:29:31 pm » |
What does it do it you never open the serial monitor?
It doesn't even create a csv file on SD card. 
|
|
|
|
|
Logged
|
|
|
|
|
Israel
Offline
Jr. Member
Karma: 0
Posts: 84
|
 |
« Reply #7 on: April 08, 2012, 03:52:55 pm » |
mstanley and Could you also use 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
Jr. Member
Karma: 1
Posts: 54
|
 |
« Reply #8 on: April 08, 2012, 05:39:42 pm » |
Could you also use 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! 
|
|
|
|
|
Logged
|
|
|
|
|
Israel
Offline
Jr. Member
Karma: 0
Posts: 84
|
 |
« Reply #9 on: April 08, 2012, 05:46:08 pm » |
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
Jr. Member
Karma: 0
Posts: 84
|
 |
« Reply #10 on: April 08, 2012, 08:01:16 pm » |
...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
Melbourne, Australia
Offline
Shannon Member
Karma: 226
Posts: 14101
Lua rocks!
|
 |
« Reply #11 on: April 08, 2012, 09:16:58 pm » |
What does the debug output show?
|
|
|
|
|
Logged
|
|
|
|
|
Israel
Offline
Jr. Member
Karma: 0
Posts: 84
|
 |
« Reply #12 on: April 08, 2012, 09:30:52 pm » |
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
Full Member
Karma: 6
Posts: 141
Author: Matrix Keypad Library
|
 |
« Reply #13 on: April 08, 2012, 09:56:26 pm » |
...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
Jr. Member
Karma: 0
Posts: 84
|
 |
« Reply #14 on: April 09, 2012, 04:46:59 pm » |
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
|
|
|
|
|
|