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:

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!

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.

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…