Electronoobs ESP8266 on arduino UNO or NANO
Aug 19th, 2019 | by: Richard Bagín | Views 377
Views 377
Electronoobs created few weeks ago a nice tutorial on YouTube how to use ESP8266 with arduino to control home appliances or read sensor values from anywhere. His code was too big to be upload on arduino UNO or NANO (ATmege328P). It was necessary to use arduino MEGA.
"Full version" of Electronoobs code will also work on arduino UNO or NANO (ATmega328P) if you store all string in program memory (flash) via "F( )" macro.

In this tutorial you will learn how to save SRAM / RAM of an arduino by using "F()" and "PROGMEM" macros of arduino wiring language and how to fix initialization of I2C LCD.

I saved 732 bytes of RAM without any big changes in code.
I fixed non compiling initialization of I2C LCD by changing one line of code.

You can download modified code (in step 1).
F() all string

"Full version" of Electronoobs code will also work on arduino UNO or NANO (ATmega328P) if you store all string in program memory (flash) via "F( )" macro.

e.g.: Serial.println(F("READY TO SEND"));   ( or lcd.print(F("...")); )

Like this I reduce the used RAM to 70% (595 bytes left).

original code: 2185 byte (RAM) - 2048max     16566 byte (FLASH) - 30720max

modified code: 1453 byte (RAM)     16950 byte (FLASH)

//part of code for demonstrate
  lcd.print(F("N1: ")); lcd.print(received_nr_1); lcd.print(F("  N2: ")); lcd.print(received_nr_2);
  lcd.print(F("N3: ")); lcd.print(received_nr_3); lcd.print(F("  N4: ")); lcd.print(received_nr_4);    
  delay(1000);//5 seconds between tries  								

I2C LCD initialization

Also I have problem with compiling the sketch because my I2C LCD library does not include member "init()" but instead of it I just write "begin()".          lcd.begin();


It depends on version of your library, just try which one would work for you. And if you have still problem with it open example sketch of your LCD I2C library and find the correct form of initializing command.

Or in some libraries you have to write some variables in this command like "lcd.begin(0x27,20,4);" (address and size).

LiquidCrystal_I2C lcd(0x27,20,4);

// one of these should work for you								

Stability problems?

Due to your modifications of code, if 595 bytes in RAM would not be enough (if it will still cause stability problems) you can also write other string (e.g.: const char SSID_ESP[] = "...";   const char SSID_KEY[] = "...";  ...) to program memory via PROGMEM macro.

     e.g.: PROGMEM const char SSID_ESP[] = "...";


But you will need to write a little bit of code.

You will need to create a buffer (in RAM) where you will write one of strings from flash which will be use in next piece of code.

Something like:

PROGMEM const char SSID_ESP[] = "someSSID";

unsigned char buffer[bufferMaxLength];

for(i=0; i

  buffer[i] = pgm_read_byte_near(&SSID_ESP[0]+i);

  if(buffer[i]=='\0' /*end of string*/) break;




    about 2 years ago

    Thanks for all these improvements!

  • Noob 1513

    about 2 years ago

    Hi , I am having an issue with the #include , how can I download this library? MAIN_ESP8266:3:23: error: avr/power.h: No such file or directory

Login or Sign Up to post comments on this tutorial.