Added a hc05 reprogramming script

This commit is contained in:
2024-06-12 11:58:46 -04:00
parent 67e91ea722
commit b2d1e6615f
4 changed files with 51 additions and 7 deletions

View File

@@ -52,6 +52,9 @@ wiring diagram for the cube is in the `documentation` directory.
- Adafruits Neopixel library - Adafruits Neopixel library
- Arduino libraries - Arduino libraries
### Bluetooth Module
On v0.1 of the baord, a seperate bluetooth module (HC-05) is being used for bluetooth. This module needs to be programmed when first plugged in. To program the module, disconnect it from power and hold the "EN" button on the module. (The button should be the only button on the HC-05 module). While still holding down the button, reconnect the module to the ESP32 and press the ESP32's reset button. Wait 5 seconds while still holding down the "EN" button on the module, then release the button, power cycle the module, and you're done.
## Run ## Run
- Power up the board and pair it with the headset over bluetooth. - Power up the board and pair it with the headset over bluetooth.
- Build and load the Unity project to the headset. - Build and load the Unity project to the headset.
@@ -112,7 +115,7 @@ Description Set the colors for one of the stacks.
- Red1, Green1, Blue1 correspond with the color of the first cube in the stack and so on. These values can be between 0-255. - Red1, Green1, Blue1 correspond with the color of the first cube in the stack and so on. These values can be between 0-255.
You can add as many colors as you want, but they wont display if the corresponding cube doesn't physically exist. You can add as many colors as you want, but they wont display if the corresponding cube doesn't physically exist.
### COmmand Name: `GoToIdle` ### Command Name: `GoToIdle`
Command Number: `3` Command Number: `3`
Format Example `!3;` Format Example `!3;`

View File

@@ -5,6 +5,7 @@
#pragma once #pragma once
// Stack pins
// Stack 1 pins // Stack 1 pins
#define STACK1_ADC_PIN 6 #define STACK1_ADC_PIN 6
#define STACK1_LED_PIN 11 #define STACK1_LED_PIN 11
@@ -37,7 +38,12 @@
#define STACK8_ADC_PIN 7 #define STACK8_ADC_PIN 7
#define STACK8_LED_PIN 12 #define STACK8_LED_PIN 12
// Stack 9 pins // Stack 9 pins
#define STACK9_ADC_PIN 17 #define STACK9_ADC_PIN 17
#define STACK9_LED_PIN 37 #define STACK9_LED_PIN 37
// Bluetooth module configuration pins
#define BT_STATE_PIN 2
#define BT_EN_PIN 3

View File

@@ -33,7 +33,6 @@ debug_init_break = tbreak setup
debug_tool = esp-builtin debug_tool = esp-builtin
build_type = debug build_type = debug
debug_speed = 20000 debug_speed = 20000
; upload_port = COM7
; debug_port = COM7 ; debug_port = COM7
; monitor_port = COM14 ; monitor_port = COM14
build_flags = -O1 -Iinclude build_flags = -O1 -Iinclude

View File

@@ -21,7 +21,7 @@ enum Commands : uint8_t{
}; };
// -------------------------------------------------- // --------------------------------------------------
// ------------- OBJECT DEFINITIONS ----------------- // ----------------- VARIABLES ----------------------
// -------------------------------------------------- // --------------------------------------------------
// BluetoothSerial SerialBT; // BluetoothSerial SerialBT;
// BluetoothSerialMessage serialMessageBT(&SerialBT); // BluetoothSerialMessage serialMessageBT(&SerialBT);
@@ -31,13 +31,47 @@ BoardLayout board(BOARD_WIDTH, BOARD_LENGTH, BOARD_HEIGHT, stacks);
// Temporary thing until we can get bluetooth color management working on the quest // Temporary thing until we can get bluetooth color management working on the quest
ColorManager colorManager(&board); ColorManager colorManager(&board);
// --------------------------------------------------
// ----------------- VARIABLES ----------------------
// --------------------------------------------------
// -------------------------------------------------- // --------------------------------------------------
// ----------------- FUNCTIONS ---------------------- // ----------------- FUNCTIONS ----------------------
// -------------------------------------------------- // --------------------------------------------------
void SetupBluetoothModule(){
pinMode(BT_STATE_PIN, INPUT);
// pull the enable pin high on boot to enable AT command mode
pinMode(BT_EN_PIN, OUTPUT);
digitalWrite(BT_EN_PIN, HIGH);
// Set the serial baud rate to 38400 which is the default for this module
Serial.begin(38400);
// Reset the module to default settings
Serial.print("AT+ORGL\r\n");
delay(100);
// Set the serial baud rate to 38400 which is the default for this module
Serial.begin(9600);
// Reset the module to default settings
Serial.print("AT+ORGL\r\n");
delay(100);
// set the baud rate of the bluetooth module to 9600
Serial.print("AT+UART=9600,0,0\r\n");
// Serial.begin(9600);
delay(100);
// Set the bluetooth's name to blockPartyBT
Serial.print("AT+NAME=blockPartyBT\r\n");
delay(100);
// // set the bluetooth's role to slave
// Serial.print("AT+ROLE=0\r\n");
// delay(100);
// // set the connection mode to slave mode
// Serial.print("AT+CMODE=0\r\n");
// delay(100);
// // remove the password
// Serial.print("AT+PSWD=\r\n");
// delay(100);
// // allow the module to be set to any address
// Serial.print("AT+ADDR=0\r\n");
// delay(100);
digitalWrite(BT_EN_PIN, LOW);
}
void printBoardState(){ void printBoardState(){
// create a buffer to hold the board state // create a buffer to hold the board state
uint16_t boardState[BOARD_WIDTH * BOARD_LENGTH]; uint16_t boardState[BOARD_WIDTH * BOARD_LENGTH];
@@ -118,6 +152,8 @@ bool boardStateHasChanged{false};
uint32_t boardStateMaxUpdatePeriod{15}; // this is a little faster than 60fps uint32_t boardStateMaxUpdatePeriod{15}; // this is a little faster than 60fps
void setup() { void setup() {
delay(1000);
SetupBluetoothModule();
Serial.begin(9600); Serial.begin(9600);
// SerialBT.begin("blockPartyBT"); // SerialBT.begin("blockPartyBT");
Color colors[] = {Color(255, 0, 0), Color(0, 0, 0), Color(0, 0, 0)}; Color colors[] = {Color(255, 0, 0), Color(0, 0, 0), Color(0, 0, 0)};