Together with Ste7an, I developed an android remote control app for MINDSTORMS and SPIKE Prime. Our goal was to enable remote control without the LEGO apps in the middle. We wanted it directly from Smart device to hub. We also wanted it to work with Python because LEGO’s solution does not support Python. The app works, but the code is still very rough. In this article, I’ll explain how to use the app. I hope you like it, and maybe you can contribute to the code.
Downloading the MINDSTORMS Remote BLE app
The app is available in the Google Play store. When you run it, it will ask for access to your location. The app needs this to detect Bluetooth devices. Without a hub, the app won’t do much. Read on to find out how to connect it to MINDSTORMS.
Programming the robot for use with an RC app
On Github, I created a repository where I share robot scripts that work with the app. Currently, I only have a script that works with the Robot Inventor Hot Rod. The script is pretty rough too. Feel free to fork it and make some pull requests. A cleaner code structure and more comments are high on my wishlist. I don’t have much time at the moment.
To use the app, build the Hot Rod first. The create a new project within the MINDSTORMS app. Copy and paste the code from Github. Then run it.
The robot now shows an ‘advertising’ animation. The animation means that the app can scan for it and connect to it. Now you can have fun and drive around!
How the MINDSTORMS and SPIKE Remote Control app works
We made the app to support two-way communication between the robot and the app. The app sets up a UART link over Bluetooth Low Energy. BLE or BT4.0 are popular names for the same protocol.
Thirty times per second, the app sends the state of the buttons and sticks to the robot. To save bandwidth, we compressed that data into a few bytes. The bytes contain the positions of all sticks, sliders, and buttons. The robot then unpacks the data like this:
l_stick_hor, l_stick_ver, r_stick_hor, r_stick_ver, l_trigger, r_trigger, setting1, setting2, buttons_char = struct.unpack("bbbbBBhhB", data)
Using these values, the robot script sets the appropriate motor speeds and voltages at thirty times per second.
Conversely, the robot can also send messages to the app. There are few possibilities.
- A representation of an image. Send
repr(Image(00000:11111:22222:33333:44444))from the robot to show an icon in the center display.
- A text message for the large display. Send
"TYour message here"to display it in the app.
- A setting for the sliders. Send
"L%d"%some_numberto change the position of the Left slider.
What’s next for the MINDSTORMS Android Remote Control app
We plan to update and expand the examples, add a better description in the play store, and expand the documentation. For now, we just wanted to share what we have so everyone can play with it!