chipKIT® Development Platform

Inspired by Arduino™

[Android App] Free Bluetooth serial communication app

Created Thu, 17 Jul 2014 04:36:49 +0000 by djgardn2


djgardn2

Thu, 17 Jul 2014 04:36:49 +0000

I wanted to share my latest application that I have been working on that enables your Android smartphone (11+ OS version) to be able to communicate to your PIC microcontroller through Bluetooth (HC-06 module or similar).

Video Demo: [url]http://www.youtube.com/watch?v=K1GrksL5-FU[/url]

The application is free to use and download.

PIC32BLUE and PIC32BLUE+

Below is the app description, and thanks for taking a look.

PIC32BLUE [url]https://play.google.com/store/apps/details?id=com.gardnertech.pic32blue&hl=en[/url] or PIC32BLUE+ [url]https://play.google.com/store/apps/details?id=com.gardnertech.pic32blueplus&hl=en[/url]

PIC32BLUE Features: ★Send information to a microcontroller. ★Receive information from a microcontroller. ★Microcontroller can make your phone talk.

PIC32BLUE+ Features: ★Everything mentioned above. ★The plus version supports text message abilities.

This application allows you to connect to your microcontroller using a serial Bluetooth module to send messages or commands to or from your Android smartphone. See example below for text message command and microcontroller code.

Simply send a message to the microcontroller and you can program any reaction that you would like.

You can setup the microcontroller to periodically send messages to your Android device through Bluetooth in a chat like form. The chat will be cleared after exiting and closing the application.

You can have the application running in the background by tapping the home button on your device and the app will maintain a connection running in the background.

Tapping the back button within the application will close and disconnect from the Bluetooth device if it is connected.

Note:

There are two versions of this application. The only difference between them is that one supports text messaging functionality and one does not.

PIC32BLUE+ supports text messaging so that you can have the microcontroller text another phone number with a message if you would like by using a special command or another phone can text your phone to have your Microcontroller do a task, like displaying a new message on a LCD.

PIC32BLUE only supports Bluetooth communication only (no text message ability).

This application was made to function with a HC-06 Bluetooth device and others may work but have not been tested.

Example of command to that is sent to device with PIC32BLUE+ installed (this will forward your message to the microcontroller):

//note the smiley face is actually a ":" and a "P" together :PIC:Hello, Microcontroller

Or

:pic:LightOn

Example of the Microcontroller telling your phone to text another phone:

//note the smiley face is actually a ":" and a "P" together :PICSMS:XXXXXXXXXX:Hello, from Microcontroller

Or

:picsms:XXXXXXXXXX:The Light is on.

Where the XXX’s is the phone number you are having your phone text. You must include the “:” colon at the end of the phone number also. Note No spaces for phone number and colon.

This application will never send out a text message or forward a command to your microcontroller unless the specific command is included in the message, place at beginning of message.

For the microcontroller to send a text message from your device you must include:

//note the smiley face is actually a ":" and a "P" together :PICSMS:XXXXXXXXXX:

Or

:picsms:XXXXXXXXXX:

For the phone to forward the received text message to your microcontroller you must include:

//note the smiley face is actually a ":" and a "P" together :PIC:

Or

:pic:

This application will never send out a text message or forward a command to your microcontroller unless the specific command is at the beginning of the message as seen above.

You can also make your microcontroller have your phone talk out loud using the :TALK: or :talk: command. For the microcontroller to have your Android phone talk out loud you must include:

:TALK:

Or

:talk:

MPIDE code example tested using a chipKIT Pi then transferring the PIC32 microcontroller off of the board. You may need to change the delays or similar to ensure correct functionality when using any other microcontroller, etc.

(If you want to reference an optimized no delay version if your design is time sensitive see the following posted below in this forum.)

// Microcontroller code example
//Change delay times if needed
String inputString ="";
int incoming = 0;
void setup ()
{
  delay(15);
  Serial1.begin(9600);
  delay(50);
}
void loop ()
{
  if(Serial1.available()>0)
  {
    while(Serial1.available()>0)
    {
      incoming = Serial1.read();
      delay(1);
      inputString += char(incoming);
    }
    delay(2);
    //must be exact spelling
    if(inputString == "Cool")
    {
      //add code here
    }
    if(inputString == "Respond")
    {
      Serial1.println("Okay.");
    }
    if(inputString == "Talk")
    {
      Serial1.println(":TALK:Hello, world.");
    }
    if(inputString == "TextOutgoing")
    {
      Serial1.println(":PICSMS:XXXXXXXXXX:Replace X's with phone #.");
    }
  }
  inputString ="";
  delay(50);
}

Thank you for checking out this application and forum post.


majenko

Thu, 17 Jul 2014 09:17:30 +0000

Your method of reading serial there isn't good. You should read and understand this:

[url]http://hacking.majenko.co.uk/reading-serial-on-the-arduino[/url]


djgardn2

Thu, 17 Jul 2014 22:45:34 +0000

Thank you for your suggestion and feedback.

I appreciate the link also very nice write up.

Below is an attached version of code that is altered to be optimized more so that time is not wasted (no delays).

Although it does require you so send a end of command character.

The code attached uses a period "." to signify the end of command.

Example to send command to microcontroller using the app:

Respond.

or

Talk.

You must include the period and no space after the period unless you plan to account for that in your next message.

No delay code below, tested on the PIC32MX250F128B using chipKIT Pi.

// Microcontroller code example
//Change delay times if needed
String inputString ="";
String commandDoneCheck = "";
int incoming = 0; 


void setup ()
{
  Serial1.begin(9600);
}
void loop ()
{
  if(Serial1.available()>0)
  {
    while(Serial1.available()>0)
    {
      incoming = Serial1.read();
      commandDoneCheck = char(incoming);
      /* Currently anything except a newline character, using PIC32BLUE apps*/
      /* change to your preference for end of command signal*/
      /* You must always send a period "." after every command*/
      /* Example input would be "Respond." */
      if(commandDoneCheck == ".")
      {
        callCommandFunction();
        break;
      }
      inputString += commandDoneCheck;
    }
  }
}


void callCommandFunction()
{
  //must be exact spelling
  if(inputString == "Cool")
  {
    //add code here
  }
  else if(inputString == "Respond")
  {
    Serial1.println("Okay.");
  }
  else if(inputString == "Talk")
  {
    Serial1.println(":TALK:Hello, world.");
  }
  else if(inputString == "TextOutgoing")
  {
    Serial1.println(":PICSMS:XXXXXXXXXX:Replace X's with phone #.");
  }
  inputString ="";
}