1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| #include <AltSoftSerial.h>
const int bluetoothTx = 9;
const int bluetoothRx = 8;
AltSoftSerial bluetooth(bluetoothTx, bluetoothRx);
void setup()
{
pinMode(bluetoothTx, OUTPUT);
pinMode(bluetoothRx, INPUT);
Serial.begin(38400);
bluetooth.begin(9600);
delay(1000);
bluetooth.print("\r\nAT+INIT\r\n"); // inizializzazione SPP
bluetooth.print("\r\nAT+ROLE=0\r\n"); // imposta come slave
bluetooth.print("\r\nAT+IAC=9E8B33\r\n"); // impostazione Inquire Access Code di default
bluetooth.print("\r\nAT+CLASS=0\r\n"); // accetta in connessione tutte le tipologie di dispositivo
bluetooth.print("\r\nAT+INQM=1,9,48\r\n"); // inquire mode: RSSI, max 9, timeout 48
bluetooth.print("\r\nAT+INQ\r\n"); // avvio
delay(1000);
Serial.print("Bluetooth should be initialized now");
}
void loop()
{
if( bluetooth.available() )
Serial.print(bluetooth.read());
if( Serial.available() )
bluetooth.write(Serial.read());
} |
Partager