{"id":1404,"date":"2018-08-26T07:54:18","date_gmt":"2018-08-26T06:54:18","guid":{"rendered":"https:\/\/ofalcao.pt\/blog\/?p=1404"},"modified":"2018-08-27T16:22:59","modified_gmt":"2018-08-27T15:22:59","slug":"progress-at-last","status":"publish","type":"post","link":"https:\/\/ofalcao.pt\/blog\/2018\/progress-at-last","title":{"rendered":"Progress at last"},"content":{"rendered":"<div class=\"seriesmeta\">This post is part 6 of 8 of \u00a0<a href=\"https:\/\/ofalcao.pt\/blog\/series\/sniffing-the-lego-interactive-motor\" class=\"series-341\" title=\"Sniffing the LEGO Interactive Motor\">Sniffing the LEGO Interactive Motor<\/a><\/div><p>No luck yet with the FTDI cable. But at least I got it with the Bus Pirate!<\/p>\n<p>So:<\/p>\n<p>No LEGO Hub here, just my laptop, the <a href=\"http:\/\/dangerousprototypes.com\/docs\/Bus_Pirate\">Bus Pirate<\/a> and the LEGO BOOST Interactive Motor.<\/p>\n<p>Wiring from the Bus Pirate to the Motor:<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li>GND -&gt; Pin 3<\/li>\n<li>3V3\u00a0 -&gt; Pin 4<\/li>\n<li>MOSI -&gt; Pin 5<\/li>\n<li>MISO -&gt; Pin 6<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<ul>\n<li style=\"list-style-type: none;\">Setup:<\/li>\n<\/ul>\n<p>Connect the Bus Pirate to the USB port, should show up as &#8216;\/dev\/ttyUSB3&#8217;.<\/p>\n<p>Access the Bus Pirate with a terminal program like <strong>picocom<\/strong>:<\/p>\n<pre>picocom -b 115200 \/dev\/ttyUSB3<\/pre>\n<p>Send this commands:<\/p>\n<p style=\"padding-left: 30px;\">&#8216;m&#8217; to choose mode<\/p>\n<p style=\"padding-left: 30px;\">&#8216;3&#8217; to choose UART<\/p>\n<p style=\"padding-left: 30px;\">&#8216;9&#8217; to choose 115200 bps<\/p>\n<p style=\"padding-left: 30px;\">&#8216;1&#8217; to choose 8 bits without parity (8N)<\/p>\n<p style=\"padding-left: 30px;\">&#8216;1&#8217; to choose 1 stop bit (so 8N1)<\/p>\n<p style=\"padding-left: 30px;\">&#8216;1&#8217; to choose receive polarity as Idle = 1 (usual TTL levels)<\/p>\n<p style=\"padding-left: 30px;\">&#8216;1&#8217; to choose output type &#8216;Open Drain (H=Hi-Z, L=GND)&#8217;<\/p>\n<p>Now that the Bus Pirate is in UART mode:<\/p>\n<p style=\"padding-left: 30px;\">&#8216;W&#8217; to turn Power Supplies ON (3V3 and 5V pins)<\/p>\n<p style=\"padding-left: 30px;\">&#8216;P&#8217; to turn Pullup resistors ON<\/p>\n<p style=\"padding-left: 30px;\">(1) to put the Bus Pirate in &#8216;Transparent bridge&#8217; mode<\/p>\n<p style=\"padding-left: 30px;\">&#8216;y&#8217; to confirm<\/p>\n<p>Now quit the terminal (thats Control+A+Q for picocom) and use a serial sniffer like <strong>jpnevulator<\/strong>:<\/p>\n<pre>jpnevulator -i 10 --tty \/dev\/ttyUSB3 --read<\/pre>\n<p>We should now receive continuous &#8217;00&#8217;<\/p>\n<p>Then send the AutoID sequence to the Motor and after that keep sending &#8217;02&#8217; every 100 ms:<\/p>\n<pre>#!\/usr\/bin\/env bash\r\n\r\necho -e -n \"\\x54\\x22\\x00\\x10\\x20\\xB9\" &gt; \/dev\/ttyUSB3\r\n\r\nfor i in {1..1000}\r\ndo\r\n    echo -e -n \"\\x02\" &gt; \/dev\/ttyUSB3\r\n    sleep 0.1\r\ndone\r\n<\/pre>\n<p>Sometimes this doesn&#8217;t work at first and we just receive a sequence of<\/p>\n<pre>C0 00 3F<\/pre>\n<p>But aborting the script and trying again will get us:<\/p>\n<pre>D8 00 00 00 00 00 00 00 00 27<\/pre>\n<p>and if we turn the axle by hand a bit (first clockwise then anticlockwise):<\/p>\n<pre>D8 00 01 00 00 00 00 00 00 26\r\nD8 00 01 00 00 00 00 00 00 26\r\nD8 00 02 00 00 00 00 00 00 25\r\nD8 00 02 00 00 00 00 00 00 25\r\nD8 00 02 00 00 00 00 00 00 25\r\nD8 00 02 00 00 00 00 00 00 25\r\nD8 00 03 00 00 00 00 00 00 24\r\nD8 00 03 00 00 00 00 00 00 24\r\nD8 00 04 00 00 00 00 00 00 23\r\nD8 00 04 00 00 00 00 00 00 23\r\nD8 00 04 00 00 00 00 00 00 23\r\nD8 00 04 00 00 00 00 00 00 23\r\nD8 00 04 00 00 00 00 00 00 23\r\nD8 00 04 00 00 00 00 00 00 23\r\nD8 00 04 00 00 00 00 00 00 23\r\nD8 00 04 00 00 00 00 00 00 23\r\nD8 00 04 00 00 00 00 00 00 23\r\nD8 00 04 00 00 00 00 00 00 23\r\nD8 00 04 00 00 00 00 00 00 23\r\nD8 00 04 00 00 00 00 00 00 23\r\nD8 00 04 00 00 00 00 00 00 23\r\nD8 00 03 00 00 00 00 00 00 24\r\nD8 00 03 00 00 00 00 00 00 24\r\nD8 00 02 00 00 00 00 00 00 25\r\nD8 FE 01 00 00 00 00 00 00 D8\r\nD8 FE 01 00 00 00 00 00 00 D8\r\nD8 00 01 00 00 00 00 00 00 26\r\nD8 00 01 00 00 00 00 00 00 26<\/pre>\n<p>If\u00a0 I stop sending this &#8217;02&#8217; every 100 ms the Motor stops sending the encoder status and returns to &#8217;00&#8217;. It also looses it&#8217;s current state if I don&#8217;t restart the whole script soon enough (or just start &#8217;02&#8217; again).<\/p>\n<p>The BitScope logic analyzer wasn&#8217;t a great help (except for the timings). I had <strong>much<\/strong> <strong>more<\/strong> success using the Bus Pirate in &#8216;Transparent Bridge&#8217; mode to capture each wire of the motor.<\/p>\n<p>Now the reason I cannot replicate this <del>is the FTDI cable is probably the lack of pullup resistors since I&#8217;m using a <a href=\"https:\/\/www.sparkfun.com\/products\/13746\">Sparkfun Beefy 3<\/a> with an internal PSU that should give enough current to the 3V3 pin. But the Motor also has its own internal pullup and pulldown resistors so this shouldn&#8217;t be a problem. <\/del>is still unknown. Reading the Bus Pirate documentation using the pull up resistors should make no difference because I would also need to manually tie the pull up voltage to 3V3&#8230; and I didn&#8217;t. Probably the Hi-Z (high impedance) state of the output pin has some importance.<del><br \/>\n<\/del><\/p>\n<p>Have to try the FTDI cable again.<\/p>\n<p>Edit: although documentation states that the Bus Pirate pull up resistors also need a manual connection to 3V3&#8230; I only have readings when activating the pull ups. And I do have a BP 3.6 board. Go figure.<\/p>\n<p>Edit #2: added &#8220;-n&#8221; to the test script to prevent sending a New Line (&#8216;0Ah&#8217;)<\/p>\n<p>Edit #3: turns out it has nothing to do with pull up resistors or Hi-Z modes&#8230; when using <strong>picocom<\/strong> to configure the Bus Pirate it changes &#8216;\/dev\/ttyUSB3&#8217; to raw mode and leaves it on that mode when quitting&#8230; so I can now use <strong>jpnevulator<\/strong> to capture all messages from the motor.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"seriesmeta\">This post is part 6  of 8 of \u00a0<a href=\"https:\/\/ofalcao.pt\/blog\/series\/sniffing-the-lego-interactive-motor\" class=\"series-341\" title=\"Sniffing the LEGO Interactive Motor\">Sniffing the LEGO Interactive Motor<\/a><\/div><p>No luck yet with the FTDI cable. But at least I got it with the Bus Pirate! So: No LEGO Hub here, just my laptop, the Bus Pirate and the LEGO BOOST Interactive Motor. Wiring from the Bus Pirate to the Motor: GND -&gt; Pin 3 3V3\u00a0 -&gt; Pin 4 MOSI -&gt; Pin 5 MISO &hellip; <a href=\"https:\/\/ofalcao.pt\/blog\/2018\/progress-at-last\" class=\"more-link\">Continuar a ler<span class=\"screen-reader-text\"> &#8220;Progress at last&#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":[],"series":[341],"class_list":["post-1404","post","type-post","status-publish","format-standard","hentry","category-sem-categoria","series-sniffing-the-lego-interactive-motor"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2Mhyv-mE","_links":{"self":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/posts\/1404","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=1404"}],"version-history":[{"count":0,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/posts\/1404\/revisions"}],"wp:attachment":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/media?parent=1404"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/categories?post=1404"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/tags?post=1404"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/series?post=1404"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}