In the first part of this miniseries on getting started with the M5GO IOT Starter kit found here: https://www.hackster.io/AJB2K3/m5go-iot-starter-kit-part-1-8ef6ae
I mentioned that the kits come with a selection of Units which can be input or output devices. In this part I will show you how to use them with UIFlow2.
Introduction to M5Stack UnitsM5Stack units use the four wire system created by seeedstudio that use the PH2.0 four pin connectors. Units are normally separated into four categories depending on the colour of the connector found on them.
- Red Connector units are I2C devices,
- Black Connector units are analog devices,
- Blue Connector units are UART devices,
- White Connector units normally generic dives like power adapters, and connection adapters.
M5GO kits don't have UART devices but they have a selection of analog or I2C devices with a three way adapter.
ENV UnitAll Kits come with an I2C ENV sensor unit but the different versions of the kit have different version of the ENV sensor. While externally the ENV Sensors look the same, the big difference is with the sensor components used inside. If you look on the M5Stack website here: https://shop.m5stack.com/pages/search-results-page?q=ENV you will find three different units available but over there years there have been five version in total.
The difference in components used is as follows:
- ENV Unit - Used the DHT12 & BMP280 Sensors,
- ENV II Unit - Used the SHT30 & BMP280 Sensors,
- ENVIII Unit - Used the SHT30 & QMP6988 Sensors,
- ENV IV Unit - Used the SHT40 & BMP280 Sensors,
- ENV IV Pro - Used the BME688 Sensor.
In UIFLow2 the ENV, ENVII, ENVIII and ENV IV are controlled with the same three basic blocks:
However, due to the additional internal sensors, the ENV IV Pro has its own set of programming blocks:
The simplest example to build in UIFlow 2 for reading the ENV sensors can be found in UIFlow2's project zone with this link: https://uiflow2.m5stack.com/?pkey=c1d49dfef3cd42a9965258b4cca36db7
In the Above example I have created three labels and set them to display the text Temperature, Pressure and humidity with the values retrieved from the sensor. The above example was created for the ENV IV unit but by clicking on the dropdown arrow next to env4_0 the unit can be changed to one of the other ENV units.
In the following example I used an ENV IV unit for an Heating control monitor for a simple Home heating system.
On the hardware I have the ENV sensor connector to the RED I2C port and a relay connected to Port B. Apparently the Central heating input on my system is around 6 amps and so the relay's rating is high enough.
Angle UnitThe Angle Unit is an analog (PortB) device with a rotation range of only 270 degrees. The angle unit has two blocks for communicating that return a floating voltage value between 0.142 V and 3.16 V or a raw value between 0 and 65535.
The M5Stack range only contains a single version or a eight way version of the angle unit (that works on I2C)
The single Angle using uses a simple resistor divider circuit consisting of a fixed 10KΩ resistor and a variable 10KΩ Potentiometer or Variable resistor to control the voltage being read by the M5GO's input port (Port B/Black). Whereas, the 8 Angle uses the same divider but connected to a chip do spit the readings out from the eight channels over I2C.
The following example reads the voltage from the angle unit and display it on the screen of the M5GO:
And this example show the value of 0 to 65535 on the display
Because the Angle unit uses a potentiometer it has an actual rotation angle of 270 degrees and so a little bit of maths is needed to convert the raw value of 65535 to 270 degrees. The following example is uses maths blocks to roughly convert the raw value into degrees.
Shasha Liu Has provided a great example on using the single Angle using as a digital protractor in the hackster project found here: https://www.hackster.io/shasha-liu/diy-protractor-with-m5stickc-e67e88
The PIR Motion Sensor unit is a basic Passive Inferred Sensor in a unit form factor allowing for easy mounting to lego pieces or directly to a flat service.
As the PIR Motion Sensor unit is a black Port B unit, it cannot be connected to the same Port B as other PortB devices like the Angle unit. The PIR Motion Sensor unit has the following function available to it in UIFlow 2.0.
The get pir_0 status is used to return a simple true or false when the sensor detects someone as in the following example:
The enable irq and disable irq blocks are used to configure the ports input pin as an interrupt pin allowing the PIR Motion Sensor unit's code to interrupt the normal flow of the program. and the when PIR was loop block is used to hold the code that need to be run only when a PIR Motion Sensor unit is activated.
The following example plays an annoying sound through the M5GO's speaker when it detects the presence of a human.
Thats it for Part 1 as this part has got rather long. Sorry for the delay with this as real life keeps getting in the way. I still have some work I want to do to this part but as far as I'm concerned, it is complete.
Contact Me.If you find this useful then there is more crossover guides coming. You can drop a Message in Hackster.io message box below of find me via the following links:
https://twitter.com/Cpt_J_Purcell
https://bsky.app/profile/jamespurcell.bsky.social
On Discord (if I ever work out how to share the profile!)https://mastodonapp.uk/@AdamBryant
And on the M5Stack Facebook group and community forum.
If you have some spare change you can now buy me a tea @ https://bmc.link/ajb2k35
Comments