Jump to content

  • Log In with Google      Sign In   
  • Create Account

Photo

MSP430 Launchpad + Android = Pinball

ms430 Android launchpad

  • Please log in to reply
9 replies to this topic

#1 rubfi

rubfi

    Noob Class

  • Members
  • 7 posts

Posted 30 December 2012 - 03:48 PM

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-everyw..._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/w...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://dozingcatsoft...ball/index.html ), adding support for serial port access (using  http://code.google.c...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  
   DCOCTL = CALDCO_1MHZ;

   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

   uart_init();

   __enable_interrupt();

   uint8_t c;

   while(1)
   {
      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?

 

 

 

 

Attached Files


  • bluehash, cde, Rickta59 and 3 others like this

#2 GeekDoc

GeekDoc

    Level 4

  • Administrators
  • 1,379 posts
  • LocationO'Fallon, Illinois (St. Louis Metro area)
  • Sparkfun Wishlist


Posted 30 December 2012 - 04:15 PM

As an Andriod AND MSP430 lover, this is awesome!  Gonna have to figure out something of my own to do.


Public Service Announcement: I am a microcontroller / electronics noob! I should usually be quietly ignored or patiently instructed.
http://blog.DocsTech.net

#3 bluehash

bluehash

    Site Admin

  • Administrators
  • 5,165 posts

Posted 30 December 2012 - 05:16 PM

This is awesome! and welcome to 43oh!


Stellarisiti - Join the new Tiva-C/Stellaris ARM Forums discussing Stellaris Microcontroller.

C2kCentral - C2000 News, Projects and Forums
43oh - MSP430 Discussion, News, Projects and Hacks
MachineGrid - Robots, Hacks and Technology!


#4 rubfi

rubfi

    Noob Class

  • Members
  • 7 posts

Posted 30 December 2012 - 11:34 PM

Thanks for the comments.

 

The schematics are very simple, just two buttons, one LED, and some cables scavenged from an old PC, together with three 330 ohm resistors. Anyway, I wanted to give a try to Fritzing, so find attached the schematics (Launchpad SVG was taken from this post: http://www.43oh.com/...g-for-fritzing/ )

Attached Thumbnails

  • MSP430Pinball_bb.jpg
  • MSP430Pinball_sc.jpg


#5 cde

cde

    Enigmatic Decadence

  • Members
  • 863 posts

Posted 30 December 2012 - 11:55 PM

Wait, so the two buttons are left floating until pressed? (opps no, you have the internal pullups enabled, all good)



#6 rubfi

rubfi

    Noob Class

  • Members
  • 7 posts

Posted 31 December 2012 - 12:10 AM

Wait, so the two buttons are left floating until pressed? (opps no, you have the internal pullups enabled, all good)

 

Yes, the internal pull-up resistors are enabled for pins 2.3 and 2.5



#7 rubfi

rubfi

    Noob Class

  • Members
  • 7 posts

Posted 31 December 2012 - 11:41 AM

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@192.168.0.11:/data/local/ )

(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.

Attached Files


  • bluehash and blankfield like this

#8 blankfield

blankfield

    Member

  • Members
  • PipPip
  • 11 posts
  • LocationPoland

Posted 01 January 2013 - 11:46 AM

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.


  • rubfi likes this

#9 rubfi

rubfi

    Noob Class

  • Members
  • 7 posts

Posted 02 January 2013 - 12:30 AM

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.



#10 jayachar88

jayachar88

    Member

  • Members
  • PipPip
  • 11 posts

Posted 06 January 2013 - 05:02 PM

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.







Also tagged with one or more of these keywords: ms430, Android, launchpad

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users