{"id":1322,"date":"2018-07-14T23:39:51","date_gmt":"2018-07-14T22:39:51","guid":{"rendered":"https:\/\/ofalcao.pt\/blog\/?p=1322"},"modified":"2018-07-15T19:11:25","modified_gmt":"2018-07-15T18:11:25","slug":"making-an-android-app-for-lego-powered-up","status":"publish","type":"post","link":"https:\/\/ofalcao.pt\/blog\/2018\/making-an-android-app-for-lego-powered-up","title":{"rendered":"Making an Android app for LEGO Powered Up"},"content":{"rendered":"<p>The new LEGO trains are now Powered Up based.<\/p>\n<p>Like WeDo 2 and BOOST, this is a Bluetooth 4 Low Energy (BLE) device that uses the new type of 6-pin plug that LEGO announced a couple of years ago with the WeDo 2. At that time this new design was referenced as Power Functions 2 or PF2 but the final name is now Powered Up.<\/p>\n<p>Unlike BOOST, the new smart hub included with the trains doesn&#8217;t include motors. LEGO found a way to arrange 6 AAA batteries inside it in such a compact way that the final size is exactly the same of the Power Functions LiPo or AAA batteries&#8230; with all the new electronics included:<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large\" src=\"https:\/\/i0.wp.com\/raw.githubusercontent.com\/JorgePe\/Puppy\/master\/IMG_20180714_222036.jpg?resize=840%2C548&#038;ssl=1\" width=\"840\" height=\"548\" \/><\/p>\n<p>Others like Sariel and Hispabrick already reviewed this device so I&#8217;ll just show how to to use it.<\/p>\n<p>This new hub announces itself as &#8220;HUB NO.4&#8221;.\u00a0 It will probably have a much better name but for now I will call it this way.<\/p>\n<p>A good thing with &#8220;HUB NO.4&#8221; is that it\u00a0 provides the same UUID services as BOOST. So most of the examples I wrote for BOOST work with Powered Up with just a few modifications.<\/p>\n<p>For instance, the LEGO WeDo 2 motors can be used the same way as with BOOST:<\/p>\n<pre>gatttool -b 90:84:2B:06:AB:5D --char-write-req --handle 0x0e --value 080081<strong>00<\/strong>115100<strong>60<\/strong><\/pre>\n<p>The handle (&#8220;0Eh&#8221;) is the same. The payload is also simillar, with the same 3 initial bytes (&#8220;080081&#8221;, hexadecimal) followed by a fourth byte that selects the output port (&#8220;00&#8221; = port A, &#8220;01&#8221; = port B), followed by the same 3 bytes (&#8220;115100&#8221;) and finally the last byte is the duty cycle (or speed) applied to the motor (&#8220;60h&#8221; = 100d = 100%).<\/p>\n<p>Since I already had an Android app made with MIT App Inventor 2 for the\u00a0 Vernie model of the BOOST set I made just a few modifications to make it work with &#8220;HUB NO.4&#8221;:<\/p>\n<ul>\n<li>removed the blocks that controlled the head and cannon trigger<\/li>\n<li>removed the blocks that sensed the colors<\/li>\n<li>added the BT address of my &#8220;HUB NO.4&#8221; to the list of devices to pick<\/li>\n<li>changed the motor commands used by BOOST (simultaneous control of pair A+B) by the motor commands of two WeDo 2 motors<\/li>\n<\/ul>\n<p>That&#8217;s it!<\/p>\n<div class=\"jetpack-video-wrapper\"><iframe loading=\"lazy\" title=\"Controlling LEGO Powered Up with Android MIT App Inventor 2\" width=\"840\" height=\"473\" src=\"https:\/\/www.youtube.com\/embed\/ykHJtEJ2xL0?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>This the Designer view:<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large\" src=\"https:\/\/i0.wp.com\/raw.githubusercontent.com\/JorgePe\/Puppy\/master\/puppy01.png?resize=336%2C490&#038;ssl=1\" width=\"336\" height=\"490\" \/><\/p>\n<p>and this is the Blocks view:<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large\" src=\"https:\/\/i0.wp.com\/raw.githubusercontent.com\/JorgePe\/Puppy\/master\/puppy02.png?resize=840%2C2916&#038;ssl=1\" width=\"840\" height=\"2916\" \/><\/p>\n<p>If you&#8217;re interested, I exported <a href=\"https:\/\/github.com\/JorgePe\/Puppy\/raw\/master\/PUP_v1_sliders.aia\">the project<\/a> as an &#8220;.aia&#8221; file. It&#8217;s not polished (for instance the blocks still make references to Vernie) but you get a good base to start.<\/p>\n<p>In my <a href=\"https:\/\/ofalcao.pt\/blog\/2018\/making-an-android-app-for-lego-powered-up-explanation\">next article<\/a> I try to explain how this App was created.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The new LEGO trains are now Powered Up based. Like WeDo 2 and BOOST, this is a Bluetooth 4 Low Energy (BLE) device that uses the new type of 6-pin plug that LEGO announced a couple of years ago with the WeDo 2. At that time this new design was referenced as Power Functions 2 &hellip; <a href=\"https:\/\/ofalcao.pt\/blog\/2018\/making-an-android-app-for-lego-powered-up\" class=\"more-link\">Continuar a ler<span class=\"screen-reader-text\"> &#8220;Making an Android app for LEGO Powered Up&#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":[38,39,233,154,18],"tags":[150,332],"series":[],"class_list":["post-1322","post","type-post","status-publish","format-standard","hentry","category-ble","category-bluetooth","category-bluetooth-pt","category-lego-en","category-lego","tag-ble-en","tag-powered-up"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2Mhyv-lk","_links":{"self":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/posts\/1322","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=1322"}],"version-history":[{"count":0,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/posts\/1322\/revisions"}],"wp:attachment":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/media?parent=1322"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/categories?post=1322"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/tags?post=1322"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/series?post=1322"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}