<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Lesson 4.2. IO Ports. Switch fire]]></title><description><![CDATA[<p dir="auto"><strong>Step 1. Go to the folder Arduino-ESP32-IDE and open the app arduino.exe (Fig. 1);</strong></p>
<p dir="auto"><img src="https://pp.userapi.com/c841632/v841632464/47868/W_NfydPVOGQ.jpg" alt="alt text" class=" img-fluid img-markdown" /><br />
Figure 1. The archive with the Arduino IDE is extracted to the folder</p>
<p dir="auto"><strong>Step 2. Select New on the File menu  (Fig. 1.1);</strong></p>
<p dir="auto"><img src="https://pp.userapi.com/c841632/v841632464/47857/qZn_RYchMvg.jpg" alt="alt text" class=" img-fluid img-markdown" /><br />
Figure 1.1. Create a new sketch</p>
<p dir="auto"><strong>Step 3. Select Include Library, M5Stack in the Sketch menu (Fig. 1.2);</strong></p>
<p dir="auto"><img src="https://pp.userapi.com/c841632/v841632464/4785f/Vvd4uby3tlM.jpg" alt="alt text" class=" img-fluid img-markdown" /><br />
Figure 1.2. Connection library M5Stack</p>
<p dir="auto"><img src="https://pp.userapi.com/c841632/v841632464/47884/oxXiqrtXCTU.jpg" alt="alt text" class=" img-fluid img-markdown" /><br />
Figure 2. The view from the top. Bus connector input/output</p>
<p dir="auto"><img src="https://pp.userapi.com/c841632/v841632464/47872/0NKFCg4ByNc.jpg" alt="alt text" class=" img-fluid img-markdown" /><br />
Figure 2.1. The view from the back side. Stickers with captions ports</p>
<p dir="auto"><strong>Step 4. Add to the beginning of system functions void setup() function call M5.begin();<br />
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.<br />
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);</strong></p>
<p dir="auto"><img src="https://pp.userapi.com/c841632/v841632464/4787a/9bQ2dfaOUg8.jpg" alt="alt text" class=" img-fluid img-markdown" /><br />
Figure 2.2 an example of the Correct preparation of the sketch</p>
<p dir="auto"><strong>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 <a href="https://arduino.cc/reference/en" target="_blank" rel="noopener noreferrer nofollow ugc">link</a></strong></p>
<p dir="auto">List 1. Functions for working with digital port</p>
<ul>
<li><strong>digitalRead(uint8_t pin);</strong> Retrieves a Boolean value of the digital signal on port pin</li>
<li><strong>digitalWrite(uint8_t pin, uint8_t value);</strong> Sets the logical value of the signal value to a digital port pin</li>
<li><strong>pinMode(uint8_t pin, uint8_t dir);</strong> Sets the operating mode of the port pin to input or output data dir</li>
</ul>
<p dir="auto"><strong>Step 7. Write a simple switch to led (Fig. 3);</strong></p>
<p dir="auto"><img src="https://pp.userapi.com/c841632/v841632464/4788c/1AOYuz70bMw.jpg" alt="alt text" class=" img-fluid img-markdown" /><br />
Figure 3. Code breaker for the led</p>
<p dir="auto"><strong>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);</strong></p>
<p dir="auto"><img src="https://pp.userapi.com/c841632/v841632464/478a0/NCsOo2qytCg.jpg" alt="alt text" class=" img-fluid img-markdown" /><br />
Figure 4. The led, resistor and M5Stack</p>
<p dir="auto"><img src="https://pp.userapi.com/c841632/v841632464/47896/9bacD6MfeB8.jpg" alt="alt text" class=" img-fluid img-markdown" /><br />
Figure 4.1. Cable</p>
<p dir="auto"><strong>Step 7. Build the scheme according to figure 5;</strong></p>
<p dir="auto"><img src="https://pp.userapi.com/c841632/v841632464/478aa/UtvdubiRxK8.jpg" alt="alt text" class=" img-fluid img-markdown" /><br />
Figure 5. Connect the led 21 to the contact</p>
<p dir="auto"><strong>Step 8. Click the Upload button (Fig. 6) to flash the device;</strong></p>
<p dir="auto"><img src="https://pp.userapi.com/c841632/v841632464/478b1/7lR-JfFsO0g.jpg" alt="alt text" class=" img-fluid img-markdown" /><br />
Figure 6. Download the firmware to the device</p>
<p dir="auto"><strong>Step 9. When the device firmware is completed, press the A button and watch the led (Fig. 7) :)</strong></p>
<p dir="auto"><img src="https://pp.userapi.com/c841632/v841632464/478bb/g7u-XfAr6yI.jpg" alt="alt text" class=" img-fluid img-markdown" /><br />
Figure 7. The control led on the digital port using the built-in buttons</p>
]]></description><link>https://community.m5stack.com/topic/50/lesson-4-2-io-ports-switch-fire</link><generator>RSS for Node</generator><lastBuildDate>Sun, 17 May 2026 14:42:53 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/50.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 13 Dec 2017 07:01:44 GMT</pubDate><ttl>60</ttl></channel></rss>