Demo Projects

Loading...

Thursday, June 6, 2013

Developing useful Android apps with infrared (IR) modules and open source libraries

Almost everyone uses infrared remote controls at home: to control your TV, your air conditioner, etc.

We naturally come to the idea of using one Android smarphone or tablet to replace these multiple remote controls.




However, developing and using infrared on most of the Android devices requires the use of external hardware. How to do it? Perhaps the easiest way is to follow what Irdroid tells us.



Irdroid is a universal infrared remote control for smartphones, tablets and other devices, working with the Google Android operating system. To control your favorite TV, STB or DVD, you need to download the Irdroid APP for Android and to purchase a Irdroid module.. The Irdroid application is available for download from the Android Market and from Appslib (for android tablets).

The biggest benefit of Irdroid is that it is compatible with the LIRC project in which database, there are a lot of supported equipment vendor’s some of the famous are Samsung, Sony, Motorola, LG, Panasonic, Philips and many, many more (see here: http://lirc.sourceforge.net/remotes/).Another benefit for the public is that the Irdroid application is free, open source and the source code can be downloaded from http://www.github.com/irdroid.

Features:

    Free and open source application and open hardware module
    Available from Android Market, AppsLib
    Low cost Irdroid infrared module
    Plug and play design
    Extended remote control range – 10+ meters
    Small Dimensions 17×43,2 mm
    Design based on the principle KISS (Keep it simple stupid!)

Let’s start with the Hardware:
The module’s main task is to amplify the signal, generated from the app and to provide an IR interface to the relevant Android device. The active amplification is necessary, because the output signal from an Android device is not powerful enough to light up IR LEDs, as well as to provide a decent remote control range.

The module practically amplifies the generated waveform from the app and emits IR Light via the IR LEDs at 940nm wavelength. The input of the module is provided by the Android Device 3.5mm Audio jack.

The Left and The Right audio channels are used, (GND) is not connected. The amplification is done using an inexpensive LM386-M1 mono audio amplifier which is configured for a gain of 200 times.

This configuration assures enough power @ 6V in order to achieve a remote control distance of about 10 meters.

Тhe Irdroid app is responsible for generating a 19kHz audio tone. The infared data is modulated on the 19kHz sine wave. The signal is amplified via the LM386 audio amplifier and rectified via the two IR leds, doubling the frequency to 38kHz. The first IR led rectifies the positive halfwave of the audio signal and the second IR led the negative halfwave of the signal.

The LM386 mono audio amplifier is configured to amplify the signal 200 times so that the radiated IR light power is enough to achieve a remote control distance of about 10 meters.

Most of the components are SMD (surface mount) only the Jumper, the two IR Leds, the Battery Holder and the audio jack are coventional parts. The download section at http://www.irdroid.com contains a zip archive of the schematics and the production files of the module:

http://www.irdroid.com/downloads/

You could use the schematics and the production files to produce boards using your favourite printed circuit board manufacturer. In most of the companies offering pcb manufacturing service you will find out that they could also solder the SMD components for you, as well as to build complete modules.

http://www.instructables.com/files/orig/FS0/UCZ4/GUXKZ9DP/FS0UCZ4GUXKZ9DP.pdf



All the documentation, schematics, user's manual and a handbook for building your own Irdroid IR module is attached to this instructable: http://www.instructables.com/answers/DIY-IR-Droid-Module-35mm-to-Infrared-Breadboa/

For more information and support: http://www.irdroid.com

Wednesday, April 10, 2013

Phone apps + Ninja Blocks = easy-to-build DIY Phone Gadgets

James, our Aussie friend who worked here with us in Paris, came back to Sydney to make one of the most interesting things on this planet: the Ninja Blocks.






The Ninja Blocks platform makes it trivial to build web & mobile apps that talk to hardware. Get up and running in minutes, and begin talking to hardware & connected devices with the web languages you already know. Focus 100% on your app, and never have to worry about embedded programming, electronics, & networking protocols again.


What can we do with Ninja Blocks?

Rule the connected devices in your lifeWith the Ninja Rules Engine we can create rules that turn on the lights when we're not at home, or send an SMS to our phone when someone is at the front door.

Run apps for the internet of things
With apps built on REST API, the Ninja Block can be whatever we want it to be. It's our security system, our wine monitor, our cat's entertainer, it's our home thermostat, and more.

Build a web connected security solutionWithin five minutes we can create a security system that texts us whenever motion is detected, or if a door or window is opened. We can even have images saved to Dropbox.

Monitor and control our things anywhereMake sure the iron is turned off or if the kids are at home? With the remote control app we can control things or keep an eye on our home from wherever we go.
Included inside the Ninja Kit are:

1x Wireless motion sensor
1x Wireless door/window contact sensor
1x Wireless button
1x Wireless temperature and humidity sensor
1x Ninja Block (BeagleBone Linux computer with and Arduino)
1x USB Wi-Fi module
1x Ethernet Cable
1x 5VDC 3 Amp Power supply with connectors for US, EU, UK, and AU



If you have a Raspberry Pi, you can turn it into a Ninja Block by following this guide:
http://ninjablocks.com/blogs/how-to/7195040-using-a-raspberry-pi-as-a-ninja-block
Here is the link to get started:
http://ninjablocks.com/pages/developers

Tuesday, July 24, 2012

Raspberry Pi runs Android for the first time in history

Porting Android on Raspberry Pi so that we can transform our TV into a big Android tablet or a connected cheap Google TV? This is a dream of many Raspberry Pi owners. Needless to say, if this can be realized, it will be a cool Smart TV device, even cheaper than the popular MK802 Android Mini-PC!

Despite the great technical difficulties and failures, after being discussed thousands of times, for the first time in history, the porting has been proven to be successful.

An image based on Cyanogenmod 7.2 version of Android 2.3 has been successfully cooked for Raspberry Pi.
It really runs, slowly, but runs! Here is a video of how it works in action:


This is pretty much smoother than the previous CM9 version two days ago.

Hackers from both the Raspberry Pi and Android communities are trying to add hardware acceleration to create faster and more usable images.

Download the image here and flash it into an SD card, exactly the same way as we flash a normal Debian image for the Pi:
https://docs.google.com/open?id=0B2qw32upVDnkT0JXNkoyY1hSOUU
Android Pi Wiki:
http://androidpi.wikia.com/wiki/Android_Pi_Wiki
Raspberry Pi Forum Page:
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=56&t=8780

Saturday, July 14, 2012

ADK 2012 for Android

Despite the popularity of the IOIO board for Android (a tool for adding external hardware to Android devices), which has the largest developer/hacker community, Google does not abandon its Accessory Development Kit (ADK). At Google I/O 2012, the team made another demo of ADK, using another board different from what we saw (or used) last year.



ADK 2011:



This time, you get some serious design:

ADK 2012:


The new Audio dock API and HID API seem to be the main interests of this ADK 2.0, which are very easy to implement.


The entire project is open-source as usual. If you want to make your own ADK 2012 board, please get the schematics and source code here:
http://developer.android.com/tools/adk/adk2.html#src-download

Once you get your ADK board, you can play with it using the official application available in the play store:


ADK 2012: https://play.google.com/store/apps/details?id=com.google.android.apps.adk2
ADK 2011: https://play.google.com/store/apps/details?id=com.diyphonegadgets.DemoKit


For example, for those of you who want to make an external audio dock for Android that is able to play audio over a USB connection, simply grab a device running Android 4.1 (API Level 16) or higher (e.g., Galaxy Nexus), prepare your ADK 2012 board, open your favorite Arduino IDE, and start your pleasant development now.

The ADK 2012 provides a reference implementation of this functionality for accessory developers. No software application is required to be installed on the connected Android device, accessory developers only need to support AOA v2. This implementation demonstrates audio output of 16bit, 44.1kHz stereo PCM source data compressed into a single channel due to the audio hardware available on the accessory.

Using the audio output features provided by the ADK library requires only a few function calls. The first few calls are in the accessory setup() routine, which prepare the accessory for USB connections and audio output, as summarized in the code example below:

ADK L;
void setup() {
  L.audioInit();
  L.usbh_init()
  L.usbStart();
}

For more information about the ADK::audioInit() function, see the libraries/ADK/Audio.c library file. For more information about the ADK::usbh_init() function, see the libraries/ADK/Usbh.c library file.

After completing this setup, the loop() function calls ADK::adkEventProcess() to handle audio output and other ADK functions:

void loop(void)
{
  ...
  L.adkEventProcess(); //let the adk framework do its thing
  ...
}

This call executes task queuing for the ADK and as part of the execution process, the task queue executes usbh_work() inlibraries/ADK/Usbh.c, which handles audio output requests. Review the implementation of this function for details. For additional implementation details on audio output, see the libraries/ADK/accessory.c library file.

Enjoy the official presentation here:


Monday, April 9, 2012

Tutorial: how to control an IR helicopter programmatically with Arduino, Android, Kinect, brain, and more!

For those of you who are not familiar with an infrared helicopter, please search "SYMA S107" on eBay or on YouTube. It's a little indoor coaxial helicopter around 20 USD, recharged through USB cable.




The original remote control that comes with the helicopter is pretty good, at least a lot easier to use than a touchscreen. 



However, our passion doesn't end here with mere manual control. Inspired by all those robodance projects, we need more joy of robotic automation. 

Let's hack the SYMA S107 helicopter to give it some artificial intelligence! 

You might wonder why this particular model (Syma S107)? Well, simply because it is perhaps the most popular one in the IR helicopter market. And many brilliant hackers have already done the work for us. We don't have to reinvent the wheel to hack it again.

As usual, let's start with an Arduino, the most simple way to prototype electronic projects. Our goal here is to make an arduino based IR transmitter to programmatically control the helicopter. 

Step 1. Prepare the circuit 


The circuit is extremely simple, we just need:

1 Arduino, 1 IR LED and 1 resister of 200 to 1000 ohm.

Optional: an IR receiver (for testing).



That's all to transmit IR signal from Arduino to the helicopter. If you already have an Arduino board, it costs you almost nothing to get the rest parts.

If you are interested in IR tests, here is a detailed tutorial: http://www.ladyada.net/learn/sensors/ir.html

Otherwise, we can directly load the Arduino code and control the helicopter!

Step 2. Program the Arduino

Fortunately, there are several existing Arduino projects we can directly use and customize. 

The first working code (tested):
//Arduino code to control a helicotper.
int IRledPin =  12;    
int incomingByte = 0;
String incomingString;
int pulseValues[33];
int pulseLength = 0;

void setup()   {                
  // initialize the IR digital pin as an output:
  pinMode(IRledPin, OUTPUT);      
  pinMode(13, OUTPUT);   
  Serial.begin(9600);

  for (int i=0; i < 13; i++) 
    pulseValues[i] = 0;


}

void loop()                     
{
  SendCode();
}


void pulseIR(long microsecs) {
  cli();  // this turns off any background interrupts

  while (microsecs > 0) {
    // 38 kHz is about 13 microseconds high and 13 microseconds low
    digitalWrite(IRledPin, HIGH);  // this takes about 3 microseconds to happen
    delayMicroseconds(10);         // hang out for 10 microseconds
    digitalWrite(IRledPin, LOW);   // this also takes about 3 microseconds
    delayMicroseconds(10);         // hang out for 10 microseconds

    // so 26 microseconds altogether
    microsecs -= 26;

  }

  sei();  // this turns them back on
}

void Zero()
{  
  pulseIR(300);
  delayMicroseconds(300);
  pulseLength += 600;
}

void One()
{
  pulseIR(300);
  delayMicroseconds(600); 
  pulseLength += 900;
}

void sendPulseValue(int pulseValue)
{
  if (pulseValue == 1)
    One();
  else
    Zero(); 
}

void checkPulseChanges()
{
  if (Serial.available() > 0)
  {
    incomingByte = Serial.read();

    //Pulse 1
    if (incomingByte == 'a')
      pulseValues[0] = 0;
    if (incomingByte == 'A')
      pulseValues[0] = 1;

    //Pulse 2
    if (incomingByte == 'b')
      pulseValues[1] = 0;
    if (incomingByte =='B')
      pulseValues[1] = 1;

    //Pulse 3
    if (incomingByte == 'c')
      pulseValues[2] = 0;
    if (incomingByte == 'C')
      pulseValues[2] = 1;

    //Pulse 4
    if (incomingByte == 'd')
      pulseValues[3] = 0;
    if (incomingByte == 'D')
      pulseValues[3] = 1;

    //Pulse 5
    if (incomingByte == 'e')
      pulseValues[4] = 0;
    if (incomingByte == 'E')
      pulseValues[4] = 1;

    //Pulse 6
    if (incomingByte == 'f')
      pulseValues[5] = 0;
    if (incomingByte == 'F')
      pulseValues[5] = 1;

    //Pulse 7
    if (incomingByte == 'g')
      pulseValues[6] = 0;
    if (incomingByte == 'G')
      pulseValues[6] = 1;    

    //Pulse 8
    if (incomingByte == 'h')
      pulseValues[7] = 0;
    if (incomingByte == 'H')
      pulseValues[7] = 1;

    //Pulse 9
    if (incomingByte == 'i')
      pulseValues[8] = 0;
    if (incomingByte == 'I')
      pulseValues[8] = 1;

    //Pulse 10
    if (incomingByte == 'j')
      pulseValues[9] = 0;
    if (incomingByte == 'J')
      pulseValues[9] = 1;

    //Pulse 11
    if (incomingByte == 'k')
      pulseValues[10] = 0;
    if (incomingByte == 'K')
      pulseValues[10] = 1;

    //Pulse 12
    if (incomingByte == 'l')
      pulseValues[11] = 0;
    if (incomingByte == 'L')
      pulseValues[11] = 1;

    //Pulse 13
    if (incomingByte == 'm')
      pulseValues[12] = 0;
    if (incomingByte == 'M')
      pulseValues[12] = 1;

    //Pulse 14
    if (incomingByte == 'o')
      pulseValues[13] = 0;
    if (incomingByte == 'O')
      pulseValues[13] = 1;

    //Pulse 15
    if (incomingByte == 'p')
      pulseValues[14] = 0;
    if (incomingByte == 'P')
      pulseValues[14] = 1;

    //Pulse 16
    if (incomingByte == 'q')
      pulseValues[15] = 0;
    if (incomingByte == 'Q')
      pulseValues[15] = 1;

    //Pulse 17
    if (incomingByte == 'r')
      pulseValues[16] = 0;
    if (incomingByte == 'R')
      pulseValues[16] = 1;

    //Pulse 18
    if (incomingByte == 's')
      pulseValues[17] = 0;
    if (incomingByte == 'S')
      pulseValues[17] = 1;

    //Pulse 19
    if (incomingByte == 't')
      pulseValues[18] = 0;
    if (incomingByte == 'T')
      pulseValues[18] = 1;

    //Pulse 20
    if (incomingByte == 'u')
      pulseValues[19] = 0;
    if (incomingByte == 'U')
      pulseValues[19] = 1;

    //Pulse 21
    if (incomingByte == 'v')
      pulseValues[20] = 0;
    if (incomingByte == 'V')
      pulseValues[20] = 1;

    //Pulse 22
    if (incomingByte == 'w')
      pulseValues[21] = 0;
    if (incomingByte == 'W')
      pulseValues[21] = 1;

    //Pulse 23
    if (incomingByte == 'x')
      pulseValues[22] = 0;
    if (incomingByte == 'X')
      pulseValues[22] = 1;

    //Pulse 24
    if (incomingByte == 'y')
      pulseValues[23] = 0;
    if (incomingByte == 'Y')
      pulseValues[23] = 1;

    //Pulse 25
    if (incomingByte == 'z')
      pulseValues[24] = 0;
    if (incomingByte == 'Z')
      pulseValues[24] = 1;

    //Pulse 26
    if (incomingByte == '1')
      pulseValues[25] = 0;
    if (incomingByte == '2')
      pulseValues[25] = 1;

    //Pulse 27
    if (incomingByte == '3')
      pulseValues[26] = 0;
    if (incomingByte == '4')
      pulseValues[26] = 1;

    //Pulse 28
    if (incomingByte == '5')
      pulseValues[27] = 0;
    if (incomingByte == '6')
      pulseValues[27] = 1;

    //Pulse 29
    if (incomingByte == '7')
      pulseValues[28] = 0;
    if (incomingByte == '8')
      pulseValues[28] = 1;

    //Pulse 30
    if (incomingByte == '9')
      pulseValues[29] = 0;
    if (incomingByte == '!')
      pulseValues[29] = 1;

    //Pulse 31
    if (incomingByte == '@')
      pulseValues[30] = 0;
    if (incomingByte == '#')
      pulseValues[30] = 1;

    //Pulse 32
    if (incomingByte == '$')
      pulseValues[31] = 0;
    if (incomingByte == '%')
      pulseValues[31] = 1;

    //Pulse 33
    if (incomingByte == '^')
      pulseValues[32] = 0;
    if (incomingByte == '&')
      pulseValues[32] = 1;      
  }

}

void SendCode() {

  while (true)
  {
    checkPulseChanges();

    pulseIR(4000);
    delayMicroseconds(2000);
    pulseLength=6000;

    sendPulseValue(pulseValues[0]);
    sendPulseValue(pulseValues[1]);
    sendPulseValue(pulseValues[2]);
    sendPulseValue(pulseValues[3]);
    sendPulseValue(pulseValues[4]);
    sendPulseValue(pulseValues[5]);
    sendPulseValue(pulseValues[6]);
    sendPulseValue(pulseValues[7]);
    sendPulseValue(pulseValues[8]);
    sendPulseValue(pulseValues[9]);
    sendPulseValue(pulseValues[10]);
    sendPulseValue(pulseValues[11]);
    sendPulseValue(pulseValues[12]);
    sendPulseValue(pulseValues[13]);
    sendPulseValue(pulseValues[14]);
    sendPulseValue(pulseValues[15]);
    sendPulseValue(pulseValues[16]);
    sendPulseValue(pulseValues[17]);
    sendPulseValue(pulseValues[18]);
    sendPulseValue(pulseValues[19]);
    sendPulseValue(pulseValues[20]);
    sendPulseValue(pulseValues[21]);
    sendPulseValue(pulseValues[22]);
    sendPulseValue(pulseValues[23]);
    sendPulseValue(pulseValues[24]);
    sendPulseValue(pulseValues[25]);
    sendPulseValue(pulseValues[26]);
    sendPulseValue(pulseValues[27]);
    sendPulseValue(pulseValues[28]);
    sendPulseValue(pulseValues[29]);
    sendPulseValue(pulseValues[30]);
    sendPulseValue(pulseValues[31]);

    //Footer
    pulseIR(360); 
    delayMicroseconds( (28600 - pulseLength) ); 
   } 
}

This is the processing code to control the helicopter using the PC's camera and mouse wheel:
 
import processing.serial.*; 
import controlP5.*;
import JMyron.*;

JMyron m;

ControlP5 controlP5;
CheckBox checkbox;
Button b;

float boxX;
float boxY;
int boxSize = 20;
boolean mouseOverBox = false;
byte[] previousFlags = new byte[32];
byte[] flagsToSend = new byte[32];
Serial port; 
String outString;

int helicopterUpSpeed = 0;
int helicopterPitch = 63;
int helicopterYaw = 68;

void setup() {
  m = new JMyron();
  m.start(640,480);
  size(640, 480);

  controlP5 = new ControlP5(this);
  checkbox = controlP5.addCheckBox("checkBox", 20, 20);  
  // make adjustments to the layout of a checkbox.
  checkbox.setColorForeground(color(120));
  checkbox.setColorActive(color(255));
  checkbox.setColorLabel(color(128));
  checkbox.setItemsPerRow(8);
  checkbox.setSpacingColumn(30);
  checkbox.setSpacingRow(10);
  // add items to a checkbox.
  checkbox.addItem("1", 0);
  checkbox.addItem("2", 0);
  checkbox.addItem("3", 0);
  checkbox.addItem("4", 0);
  checkbox.addItem("5", 0);
  checkbox.addItem("6", 0);
  checkbox.addItem("7", 0);
  checkbox.addItem("8", 0);
  checkbox.addItem("9", 0);
  checkbox.addItem("10", 0);
  checkbox.addItem("11", 0);
  checkbox.addItem("12", 0);
  checkbox.addItem("13", 0);
  checkbox.addItem("14", 0);
  checkbox.addItem("15", 0);
  checkbox.addItem("16", 0);
  checkbox.addItem("17", 0);
  checkbox.addItem("18", 0);
  checkbox.addItem("19", 0);
  checkbox.addItem("20", 0);
  checkbox.addItem("21", 0);
  checkbox.addItem("22", 0);
  checkbox.addItem("23", 0);
  checkbox.addItem("24", 0);
  checkbox.addItem("25", 0);
  checkbox.addItem("26", 0);
  checkbox.addItem("27", 0);
  checkbox.addItem("28", 0);
  checkbox.addItem("29", 0);
  checkbox.addItem("30", 0);
  checkbox.addItem("31", 0);
  checkbox.addItem("32", 0);

  checkbox.deactivateAll();


  controlP5.addButton("Up", 0, 120, 120, 35, 20);
  controlP5.addButton("Down", 0, 120, 160, 35, 20);
  
  controlP5.addButton("Forward", 0, 180, 120, 45, 20);
  controlP5.addButton("Backward", 0, 180, 160, 45, 20);  
  
  controlP5.addButton("TurnLeft", 0, 60, 120, 40, 20);
  controlP5.addButton("TurnRight", 0, 60, 160, 40, 20);  
  

  port = new Serial(this, Serial.list()[0], 9600);

  for (int i=0;i<32;i++) 
  {
    flagsToSend[i] = 0;
    previousFlags[i] = 0;
  }

  addMouseWheelListener(new java.awt.event.MouseWheelListener() { 
    public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) { 
      mouseWheel(evt.getWheelRotation());
    }
  }
  ); 

  startSetUp();
}

