apanteleev / autoblinds

MIT License
4 stars 1 forks source link

IR remote control #2

Open vulubalulu opened 1 year ago

vulubalulu commented 1 year ago

i came over from se1exin and discovered your version of the automatic blind system. I love it and I have build it successfully myself. Originally I used a4988 stepper driver but they were loud as hell and tmc have much much quieter drivers. I put the blinds in my grandmothers apartment because she is too weak to open them herself at this point. Unfortunately she is also too old to operate them through a web browser. I bought a cheap IR remote and a 3 pin IR receiver in the hope that this will bet he final solution. I also thought I would be smart enough to modify your code to implement IR control but that's not the case. I really need your guidance. My idea was to insert the IR code signal alongside the button commands of up and down, but I am simply lost. ANy help would be appreciated.

apanteleev commented 1 year ago

Thanks for your feedback!

For IR control, I would add a separate IR handler function or class, call it from the main loop, and do something like this inside:

if (IrReceiver.decode()) {
  IrReceiver.resume();
  switch(IrReceiver.decodedIRData.command) {
    case IR_COMMAND_UP: // define the constant to your preferred remote button
        if (motor.isRunning())
          motor.softStop();
        else
          motor.start(MOTOR_DIRECTION_UP, false);
    case IR_COMMAND_DOWN: // etc...
  }
}
friendlyFriend4000 commented 1 year ago

Hello Alexey and thank you for getting back to me. Your hint and code snippet helped me immensely. After many hours deep into the night I finally have a working remote control! I did spend almost all of my time troubleshooting. At first I could not get the motor to spin at all, the buttons wouldn't work either no matter what I did. Just 'IRremote.begin(PIN)' was enough for the microcontroller to freeze up. The solution was to use the library IRremoteESP8266 which magically worked off the bat if not for the random crashes. I found a exception decoder which pointed at motor.processTimer() in the onTimerInterrupt() function. This one really stumped me and I was at my wits end as googling wasn't helping either. Turns that having following the library example code and putting delays into the loop function was causing these exceptions, live and learn. Anyway, it is working and I am beyond happy. I want to thank you once again for helping me out and for creating such a great program. My grandmother sends her regards as well.

apanteleev commented 1 year ago

Cool, glad you got it all working!

The conflict of motor interrupt and IR receiver makes sense, I guess the IR libraries might use the same interrupt or other similar things.

If you can post a picture of your completed device, that would be great. :)

friendlyFriend4000 commented 1 year ago

You may use the images in any way you like.

20230716_161119 20230714_155651 20230714_155815 20230714_155824