From b2d1e6615f55d22199ef542119834da9e0965205 Mon Sep 17 00:00:00 2001 From: Quinn Date: Wed, 12 Jun 2024 11:58:46 -0400 Subject: [PATCH] Added a hc05 reprogramming script --- README.md | 5 ++++- include/PINOUT.h | 6 ++++++ platformio.ini | 1 - src/main.cpp | 46 +++++++++++++++++++++++++++++++++++++++++----- 4 files changed, 51 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 189e92c..0cf8eaa 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,9 @@ wiring diagram for the cube is in the `documentation` directory. - Adafruit’s Neopixel library - 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 - Power up the board and pair it with the headset over bluetooth. - 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. 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` Format Example `!3;` diff --git a/include/PINOUT.h b/include/PINOUT.h index af227a3..e6764b4 100644 --- a/include/PINOUT.h +++ b/include/PINOUT.h @@ -5,6 +5,7 @@ #pragma once +// Stack pins // Stack 1 pins #define STACK1_ADC_PIN 6 #define STACK1_LED_PIN 11 @@ -37,7 +38,12 @@ #define STACK8_ADC_PIN 7 #define STACK8_LED_PIN 12 + // Stack 9 pins #define STACK9_ADC_PIN 17 #define STACK9_LED_PIN 37 +// Bluetooth module configuration pins +#define BT_STATE_PIN 2 +#define BT_EN_PIN 3 + diff --git a/platformio.ini b/platformio.ini index 23589d6..b69f1c3 100644 --- a/platformio.ini +++ b/platformio.ini @@ -33,7 +33,6 @@ debug_init_break = tbreak setup debug_tool = esp-builtin build_type = debug debug_speed = 20000 -; upload_port = COM7 ; debug_port = COM7 ; monitor_port = COM14 build_flags = -O1 -Iinclude \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 6ad114c..c4cdf2f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,7 +21,7 @@ enum Commands : uint8_t{ }; // -------------------------------------------------- -// ------------- OBJECT DEFINITIONS ----------------- +// ----------------- VARIABLES ---------------------- // -------------------------------------------------- // BluetoothSerial 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 ColorManager colorManager(&board); -// -------------------------------------------------- -// ----------------- VARIABLES ---------------------- -// -------------------------------------------------- - // -------------------------------------------------- // ----------------- 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(){ // create a buffer to hold the board state 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 void setup() { + delay(1000); + SetupBluetoothModule(); Serial.begin(9600); // SerialBT.begin("blockPartyBT"); Color colors[] = {Color(255, 0, 0), Color(0, 0, 0), Color(0, 0, 0)};