In Save Slots and Toggle Behavior, we were using buttons from fingers to influence the behavior from Fursuiter but we may still want to influence it from the outside.
When you look at animatronics in films (from
Behind The Scene), they use RC Transmitters to control Servos. For my purpose, RC Transmitter is too big with only few axis to use. So I decided on using My Own Remote Controller (softwre for Mobile phone).
For communication I want to use Bluetooth. It has limited range but is present in all modern phones.
There are different approaches to using Bluetooth from Arduino. I decided on using Serial communication (like here, here or here). For it, we will use HC-05 or HC-06 Bluetooth Module.
Changing PIN
Before using our Bluetooth module, we may want to change default PIN (1234 or 0000).I do not have the module myself (right now) so I found this tutorial and will try to make mine shorter.
We need to connect RX and TX pins to the module (RX to TX, TX to RX). For setup of the module, we want to set Key pin of the module to
HIGH
(connect it to Vcc pin).Communication Protocol
All commands are case sensitive and should end byenter
or \r\n
.
Test
Command: ATOK
Reset
Command: AT+RESETOK
Get Firmware Version
Command: AT+VERSION?+VERSION:<version>
OK
Restore Defaults
Command: AT+ORGLOK
Device type: 0
Inquire code: 0x009e8b33
Module work mode: Slave Mode
Connection mode: Connect to the Bluetooth device specified
Serial parameter: Baud rate: 38400 bits/s; Stop bit: 1 bit; Parity bit: None.
Passkey: “1234”
Device name: “H-C-2010-06-01”
Get Bluetooth Address
Command: AT+ADDR?+ADDR:<address>
OK
The address will be in hexadecimal format:
NAP:UAP:LAP
Set Name
Command: AT+NAME=<name>OK
Get Name
Command: AT+NAME?+NAME:<name>
OK
FAIL
Default:
HC-05
Set Passkey
Command: AT+PSWD=<passkey>OK
Get Passkey
Command: AT+PSWD?+PSWD:<passkey>
OK
Default:
1234
Set Serial Communication
Command: AT+UART=<baud_rate>,<stop_bit>,<parity_bit>OK
Baud rate:
- 4800
- 9600
- 19200
- 38400
- 57600
- 115200
- 230400
- 460800
- 921600
- 1382400
- 0 ~ 1 bit
- 1 ~ 2 bits
- 0 ~ None
- 1 ~ Odd parity
- 2 ~ Even parity
Get Serial Communication
Command: AT+UART?+UART:<baud_rate>,<stop_bit>,<parity_bit>
OK
Default:
38400,0,0
Delete All Paired Devices
Command: AT+RMAADOK
Last Paired Device
Command: AT+MRAD?+MRAD:<address>
OK
Default:
0:0:0
Get Status
Command: AT+STATE?+STATE:<state>
OK
- INITIALIZED
- READY
- PAIRABLE
- PAIRED
- INQUIRING
- CONNECTING
- CONNECTED
- DISCONNECTED
You can find more commands here or here (both PDFs).
Changing Values
I expect you to use Arduino Leonardo or Micro because we want to have separated USB Serial and Pin 0/1 Serial.I wrote this code to allow you read main info from the module (version, address, name and passkey) and change it (name and passkey).
It will also read current state every second for testing purpose.
void setup()
{
Serial.begin(9600);
delay(100);
Serial1.begin(38400);
// Check speed
{
Serial1.println("AT");
while(Serial1.available() < 2)
delayMicroseconds(100);//0.0001
if(Serial1.read() != 'O' || Serial.read() != 'K')
{
while(true)
{
Serial.println("Module speed is not 38400.");
delay(1000);
}
}
}
// Get version
{
Serial.print("Version: ");
Serial1.write("AT+VERSION?");
for(int i = 0; i < 9; i++)// +VERSION:
Serial1.read();
char c = 0;
while(true)
{
c = Serial1.read();
if(c == '\r')
break;
Serial.write(c);
}
Serial.println();
Serial1.read();// \n
Serial1.read();// O
Serial1.read();// K
}
// Get address
{
Serial.print("Address: ");
Serial1.write("AT+ADDR?");
for(int i = 0; i < 6; i++)// +ADDR:
Serial1.read();
char c = 0;
while(true)
{
c = Serial1.read();
if(c == '\r')
break;
Serial.write(c);
}
Serial.println();
Serial1.read();// \n
Serial1.read();// O
Serial1.read();// K
}
// Get name
{
Serial.print("Name: ");
Serial1.write("AT+NAME?");
for(int i = 0; i < 6; i++)// +NAME:
Serial1.read();
char c = 0;
while(true)
{
c = Serial1.read();
if(c == '\r')
break;
Serial.write(c);
}
Serial.println();
Serial1.read();// \n
Serial1.read();// O
Serial1.read();// K
}
// Get passkey
{
Serial.print("Passkey: ");
Serial1.write("AT+PSWD?");
for(int i = 0; i < 6; i++)// +PSWD:
Serial1.read();
char c = 0;
while(true)
{
c = Serial1.read();
if(c == '\r')
break;
Serial.write(c);
}
Serial.println();
Serial1.read();// \n
Serial1.read();// O
Serial1.read();// K
}
// Set name
{
Serial.print("New name: ");
Serial1.print("AT+NAME=");
char c = 0;
while(true)
{
c = Serial.read();
if(c == '\r' || c == '\n')
break;
Serial1.write(c);
}
Serial1.println();
}
// Set passkey
{
Serial.print("New passkey: ");
Serial1.print("AT+PSWD=");
char c = 0;
while(true)
{
c = Serial.read();
if(c == '\r' || c == '\n')
break;
Serial1.write(c);
}
Serial1.println();
}
}
void loop()
{
delay(1000);
Serial1.write("AT+STATE?");
for(int i = 0; i < 7; i++)// +STATE:
Serial1.read();
char c = 0;
while(true)
{
c = Serial1.read();
if(c == '\r')
break;
Serial.write(c);
}
Serial.println();
Serial1.read();// \n
Serial1.read();// O
Serial1.read();// K
}