14. Networking and communications

Assignment

  • Individual assignment:

    • Design, build and connect wired or wireless node (s) with network or bus addresses
  • Group assignment:

    • Send a message between two projects.

Project Idea

As I wanted to test something new, I chose to try to communicate three ESP8266 using the ESP-NOW communication protocol which is like the low power 2.4 GHz wireless connectivity. To do this, the following processes were carried out:

  • To perform the communication, it is necessary to first find the MAC of the ESP8266 used. For this, the code below was used.
  • It presents the ESP’s MAC Address in the serial using the function WiFI.macAddress().

Image1 - Mac Address code

  • With the MAC Address, the master code was built, which is responsible for sending the data to the slaves who carry out operations.

Image2 - Board’s Mac Address

  • The documentation from the FVM learning website was used to assemble this code, as it was the first time that I am using this protocol.

Master Programming

  • To use this protocol, it is necessary to import the espnow library.
  • The MAC addresses of two ESP8266 that are slaves have been added.
  • I declared the communication channel, that was the 4.
  • A structure was created to send data that would be the DataStruct and which was referenced by button_ON and button_OFF.

Image3 - Master code

  • In setup, the series, and the mode WiFi_STA, that would be the station mode, are started.
  • If a communication problem occurs, then the message will be printed on the ESP serial.
  • Communication settings are made that can be better understood on the Random nerd tutorials website.
  • ON and OFF are set for button_ON and button_OFF.

Image4 - Master code

  • In loop, the sendData function is called, which checks whether the first or the second button is activated. If the D1 button is activated, it will send ON to the two ESP slaves, and if the D2 button is activated, it will send OFF to the ESP slaves.

Image5 - Master code loop and function

Programming the first ESP slave

The first ESP8266 slave is responsible for receiving the value from the master and turning on a LED, if the first button is clicked and turning off, if the second button is clicked.

  • The same procedures as the master were performed to add the ESP-NOW protocol.

Image6 - Slave1 code

  • In setup, the serial is initialized and the output pin with the LED is declared.
  • The ESP-NOW protocol is checked for functionality in the same way as the ESP master.

Image7 - Slave1 code

  • In a loop, there is no process and in the callback function, the variable sent will be received by the ESP master. The value is passed to the variable DataCompare and from that, we check if the received text is ON or OFF and with that, the LED can turn on or off and its value can be read on the serial.

Image8 - Slave1 code loop and callback functions

Programming the second ESP slave

The second esp8266 is responsible for controlling the servo. When the master sends an ON variable, the servo is 180° and when it receives OFF, it is 0°.

  • The servo’s library is imported and the servo’s instance that is called meuservo occurs.

Image9 - Slave2 code

  • In the setup function, the same process occurs as the first ESP8266 slave and also the declaration of where the servo door is, using the attach.

Image10 - Slave2 code setup

  • In the callback function, the same process as the other ESP8266 slave takes place, but instead of turning on a LED, the servo position is written, which can be 180 if the received value is ON and 0 if it is OFF.

Image11 - Slave2 code loop and callback functions

In the picture below, we can see the hero shot of the system, making it clear that the cables connected to the ESPs are only for powering.

Image12 - Hero shot (I will use my own board to improve this week assignment when covid problem get better.)

Below, there is a video explaining the operation of the system.

Video01 – System operation

Disclaimer When new Eletronic components (ESP microchips) arrives in the Lab. (problens because of the pandemic) I will use my own board to improve this week assignment.

UPDATE the ESP microchips arrived in lab!!!

This time, it was decided to make a general board using an ESP-WROOM-32 chip, for that the circuit provided by Neil in “embedded programming” was used as a basis.

  • ESP32
    • ESP32-WROOM-32
      • hello.ESP32-WROOM board components traces holes interior
        • echo.ino video ring.ino
        • Python video

Image13 - Board and components

For this, the components were first selected, and the schematic was done in the Proteus ISIS interface.

Image13 - Proteus schematic

Then, having done the schematic, the next step is to create the board design, this time, to facilitate the welding, it was chosen to use a 0.5mm separation between tracks to then create the SVG file to be used later in the mod.

Image14 - Design Layout

BOM (Bill of material):

  • 1x 30-pin Arduino female connectors (BRL 9.56)
  • 1x ESP-WROOM-32 chip (BRL 28.40)
  • 1x 3v3 Voltage Regulator (BRL 1.28)
  • 1x 0.1uF SMD capacitor (BRL 0.95)
  • 1x 1uF SMD capacitor (BRL 0.95)
  • 1x 10uF SMD capacitor (BRL 0.95)
  • 1x 10k ohm resistor (BRL 0.05)
  • 1x touch key (BRL 0.11)
  • 1x 3-state key (BRL 4.90)

Once the design was done, the RML files were created to be used in the Monofab SRM-20 machine and produce the desired board.

Image15 - Edge RML file

Image16 -Holes RML file

Image17 - Traces RML file

Then I prepared the PCB in the SRM machine and soldered the components

Image18 - PCB soldered

With that, the board was tested directly in the activity:

Video02 – Test with the ESP new PCB

Conclusion

This week was possible to learn a lot about network using ESP now.

In the future I will try other network protocols.

  • All the programming files of this week assignment can be find in the repository

Files