Buy from US Buy from UK Buy from DE Buy from FR Buy from IT Buy from ES ここでご購入を!
Buy from US Buy from UK Buy from DE Buy from FR Buy from IT Buy from ES Buy from JP

In order to connect our Things to Internet, we need to select some Internet communication protocol so that different Internet device can talk with each other. Some commonly used IoT protocols are HTTP, MQTT etc.

In this lesson, we will learn how to use HTTP protocol and    how to make simple  HTTP web server with Osoyoo MEGA-IoT shield and MEGA2560 micro-controller and show a “Hello World!”  web page to remote browser . The web page also shows the input voltage of A0 pin that is detected by Arduino analogRead() functions.

1).please plug OSOYOO MEGA-IoT Extension Board into OSOYOO Advanced Board for MEGA2560 Board:

2)Use jumper Cap to connect ESP8266 RX with A8, TX with A9)

SOFTWARE

Software Installation

Notice: Shut off your battery or Unplug your power adapter when upload sketch code to your OSOYOO Advanced Board for Arduino MEGA2560.

Open-source
Software(IDE)
Download IDE here:
https://www.arduino.cc/en/Main/Software?setlang=en
7 zip is a free zip
utility that un-zips zip files
Download 7zip here for free
https://www.7-zip.org/

Step 1 Install latest IDE (If you have IDE version after 1.1.16, please skip this step).

Download IDE from https://www.arduino.cc/en/software, then install the software.

Step 2 OSOYOO MEGA-IoT extension TX/RX pin to A9/A8 pin by default. So in your sketch code, we need use Software Serial Port to communicate with ESP8266 (set A9 as TX and A8 as RX in SoftwareSerial object).we need download WiFiEsp-master library from following link firstly: https://osoyoo.com/driver/WiFiEsp-master.zip

Step3 Open the IDE ->Sketch ->Include Library ->Add ,Zip library to load above zip files into Arduino IDE.

Step 4 After installing above library, please download the main code from following link.unzip the download zip file lesson3.zip, you will see a folder called smarthome-lesson3.
https://osoyoo.com/driver/smarthome/smarthome-lesson3.zip  

Step 5 After above operations are completed, connect the OSOYOO MEGA2560 Board to the PC with USB cable.

Step 6 Open the IDE and choose corresponding board type and port type for your project.

Step 7 IDE: Click file -> click Open -> choose code “smarthome-lesson3”, load the  sketch onto your board.

Note: In the  sketch, find   following lines:

char ssid[] = "******"; // your network SSID (name)
char pass[] = "******"; // your network password

please replace the ****** with your correct wifi SSID and password, otherwise your project can not connect to Internet.

After loading the sketch to IDE , open the serial monitor in the upper-right corner of IDE, you will see following result:

From the serial monitor ,  you can see the IP address of your MEGA2560 board in the read circle (in above picture, 192.168.50.102).

Then use your browser to visit the website http://mega2560-ip-address (in above case, http://192.168.50.102), you will see following result:

Above result also shows the A0 pin input voltage through analogRead(0) function in line 94. analogRead() can read the input 0-5V voltage and return a value between 0 to 1023 standing for the voltage.

If we connect A0 to GND via jumper wire, Analog input A0: shows 0

If we connect A0 to 5V via jumper wire ,  Analog input A0: shows 1023.

Trouble Shooting

Sometimes when running lesson3  project,  ESP8266 might have initialization problem with MEGA2560 A8,A9 pins and this cause WifiESP initializing error showing in Serial monitor as following:

[WiFiEsp] Initializing ESP module
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] Cannot initialize ESP module

To solve the problem, we need use Stable pin D10,D11 to initialize ESP8266 and then switch back to A8,A9.
To do this, please do as per following steps:

Step 1)remove the jumper caps on A8/ESP_RX and A9/ESP_TX, then use two Female-To-Male jumper wires connect ESP_RX to D11 and ESP_TX to D10,
see following picture:
Above circuit change will use D10, D11 instead of A8, A9 to connect ESP8266 serial port because MEGA2560 A8,A9 is not as stable as D10,D11.
Step 2) Now we need slightly change some code of Lesson 3 sketch file line 15:

Original line 15 is :
SoftwareSerial softserial(A9, A8); // RX, TXPlease change above line to:
SoftwareSerial softserial(10, 11); // RX, TX

Step 3) Load the sketch to IDE and the Initializing normally will pass through and show

[WiFiEsp] Initilization successful - 1.5.4 SSI 
This means your ESP8266 chip has connected to your MEGA2560. Then your OSOYOO Advanced Board for MEGA2560 Board will keep connecting your wifi SSID and Serial Monitor will tell you the IP address.
Once above procedure has been done. You can actually roll back the ESP8266 connection to A8,A9 same as original status, and change line 15 to : SoftwareSerial softserial(A9, A8); // RX, TX
Now load the original Lesson 3 sketch, it will work .