为什么arduino用串口线可以正常发送数据但用蓝牙串口就能发送?
板子上的TX灯都还是亮着的,打开串口线的串口都可以正常发送数据,但是打开蓝牙的串口就无法收到信息,无论是用电脑上的蓝牙还是手机上的。程序如下#include<Wire.h...
板子上的TX灯都还是亮着的,打开串口线的串口都可以正常发送数据,但是打开蓝牙的串口就无法收到信息,无论是用电脑上的蓝牙还是手机上的。
程序如下
#include <Wire.h>
#define Register_ID 0
#define Register_2D 0x2D
#define Register_X0 0x32
#define Register_X1 0x33
#define Register_Y0 0x34
#define Register_Y1 0x35
#define Time 500
int ADXAddress = 0xA7 >> 1; // the default 7-bit slave address
int reading = 0;
int val=0;
int X0,X1,X_out;
int Y0,Y1,Y_out;
double Xg,Yg;
void setup()
{
Wire.begin();
Serial.begin(9600);
delay(100);
// enable to measute g data
Wire.beginTransmission(ADXAddress);
Wire.write(Register_2D);
Wire.write(8); //measuring enable
Wire.endTransmission(); // stop transmitting
}
void getdate()
{
//--------------X
Wire.beginTransmission(ADXAddress); // transmit to device
Wire.write(Register_X0);
Wire.write(Register_X1);
Wire.endTransmission();
Wire.requestFrom(ADXAddress,2);
if(Wire.available()<=2)
{
X0 = Wire.read();
X1 = Wire.read();
X1=X1<<8;
X_out=X0+X1;
}
//------------------Y
Wire.beginTransmission(ADXAddress); // transmit to device
Wire.write(Register_Y0);
Wire.write(Register_Y1);
Wire.endTransmission();
Wire.requestFrom(ADXAddress,2);
if(Wire.available()<=2)
{
Y0 = Wire.read();
Y1 = Wire.read();
Y1=Y1<<8;
Y_out=Y0+Y1;
}
//----------------开始采集数据
Xg=X_out/256.0;
Yg=Y_out/256.0;
}
void loop()
{
getdate();
if (Xg > 0.5)
{
Serial.println('L');
while(Xg > 0.5)
{
delay(Time);
getdate();
}
}
if (Xg < -0.5)
{
Serial.println('R');
while(Xg < -0.5)
{
delay(Time);
getdate();
}
}
if (Yg > 0.5)
{
Serial.println('F');
while(Yg > 0.5)
{
delay(Time);
getdate();
}
}
if (Yg < -0.5)
{
Serial.println('B');
while(Yg < -0.5)
{
delay(Time);
getdate();
}
}
} 展开
程序如下
#include <Wire.h>
#define Register_ID 0
#define Register_2D 0x2D
#define Register_X0 0x32
#define Register_X1 0x33
#define Register_Y0 0x34
#define Register_Y1 0x35
#define Time 500
int ADXAddress = 0xA7 >> 1; // the default 7-bit slave address
int reading = 0;
int val=0;
int X0,X1,X_out;
int Y0,Y1,Y_out;
double Xg,Yg;
void setup()
{
Wire.begin();
Serial.begin(9600);
delay(100);
// enable to measute g data
Wire.beginTransmission(ADXAddress);
Wire.write(Register_2D);
Wire.write(8); //measuring enable
Wire.endTransmission(); // stop transmitting
}
void getdate()
{
//--------------X
Wire.beginTransmission(ADXAddress); // transmit to device
Wire.write(Register_X0);
Wire.write(Register_X1);
Wire.endTransmission();
Wire.requestFrom(ADXAddress,2);
if(Wire.available()<=2)
{
X0 = Wire.read();
X1 = Wire.read();
X1=X1<<8;
X_out=X0+X1;
}
//------------------Y
Wire.beginTransmission(ADXAddress); // transmit to device
Wire.write(Register_Y0);
Wire.write(Register_Y1);
Wire.endTransmission();
Wire.requestFrom(ADXAddress,2);
if(Wire.available()<=2)
{
Y0 = Wire.read();
Y1 = Wire.read();
Y1=Y1<<8;
Y_out=Y0+Y1;
}
//----------------开始采集数据
Xg=X_out/256.0;
Yg=Y_out/256.0;
}
void loop()
{
getdate();
if (Xg > 0.5)
{
Serial.println('L');
while(Xg > 0.5)
{
delay(Time);
getdate();
}
}
if (Xg < -0.5)
{
Serial.println('R');
while(Xg < -0.5)
{
delay(Time);
getdate();
}
}
if (Yg > 0.5)
{
Serial.println('F');
while(Yg > 0.5)
{
delay(Time);
getdate();
}
}
if (Yg < -0.5)
{
Serial.println('B');
while(Yg < -0.5)
{
delay(Time);
getdate();
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询