In this post, I’ll be begining to cover the Arduino code used to program the ESP8266, as it pertains to the CO Detector. Most of what I’ll be going over here is based off of Rui and Sara Santos’s work at https://randomnerdtutorials.com/about/. They have done a tremendous amount of work and deserve the attention for it.
The ESP8266 will be replacing the ins and outs to the CO Detector. Besides the typical operation of the CO Detector, we’ll need to do some additional tasks. Code takes memory so we’ll need to work within the limits of the ESP8266.
The code example from the Santos’s work of an ESP9266 Web Server, https://randomnerdtutorials.com/esp8266-web-server/, uses two types of memory. This is typical of most sketches. This is program storage and dynamic memory. The program storage is the core of the sketch, while the dynamic memory is used for values that change during execution. Here are the results from the compiler.
Sketch uses 261251 bytes (52%) of program storage space. Maximum is 499696 bytes.
Global variables use 34732 bytes (42%) of dynamic memory, leaving 47188 bytes for local variables. Maximum is 81920 bytes.
Their example also calls one library. Library calls are more efficient than rewriting code. This saves time coding, but could sacrifice memory space for bundled features that may or may not be used. Be aware of the pros and cons using libraries.
The code they provide does the following things. Besides calling libraries and defining constants, It binds the ESP8266 to a wireless network and starts web services so clients can connect to it.
The ESP8266 will run in this state until powered off. It’s good to note that during this time power is in use. Since our CO Detector operates on battery, we may need to reconsider the power source or set our code to use a low power standby state.
There is more to cover regarding the Arduino code that I won’t cover in this post. This is mainly to give an introduction to the code base we’ll be using later.