I am trying to send integer data from a GUI that I built up in PROCESSING to ARDUINO. There is only one variable that should assume integer numbers between 100 and 200.
The arduino code is this:
int val;
int val_set;
void setup() {
Serial.begin(9600);
}
void loop() {
if (Serial.available())
{
val = Serial.read();
}
if (val != val_set) {
Serial.println(val);
}
val_set = val;
}
First it seems, that everything works fine but sometimes the date isn't transmitted correctly as you can see in that screenshot made off the Serial Monitor of arduino IDE.
As I want to take that data for controlling an engine in a little testbed, it is important to get validated data.
I hope, someone have an idea about the mistake I made or the problem that I provoked
Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.
The technique in the 3rd example will be the most reliable.
You can send data in a compatible format with code like this (or the equivalent in any other programming language)
Thanks for the advice but that particularly doesn't solve the problem at all. I modified my sending data to "<"number as string">" and copied example 3, but the Serial Monitor seems to be the problem as it often echoes just "This ju" or "Thi" and then abruptly aborts. After sending two or three data packages, all is displayed correctly again.
I am also having issues like this with Processing to Arduino, Arduino to Processing and Arduino to Arduino Bluetooth transmissions.
I have implemented a heavily modified version of Robin2's method with start and end markers, but I still get transmissions like <123><123> or <123<123>, and while Robin2's example will deal with the first transmission example, the second one gets passed through if you are using Robin2's original example.
This is especially a problem when a sketch is uploaded and run for the first time.
JSchiltz19:
I have implemented a heavily modified version of Robin2's method with start and end markers,
That may be the problem :). There is an adage "if it works, don't fix it"
If you want help with your project it is probably best to start your own Thread and post YOUR program rather than confuse this Thread with two different projects.