- Decoding NEC protocol IR pulses from remote control with a Pico and perform keypress as a USB keyboard (HID).
- Set up your PC to point to use the Raspberry Pi Pico SDK, follow README in Raspberry Pi Pico SDK.
- Clone this GitHub repo
$ git clone https://github.com/gharishkumar/pico-ir-keyboard.git
- Change to pico-ir-keyboard directory.
$ cd pico-ir-keyboard
- Setup a CMake build directory.
For example, if not using an IDE:
$ mkdir build $ cd build $ cmake ..
- Make your target from the build directory you created.
$ make -j4
- You now have
pico_ir_keyboard.elf
to load via a debugger, orpico_ir_keyboard.uf2
that can be installed and run on your Raspberry Pi Pico via drag and drop.
NOTE :
IR rx pin
,IR command
(or)Keyboard keycode
can be customised inpico-ir-keyboard/src/main.c
.- By default
GP27
is set asINPUT
.
- It all started with adding IR remote support for Raspberry Pi 3 Model B+ with custom embedded Linux for Web Kiosk ( I know Raspberry Pi GPIO can decode IR. I have also decoded NEC protocol with Python in Raspberry Pi OS ).
- I have no patience in recompiling the OS with GPIO and Python.
- I thought it would be easy to add Raspberry Pi Pico to emulate the keyboard (USB HID). As the website already has keyboard support.
- I also found a product by Adafruit pIRkey which does the same, but they discontinued it.
✔️ It's a relatively simple and easy process available with TinyUSB, via CircuitPython, Arduino IDE (or) Raspberry Pi Pico SDK.
❌ but not MicroPython.
- Try old python code.
- Moving on, I realised that using Raspberry Pi Pico to decode IR NEC protocol and emulate a keyboard is not that easy.
- The previous program I used to decode IR NEC protocol in Raspberry Pi 3 Model B+ Python did not work in either MicroPython or CircuitPython.
- In both time differences between two pulses returned zero.
- Search for Pico specific code.
- I found micropython_ir by peterhinch in MicroPython it 🎉 works great in decoding IR NEC protocol.
- It uses
IRQ
, so no chance of running it in CircuitPython. - By default, MicroPython doesn't support HID for Raspberry Pi Pico.
- I tried including HID in the MicroPython source and compile it but had no luck; I should try that in the future.
- Changing the old code to C.
- As USB HID support is available in Arduino IDE, I convert that old Python code to C.
- It didn't work either.
- Trying with PIO.
- So, I decided to convert that Python code into PIO assembly language to include it in CircuitPython.
- After some searching, I found the same in a pending pull request by mjcross with PIO in Raspberry Pi Pico SDK Great!
- Then decided to go with Raspberry Pi Pico SDK.
- Merging is simple with the device examples provided in TinyUSB and from the pending GitHub pull request.