Reading Multiple Temperature Sensors
in
Integration and Hardware
•
4 months ago
I am trying to get my Arduino Uno to read multiple temperature sensors. I have it reading one and and outputting the time, but the second sensor keeps reading 0.00. The code is below. I have no idea why this is happening. I would appreciate any help. Thank you!
Sample Output:
1.425
24.31 0.00
2.676
24.31 0.00
3.943
24.25 0.00
5.176
24.31 0.00
6.426
24.31 0.00
7.693
24.31 0.00
8.927
24.31 0.00
10.177
24.31 0.00
11.427
24.31 0.00
12.678
24.31 0.00
13.928
24.31 0.00
15.178
24.31 0.00
16.428
24.31 0.00
17.678
24.31 0.00
18.928
24.31 0.00
20.162
24.31 0.00
21.412
24.31 0.00
- import processing.serial.*;
- PFont myFont; // The display font:
- String inString; // Input string from serial port:
- int lf = 10; // ASCII linefeed
- PrintWriter output;
- DateFormat fnameFormat= new SimpleDateFormat("yyMMdd_HHmm");
- DateFormat timeFormat = new SimpleDateFormat("hh:mm:ss");
- String fileName;
- Serial myPort; // Create object from Serial class
- short portIndex = 0; // select the com port, 0 is the first port;
- long timeold = 0;
- int interval = 500;
- int linefeed = 10; // Linefeed in ASCII
- void setup()
- {
- // Open whatever serial port is connected to Arduino.
- String portName = Serial.list()[portIndex];
- println(Serial.list());
- println(" Connecting to -> " + Serial.list()[portIndex]);
- myPort = new Serial(this, portName, 9600);
- Date now = new Date();
- fileName = fnameFormat.format(now);
- output = createWriter(fileName + ".csv"); // save the file in the sketch folder
- background(50);
- myPort.bufferUntil(linefeed);
- }
- void draw()
- {
- int val;
- String time;
- while ( myPort.available() >= 15) // wait for the entire message to arrive
- {
- long currentTime = millis();
- if(currentTime - timeold > interval) {
- String inString = myPort.readStringUntil('\n');
- String[] words = split(inString, '\t');
- String temp = words[0];
- println(temp);
- output.print(currentTime / 1000.0);
- output.print(", ");
- output.println(temp);
- }
- }
- }
- void keyPressed() {
- output.flush(); // Writes the remaining data to the file
- output.close(); // Finishes the file
- exit(); // Stops the program
- }
1