iConor’s second LIRC configuration file,Combo_PWM.conf, allows us to use LIRC command ‘irsend’ to control the speed of a LEGO Power Functions Motor or the position of a LEGO Power Functions Servo Motor much like the 8879 IR Speed Remote Control.
This shell script sends a sequence of 7 increasingly values then returns to zero and repeat it in the opposite direction:
There is a total of 256 key codes in the configuration file (16 different values for the red plug x 16 different values for the blue plug). I used just the first subset of 16 so the first byte (for the blue plug) is always ’40’ but it doesn’t matter because I connected both Servo and M-motor to the red plug .
The sequence of key codes is not exactly the same as in the configuration file – I reordered the last 7 key codes.
The ‘sleep 1.2’ makes the script wait 1.2 seconds between each command. It is more or less the time the IR keeps the command active (bigger values would make the Servo return to center and the M-motor stop).
I discover this week that it is possible to use the headphone jack to send IR signals. The intructions are for a iPhone but one can use almost any audio source… even the computer audio card! And it is already suported in LIRC (Linux Infrared Remote Control), their page even includes a simple circuit!
Then I also found this lego-lirc repo in GitHub from a guy nicknamed iConor. It has the source code to generate LIRC configuration files for the LEGO Power Functions Infrared protocol… and also two configurations files:
My audio card accepts sampling at 96 kHz but others may require lower values like 48 kHz.
I also edited /etc/lirc/lircd.conf to include both iConor configuration files
but I’m not sure if it is really needed since hardware.conf already has the right path.
I am also not sure if it is really needed or not but somewhere between my several tries I had to create a folder for lirc where it writes 2 files (one I think is a lock, the other contains just the process id)
~$ sudo mkdir /var/run/lirc/
Now let us start the lirc daemon:
~$ sudo service lirc start
and check if it is working:
~$ pgrep lirc
and what kind of transmitter does it understands:
~$ irsend LIST "" ""
For anyone who might get interested in this, I suggest first trying with just a headphone or 2 common LEDs (I used a pair of red). If there is a click or a blink then use 2 IR LEDs. Mine are L-934F3C – IR Emitter 3mm 940nm (€0.25 each) and no resistor at all but if you want to play safe use a small resistor like 8Ω.
You also need a cable (just cut the cable of a old headphone set) and a soldering iron. I also used heat shrinking tube but any kind of insulation material is OK.
The required materials:
And the completed cable:
Now about the LEDs…
These LEDs are from Kingbright, their specs say
1.2V Typ @ 20mA, 940 nm, 50° angle, 10 mW/sr Typ @20 mA
I also tried a pair of TSAL6100 950nm High Power Infrared Led from Vishay:
1.35V Typ@ 100 mA, 10° angle, 170 mW/sr @100 mA
but I got more or less the same results and as their emission angle is much smaller I needed to point more carefully to the PF RC receiver. so I kept the first pair. The audio output is intended for headphone so it isn’t much powerfull and might not give enough current to notice a difference – or i just made a mistake.
My first tests achieved a respectable 3 meter range. Not bad for something so simple and costing less than €1 – now everyone can programmaticaly control their LEGO models. Kudos for LIRC people for being so open-minded and for iConor for creating this configuration files.
Next I’m going to try the same with a LEGO Mindstorms EV3 and also a Raspberry Pi.