That covers the "hub" side. This article covers the "edge" side — the device being controlled.
Side note: in older IoT architectures, the typical naming was
Edge → Gateway → Server, since data collection was the focus.
In this setup the hub controls multiple edge devices, which doesn't fit the server/client or data-flow model well.
"Server" and "Gateway" feel wrong here.
I'll call the control brain the "hub" and the controlled devices "edge" for clarity.
Each edge device needs to handle its specific appliance.
The ultimate goal is the Roomba, but it turns out Roomba's IR protocol is more complicated than expected — so let's start with the TV.
[Note]
This method will NOT work for the Roomba.
That part comes later, using Arduino instead of Raspberry Pi.
- Gather parts.
- Set up Node-RED on the main Raspberry Pi and register it with Amazon Echo Dot
- Headless WiFi setup for Raspberry Pi Zero W
- Copy IR remote codes with Raspberry Pi [This article]
- Call IR functions from Node-RED to control the TV
- Control Arduino via HTTP API using FlashAir GPIO mode
- (Bonus) Control Roomba from Arduino via ROI serial interface
- Control Roomba from Arduino via IR
- Control Roomba from Node-RED via FlashAir/Arduino
Installing lirc
Install lirc on Raspbian to use IR with Raspberry Pi.
Searching online, you'll find older blog posts with harsh criticism of lirc —
but in my testing it works fine.
There are some quirks, but nothing serious.
Install via apt-get:
$ sudo apt-get install lirc
Next, edit /boot/config.txt.
Older guides use different config files or syntax, which causes confusion.
For Raspbian Stretch + lirc 0.9.4, find the line "#dtoverlay=lirc-rpi" and update it:
$ sudo vi /boot/config.txt
# Uncomment this to enable the lirc-rpi module
dtoverlay=lirc-rpi
dtparam=gpio_in_pin=24
dtparam=gpio_out_pin=25
gpio_in_pin is the GPIO number connected to the IR receiver's signal pin.gpio_out_pin is the GPIO number connected to the IR LED (or module input pin).
Raspberry Pi pin assignments are documented here.
The config.txt uses GPIO numbers, not physical pin numbers — they're not sequential.
On the board, the pad that's square (rather than round) is the 3.3V pin.
Next, disable the default config file that gets loaded by lirc:
It doesn't support transmission, and leaving it active causes problems later.
$ sudo mv /etc/lirc/lircd.conf.d/devinput.conf /etc/lirc/lircd.conf.d/devinput.conf.disabled
Some guides mention editing "hardware.conf" — that's no longer needed.
modprobe is also not required.
Reboot the Raspberry Pi.
After rebooting, confirm /dev/lirc0 exists.
Connecting the IR Receiver Module
Connect the IR receiver and transmitter modules as shown in the diagram.The "-" pin is GND, the unmarked middle pin is 3.3V, and "S" is the GPIO signal pin.
The receiver is an input to the Raspberry Pi → connect to gpio_in_pin (GPIO24).
The transmitter (IR LED) is an output from the Raspberry Pi → connect to gpio_out_pin (GPIO25).

After connecting, boot the Raspberry Pi and run the mode2 command targeting the lirc0 device — it will wait for input.
Point the TV remote at the IR receiver module and press a button.
You should see "Partial read 8 bytes on /dev/lirc0".
$ mode2 -d /dev/lirc0
Using driver default on device /dev/lirc0
Trying device: /dev/lirc0
Using device: /dev/lirc0
Copying TV Remote Codes
lirc includes a tool to capture and store remote codes, making this straightforward:$ irrecord -n -d /dev/lirc0
:
Please take the time to finish the file as described in
https://sourceforge.net/p/lirc-remotes/wiki/Checklist/ and send it
to <lirc@bartelmus.de> so it can be made available to others.
Press RETURN to continue.
[Press Enter and wait]
Checking for ambient light creating too much disturbances.
Please don't press any buttons, just wait a few seconds...
No significant noise (received 0 bytes)
Enter name of remote (only ascii, no spaces): [Enter a name like "TV"]
Using TV.lircd.conf as output filename
Now start pressing buttons on your remote control.
It is very important that you press many different buttons randomly
and hold them down for approximately one second. Each button should
generate at least one dot but never more than ten dots of output.
Don't stop pressing buttons until two lines of dots (2x80) have
been generated.
Press RETURN now to start recording.
[Press Enter, then randomly press buttons on the remote toward the IR receiver]
................................................................................
Got gap (106874 us)
Please keep on pressing buttons like described above.
[Press more buttons]
...................................................................................................................
Please enter the name for the next button (press <enter> to finish recording)
[Enter a name for the button, e.g. "on" or "ch1"]
Now hold down button "on".
[Press that button once]
Please enter the name for the next button (press <enter> to finish recording)
[Repeat for each button. Press Enter without a name to finish]
Checking for toggle bit mask.
Please press an arbitrary button repeatedly as fast as possible.
Make sure you keep pressing the SAME button and that you DON'T HOLD
the button down!
If you can't see any dots appear, wait a bit between button presses.
Press RETURN to continue.
[Rapidly press the same button multiple times]
Cannot find any toggle mask.
Successfully written config file TV.lircd.conf
A file called "TV.lircd.conf" is created in the current directory.Move it to /etc/lirc/lircd.conf.d/:
$ sudo mv TV.lircd.conf /etc/lirc/lircd.conf.d/
Start lircd:$ sudo service lircd start
Verify the config was loaded:$ irsend LIST "" ""
TV
$ irsend LIST TV ""
0043000001000251 on
004d000001000248 ch1
:
Now send a command to the TV:$ irsend SEND_ONCE TV on
If the TV responds — success.If you see an error like:
$ irsend SEND_ONCE AV tv
transmission failed
Error running command: Input/output error
This is almost certainly caused by forgetting to disable devinput.conf in the initial setup.This error has almost no information online — it took me a long time to figure out.
Once you're in this state, simply removing devinput.conf afterward won't fix it.
The TV.lircd.conf you created already has devinput baked in as the driver.
The fix: delete both devinput.conf and TV.lircd.conf, restart lircd, then re-create TV.lircd.conf from scratch.
At this point, the Raspberry Pi can control the TV via IR.
Next: connecting it to Node-RED and finally controlling the TV with Alexa.
No comments:
Post a Comment