Browse over 10,000 Electronics Projects

The ESP WiFi Shield: the best value for money and low energy consumption

The ESP WiFi Shield: the best value for money and low energy consumption

fig4

Serial Monitor for the communications with ESP.

 

At this stage we are ready to implement our data logger, as a simple example we are going to save the environmental temperature’s value, as measured by a simple integrated circuit such as the LM35.

The sketch for the data logger function is named ESP8266_DataLogNTP.ino, and it may be downloaded, along with the other files enclosed to this magazine’s number. In order to test this program, as a first thing you will have to type name and password of your WiFi network in the SSID and PASS fields. The temperature sensor will have to be powered by Arduino, by the GND and +5V pins, while its output will have to be connected to the analog input, AN0. This sensor supplies a voltage of 10mV for each detected Celsius degree; therefore, in order to better the resolution, it is needed to set the full scale for the A/D converter at 1.1 volts, by means of the analogReference(INTERNAL) instruction. The temperature will be acquired by converting the value read by the A/D converter by means of the following equation: TEMP = analogRead(A0)/9.31. For this sketch we considered the usage of the ESPPD (ESP8266 Power Down) line, that allows to turn off the module when it is unused, thus drastically reducing the energy consumption.

In the sketch’s opening part it is possible to define the communication mode between the ESP8266 module and Arduino. The default mode that we considered consists in making the ATmel328 microcontroller communicate with the WiFi module by means of a software serial and to let the hardware serial free for the debug function. The DEBUG variable may be set on true or false, depending on the fact you want a report that is more or less complete as regards the communications with the WiFi module.

In the case you wanted to manage the WiFi module via the hardware serial, it is enough to set the jumpers so that the ESPTX and ESPRX signals may be respectively connected to D0 and D1, but please remember that each time that you want to program Arduino, you will have to disconnect the module – by removing the jumpers – otherwise the two communications will be in conflict.



Advertisement1


 

fig 5

SD Test.

 

In the case two hardware serials are available, as in the Arduino Leonardo board, the main serial will be used for the debug while the secondary serial (Serial1) will be used for the communication with the module.

In the section related to the setup, the module and the SD are initialized, also verifying they are operational.

In the loop section the code related to the data log function is contained, the first part deals with recalling the function for the access to the WiFi network; five tries at most are allowed. The request for the date and time follows, by recalling the requestTime() function, that deals with querying the NTP server; the strings related to the date and time are available by means of the getDateString() and getTimeString() functions. These functions allow to format the data and they may be modifications, depending on which format we want to use; this is important in the case of a following processing, by means of a spreadsheet concerning the acquired data.

In order to extract the date and the time from the return string, we will use the time library, that has been specifically studied for this function; as usual it is possible to copy the whole folder (named time) inside Arduino’s library folder and then to reboot the IDE.

We need to remember that the time obtained from the NTP server is referred to the Greenwich meridian (now GMT Greenwich Mean Time); thus we will have to take the Italian time zone (+1) and possibly the daylight savings time (+1 in the summertime) into account; for such a reason we considered the UTCcorrection correction variable, that is set to 7,200, so to consider the 3,600 seconds related to the time zone and the 3,600 seconds related to the daylight savings time.

Then the module disconnects from the WiFi network and is turned off, so to save energy.

The following code lines are used in the sketch, so to build the string that will be built in the SD Card:

 String dataString = getDateString();

 dataString += ” “;

 dataString += getTimeString();

 dataString += ”   AN0=”;

 dataString += String(analogRead(A0));

Pages: 1 2 3 4 5 6 7 8

 


Top