Communicating to Arduino via android phone w/ Amarino

Just got my new bluetooth in the mail and set it up. Here are the pics I connected the

VCC bluetooth to 3.3V on the Arduino
GND bluetooth to GND on the Arduino
Tx pin of the bluetooth to the Rx pin 0 of the Arduino
Rx pin of the bluetooth to the Tx pin 1 of the Arduino

Then I disconnected the bluetooth wires from the Tx and Rx pins of the arduino and cleared my arduino with this code. Making sure to change to the baud rate to 9600, the same as the bluetooth.

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly: 
  
}

Then I opened the Testevent example code from the meetAndroid library and uploaded it.

/*
  Receives Test Events from your phone.
  After it gets a test message the led 13 will blink
  for one second.
*/
 
#include <MeetAndroid.h>

MeetAndroid meetAndroid;
int onboardLed = 13;

void setup()  
{
  // use the baud rate your bluetooth module is configured to 
  // not all baud rates are working well, i.e. ATMEGA168 works best with 57600
  Serial.begin(9600); 
  
  // register callback functions, which will be called when an associated event occurs.
  // - the first parameter is the name of your function (see below)
  // - match the second parameter ('A', 'B', 'a', etc...) with the flag on your Android application
  meetAndroid.registerFunction(testEvent, 'A');  

  pinMode(onboardLed, OUTPUT);
  digitalWrite(onboardLed, HIGH);

}

void loop()
{
  meetAndroid.receive(); // you need to keep this in your loop() to receive events
}

/*
 * This method is called constantly.
 * note: flag is in this case 'A' and numOfValues is 0 (since test event doesn't send any data)
 */
void testEvent(byte flag, byte numOfValues)
{
  flushLed(300);
  flushLed(300);
}

void flushLed(int time)
{
  digitalWrite(onboardLed, LOW);
  delay(time);
  digitalWrite(onboardLed, HIGH);
  delay(time);
}

The Led will lit up and once I connect my phone with the bluetooth the test event will begin running and the LED will blink whenever the phone says an integer to the arduino. In the monitoring section of the amarino app I will see continous messages such as "AmarinoService: send to Arduino: A46. However, when I open up the Arduino serial monitor, it is blank. Why can't I see the integer values that the phone is sending to the arduino and that the arduino should be recieving and displaying in its serial monitor. Am I not understanding something?

More pics

However, when I open up the Arduino serial monitor, it is blank. Why can't I see the integer values that the phone is sending to the arduino and that the arduino should be recieving and displaying in its serial monitor. Am I not understanding something?

You are reading from and writing to the phone how? Using the TX and RX pins. Now, you want to use them to talk to the PC, too? Think again.

Oh, I get it. The Arduino's program TestEvent is writing integer's to the phone! Not the phone writing to the arduino. Well that's is acutally exactly what I needed to do for my project. I thought that the phone was running the test event program.

I guess what's still confusing me though is why there is a TestEvent that can be iniatied from the Amarino app?
Hmmm...So the arduino can run the TestEvent code to send a random integer to the phone....But can the phone, then, run the TestEvent and send a random integer to the arduino?

The Arduino's program TestEvent is writing integer's to the phone!

No. It is toggling the LED. It does not write anything to the serial port.

I thought that the phone was running the test event program.

No.

I guess what's still confusing me though is why there is a TestEvent that can be iniatied from the Amarino app?

How else do you intend for the phone to do anything?

So the arduino can run the TestEvent code to send a random integer to the phone

It could, but it doesn't. Nor is it clear why you would want to.

But can the phone, then, run the TestEvent

No. The phone knows nothing about the callback code on the Arduino. Even if it did, the code isn't on the phone, so it can't possibly execute it.

No. It is toggling the LED. It does not write anything to the serial port

So all the TestEvent program does is toggle an LED? But it seems to only toggle it when on the phone side it says its sending random integer ' ' to the arduino, then the LED with turn on then off until the next message from my phone.

How else do you intend for the phone to do anything?

The phone isn't communicating with the arduino at all?

It could, but it doesn't. Nor is it clear why you would want to.

Doing a project to compute the distance of a discus that is thrown and I want to send the final calculated distance to my phone.

No. The phone knows nothing about the callback code on the Arduino. Even if it did, the code isn't on the phone, so it can't possibly execute it.

Okay, so the TestEvent code is entirely from the arduino side.

bump

bump

Bump?

We've hired a psychic. His start date is the 12th of never. If you want help before then, you actually need to ask a question.

PaulS:

bump

Bump?

We've hired a psychic. His start date is the 12th of never. If you want help before then, you actually need to ask a question.

I wanted to know what the program TestEvent is doing. And I need to figure out how to get the android phone to communicate with the arduino. I want the arduino to send a pre-calculated number (distance of a thrown discus) to the phone when from the phone I type the letter 'A'. Sorry I'm a bit confused.

It looks like there is some confusion here.

As far as I can see the TestEvent sketch which runs on the Arduino listens for a character 'A' (NB not an integer) to be sent by the phone and when it receives an A it flashes the led.

TestEvent doesn't try to send anything to the Arduino serial monitor.

I don't know how the A is generated on the phone, but, if you can, it would be instructive to change the phone so it sends As or Bs as selected by the user in which case the led should only flash when an A is sent. You could then change the Arduino sketch to respond to a B instead of an A. And later you could modify it to respond to A or B but not any other letter.

...R

Robin2:
It looks like there is some confusion here.

As far as I can see the TestEvent sketch which runs on the Arduino listens for a character 'A' (NB not an integer) to be sent by the phone and when it receives an A it flashes the led.

TestEvent doesn't try to send anything to the Arduino serial monitor.

I don't know how the A is generated on the phone, but, if you can, it would be instructive to change the phone so it sends As or Bs as selected by the user in which case the led should only flash when an A is sent. You could then change the Arduino sketch to respond to a B instead of an A. And later you could modify it to respond to A or B but not any other letter.

...R

Ok cool that makes sense! thanks! How would I send a message from the arduino to be displayed on the phone. Btw I'm using the Amarino app for android phones obtained here http://www.amarino-toolkit.net/.

This is just a wild guess ...

In your code there is a line "meetAndroid.receive" which seems to be used to get the data from the phone.

There is probably an equivalent function for sending data.

...R