Remote

Function Description

Remote control M5Stack via devices such as mobile phone or computer.

  • Set Title Set a title name of the control page.

  • Remote qrcode show in x y size Set the location and size of the local QR code display.

  • Add Remote Switch Button index Remote switch button control (0 or 1), each time the button is clicked, the program in Block is executed once.

  • Add Remote Button index Remote button control, each time the button is clicked, the program in Block is executed once.

  • Add Remote Slider Slider control (click the gear button on the block to add a variable before use, and pass the variable to the integer (from 0 to 100).

  • Add Remote Label index interval Display information, you can choose some built-in label types, or enter custom text.

Instructions

Add a QR code to generate a Block into the program, add a Remote Button and Slider to control RGB Bar,at the same time, display the temperature through ENV Unit.

ESP-NOW

Function Description

ESP-NOW is a short-range, low-power communication protocol that enables multiple devices to communicate without Wi-Fi. This protocol is similar to the low-power 2.4GHz wireless connection found in wireless mice—devices are paired before communicating. After pairing, the connections between devices are continuous, peer-to-peer, and do not require a handshake protocol.

  • Get mac addr Get the mac address of this machine.

  • Add peer ff as id Add the specified mac address and set it to id

  • Set pmk Set the pairing key

  • Broadcast data Broadcast specified data

  • Receive mac_addr data Receive data, get the sender's mac address and the data content carried

  • After send message flag Send a callback function, automatically execute the callback function after executing the send message, and return whether the flag bit flag is successfully sent. The success is True and the failure is False.

  • Send message id with data Send data to the device with the specified id.

Instructions

Receiver

Display the local mac address on the screen, use the data receiving block and create two variables for receiving the sender's address and data content. The data is processed inside the receiving block function for display or judgment and other operations. For example, the following program controls the LED light switch by judging whether the received data is "1".

__Note: The created variable name is not allowed to be consistent with the parameter name, ie variables with the names "addr" and "data" are not allowed to be used for data acquisition __

Sender

Add the mac address of the receiving device, fill in the sent data content in the sending program, select the id of the receiving device. Use the button program to control the data transmission. Using the callback function can help us determine whether the data is successfully sent from the machine. We need to use a variable to get its return result.

__Note: The created variable name is not allowed to be consistent with the parameter name, ie variables with the name "flag" are not allowed to be used for data acquisition __

Complete the program editing, respectively run the receiver and transmitter programs, you can achieve ESP-NOW short-range wireless communication.

Note: When running ESP-NOW, if the communication devices are connected to the same WiFi network, there is no need to configure the communication channel, and the communication can be normal. Otherwise, please configure the communication channel in the program and download the program to the device for runinng.

MQTT communication

What is MQTT?

MQTT (Message Queuing Telemetry Transport) is a "lightweight" communication protocol based on publish/subscribe (publish/subscribe) mode.

The protocol was built on the TCP/IP protocol and was released by IBM in 1999.

The biggest advantage of MQTT is that it can provide real-time and reliable message service for connecting remote devices with very little code and limited bandwidth.

As a low-overhead, low-bandwidth instant messaging protocol, it has a wide range of applications in the Internet of Things, small devices, and mobile applications.

UIFlow and MQTT

In UIFlow, we can use MQTT function to realize communication and interaction between two or more COREs, thus achieving powerful remote control functions.

MQTT server

  • Select MQTT Service

To use the MQTT protocol for data interaction, you need server support. There are many third-party server platforms to choose from. The platform we demonstrate here is CloudMQTT.

When you have created service support on the platform, you will get some configuration information, such as server address, username, password, etc., which will be used in UIFlow's MQTT block.

  • MQTT fuction

In the advanced functions of UIFlow, you can find the MQTT function block. We can simply understand the MQTT protocol as two links, "Publish" and "Subscribe".

When the publisher posts a message, the subscriber will get this information to enable communication between devices

Initialization procedure

  • MQTT configuration block

Add an MQTT configuration block and connect to the Setup block

  • information to fill in

Fill in the server information on your personal or third-party server platform to prepare for the next connection

attention

  • When you have multiple devices at the same time, the ID name (the ID below is "M5stack") is not allowed to be duplicated with other options in the configuration information, and it is not allowed to duplicate the IDs of other devices. At the same time, the same server In the device with the same ID name, only one online is allowed.
  • MQTT Start

Add a Start block below the MQTT configuration block, which means that it will start running after the configuration information.

Publish

Function Description

Publish refers to the link in the communication to publish data, including two parts for the content of the publication "topic", "content" (msg)

  • Publish "topic"

Set a publishing theme, when other devices want to get the content information under the theme, you need to subscribe to the matching theme name

  • Publish "Content" (msg)

Set content information to be published

Instructions

When the program runs to the Publish release block, the message is released. example:

When the A button is pressed, a message is posted (the subject is "RGB" and the content is "open")

When the B button is pressed, a message is posted (the subject is "RGB" and the content is "close")

Subscribe

Function Description

Subscribe subscription refers to the process of receiving data in the communication. When the publisher publishes the information, the subscriber will automatically receive the subscribed topic (message), message content (msg)

  • Subscribe "topic"

Set the topic to subscribe to

  • Get topic data "content" (msg)

Get the message content under this subscription

Instructions

Add a Subscribe block, fill in the topic to be subscribed, use the Get topic data block to get, and process the analysis, for example:

When an "open" is obtained from Publish, the RGB bar is lit, and when "close" is obtained, the RGB bar is extinguished.

Use Cases

Implementation function

Use a CORE to program a simple use case to verify functionality, it’s not inly a publisher (Publish), but a subscriber (Subscribe) as well

  • complete program

Instructions

When the A button is pressed, a message is posted (the subject is "RGB", the content is "open"), and the RGB bar lights up.

When the B button is pressed, a message is posted (the subject is "RGB", the content is "close"), and the RGB bar is extinguished.

WiFi

Function Description

Wifi network settings.

  • wifi connect Establish a wifi connection.

  • wifi reconnect If wifi is not connected, reconnect the connection.

  • wifi is connect If wifi access returns true else ruturns false.

  • Connect to Wi-Fi SSID PASSWORD Connect with ssid and password.

Instructions

Establish a wifi connection with ssid and password.

P2P

  • P2P Send To APIKey Msg Establish a point-to-point connection based on mqtt,Remote with other M5Stack and you should input the APIkey and Message to send.

  • P2P Read Establish a point-to-point connection,Read the Message from other M5Stacks

Instructions

Establish a point-to-point connection to the remote host and send a message from other M5Stacks.

SDCard

Function Description

SD card read and write operations

  • open sdcard file mode Open the specified file and perform a read or write operation. This file must exist in the r and r+ states, otherwise an error is reported. The a, w, and w+ modes are automatically created if no files exist.

  • file read all Read all the bytes of the file

  • file read bytes Read the given number of bytes

  • file read line Read a line of content

  • file write Write bytes to the file

  • file set seek Set the offset position of the read

  • file get seek Get the current offset position

  • sdcard listdir List the specified catalog file

  • file mkdir Set the offset position of the read

  • sdcard remove Delete specified file

  • sdcard rmdir Delete the specified directory

  • sdcard rename File rename

Instructions

Create a test folder, create a file named TEST.text, write helloM5Stack, and read M5Stack

Easy IO

Function Description

I/O pin configuration.

  • analog read pin Read pin analog value

  • analog write pin duty Set duty cycle to the specified pin

  • digital read Value Read pin digital value

  • digital toggle pin Toggle pin value

  • map from low from high to low to high Map values to a range proportionally

Instructions

Get the temperature value of the sensor to map the temperature to 0-100.

PIN

Function Description

Pin custom configuration

  • Init Pin mode Pull Set pin mode

  • set HIGH Set the pin high level

  • set LOW Set the pin low level

  • Get Value Get the value of pin

  • Set Value Set the value of pin

Instructions

Set pin 5 pull-up output high level

PWM

Function Description

PWM function setting

  • Init in Pin freq duty use timer Set channel pin frequency, duty cycle, and timer

  • set freq to Change frequency

  • set duty to Change duty cycle

  • Pause Disable PWM function

  • Resume Re-enable PWM function

Instructions

Use the zero timer to set the PWM0 pin 25 frequency 500 duty cycle 50

ADC

Function Description

Analog to digital conversion

  • Init in Pin Set the sampling channel pin

  • set width Set the sampling width

  • set atten Set attenuation on the input of the ADC

    • ADC.ATTN_0DB: 0dB attenuation, gives a maximum input voltage of 1.00v - this is the default configuration
    • ADC.ATTN_2_5DB: 2.5dB attenuation, gives a maximum input voltage of approximately 1.34v
    • ADC.ATTN_6DB: 6dB attenuation, gives a maximum input voltage of approximately 2.00v
    • ADC.ATTN_11DB: 11dB attenuation, gives a maximum input voltage of approximately 3.6v
  • read value read ADC

Instructions

Sampling at 36 pins using the adc0 channel, reading the value

DAC

Function Description

Digital to analog conversion

  • Init in Pin Set conversion channel

  • write value Write DA value

  • beep with freq duration scale Set the buzzer frequency, time and range

  • waveform with freq type duration scale offset invert Set the output waveform frequency amplitude offset

  • stop wave stop output

  • set freq set frequency

Instructions

Output waveform on 25-pin using dac0 channel

UART

Function Description

Serial data transmission and reception

  • set tx rx baud use uart Set serial port pin and baud rate

  • read all Read all data of serial port at one time

  • read characters Read the specified amount of data

  • read line Read data before \n

  • remain cache Read buffer remaining data

  • write number in Write numbers to the serial port

  • write a line in Write a line to the serial port

  • write in Write a string to the serial port

  • write raw date in Write raw string data(E.g b"\xff\xab") to the serial port

Instructions

Read serial data and send data to serial port

I2C

Function Description

set I2C port

  • Master slave addr Set the Master interface and slave address

  • Set at sda scl slave addr Custom SDA SCL and slave address

  • Write reg one byte Write 1 byte of data to the register address

  • Write reg one short With encode Big endian mode writes two bytes to the register address

  • Read reg one byte Read a byte from the register address

  • Read reg one short with decode Big endian mode reads two bytes from the register address

  • Read reg Read byte Read several bytes from the register address

  • Read byte Read byte

  • Available I2C address in list Check if the I2C address is available

  • Scan I2C device Scanning I2C devices

Instructions

Read data from I2C

  • Write mem data reg date type Writes the specified data type to the register address

  • Write data type Write specified data to bus

  • Read mem data reg date type Writes the specified data type to the register address

  • Read data num type Write specified data from bus

  • In data get index Extract a data from a list

Write data to I2C

Read date from I2C

Execute

Function Description

Execution of external programs

Instructions

import Library

SDCard

Function Description

SD card read and write operations

  • open sdcard file mode Open the specified file and perform a read or write operation. This file must exist in the r and r+ states, otherwise an error is reported. The a, w, and w+ modes are automatically created if no files exist.

  • file read all Read all the bytes of the file

  • file read bytes Read the given number of bytes

  • file read line Read a line of content

  • file write Write bytes to the file

  • file set seek Set the offset position of the read

  • file get seek Get the current offset position

  • sdcard listdir List the specified catalog file

  • file mkdir Set the offset position of the read

  • sdcard remove Delete specified file

  • sdcard rmdir Delete the specified directory

  • sdcard rename File rename

Instructions

Create a test folder, create a file named TEST.text, write helloM5Stack, and read M5Stack

Http

Function Description

Send HTTP protocol

  • Http Request Create an Http access request by GET, POST, DELET, PUT, PATCH, the URL is the full HTTP connection address, create the header Headers, Data data in the form of a dictionary, send successfully to execute Success, and send failure to execute Fail.

  • Get Status Code Return status code

  • Get Data Return request data

Instructions

Send a GET request to Baidu, return data and print

EEPROM

Function Description

Save the important data in the form of key-value pairs to the NVS partition to prevent data loss after shutdown (to prevent program processing from being blocked, the data is actually written in 5 seconds later), please do not write the data to the NVS partition repeatedly, otherwise it will affect the flash life and cause damage

  • EEPROM write key value Create a key-value pair to save data to EEPROM.

  • EEPROM read key Read out the data content corresponding to the keyword.

  • EEPROM read key to int Read out the data content corresponding to the keyword and convert Str to the Int.

Instructions

Create key-value to write to NVS partition and read data.

Modbus Master

Function Description

Create a Modbus Master, encapsulate the data with Modbus protocol, send the data to the Slave through serial communication, and the data value range is 0-65535.

  • Init baud tx rx in uart crc Initialize the communication interface, and specify the Baudrate, TX, RX, Serial-port and CRC check with BIG or LITTLE mode

  • Send addr function reg addr value Send the packet to the specified Slave address. addr is the Slave address, function is the function number, reg_addr is the register address, and value is the user data.

  • Rx buffer cache number Number of bytes read from buffer

  • Read rx data Read the received packets, suitable for custom processing

  • Get rx addr function data Receive packets by callback, receive parameters by variables, and update parameters automatically

Instructions

Main functions: (used together with the following Slave code) connect two M5Stack Fire, establish the Master and Slave through Modbus, the Master press the A / B button to send data, and receive the data packet returned from the Slave (receive function code 2). There are two ways to process the data packet:

1.The data package returned from the Slave is processed by loop-cycle and displayed on the screen.

According to the definition of Modbus protocol, the data package returned from the Slave contains at least 3 valid data (address, function code, data), so more than 3 bytes is regarded as valid data, and the data is parsed through the List-block.

  1. Handle the returned packets through the callback. When using the callback function, do not use loop-cycle, otherwise the callback will be blocked.

Set three variables to receive the address, function number and data returned from the Slave.

Modbus Slave

Function Description

Create a Modbus Slave, receive the data package encapsulated by Modbus, communicate with the Master through the serial interface, and the data value range is 0-65535.

  • Init addr baud tx rx in uart Initialize the communication interface, specify the Slave address, Baudrate, TX, RX and Serial-port,CRC is verified as BIG mode.

  • Init function reg addr value method Define Modbus data operation format, function is function number, reg_addr is register address, value is initial default value, method is read or write operation mode

  • Update function reg addr value Update the data in the specified register address according to the function number.

  • Get rx buffer data Read buffer data

  • Get reg write function reg addr value Obtain the data packets (function number, register address, data) sent by the Master by callback, and receive them by variables.

  • Get function reg addr value Get the content of the specified Master data package, and specify it by function number and register address.

  • send addr function reg addr value Respond to the content of the packet sent to the Master after receiving the Master packet.

Instructions

Main functions: (used together with the Master code above) connect two M5Stack Fire, and establish the Master and Slave through Modbus. The Slave receives the data package of address code 1, function number 1 and register address 1, and then parses the data. if the data is 1 to light the LED bar, and if the data is 2 to turn off the LED Bar, at the same time, the Slave updates its own corresponding data in real time and responds to the Master (through function code 2). The Slave will also report the data to theMaster in real time through pressed A / B button. There are two ways to achieve this:

1.Process the data package returned from the Slave through loop-cycle, update the data on the screen in time and respond.

Receive the specified packet and analyze the data, judge the data to respond and report to the Master (via function number 2), press A / B button to respond to itself, and send the packet report status to the Master (via function number 2)

  1. Through the callback to process the returned data, specify that the packet should add judgment processing to "fun" and "reg_addr". When using the callback function, loop should not be used, otherwise the callback will be blocked.

Set three variables to receive the address, function number and data sent by the Master, use the List-block to obtain data, judge and process the data, and report the status to the Master through (function number 2). Press the A / B button manually to report to the Master (via function number 2) while responding.

BLE UART(support M5Stack Fire only)

Function Description

Establish Bluetooth connection and enable Bluetooth passthrough service.

  • Init ble uart name Initialize settings, configure Bluetooth device name.

  • BLE UART Writre Send data using BLE UART.

  • BLE UART remain cache Check the number of bytes of BLE UART data.

  • BLE UART read all Read all data in BLE UART cache.

  • BLE UART read characters Read n data in BLE UART cache.

Instructions

Establish Bluetooth passthrough connection and send on / off control LED.

Blynk(support M5Stack Fire only)

Connect with Blynk server, use BLE to connect Blynk App, and realize M5Stack Fire control on mobilephone

  • Init blynk name token type BLE Initialize Blynk configuration, input device name and token of App.

  • Virtual write number data Write data to Virtual port number

  • Notify message Send system message notification to App

  • Tweet message Send message notifications to twitter client

  • On event write get number message Receive the data of the specified virtual port to be written from the app, if not specified, set to V*

  • On event read get number Read the virtual port number specified by the App

  • On event Callback function when Bluetooth is connected / disconnected

Instructions

Use Blynk to control the color and brightness of the RGB light bar of M5StackFire and display it on the screen in real-time

1.Download the blynk App and register your account. You can choose to use the official blynk server or build your own server. Here we provide a free server(120.24.58.30:9443) for you to test.

2.Use the email to register the blynk account, and log in with the account after successful registration.

3.Create a new project, select ESP32 Dev board, select BLE mode, and record the Auth Token.

4.Follow the steps below to add components, BLE connections are required.

Echo STT

Send speech through ATOM Echo to obtain the converted text

  • Init echo speech recognition token Input token and initialize speech service.

  • Recv echo data Callback function receives data returned by speech recognition.

  • Get recv text Receive data from speech recognition.

USAGE

ATOM Echo flash related ECHO STT firmware and controls led through speech recognition by M5StackFire.

Pin Servo

Control Servo

  • Init Pin, freq, min, max,angle range Initial setting of the servo, Pin=servo pin, freq=frequency of the servo signal, min=minimum pulse width, max=maximum pulse width, angle angle=angle range of the servo

  • rotate to degree Servo rotation angle

  • write us High level time

USAGE

Control the servo to switch between 0° and 90°

NTP

Get time via NTP web server

  • Init ntptime with host and timezone Set NTP server and time zone

  • Get timestamp Get Unix timestamp

  • Get date format with - Get the date, the display format is separator "-"

  • Get time format with - Get time, the display format is separator "-"

  • Get date format with - and time format with : Display date and time, date format is separator "-", time format is separator ":"

  • Get year Get Year

  • Get month Get Month

  • Get day Get Day

  • Get weekday Get Weekday

  • Get hour Get Hour

  • Get minute Get Minute

  • Get second Get Second

USAGE

Display the Unix timestamp and the current time and date (Note: When the download program runs offline, you need to add a WiFi connection program before the NTP initialization program to make the device connect to the network.)