jueshi / amarino

Automatically exported from code.google.com/p/amarino
Other
0 stars 0 forks source link

Cannot receive/send data in my Arduino from my NexusOne #10

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,

I am using Amarino application in my Nexus One with Android 2.1 to connect to 
my Arduino Lilypad. I am using the TestEvent to check if it works, and in the 
Lilypad I have loaded this code:

#include <MeetAndroid.h>

MeetAndroid meetAndroid;
int onboardLed13 = 13;

void setup()  
{
  Serial.begin(57600); 

  meetAndroid.registerFunction(testEvent, 'A');  

  pinMode(onboardLed13, OUTPUT);
  //digitalWrite(onboardLed, HIGH);
}

void loop()
{
  meetAndroid.receive(); 
}

void testEvent(byte flag, byte numOfValues)
{

  int randomValue = meetAndroid.getInt();

  if (randomValue>=125){
    digitalWrite(onboardLed13, HIGH);
  }
  else { digitalWrite(onboardLed13, LOW);
          delay(100);
  }

In the Monitoring screen of the N1 I can see:
   AmarinoService: message to send: 167
   AmarinoService: send to Arduino: A167
   .... (all the time random values are sent from N1 to Arduino)

But the Lilypad seems not to receive this values (the MeetAndroid.receive 
function always returns true) and doesnt blink led13...

Is it possible that the N1 is not set to 57600baud? why is he sending A167? 

I also have tried to use the MeetAndroid.send("a") in the loop(), but nothing 
is received in the N1.

Can anyone help me? Thanks!

Original issue reported on code.google.com by mferrera...@gmail.com on 21 Jul 2010 at 2:23

GoogleCodeExporter commented 9 years ago
Your code looks good. The A167 is the value with its leading flag. You register 
a function in meetAndroid.registerFunction(testEvent, 'A'); which should get 
called when messages arrive with a leading flag A.

The meetAndroid.getInt() function takes care of cutting the A off.

REgarding your issue, I think your Bluetooth module attached to the Lilypad is 
not configured to 57600 baud. You initialize it correctly with 
Serial.begin(57600) but did you also change the baud rate of your Bluetooth 
module to 57600 baud?

Original comment by bonifaz....@gmail.com on 21 Jul 2010 at 5:11

GoogleCodeExporter commented 9 years ago

I thought that with Serial.begin(57600) I was modifying the baud rate of the 
bluetooth module... do I have to modify it separed? how can I do it?

Also, I want to point out something: The monitoring screen of the Amarino app 
shows me that sends A167 plus a strange square character (here in the forum 
didnt appear when I pasted it) So, it seems like he sends a total of 5 
characters... Why this strange behaviour?

Thanks for you answer!

Original comment by mferrera...@gmail.com on 22 Jul 2010 at 12:08

GoogleCodeExporter commented 9 years ago
the strange square charater at the end it an ACK flag which is needed to signal 
the message end to MeetAndroid. Nothing strange about it ;-)

It depends on your Bluetooth Module how to changes its baud rate.
http://groups.google.com/group/amarino-toolkit/browse_thread/thread/71f295e5d3f9
ff9b
Read this thread it is about changing the baud rate of a Bluetooth Mate. Others 
are very similar to this procedure.

Original comment by bonifaz....@gmail.com on 22 Jul 2010 at 1:27

GoogleCodeExporter commented 9 years ago

Hi,

I have a problem setting up the Bluetooth module (Blue Mate from sparkfun). 
I connect it via USB using the FTDI (as you explain in the thread), and I open 
Putty. I set up the port (for me COM5), the rate to 115200, Data bits 8, Stop 
bits 1, Parity none and Flow control XON/XOFF. 

When I open the terminal, I try to type $$$ but I cannot see anything. I've 
enabled the echo and I can see what I write, but nothing is received. What 
happens?I cannot open the command mode...

Thanks 

Original comment by mferrera...@gmail.com on 23 Jul 2010 at 11:41

GoogleCodeExporter commented 9 years ago
mferreralmirall, please use the discussion group for questions about how to set 
the baud rate etc.

Original comment by bonifaz....@gmail.com on 26 Oct 2010 at 9:34