Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convenient reflashing (suggestion) #96

Open
michalmonday opened this issue Feb 7, 2019 · 0 comments
Open

Convenient reflashing (suggestion) #96

michalmonday opened this issue Feb 7, 2019 · 0 comments

Comments

@michalmonday
Copy link

michalmonday commented Feb 7, 2019

Hi, reflashing of Esp8266 requires uploading separate code to Arduino, the suggestion is to:

  • incorporate this code into the main sketch
  • 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);
  }
}

image

Switches that could be used:

wiring image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant