Lesson 4.2. IO Ports. Switch fire



  • Step 1. Go to the folder Arduino-ESP32-IDE and open the app arduino.exe (Fig. 1);

    alt text
    Figure 1. The archive with the Arduino IDE is extracted to the folder

    Step 2. Select New on the File menu (Fig. 1.1);

    alt text
    Figure 1.1. Create a new sketch

    Step 3. Select Include Library, M5Stack in the Sketch menu (Fig. 1.2);

    alt text
    Figure 1.2. Connection library M5Stack

    alt text
    Figure 2. The view from the top. Bus connector input/output

    alt text
    Figure 2.1. The view from the back side. Stickers with captions ports

    Step 4. Add to the beginning of system functions void setup() function call M5.begin();
    Next, set the working mode of the port to input (INPUT) or output (OUTPUT) data, by calling functions pinMode(nomernogo, OUTPUT); You can use an integer variable as the contact number.
    Add to the end system functions void loop() function call M5.update (); it is required for correct operation of the device with built-in buttons (Fig. 2.2);

    alt text
    Figure 2.2 an example of the Correct preparation of the sketch

    Step 5. To work with digital port you can use the standard functions Digital I/O in the Arduino IDE, which is available in list1 and the link

    List 1. Functions for working with digital port

    • digitalRead(uint8_t pin); Retrieves a Boolean value of the digital signal on port pin
    • digitalWrite(uint8_t pin, uint8_t value); Sets the logical value of the signal value to a digital port pin
    • pinMode(uint8_t pin, uint8_t dir); Sets the operating mode of the port pin to input or output data dir

    Step 7. Write a simple switch to led (Fig. 3);

    alt text
    Figure 3. Code breaker for the led

    Step 6. Prepare the led To 5 V and a resistor of 100 Ω (figure 4) and the cable, which is included in the kit (Fig. 4.1);

    alt text
    Figure 4. The led, resistor and M5Stack

    alt text
    Figure 4.1. Cable

    Step 7. Build the scheme according to figure 5;

    alt text
    Figure 5. Connect the led 21 to the contact

    Step 8. Click the Upload button (Fig. 6) to flash the device;

    alt text
    Figure 6. Download the firmware to the device

    Step 9. When the device firmware is completed, press the A button and watch the led (Fig. 7) :)

    alt text
    Figure 7. The control led on the digital port using the built-in buttons