-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOpenlogger NIGHTMARE
164 lines (142 loc) · 4.57 KB
/
Openlogger NIGHTMARE
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#include <SPI.h>
#include <SD.h>
#include <Wire.h> //I2C Library
int ledPin = 13; // LED connected to digital pin 13, up for change
//JSON
const int chipSelect = 10;
//I2C Temperature Pins
//SDA = Analog Pin 4
//SCL = Analog Pin 5
//IR Distance Sensor Pins
int IR1_pin = 2;
int IR2_pin = 3;
File myFile;
void setup()
{
pinMode(ledPin, OUTPUT);
Serial.begin(9600); //9600bps is default for OpenLog
//Serial.begin(57600); //Much faster serial, used for testing buffer overruns on OpenLog
//Serial.begin(115200); //Much faster serial, used for testing buffer overruns on OpenLog
delay(1000); //Wait a second for OpenLog to init
Serial.println();
Serial.println("Run OpenLog Test");
// wait for Serial Monitor to connect. Needed for native USB port boards only:
while (!Serial);
Serial.print("Initializing SD card...");
if (!SD.begin(10)) {
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");
if (SD.exists("example.txt")) {
Serial.println("example.txt exists.");
} else {
Serial.println("example.txt doesn't exist.");
}
// open a new file and immediately close it:
Serial.println("Creating example.txt...");
myFile = SD.open("example.txt", FILE_WRITE);
myFile.close();
// Check to see if the file exists:
if (SD.exists("example.txt")) {
Serial.println("example.txt exists.");
} else {
Serial.println("example.txt doesn't exist.");
}
}
void loop()
{
int testAmt = 10;
//At 9600, testAmt of 4 takes about 1 minute, 10 takes about 3 minutes
//At 57600, testAmt of 10 takes about 1 minute, 40 takes about 5 minutes
//testAmt of 10 will push 111,000 characters/bytes. With header and footer strings, total is 111,052
//Each test is 100 lines. 10 tests is 1000 lines (11,000 characters)
for(int numofTests = 0 ; numofTests < testAmt ; numofTests++)
{
//This loop will print 100 lines of 110 characters each
for(int k = 33; k < 43 ; k++)
{
//Print one line of 110 characters with marker in the front (markers go from '!' to '*')
Serial.print(k, BYTE); //Print the ASCII value directly: ! then " then #, etc
Serial.println(":abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-!#");
//delay(50);
//Then print 9 lines of 110 characters with new line at the end of the line
for(int i = 1 ; i < 10 ; i++)
{
Serial.print(i, DEC);
Serial.println(":abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-!#");
//delay(50);
}
if(digitalRead(ledPin) == 0)
digitalWrite(ledPin, HIGH);
else
digitalWrite(ledPin, LOW);
}
}
unsigned long totalCharacters = (long)testAmt * 100 * 110;
Serial.print("Characters pushed: ");
Serial.println(totalCharacters);
Serial.print("Time taken (s): ");
Serial.println(millis()/1000);
Serial.println("Done!");
while(1)
{
digitalWrite(ledPin, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(ledPin, LOW); // set the LED off
delay(1000); // wait for a second
}
}
//Read the Configuration information (COMMANDS.txt)
File commandFile = SD.open("COMMANDS.txt");
if (commandFile)
{
Serial.println("Reading Command File");
float decade = pow(10, (commandFile.available() - 1));
while(commandFile.available())
{
float temp = (commandFile.read() - '0');
}
Serial.print("Temperature = ");
Serial.print(temp);
Serial.println("ms");
commandFile.close();
}
else
{
Serial.println("Could not read command file.");
return;
}
//Write Log File Header
File logFile = SD.open("LOG.csv", FILE_WRITE);
if (logFile)
{
logFile.println(", , , ,"); //Just a leading blank line, incase there was previous data
String header = "ID, Light, Temp, IR1, IR2";
logFile.println(header);
logFile.close();
Serial.println(header);
}
else
{
Serial.println("Couldn't open log file");
}
//Create Data string for storing to SD card
//We will use CSV Format
String dataString = String(id) + ", " + String(temp_f) + ", " + String(IR1_val) + ", " + String(IR2_val);
//Open a file to write to
//Only one file can be open at a time
File logFile = SD.open("LOG.csv", FILE_WRITE);
if (logFile)
{
logFile.println(dataString);
logFile.close();
Serial.println(dataString);
}
else
{
Serial.println("Couldn't open log file");
}
//Increment ID number
id++;
}