I'm analyzing the VirtualWire library and in it, the send messages are being sent with digitalWrite in the "send" method. However, there is a setup speed function. I'm reading that function and I see a lot of prescalers and TCCR variables. However, I'm not quite sure what these things do. Because, if it uses digitalWrite anyway to send the bits, then really is no intrabit delay, etc. Can someone please clarify this?

Sorry if question is convoluted. Happy to do any clarification. Thank you for all guidance!

EDIT: Also, how do I transmit a block of message. Something greater than a byte? I'm trying to calculate BLER of messages and software serial only transmits 1 byte at a time. While virtualWire uses low-level error detection (and i want to avoid the use of any error detection/correction).

  • @NickGammon any thoughts on this? Main question is actually the edit.
    – Jonathan
    Nov 17, 2015 at 2:29

1 Answer 1


I think that is used for receiving. By setting the speed, it knows how often it needs to read the input pin. It does this using timer interrupts, so it will run "in the background" without interfering with the main (loop) code.

The TCCR stuff is the set the interval for the timer interrupt.

  • So, as far as the bit transmission is considered, it only uses digitalWrite to send it right? As opposed to how SoftwareSerial directly accesses the registers.
    – Jonathan
    Nov 16, 2015 at 16:57
  • Also, I only see digitalWrite being called once. and not in a loop. Am i reading the code wrong? How is it being able to transmit so many bytes? Sorry if I''m completely overlooking things.
    – Jonathan
    Nov 16, 2015 at 16:58
  • Sorry, on a second look at your post, i am slightly confused. So does that mean delays ARE or AREN'T being used during transmission? Some clarification here please? thank you!
    – Jonathan
    Nov 16, 2015 at 17:43
  • Yes, it only uses digitalWrite (not the fastest, but very portable). Looking at the code a bit better, it seems their are using the timer interrupt to both send data, as well as receive (though not at the same time). I didn't say anything about the TX side in my question. But seeing that they also use the timer for TX, their won't need any delays. So sending data is done "in the background" as well. Just like hardware serial.
    – Gerben
    Nov 16, 2015 at 19:35

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.