String addForwardZeroesTT(String inputString, int totalLength)
{

  String outString = "";
  for (int i = 0; i < (totalLength - inputString.length()); i++)
    outString += "0";

  outString = outString + inputString;

  return outString;
}


//Incremental like bits
//0000, 0001, 0010, 0011, 0100, etc
void Up()
{
  String currentSpeed = addForwardZeroesTT(binary(helicopterUpSpeed), 7);

  if(helicopterUpSpeed <= 125)
    helicopterUpSpeed += 1;

  String newSpeed = addForwardZeroesTT(binary(helicopterUpSpeed), 7);

  setNewSpeed(currentSpeed, newSpeed);
}

void Down()
{
  String currentSpeed = addForwardZeroesTT(binary(helicopterUpSpeed), 7);
  if (helicopterUpSpeed > 0)
    helicopterUpSpeed -= 1;
  String newSpeed = addForwardZeroesTT(binary(helicopterUpSpeed), 7);

  setNewSpeed(currentSpeed, newSpeed);
} 


void Backward()
{
  String currentSpeed = addForwardZeroesTT(binary(helicopterPitch), 7);

  helicopterPitch += 1;

  String newSpeed = addForwardZeroesTT(binary(helicopterPitch), 7);

   setNewPitch(currentSpeed, newSpeed);
}

