I'm trying to control a 315MHz RF socket using the RCSwitch library. I tested with an Arduino and it worked 100% of the time but when porting over to a pi zero I can only get it to correctly turn on / off about 1 in every 10-15 tries.

I'm not sure if there is a problem with my code, the library or just the pi not being fast enough to handle sending the data properly.

Here's my current code:

#include <wiringPi.h>
#include "RCSwitch.h>

int main(int argc, char** argv)

    RCSwitch sw;
    sw.send(16777173, 24);

edit: It definitely appears to be at least partly a performance problem, compiling with -O2 ups the success rate to around 1/3.

  • I'm not familiar with RCSwitch so I looked it up and there appear to be a lot of different projects to bring it to the Rpi. How did you get RCSwitch? Also in general a Rpi runs a full multitasking operating system so it can't do real time things like a microcontroller. But in your case turning on and off a RF socket shouldn't be affected by that. Also I can't find anything for Protocol 6 at least in github.com/r10r/rcswitch-pi/blob/master/RCSwitch.cpp
    – T. M.
    Feb 25, 2019 at 2:16
  • I'm using the "official" RCSwitch from github.com/sui77/rc-switch.
    – 1234123121
    Feb 25, 2019 at 2:31

1 Answer 1


The problem was with how the wiringPi handles sleeping. Actual sleeps appear to not be accurate enough so a wait loop has to be used.

The solution was to change the call to the delayMicroseconds function in RCSwitch::transmit to delayMicrosecondsHard which is defined in wiringPi.c but not exported so I copied the implementation into RCSwitch.


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.