Permalink
Browse files

v2.51 Improved command prompt parsing (now ignores '\n')

We now ignore the \n character when parsing characters from the command prompt. This makes it easier to create code on a microcontroller that correctly controls OpenLog. Previously, println or sprintf commands were adding a \n to the end of the string that would confuse OpenLog. One way around this if you have previous versions is this
 sprintf(buff, "new blah.txt\r");
 Serial.print(buff); //No println, use \r in string instead

Also - added a CommandTest sketch to demonstrate how you can control OpenLog from a microcontroller / automate the command prompt
  • Loading branch information...
1 parent 8777803 commit 13b502bf2b8e1d978636f77826edec4abc338796 @nseidle nseidle committed Jun 1, 2011
Showing with 1,843 additions and 1,756 deletions.
  1. +90 −0 OpenLog_CommandTest/OpenLog_CommandTest.pde
  2. +1,733 −1,755 OpenLog_v2/OpenLog_v2.cpp.hex
  3. +17 −0 OpenLog_v2/OpenLog_v2.pde
  4. +3 −1 README
@@ -0,0 +1,90 @@
+/*
+ 6-1-2011
+ SparkFun Electronics 2011
+ Nathan Seidle
+
+ Controlling OpenLog command line from an Arduino
+
+ This example code assumes the OpenLog is set to operate in NewLog mode, meaning OpenLog should power
+ up and output '12<'. This code then sends the three escape characters and then sends the commands
+ to create a new random file called nate###.txt where ### is a random number from 0 to 999.
+
+ Be careful when sending commands to OpenLog. println() sends extra newline characters that
+ cause problems with the command parser. The new v2.51 ignores \n commands so it should be easier to
+ talk to on the command prompt level. This example code works with all OpenLog v2 and higher.
+
+ */
+
+char buff[50];
+int fileNumber;
+
+int statLED = 13;
+int resetOpenLog = 2;
+
+void setup() {
+ pinMode(statLED, OUTPUT);
+ pinMode(resetOpenLog, OUTPUT);
+
+ randomSeed(analogRead(0));
+ Serial.begin(115200);
+
+ //Reset OpenLog
+ digitalWrite(resetOpenLog, LOW);
+ delay(100);
+ digitalWrite(resetOpenLog, HIGH);
+
+ //Wait for OpenLog to respond with '<' to indicate it is alive and recording to a file
+ while(1) {
+ if(Serial.available())
+ if(Serial.read() == '<') break;
+ }
+
+ //Send three control z to enter OpenLog command mode
+ Serial.print(byte(26));
+ Serial.print(byte(26));
+ Serial.print(byte(26));
+
+ //Wait for OpenLog to respond with '>' to indicate we are in command mode
+ while(1) {
+ if(Serial.available())
+ if(Serial.read() == '>') break;
+ }
+
+ fileNumber = random(999); //Select a random file #, 0 to 999
+
+ //Send new (random from 0 to 999) file name
+
+ //Old way
+ sprintf(buff, "new nate%03d.txt\r", fileNumber);
+ Serial.print(buff); //\r in string + regular print works with older v2.5 Openlogs
+
+ //New way
+ //sprintf(buff, "new nate%03d.txt", fileNumber);
+ //Serial.println(buff); //regular println works with v2.51 and above
+
+
+ //Wait for OpenLog to return to waiting for a command
+ while(1) {
+ if(Serial.available())
+ if(Serial.read() == '>') break;
+ }
+
+ sprintf(buff, "append nate%03d.txt\r", fileNumber);
+ Serial.print(buff);
+
+ //Wait for OpenLog to indicate file is open and ready for writing
+ while(1) {
+ if(Serial.available())
+ if(Serial.read() == '<') break;
+ }
+}
+
+void loop() {
+ Serial.println("Yay!");
+ digitalWrite(13, HIGH);
+ delay(1000);
+ digitalWrite(13, LOW);
+ delay(1000);
+}
+
+
Oops, something went wrong.

0 comments on commit 13b502b

Please sign in to comment.