void Forward()
{
  String currentSpeed = addForwardZeroesTT(binary(helicopterPitch), 7);

  helicopterPitch -= 1;

  String newSpeed = addForwardZeroesTT(binary(helicopterPitch), 7);

   setNewPitch(currentSpeed, newSpeed);
}

void TurnLeft()
{
  String currentSpeed = addForwardZeroesTT(binary(helicopterYaw), 7);

  helicopterYaw -= 1;

  String newSpeed = addForwardZeroesTT(binary(helicopterYaw), 7);

  setNewYaw(currentSpeed, newSpeed);
}

void TurnRight()
{
  String currentSpeed = addForwardZeroesTT(binary(helicopterYaw), 7);

  helicopterYaw += 1;

  String newSpeed = addForwardZeroesTT(binary(helicopterYaw), 7);

  setNewYaw(currentSpeed, newSpeed);
}


void setNewSpeed(String currentSpeed, String newSpeed)
{

  //Compare each bit and see if it needs changing.
  if  (newSpeed.charAt(6) != currentSpeed.charAt(6) )
    checkbox.toggle(23);

  if  (newSpeed.charAt(5) != currentSpeed.charAt(5) )
    checkbox.toggle(22);

  if  (newSpeed.charAt(4) != currentSpeed.charAt(4) )
    checkbox.toggle(21);    

  if  (newSpeed.charAt(3) != currentSpeed.charAt(3) )
    checkbox.toggle(20);    

  if  (newSpeed.charAt(2) != currentSpeed.charAt(2) )
    checkbox.toggle(19);    

  if  (newSpeed.charAt(1) != currentSpeed.charAt(1) )
    checkbox.toggle(18);    

  if  (newSpeed.charAt(0) != currentSpeed.charAt(0) )
    checkbox.toggle(17);
}

void setNewPitch(String currentSpeed, String newSpeed)
{
  if  (newSpeed.charAt(6) != currentSpeed.charAt(6) )
    checkbox.toggle(15);

  if  (newSpeed.charAt(5) != currentSpeed.charAt(5) )
    checkbox.toggle(14);

  if  (newSpeed.charAt(4) != currentSpeed.charAt(4) )
    checkbox.toggle(13);    

  if  (newSpeed.charAt(3) != currentSpeed.charAt(3) )
    checkbox.toggle(12);    

  if  (newSpeed.charAt(2) != currentSpeed.charAt(2) )
    checkbox.toggle(11);    

  if  (newSpeed.charAt(1) != currentSpeed.charAt(1) )
    checkbox.toggle(10);    

  if  (newSpeed.charAt(0) != currentSpeed.charAt(0) )
    checkbox.toggle(9);
}

void setNewYaw(String currentSpeed, String newSpeed)
{
  if  (newSpeed.charAt(6) != currentSpeed.charAt(6) )
    checkbox.toggle(7);

  if  (newSpeed.charAt(5) != currentSpeed.charAt(5) )
    checkbox.toggle(6);

  if  (newSpeed.charAt(4) != currentSpeed.charAt(4) )
    checkbox.toggle(5);    

  if  (newSpeed.charAt(3) != currentSpeed.charAt(3) )
    checkbox.toggle(4);    

  if  (newSpeed.charAt(2) != currentSpeed.charAt(2) )
    checkbox.toggle(3);    

  if  (newSpeed.charAt(1) != currentSpeed.charAt(1) )
    checkbox.toggle(2);    

  if  (newSpeed.charAt(0) != currentSpeed.charAt(0) )
    checkbox.toggle(1);
}

void startSetUp()
{
  //First clear the arduino.
  port.write('a'); 
  port.write('b'); 
  port.write('c'); 
  port.write('d'); 
  port.write('e'); 
  port.write('f'); 
  port.write('g'); 
  port.write('h'); 
  port.write('i'); 
  port.write('j'); 
  port.write('k'); 
  port.write('l');
  port.write('m'); 
  port.write('o'); 
  port.write('p'); 
  port.write('q');
  port.write('r'); 
  port.write('s'); 
  port.write('t'); 
  port.write('u');
  port.write('v'); 
  port.write('w'); 
  port.write('x'); 
  port.write('y'); 
  port.write('z'); 
  port.write('1'); 
  port.write('3'); 
  port.write('5');
  port.write('7'); 
  port.write('9'); 
  port.write('@'); 
  port.write('$'); 
  port.write('^');


  //Set the pulse to the basic configuration.
  checkbox.toggle(1);
  checkbox.toggle(6);


  checkbox.toggle(10);
  checkbox.toggle(11);

  checkbox.toggle(12);
  checkbox.toggle(13);
  checkbox.toggle(14);
  checkbox.toggle(15);
  checkbox.toggle(16);

  checkbox.toggle(25);

  checkbox.toggle(28);
  checkbox.toggle(29);
  checkbox.toggle(30);
}


