Jump to content

MSP430 Launchpad + Android = Pinball

Recommended Posts

Hi everyone,


I wanted to connect a MSP430 to an Android device. In fact, my idea was to use the MSP430 launchpad as a low-cost GPIO board for an Android tablet. I did a little research, and first thought on the audio port for the communication ( http://robots-everywhere.com/re_wiki/index.php?title=Serial_on_Android_using_the_audio_port ) but then I remembered that the tablet supported USB OTG. So, I compiled the CDC_ACM module for the (Allwinner A10 based) tablet in order to emulate serial port over USB.


Then, in the MSP430 Launchpad side, I needed a lib for using the serial port. I found MSP430-softuart by Stefan Wendler (https://github.com/wendlers/msp430-softuart) and used it for the bidirectional communication Android-Tablet<->MSP430-Launchpad.


In order to make a demo, I modified the code of Open Source Vector Pinball (http://dozingcatsoftware.com/VectorPinball/index.html ), adding support for serial port access (using  http://code.google.com/p/android-serialport-api/). This modified Vector Pinball has the flippers linked to MSP430 Launchpad buttons. When the buttons on P2.5 and P2.3 are pressed they flippers are activated. A LED is also connected on P1.6 in order to toggle it when receiving "toggle" command from the Android app. 


You can find the video demo here:


This is the source code for the MSP430 (find it also attached to this post)

#include <msp430.h>
#include <stdint.h>

#include "uart.h"

#define LED1 BIT0
#define LED2 BIT6
#define BUTTON1 BIT5
#define BUTTON2 BIT3

static volatile bool r = false;
static volatile bool l = false;

int main(void)
   WDTCTL = WDTPW + WDTHOLD;  // Stop watchdog timer 

   BCSCTL1 = CALBC1_1MHZ;  // Initialize clock  

   P1DIR |= (LED1 + LED2); // Set BIT0 and BIT6 as output
   P1OUT &= ~(LED1 + LED2); // LEDs off

   P2REN |= (BUTTON1 + BUTTON2); // Select pull-up resitors por P2.3 and P2.5

   P2IE |= (BUTTON1 + BUTTON2); // Enabling Button interrupts

   P2IFG &= ~(BUTTON1 + BUTTON2); // Clear interrupt flags for the buttons



   uint8_t c;

      if(uart_getc(&c)) {
         if (c == 't')
            P1OUT ^= (LED2); // Toggle LED2          
      if (l)
            uart_putc('l'); // Send "left" command via UART
            l = false;
      if (r)
            uart_putc('r'); // Send "right" command via UART
            r = false;

// Port 2 interrupt service
#pragma vector=PORT2_VECTOR

__interrupt void Port_2(void)
   if ((P2IFG & BUTTON2))
      P1OUT ^= LED1;  // Toggle LED1
      P2IFG &= ~BUTTON2; // Clear BUTTON2 interrupt flag  
      P2IES ^= BUTTON2; // Interrupt called on High-to-Low and Low-to-High 
      l = true;
   if ((P2IFG & BUTTON1))
      P1OUT ^= LED1; // Toggle LED1
      P2IFG &= ~BUTTON1; // Clear BUTTON1 Interrupt flag
      P2IES ^= BUTTON1; // Interupt called on High-to-Low and Low-to-High
      r = true;



Later today, I will include the schematic and a guide with the steps for replicating the setup in case you want to build it. 


Do you find the project interesting?






Link to post
Share on other sites

Find here a small guide for building the Android side of the app (The launchpad side can be found on the original post)


Android App Setup


Download Android Serialport API code (I used the revision 54 for the pinball proof of concept)

$ mkdir build
$ cd build
$ svn checkout -r54 http://android-serialport-api.googlecode.com/svn/trunk/ android-serialport-api 

Download Vector Pinball code (rev  04ee044b27)

$ git clone https://github.com/dozingcat/Vector-Pinball.git
$ cd Vector-Pinball/
$ git checkout 04ee044b27

Apply the modifications to the Vector Pinball (MSP430Pinball.patch is attached to this post, copy it to build dir) 

patch -p1 < ../MSP430Pinball.patch

Copy serial port code and libs on the Vector Pinball tree.

$ cp -r ../android-serialport-api/android-serialport-api/project/src/android_serialport_api/ src/
$ rm -rf src/android_serialport_api/sample/

$ cp -r ../android-serialport-api/android-serialport-api/project/libs/armeabi/libserial_port.so libs/armeabi/
$ cp -r ../android-serialport-api/android-serialport-api/project/libs/armeabi-v7a/libserial_port.so libs/armeabi-v7a/

You may need to modify "src/android_serial_port/SerialPort.java" for pointing the "su" path to the "su" command on your Android device. In my case, I did:

$ vim src/android_serialport_api/SerialPort.java
-           su = Runtime.getRuntime().exec("/system/bin/su");
+           su = Runtime.getRuntime().exec("/system/xbin/su");

To import the modified VectorPinball project to your Android Development environment (In eclipse  File > New >> Project... >> Android project from existing code -> Root directory = <path_to_vector_pinball> )


Adding Serial Port emulation over USB to your OTG supporting Android Tablet

(in my case an Allwiner A10 based)


Download the kernel source code (I used the lichee3 branch in order to create a module compatible with the kernel already in the device)

$ git clone -b lichee-3.0.8-sun4i  git://github.com/linux-sunxi/linux-sunxi.git

Configure the kernel, for adding CDC_ACM support

$ make ARCH=arm sun4i_crane_defconfig
$ make ARCH=arm menuconfig

Device Drivers >> USB Support >> <M>   USB Modem (CDC ACM) support

Compile the kernel and the modules

$ export PATH=$PATH:/<path_to_your_cross_compiler>/bin
(i.e "export PATH=$PATH:/opt/arm-2010q1/bin" )

$ export CROSS_COMPILE=arm-none-linux-gnueabi-

$ make ARCH=arm
$ make ARCH=arm modules

Copy the cdc-acm.ko module to your Android device and install it

$ scp drivers/usb/class/cdc-acm.ko root@<ip>:/data/local/
( i.e $ scp drivers/usb/class/cdc-acm.ko root@ )

(I used DropBear SSH Server II on Android as SSH server)

After copying cdc-acm.ko, you should ssh your Android device and execute as root "insmod cdc-acm.ko". (you may need to do this step every time you reboot your tablet). Check if /dev/ttyACM0 has been created after loading cdc-acm.ko in order to see if the module was installed correctly.


From Eclipse build the apk or launch the BouncyActivity app.

Hopefully, following these steps it works for you, and you can build awesome apps using MSP430 Launchpad and Android.


Link to post
Share on other sites

Really nice project especially from software side, Android is fantastic OS because of free development add-on for eclipse. If you're using UART it is easy to make wireless communication via bluetooth. I did something similar with this module and based on this Java code - it's good point to start with android.


 Thanks for your comment and for the link to the Bluetooth Debugging Assistant. It will be really useful for future projects.

Link to post
Share on other sites

This is crazy awsome. I've got couple of projects where I was using IOIO, but being able to directly use USB hostmode of tablets (Android 3.x or ICS/JB devices) with MSP430 would be so wonderful.


I've got few Allwinner A10 (rather A13) based tablets, but being able to retain warranty on them is crucial, so I am not able to either root the tablets, or install the drivers for usb mode emulation (voids the warranty). So, I can only wish that a libusb based user-mode solution like this one http://android.serverbox.ch/?p=549 (Android + Arduino over USB) could be made someday.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...