{"id":1709,"date":"2021-01-25T16:51:58","date_gmt":"2021-01-25T16:51:58","guid":{"rendered":"https:\/\/ofalcao.pt\/blog\/?p=1709"},"modified":"2021-01-27T07:34:43","modified_gmt":"2021-01-27T07:34:43","slug":"linux-and-the-lego-powered-up-mindstorms","status":"publish","type":"post","link":"https:\/\/ofalcao.pt\/blog\/2021\/linux-and-the-lego-powered-up-mindstorms","title":{"rendered":"Linux and the LEGO Powered Up MINDSTORMS"},"content":{"rendered":"\n<p>Nothing new here, just my personal notes with the LEGO Hub from 51515 MINDSTORMS Robot Inventor Set.<\/p>\n\n\n\n<p>Most of it based on <a href=\"https:\/\/medium.com\/jj-innovative-results\/how-to-set-up-bluetooth-on-the-raspberry-pi-for-a-lego-spike-61b137f98673\">this post by Jason Jurotich<\/a>. <\/p>\n\n\n\n<p>I have a LEGO 51515 set, thanks to the <a href=\"https:\/\/www.robotmak3rs.com\/\" data-type=\"URL\" data-id=\"https:\/\/www.robotmak3rs.com\/\">ROBOTMAK3RS community<\/a> (and still not sure yet if I am willing to pay so much money for this set).<br>I have an Android Lenovo tablet and an Android Samsung phone. Installed LEGO MINDSTORMS App on both but only can managed to use it on the phone &#8211; the tablet doesn&#8217;t get Activities so I could not even make Charlie play the drums.<\/p>\n\n\n\n<p>I also have a Ubuntu Linux laptop. It will have to work &#8211; last time I revived a Windows 10 virtual machine it took me a whole night just to update it in order to install LEGO App. No way!!<\/p>\n\n\n\n<p>So tanks to Jason post I can connect my laptop to the Hub:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo rfcomm connect hci0 A8:E2:C1:96:5B:9A<\/pre>\n\n\n\n<p>this gives me a &#8216;\/dev\/rfcomm0&#8217; serial device and I can access the REPL environment in 2 different ways:<\/p>\n\n\n\n<p>directly through a terminal client like &#8216;picocom&#8217;:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">picocom \/dev\/rfcomm0 -b 115200<\/pre>\n\n\n\n<p>with a more proper tool like &#8216;<a href=\"https:\/\/pypi.org\/project\/rshell\/\">rshell<\/a>&#8216;:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">rshell -p \/dev\/rfcomm0 repl<\/pre>\n\n\n\n<p>When accessing the REPL, the hub is sending values so we need to Ctrl+C to get the prompt.<\/p>\n\n\n\n<p>I found out that accessing the REPL through &#8216;picocom&#8217; lead to strange behaviors afer a while (like commands being executed but not returning to the prompt and after a while not being able to access again, like if the Hub was rebooting immediately after accessing it) so I am now using &#8216;rshell&#8217;.<\/p>\n\n\n\n<p>I also installed Adafruit &#8216;ampy&#8217; from pypi. This way I can send and execute a micropython script from my laptop without accessing the REPL:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ampy --port \/dev\/rfcomm0 run test.py<\/pre>\n\n\n\n<p>But since I know nothing about LEGO micropython environment I will use REPL a while more (before flashing Pybricks on it and probably forgetting LEGO firmware like I did with MINDTORMS EV3 original application once I discovered ev3dev).<\/p>\n\n\n\n<p>When accessing the REPL environment this is the welcome message:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Welcome to MicroPython!\n For online help please visit http:\/\/micropython.org\/help\/.\n Quick overview of commands for the board:\n   hub.info()    -- print some general information\n   hub.status()  -- print sensor data\n Control commands:\n   CTRL-A        -- on a blank line, enter raw REPL mode\n   CTRL-B        -- on a blank line, enter normal REPL mode\n   CTRL-C        -- interrupt a running program\n   CTRL-D        -- on a blank line, do a soft reset of the board\n   CTRL-E        -- on a blank line, enter paste mode\n   CTRL-F        -- on a blank line, enter filetransfer mode<\/pre>\n\n\n\n<p>of course &#8216;hub.info()&#8217; and &#8216;hub.status()&#8217; only work <strong>after<\/strong> we &#8216;import hub&#8217; library &#8211; something probably obvious for someone used to (micro)python and REPL but not so obvious for newcomers.<\/p>\n\n\n\n<p>Other important methods in this library<\/p>\n\n\n\n<p>&#8216;hub.battery.info()&#8217;:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&gt;&gt;&gt; hub.battery.info()\n{'temperature': 23.8, 'charge_voltage': 7591, 'charge_current': 251, 'charge_voltage_filtered': 7583, 'error_state': [0], 'charger_state': 0, 'battery_capacity_left': 80}         <\/pre>\n\n\n\n<p>&#8216;hub.repl_restart()&#8217; &#8211; I had used this method a few times today&#8230; and I hate reboots!<\/p>\n\n\n\n<p>&#8216;hub.power_off()&#8217;<\/p>\n\n\n\n<p>So lets find out if I can make Charlie play the drum with micropython.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Nothing new here, just my personal notes with the LEGO Hub from 51515 MINDSTORMS Robot Inventor Set. Most of it based on this post by Jason Jurotich. I have a LEGO 51515 set, thanks to the ROBOTMAK3RS community (and still not sure yet if I am willing to pay so much money for this set).I &hellip; <a href=\"https:\/\/ofalcao.pt\/blog\/2021\/linux-and-the-lego-powered-up-mindstorms\" class=\"more-link\">Continuar a ler<span class=\"screen-reader-text\"> &#8220;Linux and the LEGO Powered Up MINDSTORMS&#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":[],"class_list":["post-1709","post","type-post","status-publish","format-standard","hentry","category-sem-categoria"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2Mhyv-rz","_links":{"self":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/posts\/1709","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=1709"}],"version-history":[{"count":0,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/posts\/1709\/revisions"}],"wp:attachment":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/media?parent=1709"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/categories?post=1709"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/tags?post=1709"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/series?post=1709"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}