Go Down

Topic: Arduino 2560 with Bluetooth device (Read 458 times) previous topic - next topic

hj411335

Nov 24, 2012, 01:18 pm Last Edit: Nov 24, 2012, 01:24 pm by hj411335 Reason: 1
Hello everyone :) I am a new guy here, wanna ask a question which puzzle me for a few days...

I want to use Bluetooth device http://goods.ruten.com.tw/item/show?21204206581641
(baud 57600, Input_Voltage is 3.6V~6V, Frequency)
on my Arduino 2560 and receive data,but it did not work

Here is how I connect:
BT_device <->   arduino
VCC        <->     5V
GND        <->     GND
TX          <->     RX1(or 2 , 3)
RX          <->     TX1

The BT device did successfully connected, but it only receive "224" when I send other numbers(recive"0"or"-1"when not sending)
I have checked with PC BT_device that the message I send is correct

Is my BT device broken(that is new :P),or I missed something?

=====Here is my code=====
#include <SoftwareSerial.h>
int BTread;

void setup()
{
 Serial.begin(57600);
 Serial1.begin(57600);
}
void loop()
{
BTread =Serial1.read();
Serial.println(BTread);
}

PaulS

Code: [Select]
#include <SoftwareSerial.h>
You have 4 hardware serial ports. You connect the bluetooth device to one of them. So, why are you including this header file?

Code: [Select]
void loop()
{
BTread =Serial1.read();
Serial.println(BTread);
}

Reading data that may not have arrived, and then printing it, is not a good idea. There IS an available() method in the HardwareSerial class.

If you use that method, the data that read() method returns will fit in a char, instead of an int. I suspect that you'll be a lot happier if you can use a char, instead.

hj411335

Dear PaulS:
Thanks for you rapid reply :)
I am sorry that the problem still exist. The monitor keep showing blank(nothing) and à when I change int to char.
Is there hardware or software problem :smiley-eek:?

Thanks again
Jay

Here is my modified code:
Code: [Select]
char BTread;

void setup()
{
  Serial.begin(57600);
  Serial1.begin(57600);
}
void loop()
{
if (Serial1.available() > 0)
{
BTread =Serial1.read();
Serial.println("");
Serial.println(BTread);
}
}

The attach file is the monitor screen

Go Up