Last active
October 27, 2020 13:18
-
-
Save jenschr/38411822410e4fd392dd050b14b367ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* HC-05 Serial pass through | |
The following AT-commands are supported: | |
AT-command Description | |
---------- ---------------------------------- | |
AT+ROLE Output the current role (1=master/0=slave) | |
AT+UART Output UART com settings | |
AT+UART=115200,0,0 Setup comms to be 115200 baud | |
AT+ADDR? Check device address | |
AT+PSWD Check current connection password | |
AT+PSWD:"1234" Sets connection password to 1234 | |
AT+NAME? Check current Bluetooth device name | |
AT+NAME:xxx Sets Bluetooth device name to xxx | |
AT+VERSION Returns the device's version (e.g. "linvorV1") | |
AT+RNAME? Check name of the connected device | |
AT+RESET Reset and exit AT mode | |
AT+ORGL Restore factory settings | |
AT+MRAD? Get the address of the most recent BT device | |
Data Mode Baud Rate: 9600, 8, N, 1/* HC-05 Serial pass through | |
The following AT-commands are supported: | |
AT-command Description | |
---------- ---------------------------------- | |
AT+ROLE Output the current role (1=master/0=slave) | |
AT+UART Output UART com settings | |
AT+UART=115200,0,0 Setup comms to be 115200 baud | |
AT+ADDR? Check device address | |
AT+PSWD Check current connection password | |
AT+PSWD:"1234" Sets connection password to 1234 | |
AT+NAME? Check current Bluetooth device name | |
AT+NAME:xxx Sets Bluetooth device name to xxx | |
AT+VERSION Returns the device's version (e.g. "linvorV1") | |
AT+RNAME? Check name of the connected device | |
AT+RESET Reset and exit AT mode | |
AT+ORGL Restore factory settings | |
AT+MRAD? Get the address of the most recent BT device | |
This is our default config: | |
AT+NAME:MYTHING Sets Bluetooth device name to JAINSPECT | |
AT+PSWD:"1233" Sets connection password to 6465 | |
AT+UART=115200,0,0 Setup comms to be 115200 baud, no parity, 1 stop bit | |
Data Mode Baud Rate: 9600, 8, N, 1 | |
Command Mode Baud Rate: 38400, 8, N, 1 | |
*/ | |
#include <SoftwareSerial.h> | |
SoftwareSerial mySerial(8, 9); | |
int counter = 0; | |
char command[100]; | |
void setup() | |
{ | |
delay(500); | |
Serial.begin(115200); | |
mySerial.begin(115200); | |
pinMode(LED_BUILTIN, OUTPUT); | |
} | |
void loop() | |
{ | |
/* send everything received from the hardware uart to usb serial & vv */ | |
if (Serial.available() > 0) { | |
Serial.print("Sent: "); | |
delay(50); | |
while( Serial.available() > 0 ){ | |
char ch = Serial.read(); | |
Serial.print(ch); | |
mySerial.print(ch); | |
} | |
} | |
if (mySerial.available() > 0) { | |
Serial.print("Received: "); | |
delay(50); | |
int index = 0; | |
while( mySerial.available() ){ | |
char ch = mySerial.read(); | |
if( ch ){ | |
command[index] = ch; | |
index++; | |
} | |
} | |
// Terminate string received | |
command[index] = '\0'; | |
Serial.println(command); | |
} | |
/* Show that we're alive */ | |
counter++; | |
if( counter%50000 == 0 ){ | |
digitalWrite(LED_BUILTIN,!digitalRead(LED_BUILTIN)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment