Skip to content

Commit 3588a6e

Browse files
committed
add some code walkthrough
1 parent ef4a18f commit 3588a6e

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

README.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,43 @@ ESP8266 ESP01 - Schematic Diagram
7575

7676
The ESP8266 WiFi Module is a self-contained stack that can give any microcontroller access to your WiFi network. The ESP8266 is capable of either hosting an application or offloading all Wi-Fi networking functions from another application processor. The ESP8266 module is an extremely cost-effective board with a huge, and ever-growing, community.
7777

78-
<img align="center" src="https://github.com/MecaHumArduino/arduino-uno-aws-weather-station/blob/master/docs/esp8266-schema.png?raw=true" style="max-width:100%;" height="350">
78+
<img align="center" src="https://github.com/MecaHumArduino/arduino-uno-aws-weather-station/blob/master/docs/esp8266-schema.png?raw=true" style="max-width:100%;" height="350">
79+
80+
Code Walk Through
81+
--------------------
82+
83+
The code itself is straightforward and well commented (help is of course welcome) but I wanted to explain something I struggled with when I first was learning my way through the Arduino world, and that is the difference between `Software Serial` and `Hardware Serial`.
84+
85+
Let's go through the function called `sendDataToWiFi()`. This function allow the Arduino board (the logic board) to communicate with the ESP8266 board (The WiFi board)
86+
87+
```cpp
88+
String sendDataToWiFi(String command, const int timeout, boolean debug)
89+
```
90+
91+
So after connecting the two boards following the wiring diagram above, and initializing a new Software Serial object called `wifi`
92+
```cpp
93+
// ESP TX => Uno Pin 2
94+
// ESP RX => Uno Pin 3
95+
SoftwareSerial wifi(2, 3);
96+
```
97+
98+
Anything passed to the `print()` function will be sent through the pin 2 to the WiFi board.
99+
```cpp
100+
wifi.print(command); // send the read character to the esp8266
101+
```
102+
103+
Pin 3 is then used to read any response coming back from the WiFi board through the `read()` function.
104+
```cpp
105+
while((time+timeout) > millis()) {
106+
while(wifi.available()) {
107+
// The esp has data so display its output to the serial window
108+
char c = wifi.read(); // read the next character.
109+
response+=c;
110+
}
111+
}
112+
113+
return response;
114+
}
115+
```
116+
117+
Finally, for code that goes into the WiFi board (ESP8266 ESP01) and more explanation, please head out to this repo: https://github.com/MecaHumArduino/esp8266-01-aws-mqtt

0 commit comments

Comments
 (0)