void draw() 
{ 
  background(200);
  
  m.update();
  int[] img = m.image();
  
  //first draw the camera view onto the screen
  loadPixels();
  
  for(int i=0;i<640*480;i++){
      pixels[i] = img[i];
  }
  updatePixels();
   noFill();
  int[][] a;
   
  CheckHelicopterPosition();  
  
  
  text(" Current Speed: " + helicopterUpSpeed, 230, 135);
  text(" Pitch: " + helicopterPitch, 230, 165);
  text(" Yaw: " + helicopterYaw, 230, 195);  
}


void CheckHelicopterPosition()
{
  
  noFill();
  int[][] a;
  
  m.trackColor(255,255,0,255);
  //draw bounding boxes of globs
  a = m.globBoxes();
  stroke(255,0,0);
  
  int averageY = 0;
  
  for(int i=0;i<a.length;i++){
    int[] b = a[i];
    rect(b[0], b[1], b[2], b[3]);
    
    averageY += b[1];
    
  }
  
  if (a.length > 0)
  {
  averageY = averageY / a.length;
  line(0,averageY,640,averageY);
  
    text(" Average Y: " + averageY, 230, 215);  
    
    if (averageY > 240)
     {
      text(" Action: up ", 350, 20);
      delay(150);
      //Up();
     } 
     else
     {
      text(" Action down ", 350,20); 
      //delay(250);
      //Down();
     }
  }  

  
}  
  
  
  
void controlEvent(ControlEvent theEvent) {
  if (theEvent.isGroup()) {

    for (int i=0;i<theEvent.group().arrayValue().length;i++) 
    {
      byte n = (byte)theEvent.group().arrayValue()[i];
      flagsToSend[i] = n;
      //there was a change in the flags, send the update.
      if (previousFlags[i] != flagsToSend[i])
      {
        println(i);

        if (i==0) {   
          if (n == 0) { 
            port.write('a');
          } 
          else { 
            port.write('A');
          }
        }
        if (i==1) {   
          if (n == 0) { 
            port.write('b');
          } 
          else { 
            port.write('B');
          }
        } 
        if (i==2) {   
          if (n == 0) { 
            port.write('c');
          } 
          else { 
            port.write('C');
          }
        }
        if (i==3) {   
          if (n == 0) { 
            port.write('d');
          } 
          else { 
            port.write('D');
          }
        }                 
        if (i==4) {   
          if (n == 0) { 
            port.write('e');
          } 
          else { 
            port.write('E');
          }
        }    
        if (i==5) {   
          if (n == 0) { 
            port.write('f');
          } 
          else { 
            port.write('F');
          }
        }  
        if (i==6) {   
          if (n == 0) { 
            port.write('g');
          } 
          else { 
            port.write('G');
          }
        }
        if (i==7) {   
          if (n == 0) { 
            port.write('h');
          } 
          else { 
            port.write('H');
          }
        }
        if (i==8) {   
          if (n == 0) { 
            port.write('i');
          } 
          else { 
            port.write('I');
          }
        }
        if (i==9) {   
          if (n == 0) { 
            port.write('j');
          } 
          else { 
            port.write('J');
          }
        }
        if (i==10) {   
          if (n == 0) { 
            port.write('k');
          } 
          else { 
            port.write('K');
          }
        }
        if (i==11) {   
          if (n == 0) { 
            port.write('l');
          } 
          else { 
            port.write('L');
          }
        }
        if (i==12) {   
          if (n == 0) { 
            port.write('m');
          } 
          else { 
            port.write('M');
          }
        }
        if (i==13) {   
          if (n == 0) { 
            port.write('o');
          } 
          else { 
            port.write('O');
          }
        }  
        if (i==14) {   
          if (n == 0) { 
            port.write('p');
          } 
          else { 
            port.write('P');
          }
        }
        if (i==15) {   
          if (n == 0) { 
            port.write('q');
          } 
          else { 
            port.write('Q');
          }
        }
        if (i==16) {   
          if (n == 0) { 
            port.write('r');
          } 
          else { 
            port.write('R');
          }
        }
        if (i==17) {   
          if (n == 0) { 
            port.write('s');
          } 
          else { 
            port.write('S');
          }
        }
        if (i==18) {   
          if (n == 0) { 
            port.write('t');
          } 
          else { 
            port.write('T');
          }
        }
        if (i==19) {   
          if (n == 0) { 
            port.write('u');
          } 
          else { 
            port.write('U');
          }
        }
        if (i==20) {   
          if (n == 0) { 
            port.write('v');
          } 
          else { 
            port.write('V');
          }
        }
        if (i==21) {   
          if (n == 0) { 
            port.write('w');
          } 
          else { 
            port.write('W');
          }
        }
        if (i==22) {   
          if (n == 0) { 
            port.write('x');
          } 
          else { 
            port.write('X');
          }
        }
        if (i==23) {   
          if (n == 0) { 
            port.write('y');
          } 
          else { 
            port.write('Y');
          }
        }
        if (i==24) {   
          if (n == 0) { 
            port.write('z');
          } 
          else { 
            port.write('Z');
          }
        }
        if (i==25) {   
          if (n == 0) { 
            port.write('1');
          } 
          else { 
            port.write('2');
          }
        }
        if (i==26) {   
          if (n == 0) { 
            port.write('3');
          } 
          else { 
            port.write('4');
          }
        }
        if (i==27) {   
          if (n == 0) { 
            port.write('5');
          } 
          else { 
            port.write('6');
          }
        }
        if (i==28) {   
          if (n == 0) { 
            port.write('7');
          } 
          else { 
            port.write('8');
          }
        }
        if (i==29) {   
          if (n == 0) { 
            port.write('9');
          } 
          else { 
            port.write('!');
          }
        }
        if (i==30) {   
          if (n == 0) { 
            port.write('@');
          } 
          else { 
            port.write('#');
          }
        }
        if (i==31) {   
          if (n == 0) { 
            port.write('$');
          } 
          else { 
            port.write('%');
          }
        }
        if (i==32) {   
          if (n == 0) { 
            port.write('^');
          } 
          else { 
            port.write('&');
          }
        }
      }

      previousFlags[i]=n;
    }
  }
}


void mouseWheel(int delta) {
  if (delta == 1)
    Down();
  else
    Up();
}
We have tested it. It worked like a charm. Exactly as the project creator says:

"Utilizing the input from the webcam, it adjusts the speed until the helicopter is in the middle of the screen.
If it goes too high, it lowers the speed. If it gets too low or is stopped, it slowly increases the upwards speed."



For more details on this project, please have a glance here: http://www.avergottini.com/2011/05/arduino-helicopter-infrared-controller.html


The second working code (not yet tested by DIY Phone Gadgets):


Of course, your SYMA S107 helicopter might not always be exactly the same as others'. The first code might not work for your helicopter. Don't worry, it is possible that you have a 3-channel (30-bit) version, which uses a different protocol. Just load the following Arduino code:
/* S107 3-channel with checksum helicopter control code
 * Copyright (C) 2012, Andrew Barry, Dan Barry
 *
 * Uses an Arduino to control a S107 helicopter
 *
 *
 * Instructions:
 *  Connect an IR LED array to pin 8 (using a FET to amplify the signal)
 *  and use the serial monitor to send commands to the system
 *
 */

#define LED 8

#define STATUS 13

//#define TAKEOFF_THROTTLE 240
//#define HOLDING_THROTTLE 130

byte yawCmd, pitchCmd, throttleCmd, trimCmd;

// Set this value for the default channel
// A = 0
// B = 1
// C = 2
byte channel = 0;

/*
 * Setup function that initializes the serial port and
 * sets some default values for the control variables.
 * Also sets up the pins we'll be using.
 */
void setup()
{
 Serial.begin(9600);
 pinMode(STATUS,OUTPUT);
 digitalWrite(STATUS,LOW);

 pinMode(LED,OUTPUT);
 digitalWrite(LED,LOW);

 yawCmd = 8;
 pitchCmd = 8;
 trimCmd = 0;
 throttleCmd = 0;

 Serial.println("throttle = 0, standing by for commands.");
}

/*
 * Function that does the actual work of converting commands into
 * IR LED pulses and changes the pins in the appropriate manner.
 */
byte sendPacket(byte yaw, byte pitch, byte throttle, byte trim)
{

 int packetData[100];
 int pulseNum;

 digitalWrite(STATUS,HIGH);

 float channelDelayValue = 136500;

 // channel A B or C
 // A is 10 with 136500us packet delay
 // B is 01 with 105200us packet delay
 // C is 11 with 168700us packet delay
 if (channel == 0)
 {
   packetData[0] = 1;
   packetData[1] = 0;
   channelDelayValue = 136500;

 } else if (channel == 1)
 {
   packetData[0] = 0;
   packetData[1] = 1;
   channelDelayValue = 105200;

 } else {
   packetData[0] = 1;
   packetData[1] = 1;
   channelDelayValue = 168700;

 }
 packetData[2] = 0;
 packetData[3] = 0;

 // pitch

 packetData[7] = (pitch & 0b1000) >> 3; // direction bit

 if (pitch < 8)  {    pitch = 8 - pitch;  }  packetData[6] = (pitch & 0b0100) >> 2; // others are speed bits, note that they are reversed
 packetData[5] = (pitch & 0b0010) >> 1;
 packetData[4] = (pitch & 0b0001);

 // throttle
 // bits are reversed in the throttle command
 packetData[15] =  (throttle & 0b10000000) >> 7;
 packetData[14] =  (throttle & 0b01000000) >> 6;
 packetData[13] = (throttle & 0b00100000) >> 5;
 packetData[12] = (throttle & 0b00010000) >> 4;

 packetData[11] = (throttle & 0b00001000) >> 3;
 packetData[10] = (throttle & 0b00000100) >> 2;
 packetData[9] = (throttle & 0b00000010) >> 1;
 packetData[8] = (throttle & 0b00000001);

 // yaw
 packetData[19] = (yaw & 0b1000) >> 3; // direction bit
 if (yaw < 8)  {    yaw = 8 - yaw;  }  packetData[18] = (yaw & 0b0100) >> 2;
 packetData[17] = (yaw & 0b0010) >> 1;
 packetData[16] = (yaw & 0b0001);

 // these 4 bits are the checksum, so make sure they
 // are 0s so they don't change the XOR later on
 packetData[20] = 0;
 packetData[21] = 0;
 packetData[22] = 0;
 packetData[23] = 0;

 // yaw trim / yaw adjust (the little dial on the controller)
 // 6 bits
 packetData[24] = 0;
 packetData[25] = 0;
 packetData[26] = 0;
 packetData[27] = 0;

 packetData[28] = 0;
 packetData[29] = 0;

 // these bits are never sent but we do the checksum
 // computation in 4-bit chunks, with the trailing two
 // bits set to zero, so we set them to zero here to make
 // the checksum a bit easier to compute
 packetData[30] = 0;
 packetData[31] = 0;

 int i;

 int checksum[10];
 checksum[0] = 0;
 checksum[1] = 0;
 checksum[2] = 0;
 checksum[3] = 0;

 // compute checksum -- bitwise XOR of 4-bit chunks
 // with two zeros padding the *end* of the last two bits
 for (i=0; i 0)
  {
    if (Serial.available() == true)
    {
      Serial.println("HOLD ABORTED");
      break;
    }

    packetDelay = sendPacket(yawIn, pitchIn, throttleIn, trimCmd);
    delayTime = delayTime - packetDelay;

    delay(packetDelay);

    delay(delayAmount);
    delayTime = delayTime - delayAmount;
  }
  Serial.println("Done holding.");
}

void Land()
{
 static int i;
 Serial.println("Landing");
 for(i=throttleCmd;i>0;i--){
   HoldCommand(8,8,throttleCmd,50);
 }
 throttleCmd = 0;
}

/*
 * Function that manages receiving data from the serial port.
 * Mostly changes the global variables that are passed to the
 * control functions.
 */
