Avatar
Electronoobs ESP8266 on arduino UNO or NANO
Aug 19th, 2019 | by: R B | Views 1011
Views 1011
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.clear();
  lcd.setCursor(0,0);
  lcd.print(F("N1: ")); lcd.print(received_nr_1); lcd.print(F("  N2: ")); lcd.print(received_nr_2);
  lcd.setCursor(0,1);
  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).


#include 
LiquidCrystal_I2C lcd(0x27,20,4);

lcd.begin();
lcd.init();
// 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;

}

14 Comments

  • ELECTRONOOBS

    about 5 years ago

    Thanks for all these improvements!

    Noob 19129

    about 8 months ago

    Please try a hrefhttpswwwgooglecomGooglea before asking about a hrefhttpsempressleakxyzblog149232Useful Product Infoa 4aa023d

    Noob 19129

    about 5 months ago

    Please try a hrefhttpswwwgooglecomGooglea before asking about a hrefhttpprakardsodcomindexphptopic1510newnewUseful Product Bloga 9e0b59a

    Noob 19129

    about 5 months ago

    Please try a hrefhttpswwwgooglecomGooglea before asking about a hrefhttpsbbsidentityvjpforumphpmodviewthreadtid312pid3042270page6extrapid3042270Best Product Websitea 6595dd

    Noob 19129

    about 5 months ago

    Please try a hrefhttpswwwgooglecomGooglea before asking about a hrefhttpsuokananetmybbshowthreadphptid570437pid1204653pid1204653Excellent Product Guidea a023d94

    Noob 19129

    about 5 months ago

    Please try urlhttpswwwgooglecomGoogleurl before asking about urlhttpsallgaeuadlerdeshowthreadphptid170639pid601807pid601807Updated Product Blogurl 4aa023d

    Noob 19129

    about 4 months ago

    Please try urlhttpswwwgooglecomGoogleurl before asking about urlhttpswwwallgaeuadlerdeshowthreadphptid92457pid616081pid616081Updated Product Websiteurl aa023d9

    Noob 19129

    about 3 months ago

    Please try urlhttpswwwgooglecomGoogleurl before asking about urlhttpsforumesperantoczshowthreadphptid208646pid1520150pid1520150Best Product Websiteurl 7057988

    Noob 19129

    about 3 months ago

    Please try urlhttpswwwgooglecomGoogleurl before asking about urlhttpcalaveroorgshowthreadphptid81411pid934853pid934853Best Product Websiteurl 94c5f79

    Noob 19129

    about 2 months ago

    Please try urlhttpswwwgooglecomGoogleurl before asking about urlhttpspimpforumsxyzshowthreadphptid6846pid29817pid29817New Product Tipsurl c5f79e0

    Noob 19129

    about 1 month ago

    Please try urlhttpswwwgooglecomGoogleurl before asking about urlhttpswwwforumvuwpgsaacnzviewtopicphpp393969p393969Great Product Tipsurl 23d94c5

  • Noob 1513

    about 5 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

  • Noob 13506

    about 1 year ago

    Hola muy buen día a esta boinita comunidad tengo un problema a la hora de crear el sitio web y en la parte de subir los archivos que ELECTRONOOBS compartió, me arroja un error en el código (index.php) y a la hora de entrar al sitio web me arroja este error "Uncaught TypeError: mysqli_query(): Argument #1 ($mysql) must be of type mysqli, bool given in /storage/ssd3/757/20785757/public_html/index.php:34 Stack trace: #0 /storage/ssd3/757/20785757/public_html/index.php(34): mysqli_query() #1 {main} thrown in /storage/ssd3/757/20785757/public_html/index.php on line 34". Alguien me podria ayudar con este tema por favor, se lo agradeceria mucho.

  • Alex Juvion

    about 10 months ago

    congratulations and thanks for letting us know 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. Alex, Worried about deadlines? Our UK-based coursework help UK guarantees on-time delivery. Let us assist you in completing your coursework stress-free and well before your submission date.

Login or Sign Up to post comments on this tutorial.