Skip to main content
Arduino

Return to Question

replaced http://arduino.stackexchange.com/ with https://arduino.stackexchange.com/
Source Link

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.

added 144 characters in body; edited title
Source Link
mike
  • 347
  • 6
  • 20

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...

deleted 406 characters in body
Source Link
mike
  • 347
  • 6
  • 20

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;
 }
}
added 712 characters in body
Source Link
mike
  • 347
  • 6
  • 20
Loading
added 712 characters in body
Source Link
mike
  • 347
  • 6
  • 20
Loading
Another code example I tried
Source Link
mike
  • 347
  • 6
  • 20
Loading
edited title
Link
mike
  • 347
  • 6
  • 20
Loading
Source Link
mike
  • 347
  • 6
  • 20
Loading

AltStyle によって変換されたページ (->オリジナル) /