Pages: [1]   Go Down
Author Topic: Arduino 2560 with Bluetooth device  (Read 407 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
New learner from Taiwan, Hello!!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello everyone smiley 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 smiley-razz),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);
}
« Last Edit: November 24, 2012, 07:24:27 am by hj411335 » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
#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:
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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
New learner from Taiwan, Hello!!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Dear PaulS:
Thanks for you rapid reply smiley
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:
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


* 未命名.jpg (81.16 KB, 1440x900 - viewed 21 times.)
Logged

Pages: [1]   Go Up
Jump to: