{"id":802,"date":"2014-11-14T15:39:13","date_gmt":"2014-11-14T15:39:13","guid":{"rendered":"http:\/\/ofalcao.pt\/blog\/?p=802"},"modified":"2016-06-14T15:28:47","modified_gmt":"2016-06-14T14:28:47","slug":"infrared-remote-control","status":"publish","type":"post","link":"https:\/\/ofalcao.pt\/blog\/2014\/infrared-remote-control","title":{"rendered":"Infrared Remote Control"},"content":{"rendered":"<p>I discover this week that it is possible to <a href=\"http:\/\/www.instructables.com\/id\/DIY-Infrared-transmitter-for-iPhone-iPod\/\">use the headphone jack to send IR signals<\/a>. The intructions are for a iPhone but one can use almost any audio source&#8230; even the computer audio card! And it is already <a href=\"http:\/\/www.lirc.org\/html\/audio.html\">suported in LIRC<\/a> (Linux Infrared Remote Control), their page even includes a simple circuit!<\/p>\n<figure style=\"width: 318px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.lirc.org\/html\/audio.html\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"\" src=\"https:\/\/i0.wp.com\/www.lirc.org\/images\/audio_transmitter.png?resize=318%2C146\" alt=\"\" width=\"318\" height=\"146\" \/><\/a><figcaption class=\"wp-caption-text\">LIRC &#8211; audio IR transmitter<\/figcaption><\/figure>\n<p>Then I also found this <a href=\"https:\/\/github.com\/iConor\/lego-lirc\">lego-lirc<\/a> 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&#8230; and also two configurations files:<\/p>\n<ul>\n<li><a href=\"http:\/\/ofalcao.pt\/blog\/wp-content\/uploads\/2014\/11\/Combo_Direct.conf_.zip\">Combo_Direct<\/a><\/li>\n<li><a href=\"http:\/\/ofalcao.pt\/blog\/wp-content\/uploads\/2014\/11\/Combo_PWM.conf_1.zip\">Combo_PWM<\/a><\/li>\n<\/ul>\n<p>The first file works like the <a href=\"http:\/\/powerfunctions.lego.com\/en-us\/ElementSpecs\/8885.aspx\">8885 &#8211; PF IR Remote Control<\/a> and contains the usual FORWARD \/ BACKWARD \/ HOLD \/ BREAK codes; the second file works like the <a href=\"http:\/\/powerfunctions.lego.com\/en-us\/ElementSpecs\/8879.aspx\">8879 &#8211; PF IR Speed Remote Control<\/a> and contains the codes to control the speed (duty cycle) of the motors.<\/p>\n<p>So&#8230; why not give it a try?<\/p>\n<p>I searched for more info about &#8216;lego-lirc&#8217; but found nothing so I opened an issue asking iConor permission to publish those two files (and he promptly agreed, thank you iConor!).<\/p>\n<p>My laptop has Ubuntu 14.10 x64. I installed LIRC and the required Portaudio library for using the audio card:<\/p>\n<pre>$ sudo apt-get install lirc libportaudio0<\/pre>\n<p>When LIRC is being installed it asks for an IR Receiver and an IR Transmitter, I chose &#8216;none&#8217; twice.<\/p>\n<p>Then I copied iConor configuration files to LIRC folder:<\/p>\n<pre>sudo cp Combo_Direct.conf \/etc\/lirc\/lircd.conf\r\nsudo cp Combo_PWM.conf\u00a0 \/etc\/lirc\/lircd.conf<\/pre>\n<p>and edited \/etc\/lirc\/hardware.conf to create a LEGO_Combo_Direct transmitter associated to the audio card output:<\/p>\n<pre>(...)\r\n#Chosen IR Transmitter\r\nTRANSMITTER=\"LEGO_Combo_Direct\"\r\nTRANSMITTER_MODULES=\"\"\r\nTRANSMITTER_DRIVER=\"audio\"\r\nTRANSMITTER_DEVICE=\"hw@96000\"\r\nTRANSMITTER_SOCKET=\"\"\r\nTRANSMITTER_LIRCD_CONF=\"\/usr\/lirc\/Combo_Direct.conf\"\r\nTRANSMITTER_LIRCD_ARGS=\"\"\r\n(...)<\/pre>\n<p>My audio card accepts sampling at 96 kHz but others may require lower values like 48 kHz.<\/p>\n<p>I also edited \/etc\/lirc\/lircd.conf to include both iConor configuration files<\/p>\n<pre>(...)\r\ninclude \"\/etc\/lirc\/Combo_Direct.conf\"\r\ninclude \"\/etc\/lirc\/Combo_PWM.conf\"\r\n(...)<\/pre>\n<p>but I&#8217;m not sure if it is really needed since hardware.conf already has the right path.<\/p>\n<p>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)<\/p>\n<pre>~$ sudo mkdir \/var\/run\/lirc\/<\/pre>\n<p>Now let us start the lirc daemon:<\/p>\n<pre>~$ sudo service lirc start<\/pre>\n<p>and check if it is working:<\/p>\n<pre>~$ pgrep lirc\r\n1234<\/pre>\n<p>and what kind of transmitter does it understands:<\/p>\n<pre>~$ irsend LIST \"\" \"\"\r\nirsend: LEGO_Combo_Direct\r\nirsend: LEGO_Combo_PWM<\/pre>\n<p>and also\u00a0 what codes are available:<\/p>\n<pre>$ irsend LIST LEGO_Combo_Direct \"\"\r\nirsend: 000000000000010e FLOAT_FLOAT\r\nirsend: 000000000000011f FLOAT_FORWARD\r\nirsend: 000000000000012c FLOAT_BACKWARD\r\nirsend: 000000000000013d FLOAT_BRAKE\r\nirsend: 000000000000014a FORWARD_FLOAT\r\nirsend: 000000000000015b FORWARD_FORWARD\r\nirsend: 0000000000000168 FORWARD_BACKWARD\r\nirsend: 0000000000000179 FORWARD_BRAKE\r\nirsend: 0000000000000186 BACKWARD_FLOAT\r\nirsend: 0000000000000197 BACKWARD_FORWARD\r\nirsend: 00000000000001a4 BACKWARD_BACKWARD\r\nirsend: 00000000000001b5 BACKWARD_BRAKE\r\nirsend: 00000000000001c2 BRAKE_FLOAT\r\nirsend: 00000000000001d3 BRAKE_FORWARD\r\nirsend: 00000000000001e0 BRAKE_BACKWARD\r\nirsend: 00000000000001f1 BRAKE_BRAKE<\/pre>\n<p>OK, we&#8217;re ready! Now suppose we want to make both motors spin forward:<\/p>\n<pre>~$ irsend SEND_ONCE LEGO_Combo_Direct FORWARD_FORWARD<\/pre>\n<p>Yeah! The motor(s) spin for about 1 second.<\/p>\n<p>So if we want shorter runs we can send a BREAK or a FLOAT after a short time, say 0.1 second:<\/p>\n<pre>~$ irsend SEND_ONCE LEGO_Combo_Direct FORWARD_FORWARD; sleep 0.1; irsend SEND_ONCE LEGO_Combo_Direct FLOAT_FLOAT<\/pre>\n<p>I faced some strange behaviours (delays, lags) until I better read the LIRC audio page and saw this warning:<\/p>\n<p style=\"padding-left: 30px;\">&#8220;It takes some time to set up (50 ms or so) so when no clients are connected to lircd the first transmission will have some higher latency.<\/p>\n<p style=\"padding-left: 30px;\">A workaround for this is to keep irw running with a bash script like this:<\/p>\n<pre style=\"padding-left: 30px;\"><code> #!\/bin\/bash\r\n while [ true ]; do\r\n irw || true\r\n sleep 1\r\n done<\/code><\/pre>\n<p style=\"padding-left: 30px;\">(&#8230;)&#8221;<\/p>\n<p>So i created a &#8216;lirc-keepalive.sh&#8217; file, gave it execution permissions and executed in the background:<\/p>\n<pre>~$ chmod +x lirc-keepalive.sh\r\n~$ .\/lirc-keepalive.sh &amp;<\/pre>\n<p>And it makes a REALLY BIG difference.<\/p>\n<p>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 <a href=\"http:\/\/www.ptrobotics.com\/opticos\/1794-l-934f3c-ir-emitter-3mm-940nm.html\">L-934F3C &#8211; IR Emitter 3mm 940nm (<\/a>\u20ac0.25 each) and no resistor at all but if you want to play safe use a small resistor like 8\u03a9.<\/p>\n<p>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.<\/p>\n<p>The required materials:<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/www.brickshelf.com\/gallery\/jorgepereira\/PFaudioIR\/pfaudioir-01.jpg\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/i0.wp.com\/www.brickshelf.com\/gallery\/jorgepereira\/PFaudioIR\/thumb\/pfaudioir-01.jpg_thumb.jpg?resize=128%2C72\" alt=\"\" width=\"128\" height=\"72\" \/><\/a><\/p>\n<p>And the completed cable:<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/www.brickshelf.com\/gallery\/jorgepereira\/PFaudioIR\/pfaudioir-02.jpg\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/i0.wp.com\/www.brickshelf.com\/gallery\/jorgepereira\/PFaudioIR\/thumb\/pfaudioir-02.jpg_thumb.jpg?resize=128%2C72\" alt=\"\" width=\"128\" height=\"72\" \/><\/a><\/p>\n<p>Now about the LEDs&#8230;<\/p>\n<p>These LEDs are from Kingbright, their specs say<\/p>\n<pre>1.2V Typ @ 20mA, 940 nm, 50\u00b0 angle, 10 mW\/sr Typ @20 mA<\/pre>\n<p>I also tried a pair of TSAL6100 950nm High Power Infrared Led from Vishay:<\/p>\n<pre>1.35V Typ@ 100 mA, 10\u00b0 angle, 170 mW\/sr @100 mA<\/pre>\n<p>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&#8217;t much powerfull and might not give enough current to notice a difference &#8211; or i just made a mistake.<\/p>\n<p>My first tests achieved a respectable 3 meter range. Not bad for something so simple and costing less than \u20ac1 &#8211; now everyone can\u00a0programmaticaly control their LEGO models. Kudos for LIRC people for being so open-minded and for iConor for creating this configuration files.<\/p>\n<div class=\"jetpack-video-wrapper\"><iframe loading=\"lazy\" title=\"LEGO Infrared Remote Control from audio output\" width=\"840\" height=\"473\" src=\"https:\/\/www.youtube.com\/embed\/xFRRFH6_cYw?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/div>\n<p>Next I&#8217;m going to try the same with a LEGO Mindstorms EV3 and also a Raspberry Pi.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8230; even the computer audio card! And it is already suported in LIRC (Linux Infrared Remote Control), their page even includes a simple circuit! Then &hellip; <a href=\"https:\/\/ofalcao.pt\/blog\/2014\/infrared-remote-control\" class=\"more-link\">Continuar a ler<span class=\"screen-reader-text\"> &#8220;Infrared Remote Control&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[1],"tags":[237,239,241,136],"series":[],"class_list":["post-802","post","type-post","status-publish","format-standard","hentry","category-sem-categoria","tag-audio-pt","tag-infrared-pt","tag-ir-pt","tag-remote-control"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2Mhyv-cW","_links":{"self":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/posts\/802","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/comments?post=802"}],"version-history":[{"count":0,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/posts\/802\/revisions"}],"wp:attachment":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/media?parent=802"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/categories?post=802"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/tags?post=802"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/series?post=802"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}