Non-delayed polling of Ping1D

Hi,

I am integrating a Ping1d on a Teensy (think: powerful Arduino) based breakout. There are quite few different UART- and I2C-interfaces (Servos, ESC, battery) running on the board and all are scheduled in little cyclic tasks. In order to maintain consistent timing behaviour, I generally use an approach like this:

  • Send command to hardware_xx requesting feedback
  • Do something else - while in the meantime, hardware_xx replies
  • Parse UART buffer for hardware_xx
  • Do yet something else and eventually repeat overall progress

The Arduino-lib for Ping1D contains a delay() inside the update(), which sort of breaks the system’s timing. So I was looking through the lib for obvious ways to break Ping1D-interfacing into this Request →Parse → Request →Parse→etc.-structure.

There is indeed the ping.request(…) method in the library, but it also appears to include a delay() in side. So it is not what I need - I believe… So the question is essentially, if I am overlooking some very obvious solution? Or has someone faced the same problem and solved in a very elegant way? :slight_smile:

Best
Max

Haaang on, I guess that one sometimes has to ask questions before seeing the obvious answers just in front of one’s own nose…

The Request → parse → Request → parse…-approach is essentially what is described in the pingmessage.ino example, right?

Best
Max

Hi @MaxForPresident, welcome to the forum :slight_smile:

request is a convenience method that’s intended for synchronous access - you request a message and you receive the response, if it arrived within the specified timeout period, where the timeout period is generally as described in the protocol specification.

If you prefer low level control so that you can more easily interleave other tasks while waiting for a response then yes, if you want to you can manually construct and write the request messages and only check for a response once you’re ready to do so, and that does indeed appear to be the approach taken in the pingmessage.ino example :slight_smile: