Sparki + Android™: Introduction

Introduction

In this lesson we will learn how to control a Sparki from an Android™ mobile device.

The Android robot is reproduced or modified from work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License.

For this purpose we will also learn the basics of MIT’s App Inventor, a free and easy to use graphical programming environment for Android™: But before digging in Android™ programming, please be sure that you understand the basic concepts of Sparki’s Bluetooth and Serial communications. Also, we are going to make extensive use here of the programs explained in the Computer Inputs lesson.

What You’ll Need

  • Sparki.
  • The Bluetooth module (included with the Sparki).
  • An Android™ device (more about device compatibility in the next section).
  • A working internet connection (since App Inventor runs in the cloud).
  • If you are going to use a WiFi connected Android™ device (more on this below in this lesson), you will need a WiFi router/access point connected to the internet. The computer that you will use to run App Inventor has to be connected to the same WiFi connection as your Android™ device.
 

Device compatibility

To ensure that the examples on this lesson works with a wide range of Android™ devices, we have tested everything with an small Android™ cellphone running Android™ 2.3.6. So, newer Android™ versions should work even better, but we did not make exhaustive testing, nor we ensure device compatibility of any kind. The examples provided here are for the purpose of only demonstrating a possible way of Sparki’s usage with some mobile devices. Finally, we have included a small troubleshooting section at the end of this lesson with some tips to avoid common problems that we have found when working with some Android™ devices.  

Connecting Sparki to an Android™ device.

##Under construction.  

Getting Started with App Inventor

The easiest way of setting up an Android™ device to work with App Inventor is by using a WiFi connection, as explained here. This is the way that we have tested and worked with to create the examples on this lesson. ##Under construction.  

First Example: Moving the Robot

Let’s start by a simple serial remote control example using Sparki’s Bluetooth module. Before starting the work on the Android side, please upload to your Sparki the following sketch using the SparkiDuino software. This small program is nothing else than “Asynchronous Events” example from the previous Computer Inputs lesson, with the modifications to work with the Serial1 (Bluetooth) port: Warning_Triangle Please remember to check that the batteries are properly connected (and charged!). And as we are going to use the motors here, please check that the On/Off Switch is on.  Another important thing to take care of when playing with the robot’s motors is to be careful not to be working over a table. A fall from that table could permanently damage your Sparki. So now, we can start to code using App Inventor. Here is a screenshot of how our application will look once it’s ready and running on our mobile device: If you are impatient and want to start playing around with the app before we learn how it works, you can download the complete source code here:

Once downloaded you will a file with the .aia extension which can be imported into your App Inventor user account using the Project->Import project (aia) from my computer menu option:   Now, let’s see how it works… ##Under construction ##Under construction ##Under construction ##Under construction ##Under construction ##Under construction ##Under construction ##Under construction To understand the commands that we are sending with the previous code, please remember the code inside Sparki which interprets these simple one character instructions: ##Under construction  

Reading Sparki’s Ultrasonic Ranger

##Under construction Before continuing, we will use a slightly modified firmware on the Sparki side for this example. So we will just comment some parts of the previous program and modify a bit the code related to the ping sensor’s value sending through the serial connection: ##Under construction ##Under construction ##Under construction ##Under construction Here is the App Inventor code:

 

Making a Better Android™ Application

##Under construction ##Under construction Here is the App Inventor code:  

Building an .apk File and Deploying It

If you want to upload your own application to Google Play to share it not just as an App Inventor source project, but as an app available on that online store, here are the instructions. Once you have registered and followed the required steps, you will need to create an apk file. This can be easily done by selecting the Build->App (save .apk to my computer) menu in App Inventor:

 

You can find more information about how to upload the apk to Google Play on this page.  

Troubleshooting

If you experiment any problem when regarding App Inventor and Sparki, please visit the Sparki Troubleshooting page, section 7:  Sparki + App Inventor (Android™) problems.   

Related Lessons & Extra Activities

Now that we can use our Android™ mobile device as Sparki’s brain, there are really a lot of things that we can accomplish. Just think about the possibilities! From now you can continue developing your own ideas, given the processing and sensoring power of mobile devices combined with Sparki. But we have also created more lessons integrating Sparki with Android™ devices. If you want to follow the lessons in an increasing complexity order, please take a look to the Sparki + Android™: Multiple Sensors lesson.