We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello,
I have a problem with my Processing and Arduino code. I don't know if my problem come forum my Arduino or Processing code. I have a project, I have to display the temperature (°C), the height (kg), the sound (dB), the humidity and the counting bees. The counting bees ? Yeah, this is an interface that displays the values that give integrated sensors in intelligent hive. Next, my interface is finished but I have one problem. I'm using a potentiometer to do a simulation with the interface like that : simulation. As you can see, we have the temperature. But now, I want to display the height, the sound, the counting bees and the humidity. With Arduino, I have a potentiometer and I do simulation, I'm using analogRead(A0) for the temperature, analogRead(A1) for the height and others... The problem is when I'm in A0 (in my arduino card), I have the temperature and and the other values. What I want is that when I 'm on A0, I only have the temperature and not other values. And when I'm on A1, I have only the height...
PS : You can check this thread first : https://forum.processing.org/two/discussion/15328/g4p-library-processing-with-arduino-isis-proteus-and-vspe#latest
My Processing code :
// Global variable created
void serialEvent (Serial monPort)
{
//Récupération sur le port série de la tension sous forme de chaine de caractères
String listeInfo = monPort.readStringUntil('\n');
if(listeInfo == null)
return; //Aucune données reçues
String[] tableauInfo = listeInfo.split(";"); //Chacun des 5 premières cases contient une info
if (tableauInfo.length != 5)
return; //Manque des données
/*** TEMPERATURe ***/
String tensionCar = trim(tableauInfo[0]); // Suppression des blancs au début et à la fin de la chaine de caractère
int tensionNum = int(tensionCar); // Conversion de la tension codée en CHAR en valeur décimale puis calcul température
temperature = round(((500 * tensionNum) / (3.3 * 1024)) - 50.0);
/*** MASSE ***/
String masse2 = trim(tableauInfo[1]);
int tension2Num = int(masse2);
masse = round(((500 * tension2Num) / (3.3 * 1024)) - 50.0);
/*** HUMIDITE ***/
String humidite = (tableauInfo[2]);
/*** COMPTAGE ***/
String comptage = (tableauInfo[3]);
/*** SON ***/
String son = (tableauInfo[4]);
//Suite du code...
}
My Arduino code :
int temperature;
int masse;
int humidite;
int comptage;
int son;
void setup()
{
Serial.begin(9600);
}
void loop()
{
//Lecture des données
temperature = analogRead(A1);
masse = analogRead(A2);
humidite = analogRead(A3);
comptage = analogRead(A4);
son = analogRead(A5);
//Écriture des données
Serial.print(temperature);
Serial.print(";");
Serial.print(masse);
Serial.print(";");
Serial.print(humidite);
Serial.print(";");
Serial.print(comptage);
Serial.print(";");
Serial.println(son);
Serial.print(";");
delay(1000);
}
I have to make this project for the 17/05, I hope to help in the meantime. (Can skype for more information) Regards,
Answers
You'd be better off if you had followed the approaches from:
https://Forum.Processing.org/two/discussion/14988/drawing-of-graphs-from-i2c-imu#Item_3
The model above expects to receive 1 TSV (Tab-Separated Values) row for each serialEvent().
For the Arduino side, adapting the solution from this link below:
https://Forum.Processing.org/two/discussion/14988/drawing-of-graphs-from-i2c-imu#Item_6
Would get something like this for your particular case: *-:)
That works, thanks. But I have a problem. My problem is that when I'm on A1, I have all values as I only want the temperature in A1, A2 only height etc ...
There's nothing in your examples that alludes you need to send just 1 category of data.
Your model clearly sends this sequence: temperature, masse, humidite, comptage, son.
And apparently, all as
int
datatype too. I wonder whether any of them might befloat
instead? :-/If rather you just wanna send temperature, simply go w/ this:
If it's something more complex, you're gonna need to come up w/ some logical model for it. 8-|
That's what I thought, or my teacher told me that it is possible is my concern... Thank you for your help and your patience ^_^ So my program is fully functional with your help ! I will divide the code in cases where at the end of my project if someone is interested in an interface connecting a hive that is managed from multiple sensors and XBEE.
Regards,
@Itachi, since only 1 value is being sent out, there's no need for any array in order to receive it.
Instead you can use the solution model from this old forum thread: *-:)
https://Forum.Processing.org/two/discussion/14534/myport-available-always-0#Item_1
@GoToLoop
Everything works fine now, it was enough to send simulated values from and set on Processing for example, the first simulated value is read by Arduino and Processing temperature on the window which comes to the analogRead(A1)... My problem was because I was using 5 potentiometers, or now I currently use 3 and it works.
Your code with the vals is good.