Skip to content

Commit 88e1a41

Browse files
Arduino CSV
0 parents  commit 88e1a41

File tree

3 files changed

+126
-0
lines changed

3 files changed

+126
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//TMP36 Pin Variables
2+
int sensorPin = 0; //the analog pin the TMP36's Vout (sense) pin is connected to
3+
//the resolution is 10 mV / degree centigrade with a
4+
//500 mV offset to allow for negative temperatures
5+
6+
/*
7+
* setup() - this function runs once when you turn your Arduino on
8+
* We initialize the serial connection with the computer
9+
*/
10+
void setup()
11+
{
12+
Serial.begin(9600); //Start the serial connection with the computer
13+
//to view the result open the serial monitor
14+
}
15+
16+
void loop() // run over and over again
17+
{
18+
//getting the voltage reading from the temperature sensor
19+
int reading = analogRead(sensorPin);
20+
21+
// converting that reading to voltage, for 3.3v arduino use 3.3
22+
float voltage = reading * 5.0;
23+
voltage /= 1024.0;
24+
25+
// now calculate temperature in Celcius
26+
float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset
27+
//to degrees ((voltage - 500mV) times 100)
28+
29+
// now convert to Fahrenheit
30+
float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
31+
Serial.print(temperatureF); Serial.println("F");
32+
33+
delay(1000); //waiting a second
34+
}
35+
36+
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import processing.serial.*;
2+
Serial myPort;
3+
String sensorReading="";
4+
import java.io.BufferedWriter;
5+
import java.io.FileWriter;
6+
String outFilename = "data.csv";
7+
8+
String timestamp = "";
9+
10+
void setup() {
11+
size(400,200);
12+
myPort = new Serial(this,"/dev/cu.usbmodem1411", 9600); //Arduino Port
13+
myPort.bufferUntil('\n');
14+
writeText("data visualization, stop with any key"); //Data Vizualization
15+
16+
}
17+
18+
void draw() {
19+
//The serialEvent controls the display
20+
}
21+
22+
void serialEvent (Serial myPort){
23+
sensorReading = myPort.readStringUntil('\n');
24+
if(sensorReading != null){
25+
sensorReading=trim(sensorReading);
26+
timestamp=year()+"/"+month()+"/"+day()+" "+hour()+":"+minute()+":"+second()+"," ;
27+
}
28+
// make a timestamp
29+
30+
31+
writeText("Sensor Reading: " + timestamp + sensorReading);
32+
33+
appendTextToFile(outFilename, timestamp + sensorReading);
34+
35+
}
36+
37+
38+
void writeText(String textToWrite){
39+
background(255);
40+
fill(0);
41+
text(textToWrite, width/20, height/2);
42+
}
43+
44+
45+
void keyPressed() {
46+
47+
exit(); // Stops the program with any key pressed
48+
}
49+
50+
/**
51+
* Appends text to the end of a text file located in the data directory,
52+
* creates the file if it does not exist.
53+
* Can be used for big files with lots of rows,
54+
* existing lines will not be rewritten
55+
*/
56+
57+
void appendTextToFile(String filename, String text){
58+
File f = new File(dataPath(filename));
59+
if(!f.exists()){
60+
createFile(f);
61+
}
62+
try {
63+
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f, true))); // true to append the output
64+
out.println(text);
65+
out.close(); // clean close allows to read / copy file while processing runs
66+
}catch (IOException e){
67+
e.printStackTrace();
68+
}
69+
}
70+
71+
// The below part create new subfolder.
72+
73+
void createFile(File f){
74+
File parentDir = f.getParentFile();
75+
try{
76+
parentDir.mkdirs();
77+
f.createNewFile();
78+
}
79+
catch(Exception e){
80+
e.printStackTrace();
81+
}
82+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
null
2+
2015/7/21 12:20:59,79.11F
3+
2015/7/21 12:20:59,78.23F
4+
2015/7/21 12:21:0,78.23F
5+
2015/7/21 12:21:1,79.11F
6+
2015/7/21 12:21:2,78.23F
7+
2015/7/21 12:21:3,78.23F
8+
2015/7/21 12:21:4,79.11F

0 commit comments

Comments
 (0)