{"id":960,"date":"2016-09-08T15:40:59","date_gmt":"2016-09-08T14:40:59","guid":{"rendered":"http:\/\/ofalcao.pt\/blog\/?p=960"},"modified":"2016-09-08T15:40:59","modified_gmt":"2016-09-08T14:40:59","slug":"lego-wedo-2-0-with-mit-app-inventor","status":"publish","type":"post","link":"https:\/\/ofalcao.pt\/blog\/2016\/lego-wedo-2-0-with-mit-app-inventor","title":{"rendered":"LEGO WeDo 2.0 with MIT App Inventor"},"content":{"rendered":"<p>I got a request for help today, Mr. Rocha is trying to use MIT App Inventor to control the WeDo 2.0 Smart Hub RGB LED.<\/p>\n<p>I&#8217;ve never used <a href=\"http:\/\/appinventor.mit.edu\/\">App Inventor<\/a> before but I had already installed the Companion once in my Android Phone because I read something somewhere and found it quite similar to Snap! and Scratch (and\u00a0 also just because it is from MIT&#8230; I have a fetiche for MIT back from when I was at college and read <a href=\"https:\/\/www.google.pt\/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=1&amp;cad=rja&amp;uact=8&amp;ved=0ahUKEwi-zoTp-f_OAhUD7xQKHbQVC1MQFggbMAA&amp;url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FNicholas_Negroponte&amp;usg=AFQjCNEZb1b-aSLGj0CESeuPoEdtEJtxfg&amp;sig2=yPY5lCfR-c0SIqEeWgSzvQ&amp;bvm=bv.131783435,d.d24\">Nicholas Negroponte<\/a> articles on Wired). So let&#8217;s give it a try.<\/p>\n<p>I just wanted to connect to the WeDo 2.0 Smart Hub and change the color to RED. When using gatttool that&#8217;s done with just<\/p>\n<pre>char-write-cmd 3d 06040109<\/pre>\n<p>Just needed to add the <a href=\"http:\/\/appinventor.mit.edu\/extensions\/\">BLE extension<\/a> to start working, getting a connection was easy but writing to the handle took a while since App Inventor BLE extension doesn&#8217;t use handles, just UUIDs. So I had to go back to my notes and find the Service UUID and the Characteristic UUID:<\/p>\n<pre>service_uuid = 00004f0e-1212-efde-1523-785feabcd123\r\ncharacteristic_uuid = 00001565-1212-efde-1523-785feabcd123<\/pre>\n<p>Then I tried a block called &#8220;call BluetoothLE. WriteStringValue&#8221; but I couldn&#8217;t find a way to convert an hexadecimal string (&#8220;06040109&#8221;) to a proper string to send.<\/p>\n<p>So I tried another block, &#8220;call BluetoothLE.WriteIntValue&#8221;. At first I made an old mistake, converting &#8220;06040109h&#8221; to &#8220;100925705&#8221;. Didn&#8217;t work.<\/p>\n<p>Then I wrote it in reverse (&#8220;09010406h&#8221;) and converted it to &#8220;151061510&#8221;. And now it works!<\/p>\n<p><a href=\"https:\/\/flic.kr\/p\/LyZzuC\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/farm9.staticflickr.com\/8268\/29253059720_cef08cf139_b.jpg?resize=824%2C520&#038;ssl=1\" alt=\"WeDoLED\" width=\"824\" height=\"520\" \/><\/a><\/p>\n<p>Now that I finally started, I think I will use App Inventor some more times. Damn easy to create an BLE Android app!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I got a request for help today, Mr. Rocha is trying to use MIT App Inventor to control the WeDo 2.0 Smart Hub RGB LED. I&#8217;ve never used App Inventor before but I had already installed the Companion once in my Android Phone because I read something somewhere and found it quite similar to Snap! &hellip; <a href=\"https:\/\/ofalcao.pt\/blog\/2016\/lego-wedo-2-0-with-mit-app-inventor\" class=\"more-link\">Continuar a ler<span class=\"screen-reader-text\"> &#8220;LEGO WeDo 2.0 with MIT App Inventor&#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-960","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-fu","_links":{"self":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/posts\/960","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=960"}],"version-history":[{"count":0,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/posts\/960\/revisions"}],"wp:attachment":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/media?parent=960"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/categories?post=960"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/tags?post=960"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/series?post=960"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}