Arduino to Processing Communication Issue
hello,
i have code uses 2 temperature sensors. works great on arduino , able output serial monitor. problem comes when attempt send data processing , create .csv file data. arduino , processing both attempting use com3, , of course can't @ same time. processing creates .csv file, not have data in it. point out issue? have tried can think of @ point. code below:
arduino:
processing:
thank in advance!!!
i have code uses 2 temperature sensors. works great on arduino , able output serial monitor. problem comes when attempt send data processing , create .csv file data. arduino , processing both attempting use com3, , of course can't @ same time. processing creates .csv file, not have data in it. point out issue? have tried can think of @ point. code below:
arduino:
code: [select]
#include <onewire.h>
#include <dallastemperature.h>
#define one_wire_bus 2 /*-(connect pin 2 )-*/
#define bus2 4
onewire ourwire(one_wire_bus);
onewire ourwire2(bus2);
dallastemperature sensors(&ourwire);
dallastemperature sensors2(&ourwire2);
void setup()
{
serial.begin(9600);
delay(1000);
sensors.begin();
}
void loop()
serial.println();
sensors.requesttemperatures();
serial.print(sensors.gettempcbyindex(0));
serial.print(", ");
sensors2.requesttemperatures();
serial.print(sensors2.gettempcbyindex(0));
delay(1000);
}
processing:
code: [select]
import processing.serial.*;
printwriter output;
dateformat fnameformat= new simpledateformat("yymmdd_hhmm");
dateformat timeformat = new simpledateformat("hh:mm:ss");
string filename;
serial myport;
short portindex = 0;
char header = 'h';
void setup()
{
size(200, 200);
string portname = serial.list()[portindex];
println(serial.list());
println(" connecting -> " + serial.list()[portindex]);
myport = new serial(this, portname, 9600);
date = new date();
filename = fnameformat.format(now);
output = createwriter(filename + ".csv");
}
void draw()
{
int val;
string time;
if ( myport.available() >= 15)
{
if( myport.read() == header)
{
string timestring = timeformat.format(new date());
println("message received @ " + timestring);
output.println(timestring);
val = readarduinoint();
// print value of each bit
for(int pin=2, bit=1; pin <= 13; pin++){
print("digital pin " + pin + " = " );
output.print("digital pin " + pin + " = " );
int isset = (val & bit);
if( isset == 0){
println("0");
output.println("0");
}
else {
println("1");
output.println("0");
}
bit = bit * 2;
}
// print 6 analog values
for(int i=0; < 6; ++){
val = readarduinoint();
println("analog port " + + "= " + val);
output.println("analog port " + + "= " + val);
}
println("----");
output.println("----");
}
}
}
void keypressed() {
output.flush();
output.close();
exit();
}
int readarduinoint()
{
int val;
val = myport.read();
val = myport.read() * 256 + val;
return val;
}
thank in advance!!!
please use # button when posting code, becomes better readable. can modify post, select code , press # button above smileys proper tags.
thank you.
thank you.
Arduino Forum > Using Arduino > Interfacing w/ Software on the Computer > Arduino to Processing Communication Issue
arduino
Comments
Post a Comment