|
1 |
| -/* |
2 |
| - 6-1-2011 |
3 |
| - SparkFun Electronics 2011 |
4 |
| - Nathan Seidle |
5 |
| - |
6 |
| - Controlling OpenLog command line from an Arduino |
7 |
| - |
8 |
| - Connect the following OpenLog to Arduino: |
9 |
| - TXO of OpenLog to RX of the Arduino |
10 |
| - RXI to TX |
11 |
| - GRN to 2 |
12 |
| - VCC to 5V |
13 |
| - GND to GND |
14 |
| - |
15 |
| - NOTE: When uploading this example code you must temporarily disconnect TX and RX while uploading |
16 |
| - the new code to the Arduino. Otherwise you will get a "avrdude: stk500_getsync(): not in sync" error. |
17 |
| - |
18 |
| - This example code assumes the OpenLog is set to operate at 9600bps in NewLog mode, meaning OpenLog |
19 |
| - should power up and output '12<'. This code then sends the three escape characters and then sends |
20 |
| - the commands to create a new random file called nate###.txt where ### is a random number from 0 to 999. |
21 |
| - |
22 |
| - This code assume OpenLog is in the default state of 9600bps with ASCII-26 as the esacape character. |
23 |
| - |
24 |
| - Be careful when sending commands to OpenLog. println() sends extra newline characters that |
25 |
| - cause problems with the command parser. The new v2.51 ignores \n commands so it should be easier to |
26 |
| - talk to on the command prompt level. This example code works with all OpenLog v2 and higher. |
27 |
| - |
28 |
| - */ |
29 |
| - |
30 |
| -char buff[50]; |
31 |
| -int fileNumber; |
32 |
| - |
33 |
| -int statLED = 13; |
34 |
| -int resetOpenLog = 2; |
35 |
| - |
36 |
| -void setup() { |
37 |
| - pinMode(statLED, OUTPUT); |
38 |
| - pinMode(resetOpenLog, OUTPUT); |
39 |
| - |
40 |
| - randomSeed(analogRead(0)); |
41 |
| - Serial.begin(9600); |
42 |
| - |
43 |
| - //Reset OpenLog |
44 |
| - digitalWrite(resetOpenLog, LOW); |
45 |
| - delay(100); |
46 |
| - digitalWrite(resetOpenLog, HIGH); |
47 |
| - |
48 |
| - //Wait for OpenLog to respond with '<' to indicate it is alive and recording to a file |
49 |
| - while(1) { |
50 |
| - if(Serial.available()) |
51 |
| - if(Serial.read() == '<') break; |
52 |
| - } |
53 |
| - |
54 |
| - //Send three control z to enter OpenLog command mode |
55 |
| - //This is how Arduino v0022 used to do it. Doesn't work with v1.0 |
56 |
| - //Serial.print(byte(26)); |
57 |
| - //Serial.print(byte(26)); |
58 |
| - //Serial.print(byte(26)); |
59 |
| - |
60 |
| - //Works with Arduino v1.0 |
61 |
| - Serial.write(26); |
62 |
| - Serial.write(26); |
63 |
| - Serial.write(26); |
64 |
| - |
65 |
| - //Wait for OpenLog to respond with '>' to indicate we are in command mode |
66 |
| - while(1) { |
67 |
| - if(Serial.available()) |
68 |
| - if(Serial.read() == '>') break; |
69 |
| - } |
70 |
| - |
71 |
| - fileNumber = random(999); //Select a random file #, 0 to 999 |
72 |
| - |
73 |
| - //Send new (random from 0 to 999) file name |
74 |
| - |
75 |
| - //Old way |
76 |
| - sprintf(buff, "new nate%03d.txt\r", fileNumber); |
77 |
| - Serial.print(buff); //\r in string + regular print works with older v2.5 Openlogs |
78 |
| - |
79 |
| - //New way |
80 |
| - //sprintf(buff, "new nate%03d.txt", fileNumber); |
81 |
| - //Serial.println(buff); //regular println works with v2.51 and above |
82 |
| - |
83 |
| - //Wait for OpenLog to return to waiting for a command |
84 |
| - while(1) { |
85 |
| - if(Serial.available()) |
86 |
| - if(Serial.read() == '>') break; |
87 |
| - } |
88 |
| - |
89 |
| - sprintf(buff, "append nate%03d.txt\r", fileNumber); |
90 |
| - Serial.print(buff); |
91 |
| - |
92 |
| - //Wait for OpenLog to indicate file is open and ready for writing |
93 |
| - while(1) { |
94 |
| - if(Serial.available()) |
95 |
| - if(Serial.read() == '<') break; |
96 |
| - } |
97 |
| -} |
98 |
| - |
99 |
| -void loop() { |
100 |
| - Serial.println("Yay!"); |
101 |
| - digitalWrite(13, HIGH); |
102 |
| - delay(1000); |
103 |
| - digitalWrite(13, LOW); |
104 |
| - delay(1000); |
105 |
| -} |
106 |
| - |
107 |
| - |
| 1 | +/* |
| 2 | + 6-1-2011 |
| 3 | + SparkFun Electronics 2011 |
| 4 | + Nathan Seidle |
| 5 | + |
| 6 | + Controlling OpenLog command line from an Arduino |
| 7 | + |
| 8 | + Connect the following OpenLog to Arduino: |
| 9 | + TXO of OpenLog to RX of the Arduino |
| 10 | + RXI to TX |
| 11 | + GRN to 2 |
| 12 | + VCC to 5V |
| 13 | + GND to GND |
| 14 | + |
| 15 | + NOTE: When uploading this example code you must temporarily disconnect TX and RX while uploading |
| 16 | + the new code to the Arduino. Otherwise you will get a "avrdude: stk500_getsync(): not in sync" error. |
| 17 | + |
| 18 | + This example code assumes the OpenLog is set to operate at 9600bps in NewLog mode, meaning OpenLog |
| 19 | + should power up and output '12<'. This code then sends the three escape characters and then sends |
| 20 | + the commands to create a new random file called nate###.txt where ### is a random number from 0 to 999. |
| 21 | + |
| 22 | + This code assume OpenLog is in the default state of 9600bps with ASCII-26 as the esacape character. |
| 23 | + |
| 24 | + Be careful when sending commands to OpenLog. println() sends extra newline characters that |
| 25 | + cause problems with the command parser. The new v2.51 ignores \n commands so it should be easier to |
| 26 | + talk to on the command prompt level. This example code works with all OpenLog v2 and higher. |
| 27 | + |
| 28 | + */ |
| 29 | + |
| 30 | +char buff[50]; |
| 31 | +int fileNumber; |
| 32 | + |
| 33 | +int statLED = 13; |
| 34 | +int resetOpenLog = 2; |
| 35 | + |
| 36 | +void setup() { |
| 37 | + pinMode(statLED, OUTPUT); |
| 38 | + pinMode(resetOpenLog, OUTPUT); |
| 39 | + |
| 40 | + randomSeed(analogRead(0)); |
| 41 | + Serial.begin(9600); |
| 42 | + |
| 43 | + //Reset OpenLog |
| 44 | + digitalWrite(resetOpenLog, LOW); |
| 45 | + delay(100); |
| 46 | + digitalWrite(resetOpenLog, HIGH); |
| 47 | + |
| 48 | + //Wait for OpenLog to respond with '<' to indicate it is alive and recording to a file |
| 49 | + while(1) { |
| 50 | + if(Serial.available()) |
| 51 | + if(Serial.read() == '<') break; |
| 52 | + } |
| 53 | + |
| 54 | + //Send three control z to enter OpenLog command mode |
| 55 | + //This is how Arduino v0022 used to do it. Doesn't work with v1.0 |
| 56 | + //Serial.print(byte(26)); |
| 57 | + //Serial.print(byte(26)); |
| 58 | + //Serial.print(byte(26)); |
| 59 | + |
| 60 | + //Works with Arduino v1.0 |
| 61 | + Serial.write(26); |
| 62 | + Serial.write(26); |
| 63 | + Serial.write(26); |
| 64 | + |
| 65 | + //Wait for OpenLog to respond with '>' to indicate we are in command mode |
| 66 | + while(1) { |
| 67 | + if(Serial.available()) |
| 68 | + if(Serial.read() == '>') break; |
| 69 | + } |
| 70 | + |
| 71 | + fileNumber = random(999); //Select a random file #, 0 to 999 |
| 72 | + |
| 73 | + //Send new (random from 0 to 999) file name |
| 74 | + |
| 75 | + //Old way |
| 76 | + sprintf(buff, "new nate%03d.txt\r", fileNumber); |
| 77 | + Serial.print(buff); //\r in string + regular print works with older v2.5 Openlogs |
| 78 | + |
| 79 | + //New way |
| 80 | + //sprintf(buff, "new nate%03d.txt", fileNumber); |
| 81 | + //Serial.println(buff); //regular println works with v2.51 and above |
| 82 | + |
| 83 | + //Wait for OpenLog to return to waiting for a command |
| 84 | + while(1) { |
| 85 | + if(Serial.available()) |
| 86 | + if(Serial.read() == '>') break; |
| 87 | + } |
| 88 | + |
| 89 | + sprintf(buff, "append nate%03d.txt\r", fileNumber); |
| 90 | + Serial.print(buff); |
| 91 | + |
| 92 | + //Wait for OpenLog to indicate file is open and ready for writing |
| 93 | + while(1) { |
| 94 | + if(Serial.available()) |
| 95 | + if(Serial.read() == '<') break; |
| 96 | + } |
| 97 | +} |
| 98 | + |
| 99 | +void loop() { |
| 100 | + Serial.println("Yay!"); |
| 101 | + digitalWrite(13, HIGH); |
| 102 | + delay(1000); |
| 103 | + digitalWrite(13, LOW); |
| 104 | + delay(1000); |
| 105 | +} |
| 106 | + |
| 107 | + |
0 commit comments