I purchased two ESP32 C6 super mini modules from Aliexpress. I want to use a small footprint bluetooth module to control a TB6612FNG module to experiment with battery powered HO scale model trains.
I was using the Live Mini Kit ESP32 which worked fine but was hoping to use the C6 smaller footprint.
However I cannot upload the sketch. I have tried several different boards in Arduino but no success.
I have tried to hold the boot button down , press and release the reset button. This brings on the blue led and changes the port available in Arduino from 10 to 14. But I get the same failed upload.
Here’s the code
#include <BluetoothSerial.h>
// Check if Bluetooth is available
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to enable it
#endif
// Check Serial Port Profile
#if !defined(CONFIG_BT_SPP_ENABLED)
#error Serial Port Profile for Bluetooth is not available or not enabled. It is only available for the ESP32 chip.
#endif
BluetoothSerial SerialBT;
const int PWM_CHANNEL = 0; // ESP32 has 16 channels which can generate 16 independent waveforms
const int PWM_FREQ = 3000; // Recall that Arduino Uno is ~490 Hz. Official ESP32 example uses 5,000Hz
const int PWM_RESOLUTION = 8; // We'll use same resolution as Uno (8 bits, 0-255) but ESP32 can go up to 16 bits
// The max duty cycle value based on PWM resolution (will be 255 if resolution is 8 bits)
const int MAX_DUTY_CYCLE = (int)(pow(2, PWM_RESOLUTION) - 1);
const int OUTPUT_PIN = 19;
const int DELAY_MS = 100; // delay between fade increments
// input codes from Battery Throttle
bool Power = 0; // P0 = power off, P1 = power on
bool Direction = 1; // D0 = reverse, D1 = forward
bool HLights = 0; // HL0 = headlights off, HL1 = headlights on
bool TLights = 0; // TL0 = taillights off, TL1 = taillights on.
bool Horn = 0; // S0 = Horn off, S1 = Horn on
int AIN1 = 16; // D2 direction output
int AIN2 = 17; // D3 direction output
int STBY = 32; // D4 must be High to drive motor
String loco_ID = "L4599"; //store loco_ID etc in eeprom.
char buffer[2];
int DataReadIn[2];
bool locoDirection = 0; //forward
int Speed = 0;
int debug = 1; //set to 1 to show debug info on serial port.
String commandString;
void setup() {
pinMode(AIN1, OUTPUT);
pinMode(AIN2, OUTPUT);
pinMode(STBY, OUTPUT);
digitalWrite(STBY, HIGH); //high to enable DRV8833
Serial.begin(115200);
SerialBT.begin(loco_ID);
DataReadIn[0] = 0;
DataReadIn[1] = 0;
DataReadIn[2] = 0;
// Sets up a channel (0-15), a PWM duty cycle frequency, and a PWM resolution (1 - 16 bits)
ledcAttachChannel(OUTPUT_PIN, PWM_FREQ, PWM_RESOLUTION, PWM_CHANNEL);
}
void loop() {
if (SerialBT.available()>0) {
commandString = SerialBT.readStringUntil(62); //>
interpretCommand();
if (debug){
Serial.print("Values In [0]= ");
Serial.print(DataReadIn[0]);
Serial.print(" and [1]= ");
Serial.print(DataReadIn[1]);
Serial.print(" and [2]= ");
Serial.println(DataReadIn[2]);
}
delay(2000);
}
SerialBT.flush();
}
void interpretCommand(){
int index1 = commandString.indexOf("L");
String whichLoco = commandString.substring(index1, 5);
if (whichLoco == loco_ID){
Serial.println ("Command is for this loco");
int commandCode = commandString.substring(6, 1).toInt();
switch (commandCode){
case 1: {doEStopStart();} break; // Emergency stop
case 2: {doDirection();} break; // direction
case 3: {doSpeed();} break; // speed
case 4: {doHLights();} break; // head lights
case 5: {doTLights();} break; // tail lights
case 6: {doHorn();} break; // horn
}
}
}
void doHLights(){
int commandValue = commandString.substring(7, 1).toInt();
switch (commandValue){
case 0: {Serial.println("Head lights Off");} break; // Hlights off
case 1: {Serial.println("Head lights On");} break;
}
}
void doTLights(){
int commandValue = commandString.substring(7, 1).toInt();
switch (commandValue){
case 0: {Serial.println("Tail lights Off");} break; // Tlights off
case 1: {Serial.println("Tail lights On");} break;
}
}
void doHorn(){
int commandValue = commandString.substring(7, 1).toInt();
switch (commandValue){
case 0: {Serial.println("Horn Off");} break; // horn off
case 1: {Serial.println("Horn On");} break;
}
}
void doDirection(){
int commandValue = commandString.substring(7, 1).toInt();
switch(commandValue){
case 0: {Serial.println("Direction is reverse");
digitalWrite(AIN1, LOW);
digitalWrite(AIN2, HIGH);} break;
case 1: {Serial.println("Direction is forward");
digitalWrite(AIN1, HIGH);
digitalWrite(AIN2, LOW);} break;
}
}
void doSpeed(){
int commandValue = commandString.substring(7, 1).toInt();
if (commandValue>=0){
if (debug){
Serial.print("Speed is ");
Serial.println(commandValue);
}
int dutyCycle = (commandValue);
analogWrite(OUTPUT_PIN, dutyCycle);
}
if (debug) {
Serial.print("Speed is ");
Serial.println(commandValue);
}
}
void doEStopStart(){
int commandValue = commandString.substring(7, 1).toInt();
switch (commandValue){
case 0:{
digitalWrite(STBY, LOW);
digitalWrite(AIN1, LOW);
digitalWrite(AIN2, LOW);
Serial.println("STOP");} break;
case 1:{
digitalWrite(STBY, HIGH);
Serial.println("RUN");} break;
}
}
and this is the error message
Compilation error. #error Bluetooth is not enabled! Please run make menuconfig to enable it.
Where can I find make menuconfig? A search on Google only directs me to Linux articles.
The board selected is the ESP32C3 Dev module. I get the same error when ESP32C6 Dev module selected.
My apologies if I have posted this article in the wrong place.
Hope someone can make sense of my problem and help me out.
