LEGO WeDo 2.0 with MIT App Inventor

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’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! and Scratch (and  also just because it is from MIT… I have a fetiche for MIT back from when I was at college and read Nicholas Negroponte articles on Wired). So let’s give it a try.

I just wanted to connect to the WeDo 2.0 Smart Hub and change the color to RED. When using gatttool that’s done with just

char-write-cmd 3d 06040109

Just needed to add the BLE extension to start working, getting a connection was easy but writing to the handle took a while since App Inventor BLE extension doesn’t use handles, just UUIDs. So I had to go back to my notes and find the Service UUID and the Characteristic UUID:

service_uuid = 00004f0e-1212-efde-1523-785feabcd123
characteristic_uuid = 00001565-1212-efde-1523-785feabcd123

Then I tried a block called “call BluetoothLE. WriteStringValue” but I couldn’t find a way to convert an hexadecimal string (“06040109”) to a proper string to send.

So I tried another block, “call BluetoothLE.WriteIntValue”. At first I made an old mistake, converting “06040109h” to “100925705”. Didn’t work.

Then I wrote it in reverse (“09010406h”) and converted it to “151061510”. And now it works!

WeDoLED

Now that I finally started, I think I will use App Inventor some more times. Damn easy to create an BLE Android app!

11 opiniões sobre “LEGO WeDo 2.0 with MIT App Inventor”

  1. Hello,
    Thanks a lot for your blog on Lego and especially Lego WeDo2.0. I’ve followed your example from above, and built the same WeDo app in App Inventor…quite easy like you said. Good..so I can check off controlling the motors from Android. Next, I was able to make do the same based upon your tutorial in the ev3dev.org site using my BrickPi (RPi 3B…compiling the python GATTRequester was quite easy on that platform (not nearly the headaches you mentioned with the EV3 brick). Anyway, I could control the WeDo from RPi as well using the gatttool and the python libraries as well.
    So, I’m wondering if you’ve deciphered the rest of the control and data codes for the Smart Hub? Mainly, I’m looking for:
    – activating 2 motors at once
    -controlling the speed of the motor
    -getting feedback from the proximity and tilt sensor
    – (from your EV3Dev posting, I got most of the motor control codes)
    -it would also be nice to know the trick things, like determining the button state (pushed/unpushed), making tones with the piezo buzzer, color codes for the RGB LED (you already posted the one for “red” above)
    Many thanks for your help!

    1. Hi!
      Thanks for your comment, I feel delighted whenever someone gets something done thanks to something I write here.
      LEGO released the WeDo 2.0 SDK some months ago (https://education.lego.com/en-us/support/wedo-2/developer-kits). I’m not a programmer so I’m not used to SDK’s but I was expecting something much more clear and with better documentation.
      I paused the work with WeDo 2.0 for a while, but you can find the basic color codes here:
      http://ofalcao.pt/blog/2016/wedo-2-0-colors-with-python
      and a few more functions (including sound) in these group of posts:
      http://ofalcao.pt/blog/series/wedo-2-0-reverse-engineering

      1. Thanks for the links. I’ll try to add these to my App Inventor app, and see how it goes. My basic idea was to create a WeDo 2.0 control using the accelerometer tilt like in the App Inventor EV3 example. I’ll probably post it to the App Inventor projects when/if I get it working.
        Also, I was digging around in the Lego WeDo SDK Windows 8 code a bit last night….not much success finding a direct statement of the byte codes sent via BLE. Maybe I should invest in the BLE sniffer.
        I’ll let you know if I get the app fully working.

      2. Hi Again, and Happy New Year!
        I got the Lego WeDo2 car app to work based on your blog and the EV3Dev postings. I couldn’t post the code to the MIT App Inventor gallery, since they don’t allow apps with ‘experimental’ extensions. So I published the finished app in Google Play:
        https://play.google.com/store/apps/details?id=appinventor.ai_dan_cameron_2007.LegoWeDo2_TiltToDrive
        Also, I added a blog entry to document the code in case others want to try it as well:
        https://chroniclesofrexbarker.wordpress.com/2016/12/31/appy-hour-build-your-own-lego-wedo-2-0-car-tilttodrive-app-for-android/
        I got almost all of the parts to work: motors + LED. But the piezo control failed me. I believe all of the inputs were correct, and I tried manually passing the values, but it still just left the Smart Hub with a continuous mono-tone buzz. The Lego WeDo2 app didn’t implement the Piezo control either, which makes me wonder if they also had a problem with the Android version of this control.
        Anyway, all of this was based on your inputs, and I just implemented some code. Thanks again for all of the critical inputs. Let me know if you have suggestions on how to improve or further the app. I would like to move on to adding computer vision control, but this may require the full blown Android SDK + Lego SDK. I’ll see how ambitious I am…

      3. Hi again and happy New Year,
        I got the lego WeDo Tilt to drive app fully working. All of it was based on your blog posts…I only implemented it in a bit of code.
        I released the app to Google Play:
        https://play.google.com/store/apps/details?id=appinventor.ai_dan_cameron_2007.LegoWeDo2_TiltToDrive

        Also, the description of how to build the app is on my blog:
        https://chroniclesofrexbarker.wordpress.com/2016/12/31/appy-hour-build-your-own-lego-wedo-2-0-car-tilttodrive-app-for-android/
        Many thanks again for your insights to the Lego WeDo!

Deixar uma resposta

O seu endereço de email não será publicado. Campos obrigatórios marcados com *