我克隆并尝试运行此库。
https://github.com/akexorcist/Android-BluetoothSPPLibrary
并尝试它是否可行,不幸的是,我无法从我的Android APP收到任何数据
我使用BT Simple Terminal测试了我的蓝牙,
它可以从我的arduino接收我的蓝牙数据..
但使用蓝牙SPP库它不能。
我假设我应该在这里用SPP Library在这里阅读 TerminalActivity。但没有收到。
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");
}
}
}