If important: the pairs i need to send are unsigned, 1 byte and another one with 2 bytes. The values are in the range of [0;7]
and [1000;2000]
. Thanks for any advice. Disclaimer, I read a lot, including this this, but most questions go into detail about the packaging format, whereas I am concerned about the reading method.
If important: the pairs i need to send are unsigned, 1 byte and another one with 2 bytes. The values are in the range of [0;7]
and [1000;2000]
. Thanks for any advice. Disclaimer, I read a lot, including this, but most questions go into detail about the packaging format, whereas I am concerned about the reading method.
If important: the pairs i need to send are unsigned, 1 byte and another one with 2 bytes. The values are in the range of [0;7]
and [1000;2000]
. Thanks for any advice. Disclaimer, I read a lot, including this, but most questions go into detail about the packaging format, whereas I am concerned about the reading method.
Reading 2 numbers from serial fast
I use serialEvent and thought this would be a callback and could practically miss no byteAs turned out, but it is not really a considerable improvement over Serial.read()
and a simple poll withmy problem was in another portion of the code and if (Serial.available())
.all below code works perfectly as is!
Turns out all of those methods work (more or less elegantly), but having a "delay" within an ISR isn't such a good idea - even intermediately...
Reading numbers from serial fast
I use serialEvent and thought this would be a callback and could practically miss no byte, but it is not really a considerable improvement over Serial.read()
and a simple poll with and if (Serial.available())
.
Reading 2 numbers from serial
As turned out, my problem was in another portion of the code and all below code works perfectly as is!
Turns out all of those methods work (more or less elegantly), but having a "delay" within an ISR isn't such a good idea - even intermediately...
Another try inspired by an answer here, where I send "3 1500\n" over the serial line:
void serialEvent() {
if (!newdata) {
channel = Serial.parseInt();
signal = Serial.parseInt();
signal2 = Serial.parseInt();
newdata = true;
}
}
And after sending the string: "3 1098\n" at 20 Hz I get the following result, where I'd expect to receive 3 1098 0 each time.
ch: 3 signal: 1098 3
ch: 74 signal: 3 1098
ch: 3 signal: 1098 3
ch: 8 signal: 3 1098
ch: 3 signal: 1098 3
ch: 74 signal: 3 98
ch: 3 signal: 98 3
ch: 74 signal: 3 1098
ch: 3 signal: 1098 3
ch: 74 signal: 3 109
ch: 3 signal: 109 3
Another try inspired by an answer here:
void serialEvent() {
if (!newdata) {
channel = Serial.parseInt();
signal = Serial.parseInt();
signal2 = Serial.parseInt();
newdata = true;
}
}
And after sending the string: "3 1098\n" at 20 Hz I get the following result, where I'd expect to receive 3 1098 0 each time.
ch: 3 signal: 1098 3
ch: 74 signal: 3 1098
ch: 3 signal: 1098 3
ch: 8 signal: 3 1098
ch: 3 signal: 1098 3
ch: 74 signal: 3 98
ch: 3 signal: 98 3
ch: 74 signal: 3 1098
ch: 3 signal: 1098 3
ch: 74 signal: 3 109
ch: 3 signal: 109 3
Another try inspired by an answer here, where I send "3 1500\n" over the serial line:
void serialEvent() {
if (!newdata) {
channel = Serial.parseInt();
signal = Serial.parseInt();
newdata = true;
}
}