<?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 21. UNITS. EARTH]]></title><description><![CDATA[<h3>The purpose of this lesson</h3>
<p dir="auto">Hi! Today we will get acquainted with the earth blocks and learn how to determine the soil moisture in a pot with a plant (figure 1).</p>
<p dir="auto"><img src="https://pp.userapi.com/c847020/v847020151/17307d/PK8qsB5Av20.jpg" alt="" class=" img-fluid img-markdown" /></p>
<p dir="auto">Figure 1</p>
<p dir="auto">This lesson will teach you how to obtain and process analog soil moisture data from a sensor.</p>
<h3>Short info</h3>
<ul>
<li>Purpose: used to determine soil moisture</li>
<li>Scope: agriculture and science</li>
<li>Connection interface: I / O (Groove Port b connector)</li>
<li>Supply voltage: 5 V</li>
<li>Compatibility: M5 FIRE</li>
<li>Form factor: LEGO compatible</li>
</ul>
<h3>Brief overview</h3>
<p dir="auto">EARTH-one of the large family of additional modules (UNITS), designed primarily for M5 Fire. This module is supplied in a plastic box. The kit includes an excellent cable (15 cm) with Groove plugs (figure 2). On the front side of the sensor there is a sticker with the name of the module and the designation of contacts. Interestingly, the sensor can operate in two modes: analog and digital.</p>
<p dir="auto"><img src="https://pp.userapi.com/c847020/v847020151/173086/jlIhFTSlFVI.jpg" alt="" class=" img-fluid img-markdown" /></p>
<p dir="auto">Figure 2</p>
<p dir="auto">In order to set the trigger threshold for the digital output, there is a trimmer resistor motor on the back of the sensor (figure 3), which can be rotated with a screwdriver.</p>
<p dir="auto"><img src="https://pp.userapi.com/c847020/v847020151/173090/ZHGO9vV1wzM.jpg" alt="" class=" img-fluid img-markdown" /></p>
<p dir="auto">Figure 3</p>
<p dir="auto">Overall dimensions of the sensor are ridiculous, and the problems with installation is not (figure 4) :)</p>
<p dir="auto"><img src="https://pp.userapi.com/c847020/v847020151/17309a/JpAzWTRajxM.jpg" alt="" class=" img-fluid img-markdown" /></p>
<p dir="auto">Figure 4</p>
<p dir="auto">Connect the sensor directly to the above M5 port using the supplied cable (figure 5). The sensor can be mounted with a fork in the ground to the black layer.</p>
<p dir="auto"><img src="https://pp.userapi.com/c847020/v847020151/1730a4/bOw8fI42iTM.jpg" alt="" class=" img-fluid img-markdown" /></p>
<p dir="auto">Figure 5</p>
<h2>Let's start!</h2>
<h3>Blockly (<a href="http://flow.m5stack.com" target="_blank" rel="noopener noreferrer nofollow ugc">UI Flow</a>)</h3>
<p dir="auto">First of all, we need to make sure that the Flow UI is connected to the M5. If You see the words "Disconneted", then repeatedly press the arrows (1) as long as the label (2) does not change to "Connected". Great! Now we can add UNITS by clicking on plus (3) (figure 6).</p>
<p dir="auto"><img src="https://pp.userapi.com/c847020/v847020151/1730c1/nzbUMgRky8s.jpg" alt="" class=" img-fluid img-markdown" /></p>
<p dir="auto">Figure 6</p>
<p dir="auto">OK, now check the box next to EARTH (1), then click OK (2) (figure 6.1).</p>
<p dir="auto"><img src="https://pp.userapi.com/c847020/v847020151/1730ad/VGi4XTgzDbA.jpg" alt="" class=" img-fluid img-markdown" /></p>
<p dir="auto">Figure 6.1</p>
<p dir="auto">In order to get analog data from the module, you need to add The corresponding blockly puzzle. Click UNITS (1), then Earth (2), then drag the Analog Value (3) puzzle to the workspace (figure 6.2).</p>
<p dir="auto"><img src="https://pp.userapi.com/c847020/v847020151/1730b7/npYL4TDyIsk.jpg" alt="" class=" img-fluid img-markdown" /></p>
<p dir="auto">Figure 6.2</p>
<p dir="auto">Wow! Now we want to change the image depending on the soil moisture. First, you need to download images from the Images archive.zip to the device. To do this, click on the Resource Manager icon (1) (figure 6.3).</p>
<p dir="auto"><img src="https://pp.userapi.com/c847020/v847020455/1710b7/GYp5nVpXUmg.jpg" alt="" class=" img-fluid img-markdown" /></p>
<p dir="auto">Figure 6.3</p>
<p dir="auto">Next, click the Add Image button (1) and load all four images one by one, then click Cancel (2) (figure 6.4). This completes the uploading of images to the device.</p>
<p dir="auto"><img src="https://pp.userapi.com/c847020/v847020455/1710c1/LADSBxMSFjQ.jpg" alt="" class=" img-fluid img-markdown" /></p>
<p dir="auto">Figure 6.4</p>
<p dir="auto">Drag the Image and drop it onto the virtual device display (1). Click on the image that appears, then the properties table opens. You must change the first four properties according to the picture number (2) (figure 6.5). Repeat this step for each image.</p>
<p dir="auto"><img src="https://pp.userapi.com/c847020/v847020455/1710f1/CBsU_HjlhD4.jpg" alt="" class=" img-fluid img-markdown" /></p>
<p dir="auto">Figure 6.5</p>
<p dir="auto">Good. Do not forget to convert the resulting value from the analog input from the float type to the integer type using the corresponding puzzle (figure 7).</p>
<p dir="auto"><img src="https://pp.userapi.com/c847020/v847020151/1730ca/Mt_oLZlmwPc.jpg" alt="" class=" img-fluid img-markdown" /></p>
<p dir="auto">Figure 7.</p>
<p dir="auto">The lesson is finished! :)</p>
<h3>MicroPython (<a href="http://flow.m5stack.com" target="_blank" rel="noopener noreferrer nofollow ugc">UI Flow</a>)</h3>
<pre><code>from m5stack import *
from m5ui import *
import units

clear_bg(0x111111)
earth0 = units.Earth(units.PORTB)


btnA = M5Button(name="ButtonA", text="ButtonA", visibility=False)
btnB = M5Button(name="ButtonB", text="ButtonB", visibility=False)
btnC = M5Button(name="ButtonC", text="ButtonC", visibility=False)
image0 = M5Img(20, 20, "res/0.jpg", True)
image1 = M5Img(20, 20, "res/1.jpg", True)
image2 = M5Img(20, 20, "res/2.jpg", True)
image3 = M5Img(20, 20, "res/3.jpg", True)

wet = None
percent = None
dry = None



while True:
  wet = int((earth0.a_read()))
  percent = wet * 100
  percent = percent / 1024
  wet = wet * 255
  wet = wet / 1024
  dry = 255 - wet
  rgb.set_all(int('0x%02x%02x%02x' % (round(min(100, max(0, dry)) * 2.55), round(min(100, max(0, dry)) * 2.55), round(min(100, max(0, wet)) * 2.55))))
  if percent &gt;= 50:
    image0.show()
  else:
    if percent &gt;= 30:
      image1.show()
    else:
      if percent &gt;= 20:
        image2.show()
      else:
        image3.show()
  wait(0.1)
  wait(0.001)
</code></pre>
<h3>C &amp; C++ (<a href="https://www.arduino.cc/en/Main/Software" target="_blank" rel="noopener noreferrer nofollow ugc">Arduino IDE</a>)</h3>
<p dir="auto">Example not yet written ^_^</p>
<h3>Downloads</h3>
<ol>
<li><a href="https://yadi.sk/d/pavvcKByDy1iyA" target="_blank" rel="noopener noreferrer nofollow ugc">Images</a></li>
</ol>
<h3>Demo</h3>
<ol>
<li><a href="https://youtu.be/II13VrG-BkU" target="_blank" rel="noopener noreferrer nofollow ugc">YouTube</a></li>
</ol>
]]></description><link>https://community.m5stack.com/topic/494/lesson-21-units-earth</link><generator>RSS for Node</generator><lastBuildDate>Tue, 12 May 2026 21:36:50 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/494.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 10 Jan 2019 09:51:08 GMT</pubDate><ttl>60</ttl></channel></rss>