Odešel mě HC05 jako BT programátor.
Udělal jsem narychlo programátor přes ESP32 a funguje to dobře.
Možná se to bude někomu hodit. Odzkoušeno na 328p a 2560.
//*****************************************************************************************
// Programator pres BT
//****************************************************************************************
#include "BluetoothSerial.h" // Include the Serial bluetooth library
#define LED_BT 22 // PIN ledky
#define RES_BT 23 // PIN resetu pro programovany procesor
bool ledBtState = false; // blik led
bool MasterConnected; // true = pripojeno / false = nepripojeno
String device_name = "ESP32-BT-Programer"; // jmeno
unsigned long previousMillis; // neco pro blikani LEDky
#define baud 115200 // speed UART
// Bluetooth je?
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run make menuconfig to and enable it
#endif
// Serial Bluetooth JE?
#if !defined(CONFIG_BT_SPP_ENABLED)
#error Serial Bluetooth not available or not enabled. It is only available for the ESP32 chip.
#endif
BluetoothSerial SerialBT; // nastaveni object SerialBT
// Bt_Status callback function
void Bt_Status (esp_spp_cb_event_t event, esp_spp_cb_param_t *param) {
if (event == ESP_SPP_SRV_OPEN_EVT) { //
MasterConnected = true; //
pinMode(RES_BT,OUTPUT); //
digitalWrite(RES_BT, LOW); //
delay(100); //
digitalWrite(RES_BT, HIGH); //
pinMode(RES_BT,INPUT); //
}
else if (event == ESP_SPP_CLOSE_EVT ) { //
MasterConnected = false; //
digitalWrite(LED_BT, LOW); //
}
}
void setup() {
pinMode(RES_BT,INPUT);
pinMode(LED_BT,OUTPUT);
Serial2.begin(baud);
SerialBT.register_callback (Bt_Status);
SerialBT.begin(device_name);
}
void loop() {
if (MasterConnected) {
if (millis() - previousMillis >= 250)
{
if (ledBtState == false)
{
ledBtState = true;
}
else
{
ledBtState = false;
}
digitalWrite(LED_BT, ledBtState);
previousMillis = millis();
}
}
while (Serial2.available())
{
SerialBT.write(Serial2.read());
}
while (SerialBT.available())
{
Serial2.write(SerialBT.read());
}
esp32_bt_programer.pdf (16.9 kB)