void serialEvent()
{
 char cmd = Serial.read();
 Serial.println();
 Serial.print("command received is ");
 Serial.println(cmd);

 switch (cmd)
 {
   // Take off with 't'
   case 't':
     Serial.println("Taking Off");

     // Yaw: 1-15
     //    8 = no turn
     //    1 = max right turn
     //    15 = max left turn
     //
     // Pitch: 1-15
     //    8 = no pitch
     //    15 = max forward
     //    1 = max backwards
     //
     // Throttle: 0-255
     //    0 = off
     //    ~130 = steady flight
     //    ~240 = fast climb

     // First, go up with lots of throttle for 650ms
     // yaw: 8 --> no yaw
     // pitch: 8 --> no pitch
     // throttle: 240 --> fast climb
     // delay: 650ms --> enough time to climb, not too long so won't hit ceiling

     // HoldCommand: a function that sends the same data for a given amount of time
     // HoldCommand(yaw, pitch, throttle, time-to-hold-in-ms);
     HoldCommand(8, 8, 240, 650);

     // set the *global* throttle to steady flight throttle
     throttleCmd = 130;
     break;

   // land with 'x' or 'q'
   case 'x':
   case 'q':
     Land();
     break;

   // throttle commands
   case '0':
   case '1':
   case '2':
   case '3':
   case '4':
   case '5':
   case '6':
   case '7':
   case '8':
   case '9':
     throttleCmd = atoi(&cmd) * 25;  //single character, so we can go from 0 to 255 by inputting 0 to 9 in the serial monitor
     break;

   // turn left
   case 'a':
     if (yawCmd < 15)      {        yawCmd ++;      }      Serial.print("Yaw is ");      Serial.println(yawCmd);      break;    // turn right    case 'd':      if (yawCmd > 1)
     {
       yawCmd --;
     }
     Serial.print("Yaw is ");
     Serial.println(yawCmd);
     break;

   // move forwards
   case 'w':
     if (pitchCmd < 15){        pitchCmd ++;  // moves forward      }      Serial.print("Pitch is ");      Serial.println(pitchCmd);      break;      // move backwards    case 's':      if (pitchCmd > 1)
     {
       pitchCmd --;  // moves backward
     }
     Serial.print("Pitch is ");
     Serial.println(pitchCmd);
     break;

   // increase throttle
   case 'u':
     if (throttleCmd < 255 - 6)      {        throttleCmd += 6;      }      Serial.print("Throttle is ");      Serial.println(throttleCmd);      break;        // decrease throttle    case 'j':      if (throttleCmd > 6)
     {
       throttleCmd -= 6;
     }
     Serial.print("Trottle is ");
     Serial.println(throttleCmd);
     break;

   // change channel
   case 'c':
     Serial.println("Changing channel");
     if (channel >= 2)
     {
       channel = 0;
     } else
     {
       channel ++;
     }
     Serial.print("Channel is: ");
     Serial.println(channel);
     break;

   // reset yaw and pitch
   case 'r':
     Serial.println("resetting yaw and pitch");
     yawCmd = 8;
     pitchCmd = 8;
     break;

   default:
     Serial.println("Unknown command");
 }
 Serial.print("Throttle is at ");
 Serial.println(throttleCmd);
}

/*
 * Loops continuously sending and delaying for the transmission
 */
void loop()

{
   // Note that serialEvent() gets called on each path of the loop
   // and runs if there is data at the serial port

   // we call delay here on the return value of sendPacket because that will
   // cause us to put the right amount of time between packets.  The delay is
   // not constant, but is instead based on how long the packet was
   // that we sent
   delay(sendPacket(yawCmd, pitchCmd, throttleCmd, trimCmd));
}


To use the code, open the Serial Monitor (Tools > Serial Monitor) and use the following commands:

0-9: throttle
w: forward
a: left
s: backwards
d: right
t: take off
u: increase throttle
j: decrease throttle
r: reset pitch and yaw

For more details on this project, please go to:
http://www.abarry.org/likelytobeforgotten/?p=55

What's next?


Now that we can successfully send programmatical commands from Arduino, we can take advantage of the solutions we have learned here  in DIY Phone Gadgets to control the IR helicopter using PCs, game consoles, Kinect, tablets, smartphones or whatever electronic gadgets.

Here is a project using Kinect:


Here is a project using brain (your mind) to control a helicopter:


Or a Nunchuk-Wiimote-controlled helicopter, if you need more accuracy:



How to decode IR signal (very useful if you don't have a SYMA S107):

Of course, you can always decode the IR signal from scratch, if your helicopter is not SYMA S107. Here is a great video tutorial:


Here is the project owner's original blog: http://technologyonmymind.blogspot.fr/2012/03/helicopter-auto-pilot-introduction.html

DIY Phone-controlled helicopters with Arduino:


Needless to say, using Arduino as a bridge, we can easily control helicopters. Here is "Yan's helicopter Controller" from DIY Phone Gadgets.

Here is how it works:

1. The Android phone is controlling the Arduino using bluetooth.
2. Arduino is controlling the original helicopter transmitter.
3. The transmitter is programmatically controlling the helicopter.











DIY Phone-controlled helicopters with audio dongle:


There are already some fantastic existing tools in the toy market that are really helpful. Like these audio jack dongles:




These dongles capture the audio signal in the 3.5 audio jack and translate the audio signal into wireless signal.

For normal users, these dongles are just wireless transmitters, compatible with Android or iPhone apps. They can use it to control the helicopter with their smartphones.

For DIYers, the dongles should be capable of transmitting IR or other wireless signals from any smartphone or tablet (Android, iPhone, Blackberry or Windows Phone). You simply produce programmatically some audio sound from the phone. To make a touchscreen controller is so boring because the physical joysticks are way better and more precise. A phone should be a mobile command station to interact with the helicopter with a lot more intelligence. The helicopter should be able to dance with your own written program!

The easiest way to get these dongles is searching "iPhone Android Helicopter" on eBay. Then write your iOS or Android code to produce some audio signal, control your TV, fly your helicopter! Don't forget to share your exciting discoveries with the DIY Phone Gadgets community.

Imagine that you are playing your favorite music while watching a bunch of helicopters dancing in the sky, following the melody and rhythm. Yes, that's so geeky. But you are so happy. What's more beautiful than a creative mind? 

Saturday, November 12, 2011

Android + Raspberry Pi + Microcontroller = Intelligent gadgets with everything possible

1. What is Rapsberry Pi?

I have always wanted to talk about my favorite thing of the year: the cheap tiny linux PC - Yes, the Raspberry Pi!

It will be avaiblable soon by the end of the year 2011, let's hope.

Size: same as a credit card (for model A, even smaller, like a pen)

Price: 25 dollars

It is a full linux PC on which we can install Ubuntu, or even play Quake smoothly.



2. Why is Raspebrry Pi so interesting for DIY Phone Gadgets?


Android = Gorgeous user Interface, portable telecommunications services and the Internet of things everywhere with you

Raspberry Pi = Cheap, smart, tiny linux PC that can be powerful brains of any intelligent gadget and easily uses the USB port to add Microcontrollers like Arduino to control any motor or light or whatever sensors

Conclusion: Every project that combines Android and Raspberry Pi can make a powerful gadget.

3. How to make DIY Phone Gadgets combining Rasperry Pi and Android?


Mode 1. Android as a standalone remote control and Raspebrry Pi as a part of the gadget.


There are two possible types of communications:

a. Short range low delay communication


We can plug USB WiFi or Bluetooth dongles on Raspberry Pi, connecting it to the Arduino or whatever microcontroller, and use Android to interact with it.

Typical examples can be home automation gadgets such as an NFC lock or an intelligent airconditionner, showing user interface on the Android phone. WiFi toys with augmented reality feature can be interesting too. In UAV, you can connect Raspberry Pi to ArduPilot, and do some near real-time telemetry and video feedback via WiFi to be displayed on the Android phone, seamlessly working with Google Maps.

b. Cloud communication

We can connect the Raspberry Pi powered gadget to the Internet, and use Android to "chat" with it from everywhere in the world.

An example that I can imagine would be a surveillance robot with USB camera at home (of course its brain is the tiny Raspberry Pi). While the robot is wandering at home, we can chat with it on Google Talk using our Android phone from another end of the world. The QoS on some 3G or 4G networks can be good enough to support video chat and voip. Android will use XMPP, Web RTC or whatever promising or classical Internet protocols to interract with the gadget.

Mode 2. Android and Raspberry Pi together as a part of the gadget.

This mode takes advantage of the Android's built-in software and hardware (GPS, sensors, WiFi, bluetooth, etc) and the advantage of Raspberry Pi's good hardware extensitivity (because it is a linux PC with USB 2.0 OTG ports).

In this mode, the Android is directly connected to Raspberry Pi using a USB cable, just as it is connected to any PC. So ADB and USB tethering can be great protocols to help realizing fast bidirectional communication.

An example can be a sophisticated RC controller with many physical buttons and joysticks, and of course Android's large touch screen. You can download many different Android applications for this gadget, or add different 2.4Ghz radio modules. So there is a both a greater software and hardware flexibility compared to the classical radio controls from different manufacturers.

Mode 3. Installing Android on Raspberry Pi...And make cheap gadgets.


This seems a bit difficult for now because higher versions of Android are demanding in terms of hardware capabilties.

3. What can be done to help developers of DIY Phone Gadgets?


The idea is to buid up some good libraries in Raspberry Pi that can work with a special microcontroller such as Arduino, while supporting different types of connections with Android. The ultimate purpose is to provide a simple and single way to develop, instead of always developing on different platforms and trying to figure out how to bridge.

I really like the way how projects like IOIO and Amarino integrate the electronics programming in Android development. If Raspberry Pi can provide such a platform to handle PWM, UART etc while easily supporting WiFi dongles, and it is so cheap, why not?

4. Limitations of using Raspebrry Pi in DIY Phone Gadgets


Unfortunately, as Raspeberry Pi is so tiny and squeezes all cool things into a small board, there are not enough I/O pins for hardware developers. This is what is better considered on the more expensive BeagleBone. However, we can always connect a cheap Arduino board to it and it's all done easy and clean. Remember it is a PC and it is USB-friendly. For those of you who are curious about the I/O on Raspberry Pi, please read the official WiKi:

http://elinux.org/RaspberryPiBoard#General_Purpose_Input.2FOutput_.28GPIO.29.2C_I2C.2C_I2S.2C_SPI

There are approximately 16 spare GPIOs, which on the Alpha board are brought out to 1.27mm pin-strip. Voltage levels are 3v3. The connector choice is deliberately annoying to connect to directly; there is no over-voltage protection on the board so the intention is that people interested in serious interfacing will use an external board with buffers, level conversion and analog I/O rather than soldering directly onto the main board. It brings 2x I2C (3v3), I2S and an SPI (3v3) interface out to the same connector. It supports one slave interface for I2C and one for SPI. The UART has four PINs: 3.3V, GND, TX and RX. Kernel boot messages go to this UART at 115200bps.

Good ideas are happily discussed on Raspberry Pi Forum here:
http://www.raspberrypi.org/forum?mingleforumaction=viewtopic&t=1158
or in IOIO User Group here:
http://groups.google.com/group/ioio-users/browse_thread/thread/d23be2c908a9d5ae/be8101778a202a52

Friday, November 11, 2011

Using Android to develop healthcare applications and devices

Believe or not, most makers of DIY Gadgets are very greenpeace-compatible because many DIY projects recycle garbage to create something useful. Healthcare is certainly one of the many topics we shouldn't ignore, not only because of the ethical nature that gears to what a DIYer would love, but also because it involves many external hardware devices, great gadgets for curing illness and saving lives.

Since Android Ice Cream Sandwich (Android 4.0, API 14), we can develop Android applications for Bluetooth Health devices.

The official Android Developer site indicates that the BluetoothHealth API allows communication with devices that implement the Bluetooth Health Profile (HDP).

What is that? What can we do?

Let's see what a Bluetooth profile is: it is a wireless interface specification for Bluetooth-based communication between devices. In order to use Bluetooth technology, a device must be compatible with the subset of Bluetooth profiles necessary to use the desired services. A Bluetooth profile resides on top of the Bluetooth Core Specification and (optionally) additional protocols. While the profile may use certain features of the core specification, specific versions of profiles are rarely tied to specific versions of the core specification.

Bluetooth headset users are very familiar with the Advanced Audio Distribution Profile (A2DP). This profile defines how high quality audio (stereo or mono) can be streamed from one device to another over a Bluetooth connection. For example, music can be streamed from a mobile phone, to a wireless headset, hearing aid & cochlear implant streamer, or car audio or from a laptop/desktop to a wireless headset.

Health Device Profile (HDP) is also a traditional Bluetooth profile. It is designed to facilitate transmission and reception of Medical Device data. The APIs of this layer interact with the lower level Multi-Channel Adaptation Protocol (MCAP layer), but also perform SDP behavior to connect to remote HDP devices. It also makes use of the Device ID Profile (DIP).

Here are some documents: 
http://www.ars2000.com/Bluetooth_HDP.pdf
http://www.ars2000.com/Health-Device-Whitepaper.pdf

Ok, too much new information for non bluetooth-experts. Let's see some examples. These videos are really old where you can find some ancient phones. but you can imagine with today's beyond-smart-phones, everything can be greatly refined.

Video links:
http://www.youtube.com/watch?v=ERafau_GKxs
http://www.youtube.com/watch?v=oXFUXIF5Spo
http://www.youtube.com/watch?v=Vrji-kC1rk4


How to use BluetoothHealth API in Android?

It is fairly easy, just create a BluetoothHealth object. BluetoothHealth is a proxy object for controlling the Bluetooth Service via IPC. If you don't know what IPC is, check it out here.

How to connect to an external health device which is acting in the source role:

  • Use getProfileProxy(Context, BluetoothProfile.ServiceListener, int) to get the BluetoothHealth proxy object. 
  • Create an BluetoothHealth callback and call registerSinkAppConfiguration(String, int, BluetoothHealthCallback) to register an application configuration 
  • Pair with the remote device. This currently needs to be done manually from Bluetooth Settings 
  • Connect to a health device using connectChannelToSource(BluetoothDevice, BluetoothHealthAppConfiguration). Some devices will connect the channel automatically. The BluetoothHealth callback will inform the application of channel state change. 
  • Use the file descriptor provided with a connected channel to read and write data to the health channel. 
  • The received data needs to be interpreted using a health manager which implements the IEEE 11073-xxxxx specifications. 
  • When done, close the health channel by calling disconnectChannel(BluetoothDevice, BluetoothHealthAppConfiguration, int) and unregister the application configuration calling unregisterAppConfiguration(BluetoothHealthAppConfiguration) 

PS: There multiple BLE Health related profiles, the profile that Android uses is a very traditional one, which is not to be confused with similar Bluetooth Low Energy (BLE) profiles such as Health Thermometer and Hear Rate Monitor.

Now that Android is starting to provide official APIs, and that wireless integration with Healthcare has always been a great topic, it is worth getting started.

Imagine when you combine the Android BluetoothHealth API with Google Health APIs, that can create something really neat.

The Java Health Client APIs are documented at:

http://code.google.com/apis/health/docs/2.0/developers_guide_java.html

You can use "gdata" APIs on Android:

http://code.google.com/p/gdata-java-client/downloads/list

For authentication, there's a section in the Health API docs on choosing the appropriate mechanism:

http://code.google.com/apis/health/docs/2.0/developers_guide_protocol.html#Authenticating

One more thing: if you are not very interested in Bluetooth, start with something easy but really usesful, with your imagination.

Last weekend I made this application, pure software, aiming at helping people to better sleep without signal radiation and data consumption. It is called "Auto Signal Off When I Sleep", available in Android Market here.



That's way simple! You'd say. Well, it is a useful healthcare application, ain't it? Start your own healthcare applications now.



Disqus for DIY Phone Gadgets