将蓝牙数据从Arduino读取到Android应用程序

将蓝牙数据从Arduino读取到Android应用程序,android,bluetooth,arduino,Android,Bluetooth,Arduino,我已克隆并尝试运行此库。 如果可以,请尝试一下。不幸的是,我无法从我的Android应用程序收到任何数据。 我已使用, 它可以从我的arduino接收我的蓝牙数据。 但使用Bluetooth SPP库它不能 我假设我应该在这一行中阅读它,SPP库位于 终末活性。但什么也没有收到 bt.setOnDataReceivedListener(new BluetoothSPP.OnDataReceivedListener() { public void onDataRecei

我已克隆并尝试运行此库。

如果可以,请尝试一下。不幸的是,我无法从我的Android应用程序收到任何数据。
我已使用,
它可以从我的arduino接收我的蓝牙数据。
但使用Bluetooth SPP库它不能

我假设我应该在这一行中阅读它,SPP库位于
终末活性。但什么也没有收到

 bt.setOnDataReceivedListener(new BluetoothSPP.OnDataReceivedListener() {
            public void onDataReceived(byte[] data, String message) {
                textRead.append(message + "\n");
            }
        });
对于我的Arduino代码

#include <LiquidCrystal.h>
#include <Keypad.h>
#include <SoftwareSerial.h>
const byte ROWS = 4; // Four rows
const byte COLS = 3; // Three columns
// Define the Keymap
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 22, 24, 26, 28 };
// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 30, 32, 34 }; 
int row=0;
int col=0;
// Create the Keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
// Create the LCD
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
SoftwareSerial BTSerial(10, 11);

void setup() {

  pinMode(9, OUTPUT);
  digitalWrite(9, HIGH);
  lcd.begin(16, 2);
  lcd.print("[1]Attendance");
  lcd.setCursor(0, 2);
  lcd.print("[2]Get Finger ID");

  Serial.begin(9600);
  Serial.println("Enter AT commands:");
  BTSerial.begin(38400);
}

void loop()
{
  char key = kpd.getKey();
  if(key){
    if(col>=16){
      col=0;
      row=1;
    }
    lcd.setCursor(col, row);
    lcd.print(key);
    col++;
    if(key=='*'){
        BTSerial.write("Test");
    }  
 }
}
#包括
#包括
#包括
常量字节行=4;//四排
常量字节COLS=3;//三列
//定义键映射
字符键[行][列]={
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
//将键盘第0行、第1行、第2行和第3行连接到这些Arduino引脚。
字节rowPins[行]={22,24,26,28};
//将键盘COL0、COL1和COL2连接到这些Arduino引脚。
字节colPins[COLS]={30,32,34};
int行=0;
int col=0;
//创建小键盘
小键盘kpd=小键盘(makeyMap(键)、行PIN、列PIN、行、列);
//创建LCD
液晶显示器(7,6,5,4,3,2);
软件串行BTSerial(10,11);
无效设置(){
pinMode(9,输出);
数字写入(9,高);
lcd.begin(16,2);
lcd.打印(“[1]出席”);
lcd.setCursor(0,2);
lcd.print(“[2]获取手指ID”);
Serial.begin(9600);
Serial.println(“Enter AT commands:”);
BTSerial.begin(38400);
}
void循环()
{
char key=kpd.getKey();
如果(关键){
如果(列>=16){
col=0;
行=1;
}
lcd.setCursor(列,行);
lcd.打印(按键);
col++;
如果(键=='*'){
BTSerial.write(“测试”);
}  
}
}

也许您需要读取byte[]数据参数?请调试,查看是否有任何数据。没有任何数据。尝试打印一些文本,但在setOnDataReceivedListener下无法打印。但在BT终端中,我可以从蓝牙接收数据。