I'm looking at he following page, that describes functions from VirtualWire library and provides some examples.


Some basic questions I have after reading it:

  1. The description of vw_get_message function states.

    Read the last received message. This should be called only when a message is known to be received with any of the 3 functions above.

    "3 functions above" refers to vw_have_message, vw_wait_rx and vw_wait_rx_max functions.

    However, in the example on that very same page vw_get_message function is called from receiver's loop() without making any attempts to call any of those 3 functions first.

    Why? Is it legal to use vw_get_message by itself? And how does it work in this case, i.e. what is the semantics of the return value?

    The function is explicitly described as non-blocking, apparently implying that if this usage is legal, there's no way to tell "corrupted message" situation from "no message" situation.

  2. Does the library preserve the granularity/separation of messages? I.e if the TX side sends 1-byte messages, does it guarantee that each call to vw_get_message on RX side will return 1-byte messages? It seems to be implied by the description of the protocol, but I'd like to ask just in case.

  3. If the answer to the second question is "yes", then does this API preserve zero-length messages? Or are they discarded immediately?


1 Answer 1

  1. The example with only vw_get_message is the common usage of the VirtualWire library. It returns true if something was received and the checksum was okay.

  2. Yes, each message is seperated from the other messages. Each message gets extra bits (intro bits) and extra bytes (checksum and length).

  3. I don't know, I have never tested that. Looking at the source code, there is no problem with zero length messages.

The VirtualWire library is outdated, although it is still used with Arduino boards with little memory (Arduino Uno, Nano, Leonardo, Pro Mini, and so on).
The RadioHead library (www.airspayce.com/mikem/arduino/RadioHead) has included the VirtualWire protocol with the RH_ASK mode. The examples for the RH_ASK mode shows that the usage is almost the same. The RadioHead library should be used when there is more memory (Arduino MKR, Zero, Due, and so on).

  • That makes sense, thank you. BTW, someone mentioned in the comments (now deleted), that this usage will probably lead to vw_get_message reading the same message (and returning true) again and again from every call, until a new message is received to replace the previous one. Do you know if this is the case? Apr 29, 2019 at 20:19
  • No, that is not the case. The received message is used just once. If you look at the source code, a flag vw_rx_done is used for that. The flag is set true when data has been received, and the vw_get_message sets it to false to indicate that the new data has been read.
    – Jot
    Apr 29, 2019 at 22:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.