RF Timing problems on Photon when controlling a HomeEasy dimmer

Hello! Really enjoying my Photon, great job with it.

I’m however having some trouble controling a HomeEasy (Nexa) dimmer through 433mhz RF. The (almost) identical code ALWAYS works on an Arduino Uno, but only sometimes on the Photon, using the same transmitter. I had to do some minor changes to the library to make it run on the Photon, mainly replacing:

  • cli() => noInterrupts()
  • sei() => interrupts()

Which may not be equivalent. This has lead me to believe that the problem lies in the signal timing, as the HomeEasy protocol seems to require quite precise timing. Perhaps the dimmer isn’t as strict about the timings, as it works sometimes?

My port of the original library. Sketch running on the Photon.

Any help or ideas are much appreciated, as I’m pretty much scratching my head right now.

One minor hint if speed and timing is a concern is to replace digitalWrite() with its more speedy relatives pinSetFast(), pinResetFast() and digitalWriteFast().
Inlining your TransmitLatch functions might also be worth a thought.

Another thing instead of blocking interrupts during your action you could give using an interrupt (e.g. via SparkIntervalTimer library) a try. I’m not sure about the priority of the used hardware timer interrupts in relation to possibly interfering interrupts tho’.

 // for power <= 31 
 1 << power; // faster than the implementation of power2(int power)

I haven’t dug into the actual meaning of itob() but since the Particles are 32bit devices I’d guess this could also be done easier/quicker with shift operations (<</ >>).

strtol() would be a standard replacement for your htol().

Thank you very much for your help, ScruffR. I’ve implemented your suggestions, and works about ~85% of the time now. I’m driving the transmitter with the Photon’s 3.3V and the Uno’s 5V (it’s rated for 3V), but the problem persist even after testing another transmitter with another brand, so it probably isn’t an electrical problem.

I’ll continue investigating.

Are the ~85% an improvement to before or not?

Just to exclude the WiFi/cloud side of the equation try using SYSTEM_MODE(MANUAL).

To perform OTA flashing, you’d either need to add some code to reestablish WiFi/cloud connection on demand or put your device into Safe Mode before you try flashing.