Hi guys
I will try to make a "monitoring system" to see how the temperature and humidity in my little green house changes.
While i am waiting for the parts, i thought i would start checking out how to write the Processing Sketch (which i have NEVER used) to read and display the values sent from the Arduino.
In the final project, i will have 4 sensors (two temperature and two humidity) which i would like to read from the Arduino and save into a file (which i will later use to make some kind of graphic).
Now i am just trying things out with a pot.
As i said before, i have no experience with processing. I have read some tutorials to try to learn a bit how things work, but it seems i am doing something wrong.
On the Arduino side i am using this little code:
int pot = A0;
// set the lastPotValue to 11 to ensure first potVal prints
unsigned int lastPotVal = 11;
void setup() {
pinMode(pot,INPUT);
Serial.begin(9600);
}
void loop() {
int potRead = analogRead(pot);
// mapped from 0 to 1015 to help get a clean mapped 5
// if mapped from 0 to 1023 the mapped 5 would sometimes "bounce" to 4
int potVal = map(potRead, 0, 1015, 0, 5);
if(potVal != lastPotVal){
Serial.println(potVal);
lastPotVal = potVal;
delay(10);
}
}
would this work as a way to send data to Processing? Is there a better way?
Taking bits and pieces from online tutorials and examples and trying to get it to do what i want, i got to this little Processing sketch:
import processing.serial.*;
Serial myPort; // The serial port
void setup () {
// set the window size:
size(400, 400);
// List all the available serial ports
println(Serial.list());
// I know that the first port in the serial list on my mac
// is always my Arduino, so I open Serial.list()[0].
// Open whatever port is the one you're using.
myPort = new Serial(this, Serial.list()[0], 9600);
// don't generate a serialEvent() unless you get a newline character:
myPort.bufferUntil('\n');
// set inital background:
background(0);
}
void serialEvent (Serial myPort) {
// get the string:
String inputRead = myPort.readStringUntil('\n');
fill(255);
text(inputRead,10,10,70,80);
}
... but it isn't working as intended.
I would like the value to be updated each time it changes. Now it is just "printing" of top of the old one...
I saw that there are some libraries available. Would you advise me to use one, or is this (and then final project) simple enough to write my own little sketch?
How would it be possible to write the values to a file instead of displaying them on screen?
Ai, ai, ai... when i was starting to feel that i finally know a little bit about my Arduino, i feel again like i actually know nothing!!! (which is very true!) 8)
I am very grateful for any help and will gladly read any links and tutorials you can give me talking about this.
Thanks!
=)