{"id":1194,"date":"2017-10-05T18:38:06","date_gmt":"2017-10-05T17:38:06","guid":{"rendered":"http:\/\/ofalcao.pt\/blog\/?p=1194"},"modified":"2017-10-06T11:37:39","modified_gmt":"2017-10-06T10:37:39","slug":"ressurecting-the-lego-interface-a","status":"publish","type":"post","link":"https:\/\/ofalcao.pt\/blog\/2017\/ressurecting-the-lego-interface-a","title":{"rendered":"Ressurecting the LEGO Interface A"},"content":{"rendered":"<div class=\"seriesmeta\">This post is part 2 of 4 of \u00a0<a href=\"https:\/\/ofalcao.pt\/blog\/series\/lego-interface-a\" class=\"series-317\" title=\"LEGO Interface A\">LEGO Interface A<\/a><\/div><p>By modern criteria, the Interface A is quite simple: it has 2 inputs that accept TTL levels and 6 power outputs able to turn ON or OFF 6 &#8216;devices&#8217; like motors or lamps. These 6 output can be used independently or in pairs. A motor connected to a single output just turns ON or OFF so it rotates always in the same direction but when connected to a pair of outputs it can rotate in both directions. I think (but I&#8217;m not sure) that this is implemented through an H-bridge &#8211; if true, motors can also stop in two ways (Break and Coast).<\/p>\n<p>There are a few web resources with excellent information about the LEGO Interface A:<\/p>\n<ul>\n<li><a href=\"http:\/\/lgauge.com\/technic\/LEGOInterfaceA\/9750(1093).htm\">9750 (1093) LEGO Technic Interface A<\/a><\/li>\n<li><a href=\"http:\/\/lukazi.blogspot.pt\/2014\/07\/lego-legos-first-programmable-product.html\">LEGO &#8211; LEGO&#8217;s first programmable product<\/a><\/li>\n<li><a href=\"https:\/\/web.archive.org\/web\/20160413150953\/http:\/\/isodomos.com\/Lego-Sets\/1093.html\">LEGO TC LOGO Set 1093 Instructions<\/a> (now available only through the Web Archive)<\/li>\n<\/ul>\n<p>So the Interface A uses 6 pins from the Data port of the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Parallel_port\">Parallel Printer Interface<\/a> (D0..D5) for Output and 2 pins from the Status port (Paper Empy and Select) for Input. Two other pins from the Control port (STROBE and AUTO FEED) are used to get the +5 Volt that power the optocouplers that assure electric isolation between the computer circuits and the external world circuits &#8211; these are also powered by a 7.5V AC transformer with at least 11 Watt (VA), not easy to find but we can use a good 12V power adapter with at least 1A output (preferably 15V\/2A) because there is an internal rectifier bridge [that reduces average voltage to half].<\/p>\n<p>A note about the power adapter: my first attempts were with a cheap linear &#8220;universal&#8221; wall adapter, just 300 mA output, at 12V. It worked but when issuing commands to motors, every time the motor stopped I saw both Input green LEDs blinking. With a decent switched wall adapter, 2000 mA, also at 12V, never happened again.<\/p>\n<p>Before using the FTDI adapter I manually tested my Interface A, using a 4.5V battery to power the optocouplers (just need to connect one of the two Control pins, they are internally shorted; same for Ground pins). Some jumper wires directly attached to the 20-pin IDC connector and I was controlling a 4.5V Technic motor:<\/p>\n<figure style=\"width: 1523px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"size-large\" src=\"https:\/\/lh3.googleusercontent.com\/jPOHv2leum5DaVxQOtMQ6rxHwWFz4merhjzAnIGris503fPALWtC0_5xfrA2kIDlQe5cef8fH8jsPPok9pGjRMROvqWPRriSclbIOVh5ggvKy7qYq8gqUpAJhb1T9ZkS4DQiPCLCgLC0okg98yynPUzL8l0UJEiSOUXnRuIX2R7mbnx2W7Nnr6gz7l7Gy8o6d6IKllC_Gxxp_NpImzuPVh9PKHLR6VXjxqy6F7W4q3W_dj6v2x4faidVW9l7b4x5kA3MVKSPCGrYe30yO0P_l2QnalD5U1hhxqm33wrzRa0uv_8e5jBKSw4TL7qCXNK6eKxaqmBAi4Bx54DKEJg9B2x4jqmvQ0j3P0KpOADOxm_Sx1YHI4fbmXJac6aWXgCmNkmiw69q7qfM5PEGYfZjdTBn7dzZPSbw9_U7DbBMxve-IBV4UEYj02TTCqXVhvL81EYskssH7b697nVIDfr5qlbodD_VxdQ7PMP8emj5Lu0Uhw82KahKifEyxqhNoURSlgsOISAh0VzeGDn2dsAZ60PCFvPz8tJYcKK4AAzQEZw6U5WWojM6bzO32JfNk_WoiXQbJQfGENDdHRGEKYRQnTogGzlPgKEuqMFWBTcCPQ=w1523-h855-no\" width=\"1523\" height=\"855\" \/><figcaption class=\"wp-caption-text\">Manually testing the Interface A<\/figcaption><\/figure>\n<p>Only issue was finding pin 1: it is the top pin from right. I made a mistake and started with the top pin from left and it started to smell bad &#8211; amazingly, it didn&#8217;t destroy my Interface A.<\/p>\n<p>So these are the pins (based on the table available at <a href=\"http:\/\/lgauge.com\/technic\/LEGOInterfaceA\/9750(1093).htm\">L Gauge<\/a>)<\/p>\n<table style=\"height: 908px;\" border=\"0\" width=\"416\" cellspacing=\"0\">\n<colgroup width=\"88\"><\/colgroup>\n<colgroup width=\"104\"><\/colgroup>\n<tbody>\n<tr>\n<td align=\"center\" height=\"13\"><strong>Pin<\/strong><\/td>\n<td align=\"center\"><strong>Function<\/strong><\/td>\n<\/tr>\n<tr>\n<td align=\"center\" height=\"13\">1<\/td>\n<td align=\"center\">VCC: +5V<\/td>\n<\/tr>\n<tr>\n<td align=\"center\" height=\"13\">2<\/td>\n<td align=\"center\">&#8211;<\/td>\n<\/tr>\n<tr>\n<td align=\"center\" height=\"13\">3<\/td>\n<td align=\"center\">VCC: +5V<\/td>\n<\/tr>\n<tr>\n<td align=\"center\" height=\"13\">4<\/td>\n<td align=\"center\">&#8211;<\/td>\n<\/tr>\n<tr>\n<td align=\"center\" height=\"13\">5<\/td>\n<td align=\"center\">Ground<\/td>\n<\/tr>\n<tr>\n<td align=\"center\" height=\"13\">6<\/td>\n<td align=\"center\">Output Bit 0<\/td>\n<\/tr>\n<tr>\n<td align=\"center\" height=\"13\">7<\/td>\n<td align=\"center\">Ground<\/td>\n<\/tr>\n<tr>\n<td align=\"center\" height=\"13\">8<\/td>\n<td align=\"center\">Output Bit 1<\/td>\n<\/tr>\n<tr>\n<td align=\"center\" height=\"13\">9<\/td>\n<td align=\"center\">Ground<\/td>\n<\/tr>\n<tr>\n<td align=\"center\" height=\"13\">10<\/td>\n<td align=\"center\">Output Bit 2<\/td>\n<\/tr>\n<tr>\n<td align=\"center\" height=\"13\">11<\/td>\n<td align=\"center\">Ground<\/td>\n<\/tr>\n<tr>\n<td align=\"center\" height=\"13\">12<\/td>\n<td align=\"center\">Output Bit 3<\/td>\n<\/tr>\n<tr>\n<td align=\"center\" height=\"13\">13<\/td>\n<td align=\"center\">Ground<\/td>\n<\/tr>\n<tr>\n<td align=\"center\" height=\"13\">14<\/td>\n<td align=\"center\">Output Bit 4<\/td>\n<\/tr>\n<tr>\n<td align=\"center\" height=\"13\">15<\/td>\n<td align=\"center\">Ground<\/td>\n<\/tr>\n<tr>\n<td align=\"center\" height=\"13\">16<\/td>\n<td align=\"center\">Output Bit 5<\/td>\n<\/tr>\n<tr>\n<td align=\"center\" height=\"13\">17<\/td>\n<td align=\"center\">Ground<\/td>\n<\/tr>\n<tr>\n<td align=\"center\" height=\"13\">18<\/td>\n<td align=\"center\">Input Bit 6<\/td>\n<\/tr>\n<tr>\n<td align=\"center\" height=\"13\">19<\/td>\n<td align=\"center\">Ground<\/td>\n<\/tr>\n<tr>\n<td align=\"center\" height=\"13\">20<\/td>\n<td align=\"center\">Input Bit 7<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Don&#8217;t need to use all pins &#8211; pin 1 and 3 (VCC) are internally connected, as all Ground pins &#8211; if we keep wires short between the FTDI adapter and the Interface A, we don&#8217;t need so many Ground wires (on a long flat cable they help minimizing noise). I used just 10 (VCC, GND and 8xI\/O).<\/p>\n<p>Now I need to connect these pins to an USB FTDI adapter with enough pins, like the <a href=\"https:\/\/www.sparkfun.com\/products\/12731\">Sparkfun Breakout Board for FT232RL USB to Serial<\/a>.<\/p>\n<p>Most of the information needed I got from this post: <a href=\"https:\/\/m8051.blogspot.pt\/2010\/05\/ft232rbit-bang-using-python.html\">FT232: FTDI&#8217;s Bit Bang using Python (Parallel Port Replaced !!)<\/a><\/p>\n<p>I used the 8 pins available in Bitbang mode:<\/p>\n<pre>Output 0               TXD\r\nOutput 1               RXD\r\nOutput 2               RTS#\r\nOutput 3               CTS#\r\nOutput 4               DTR#\r\nOutput 5               DSR#\r\nInput 6                DCD#\r\nInput 7                RI#<\/pre>\n<p>To use these pins we just need to configure the bitbang port to use the 2 most significant bits as inputs and the 6 least significant bits as outputs.<\/p>\n<p>The +5 Volt to power the optocouplers is also available as VCC.<\/p>\n<p>So these are the pins I use:<\/p>\n<figure style=\"width: 600px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"size-large\" src=\"https:\/\/lh3.googleusercontent.com\/SL0jBq1rF2YsncIV5z2DPTfXROEvUUwhq3AtAL54vTPVS8HQ6MKXuCxZBDysFgOW9ZbBffufqdHx1D9Aw0QTxRuTTIInhGqUcJt7r5O7FKi-rj-ZOxpXB-uO1DmrAgv4KW-QLZmIrHl4A5TdZK0oC6Hlk68x7YIAorHTI-UyKeRDiANh4neWUVZ9iIn1XwHnE6CmRtUbb-4T9Hw7di9xQKzkC4CXwA9YZ98ack-FjUNrSWuKE8cGA3XRg9lWMLKNVzkjC-o2f1YnjVMKIYJVEXbHh_9nbXg4-Z59KGpzlWp840ggfF9Q1OXdP4Fxm-Sh4MjwQjO4nkVTDT1MCUDsIinPHUr6Xu7y8O9EI1NLErav1ncqpRcDqzKOZFADsPPFs4b7-T-vBq3LGMhl3OV_wOLPrnP5iCZJpggxt5LYNPng9ClfbbKmlroGqDJT1MWdcSYuA5gsOFrsAyf1v6ePDYxI9clE-tYBtsX77ySKNqsnIcoDW2W7wiPd9rIlYpVXQalt_lKngrfpzdTbRg3fAOy1iUFS4qNd9gr0RcZMaRrGf32VL7xVkA1OqojP_X-S2l3mTl0-vEUU1NUBG3Ng15wHmdXnZBJtY_89JdZdWw=s600-no\" width=\"600\" height=\"600\" \/><figcaption class=\"wp-caption-text\">FTDI adapter for Interface A<\/figcaption><\/figure>\n<p>(and, of course, at least one GND pin)<\/p>\n<p>I decided to use <a href=\"http:\/\/pylibftdi.readthedocs.io\/en\/0.16.1\/index.html\">pylibftdi<\/a>. On my Ubuntu 17.04 I just needed<\/p>\n<pre>sudo apt-get install libftdi1-dev\r\nsudo pip3 install pylibftdi<\/pre>\n<p>To use it I need to know the serial number of my FTDI. That&#8217;s available from dmesg:<\/p>\n<pre>[ 253.177269] usb 1-6.2: new full-speed USB device number 10 using xhci_hcd\r\n[ 253.272003] usb 1-6.2: New USB device found, idVendor=0403, idProduct=6001\r\n[ 253.272012] usb 1-6.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3\r\n[ 253.272017] usb 1-6.2: Product: FT232R USB UART\r\n[ 253.272022] usb 1-6.2: Manufacturer: FTDI\r\n[ 253.272027] usb 1-6.2: SerialNumber: A105BPBO\r\n[ 253.317758] usbcore: registered new interface driver ftdi_sio\r\n[ 253.317781] usbserial: USB Serial support registered for FTDI USB Serial Device\r\n[ 253.317912] ftdi_sio 1-6.2:1.0: FTDI USB Serial Device converter detected\r\n[ 253.317949] usb 1-6.2: Detected FT232RL\r\n[ 253.319094] usb 1-6.2: FTDI USB Serial Device converter now attached to ttyUSB3<\/pre>\n<p>Or we can use the &#8216;pylibftdi.examples.list_devices&#8217; provided with the library:<\/p>\n<pre>sudo python3 -m pylibftdi.examples.list_devices\r\nFTDI:FT232R USB UART:A105BPBO<\/pre>\n<p>(pylibftdi requires root privileges unless we write an udev rule for our device)<\/p>\n<p>So I&#8217;m writing a <a href=\"https:\/\/github.com\/JorgePe\/InterfaceA\/blob\/master\/ftdi01.py\">python script<\/a> that uses the computer keyboard to control the individual output ports 0..5 or the pair ports A..C and constantly polls the state of the input ports 6 and 7.<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"seriesmeta\">This post is part 2  of 4 of \u00a0<a href=\"https:\/\/ofalcao.pt\/blog\/series\/lego-interface-a\" class=\"series-317\" title=\"LEGO Interface A\">LEGO Interface A<\/a><\/div><p>By modern criteria, the Interface A is quite simple: it has 2 inputs that accept TTL levels and 6 power outputs able to turn ON or OFF 6 &#8216;devices&#8217; like motors or lamps. These 6 output can be used independently or in pairs. A motor connected to a single output just turns ON or OFF &hellip; <a href=\"https:\/\/ofalcao.pt\/blog\/2017\/ressurecting-the-lego-interface-a\" class=\"more-link\">Continuar a ler<span class=\"screen-reader-text\"> &#8220;Ressurecting the LEGO Interface A&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","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":[],"series":[317],"class_list":["post-1194","post","type-post","status-publish","format-standard","hentry","category-sem-categoria","series-lego-interface-a"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2Mhyv-jg","_links":{"self":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/posts\/1194","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=1194"}],"version-history":[{"count":0,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/posts\/1194\/revisions"}],"wp:attachment":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/media?parent=1194"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/categories?post=1194"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/tags?post=1194"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/series?post=1194"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}