add a switch (off = normal operation, on = the incorporated code runs in a "while loop" allowing Esp8266 to be reprogrammed without uploading any separate code to Arduino)
Here's example of how it could look like:
Top of the code:
// using #defines to save dynamic memory
#define WIFI_DUCKY_PROGRAMMING_MODE_SWITCH_PIN 3 // 3 of Arduino Pro Micro, SCL, PD0 (18 of Atmega32u4)
#define WIFI_DUCKY_GPIO_0_CONTROL_PIN 2 // 2 of Arduino Pro Micro, SDA, PD1 (19 of Atmega32u4)
#define WIFI_DUCKY_ENABLE_CONTROL_PIN 20 // 20 of Arduino Pro Micro, A2, PF5 (38 of Atmega32u4)
Begining of the setup function:
void setup(){
Wifi_ducky_programming_mode();
Anywhere, or at the end:
void Wifi_ducky_programming_mode(){
pinMode(WIFI_DUCKY_PROGRAMMING_MODE_SWITCH_PIN, INPUT_PULLUP);
pinMode(WIFI_DUCKY_GPIO_0_CONTROL_PIN, OUTPUT);
pinMode(WIFI_DUCKY_ENABLE_CONTROL_PIN, OUTPUT);
if(digitalRead(WIFI_DUCKY_PROGRAMMING_MODE_SWITCH_PIN) == LOW){
// If switch was activated then pass all data through Serial1 and allow programming Esp8266 with "Nodemcu Flasher" program.
Serial1.begin(115200);
Serial.begin(115200);
digitalWrite(WIFI_DUCKY_GPIO_0_CONTROL_PIN,LOW);
digitalWrite(WIFI_DUCKY_ENABLE_CONTROL_PIN,HIGH);
/* Flash LED 3 times quickly to show that the constant loop was reached and the Esp8266 can be programmed.
Device is unusable in this mode (this mode is for flashing esp only) and has to be replugged in order to work again (plugged out + switch turned the other side + plugged back in) */
digitalWrite(LED_BUILTIN, HIGH); delay(300); digitalWrite(LED_BUILTIN, LOW); delay(300); digitalWrite(LED_BUILTIN, HIGH); delay(300); digitalWrite(LED_BUILTIN, LOW); delay(300); digitalWrite(LED_BUILTIN, HIGH); delay(300); digitalWrite(LED_BUILTIN, LOW);
while(true){
while(Serial1.available()){
Serial.write((uint8_t)Serial1.read());
}
if(Serial.available()){
while(Serial.available()){
Serial1.write((uint8_t)Serial.read());
}
}
}
}else{
digitalWrite(WIFI_DUCKY_GPIO_0_CONTROL_PIN,HIGH);
digitalWrite(WIFI_DUCKY_ENABLE_CONTROL_PIN,HIGH);
}
}
Hi, reflashing of Esp8266 requires uploading separate code to Arduino, the suggestion is to:
Here's example of how it could look like:
Top of the code:
Begining of the setup function:
Anywhere, or at the end:
Switches that could be used: