Skip to content

Instantly share code, notes, and snippets.

@garrows
Last active December 17, 2022 12:30
Show Gist options
  • Save garrows/f8f787dac6e85591737c to your computer and use it in GitHub Desktop.
Save garrows/f8f787dac6e85591737c to your computer and use it in GitHub Desktop.
Configure HC-06 bluetooth chip to work with the Johnny-Five javascript robotics library
/*
This is for configuring the hc-06 bluetooth chip to work with Johnny-Five javascript robotics library.
Might also work with the hc-05.
Author: Glen Arrowsmith (@garrows)
*/
#define ROBOT_NAME "RandomBot"
// If you haven't configured your device before use this
#define BLUETOOTH_SPEED 9600
// If you are modifying your existing configuration, use this:
// #define BLUETOOTH_SPEED 57600
#include <SoftwareSerial.h>
// Swap RX/TX connections on bluetooth chip
// Pin 10 --> Bluetooth TX
// Pin 11 --> Bluetooth RX
SoftwareSerial mySerial(10, 11); // RX, TX
/*
The posible baudrates are:
AT+BAUD1-------1200
AT+BAUD2-------2400
AT+BAUD3-------4800
AT+BAUD4-------9600 - Default for hc-06
AT+BAUD5------19200
AT+BAUD6------38400
AT+BAUD7------57600 - Johnny-five speed
AT+BAUD8-----115200
AT+BAUD9-----230400
AT+BAUDA-----460800
AT+BAUDB-----921600
AT+BAUDC----1382400
*/
void setup()
{
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.println("Starting config");
mySerial.begin(BLUETOOTH_SPEED);
delay(1000);
// Should respond with OK
mySerial.print("AT");
waitForResponse();
// Should respond with its version
mySerial.print("AT+VERSION");
waitForResponse();
// Set pin to 0000
mySerial.print("AT+PIN0000");
waitForResponse();
// Set the name to ROBOT_NAME
mySerial.print("AT+NAME");
mySerial.print(ROBOT_NAME);
waitForResponse();
// Set baudrate to 57600
mySerial.print("AT+BAUD7");
waitForResponse();
Serial.println("Done!");
}
void waitForResponse() {
delay(1000);
while (mySerial.available()) {
Serial.write(mySerial.read());
}
Serial.write("\n");
}
void loop() {}
@TomasPangzi
Copy link

It cannot work. Sad

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment