|
| 1 | +/* |
| 2 | + Example of creating a file, reading a file, and reading the disk properties on OpenLog |
| 3 | + By: Nathan Seidle |
| 4 | + SparkFun Electronics |
| 5 | + Date: September 22nd, 2013 |
| 6 | + License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license). |
| 7 | +
|
| 8 | + This example reads the firmware version of the OpenLog without the need for a USB to serial connection. |
| 9 | + The firmware version of your OpenLog is very helpful if you need tech support. |
| 10 | + |
| 11 | + Connect the following OpenLog to Arduino: |
| 12 | + RXI of OpenLog to pin 2 on the Arduino |
| 13 | + TXO to 3 |
| 14 | + GRN to 4 |
| 15 | + VCC to 5V |
| 16 | + GND to GND |
| 17 | + |
| 18 | + This example code assumes the OpenLog is set to operate in default mode. This is 9600bps |
| 19 | + in NewLog mode, meaning OpenLog should power up and output '12<'. This code then sends the |
| 20 | + three escape characters and then sends the commands to bring up the help menu '?' and then |
| 21 | + looks for the "OpenLog v4.0" text at the top of the menu. It will then print the version |
| 22 | + # to the serial terminal. |
| 23 | + |
| 24 | + This code assume OpenLog is in the default state of 9600bps with ASCII-26 as the esacape character. |
| 25 | + If you're unsure, make sure the config.txt file contains the following: 9600,26,3,0 |
| 26 | + |
| 27 | + Be careful when sending commands to OpenLog. println() sends extra newline characters that |
| 28 | + cause problems with the command parser. v2.51 and above ignores \n commands so it should be easier to |
| 29 | + talk to on the command prompt level. This example code works with all OpenLog v2 and higher. |
| 30 | + |
| 31 | + */ |
| 32 | + |
| 33 | +#include <SoftwareSerial.h> |
| 34 | + |
| 35 | +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- |
| 36 | +//Connect TXO of OpenLog to pin 3, RXI to pin 2 |
| 37 | +SoftwareSerial OpenLog(3, 2); //Soft RX on 3, Soft TX out on 2 |
| 38 | +//SoftwareSerial(rxPin, txPin) |
| 39 | + |
| 40 | +int resetOpenLog = 4; //This pin resets OpenLog. Connect pin 4 to pin GRN on OpenLog. |
| 41 | +//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- |
| 42 | + |
| 43 | +int statLED = 13; |
| 44 | + |
| 45 | +void setup() { |
| 46 | + pinMode(statLED, OUTPUT); |
| 47 | + Serial.begin(9600); |
| 48 | + |
| 49 | + Serial.println("Find OpenLog Firmware Version"); |
| 50 | + |
| 51 | + setupOpenLog(); //Resets logger and waits for the '<' I'm alive character |
| 52 | + Serial.println("OpenLog online"); |
| 53 | + |
| 54 | + gotoCommandMode(); //Puts OpenLog in command mode |
| 55 | + OpenLog.println('?'); //Send a character to get help menu |
| 56 | + delay(100); |
| 57 | + |
| 58 | + byte counter = 200; |
| 59 | + while(OpenLog.available() && counter > 0) |
| 60 | + { |
| 61 | + byte incoming = OpenLog.read(); |
| 62 | + if(incoming == 'v') counter = 4; //Get the next four characters |
| 63 | + |
| 64 | + Serial.write(incoming); |
| 65 | + counter--; |
| 66 | + } |
| 67 | + Serial.println(); |
| 68 | +} |
| 69 | + |
| 70 | +void loop() { |
| 71 | + //Do nothing |
| 72 | +} |
| 73 | + |
| 74 | +//Setups up the software serial, resets OpenLog so we know what state it's in, and waits |
| 75 | +//for OpenLog to come online and report '<' that it is ready to receive characters to record |
| 76 | +void setupOpenLog(void) { |
| 77 | + pinMode(resetOpenLog, OUTPUT); |
| 78 | + OpenLog.begin(9600); |
| 79 | + |
| 80 | + //Reset OpenLog |
| 81 | + digitalWrite(resetOpenLog, LOW); |
| 82 | + delay(100); |
| 83 | + digitalWrite(resetOpenLog, HIGH); |
| 84 | + |
| 85 | + //Wait for OpenLog to respond with '<' to indicate it is alive and recording to a file |
| 86 | + while(1) { |
| 87 | + if(OpenLog.available()) |
| 88 | + if(OpenLog.read() == '<') break; |
| 89 | + } |
| 90 | +} |
| 91 | + |
| 92 | +//This function pushes OpenLog into command mode |
| 93 | +void gotoCommandMode(void) { |
| 94 | + //Send three control z to enter OpenLog command mode |
| 95 | + //Works with Arduino v1.0 |
| 96 | + OpenLog.write(26); |
| 97 | + OpenLog.write(26); |
| 98 | + OpenLog.write(26); |
| 99 | + |
| 100 | + //Wait for OpenLog to respond with '>' to indicate we are in command mode |
| 101 | + while(1) { |
| 102 | + if(OpenLog.available()) |
| 103 | + if(OpenLog.read() == '>') break; |
| 104 | + } |
| 105 | +} |
0 commit comments