add advanced mpy api

This commit is contained in:
Sean
2021-03-15 16:43:18 +08:00
parent ab2d17e5c9
commit 34db8593e7
8 changed files with 482 additions and 10 deletions
+1
View File
@@ -106,6 +106,7 @@ The power input interface is DC/9-24V, the motor drive current can reach 1.5A, a
## Related Link
- [DRV8825 Datasheet](https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/docs/datasheet/module/DRV8825_en.pdf)
- [GRBL-Firmware](https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/docs/GRBL13.2-Module-Arduino-Library.zip)
## PinMap
+8 -2
View File
@@ -4,8 +4,6 @@
<div class="product_pic"><img src="assets/img/product_pics/module/module_stepmotor_01.webp"> <img src="assets/img/product_pics/module/module_stepmotor_02.webp"></div>
<!-- <img src="assets/img/product_pics/module/module_stepmotor_04.webp" width="30%" height="30%"> -->
## Description
**STEPMOTOR** is used for stepper motor control. It is perfect for any motion project as it can drive up to 3 Stepper motors with **GRBL** control.
@@ -38,6 +36,14 @@ Integrated 3 DRV8825, a simple but very powerful board that can control one bipo
<td>Resources</td>
<td>Parameter</td>
</tr>
<tr>
<td>DC Interface</td>
<td>XT30</td>
</tr>
<tr>
<td>Motor Interface</td>
<td>HY2.0-4P</td>
</tr>
<tr>
<td>Net weight</td>
<td>24g</td>
+290
View File
@@ -0,0 +1,290 @@
# wifiCfg
>Use the API in the wifiCfg module to configure the device WiFi connection.
```clike
import wifiCfg
//Automatically connect to the saved WiFi, the screen displays the connection UI
wifiCfg.autoConnect(lcdShow=True)
//Connect to the specified WiFi
wifiCfg.doConnect(ssid, pwd)
//Connect to the specified WiFi and specify the connection timeout period
wifiCfg.connect(ssid, pwd, timeout, block=False)
//WiFi reconnect
wifiCfg.reconnect()
//Is it connected
print(wifiCfg.wlan_sta.isconnected())
```
# M5mqtt
>Use the API in the M5mqtt module to connect to the mqtt server and subscribe to publish message content.
-Connect to mqtt server
```clike
from m5mqtt import M5mqtt
//Create connection instance
m5mqtt = M5mqtt(
client_id,
server,
port=0,
user=None,
password=None,
keepalive=0,
ssl=False,
ssl_params=None
)
//Start connection
m5mqtt.start()
while True:
```
-Subscribe and publish news
```clike
//Subscribe news
def callback(topic_data):
print(topic_data)
m5mqtt.subscribe(topic, callback)
//release the news
m5mqtt.publish(topic, data)
```
-Other configurations
```clike
//Configure the client will message
m5mqtt.set_last_will(topic, msg)
//Disconnect
m5mqtt.deinit()
```
# ESP-NOW
>Using ESP-NOW technology to wirelessly transmit data to other ESP32 master control devices
```clike
import espnow
//initialization
espnow.init()
//Set the channel
//Get the local mac_addr
espnow.get_mac_addr()
//broadcast
espnow.broadcast(data='Hello')
//Set the peer list
espnow.add_peer(slave_mac_addr, id)
//send messages
espnow.send(id, data='World')
//Send message callback
def send_cb(flag):
if flag:
print('succeed')
else:
print('Failed')
espnow.send_cb(send_cb)
//Receive message callback
def recv_cb():
//retrieve data
sender_address, _, receive_data = espnow.recv_data(encoder='str')
espnow.recv_cb(recv_cb)
```
# HTTP
>Use the API in the HTTP module to send HTTP requests to the server to obtain data.
```clike
import urequests
//GET request
req = urequests.request(
method='GET',
url='http://api.m5stack.com/v1',
headers={'Content-Type':'text/html'}
)
//POST request
req = urequests.request(
method='POST',
url='http://api.m5stack.com/v1',
json={'KEY':'VALUE'},
headers={'Content-Type':'text/html'}
)
//Get the response body status code
print(req.status_code)
//Get the response body Reason-Phrase
print(req.reason)
//Get the native response body
print(req.content)
//Get response body string
print(req.text)
//Get response body JSON
print(req.json)
```
# NTP
>Get current time information through NTP server.
```clike
import ntptime
//Set up NTP server
//eg:
//ntp = ntptime.client(host='jp.pool.ntp.org', timezone=8)
//ntp = ntptime.client(host='sg.pool.ntp.org', timezone=8)
//ntp = ntptime.client(host='tw.pool.ntp.org', timezone=8)
//ntp = ntptime.client(host='hk.pool.ntp.org', timezone=8)
//ntp = ntptime.client(host='tw.pool.ntp.org', timezone=8)
//ntp = ntptime.client(host='hk.pool.ntp.org', timezone=8)
//ntp = ntptime.client(host='us.pool.ntp.org', timezone=8)
//ntp = ntptime.client(host='de.pool.ntp.org', timezone=8)
ntp = ntptime.client(host='cn.pool.ntp.org', timezone=8)
//Get the timestamp
ntp.getTimestamp()
//Format the date
ntp.formatDate('-')
//Format the time
ntp.formatTime('-')
//Format date & time
ntp.formatDatetime('-',':')
ntp.year()
ntp.month()
ntp.day()
ntp.hour()
ntp.minute()
ntp.second()
ntp.weekday()
```
# EEPROM
>Save data persistently through EEPROM.
```clike
import nvs
//data input
nvs.write_str(KEY, VALUE)
//Read data
nvs.read_str(KEY)
```
# UART
>Send and receive data via UART.
```clike
//Create a serial port instance
uart1 = machine.UART(1, tx=1, rx=3)
//Initialize the serial port
uart1.init(115200, bits=8, parity=None, stop=1)
//Is there any content in the cache?
uart1.any()
//Read the content in the buffer area
uart1.read()
//Write content to the serial port
uart1.write('Hello')
//Read/write case
while True:
if uart1.any():
print(uart1.read())
uart1.write('Hello')
```
# SD-Card
```clike
import os
//Read file
with open('/sd/FileName.*','r') as fs:
print(fs.read())
//Write file
with open('/sd/test.txt','w+') as fs:
fs.write('Hello World')
//File read and write mode
w is opened for writing,
w+ open in read-write mode
r open in read mode
r+ open in read-write mode
a Open in append mode
//Set the file cursor
fs.seek(0)
//View catalog
os.listdir('/sd/DirectoryPath')
//Determine whether the path is a file
os.stat('/sd/FilePath')[0] == 0x8000)
//Determine whether the path is a directory
os.stat('/sd/DirectoryPath')[0] == 0x4000)
//Determine whether the file exists in the specified directory
'FileName.*' in os.listdir('/sd/DirectoryPath')
```
+16 -1
View File
@@ -59,13 +59,28 @@ const unit = {
"id":"unit_api"
};
const advanced = {
'title':"Advanced",
'item':{
'WiFi':'#/en/mpy/advanced?id=wificfg',
'MQTT':'#/en/mpy/advanced?id=m5mqtt',
'ESP-NOW':'#/en/mpy/advanced?id=esp-now',
'HTTP':'#/en/mpy/advanced?id=http',
'NTP':'#/en/mpy/advanced?id=ntp',
'EEPROM':'#/en/mpy/advanced?id=eeprom',
'UART':'#/en/mpy/advanced?id=uart'
},
"id":"advanced_api"
};
var arduino_home_page = new Vue({
el:'#arduino_home_page',
data() {
return {
list: {
quickstart: quickstart,
unit: unit
unit: unit,
advanced: advanced
}
};
}
+1
View File
@@ -103,6 +103,7 @@
## 相关链接
- [DRV8825 Datasheet](https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/docs/datasheet/module/DRV8825_en.pdf)
- [GRBL-Firmware](https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/docs/GRBL13.2-Module-Arduino-Library.zip)
## 管脚映射
+8 -2
View File
@@ -4,8 +4,6 @@
<div class="product_pic"><img src="assets/img/product_pics/module/module_stepmotor_01.webp"><img src="assets/img/product_pics/module/module_stepmotor_02.webp"></div>
<!-- <img src="assets/img/product_pics/module/module_stepmotor_04.webp" width="30%" height="30%"> -->
## 描述
**STEPMOTOR** 是M5Stack堆叠模块系列中的一款,步进电机驱动模块.该模块能够通过 **GRBL** 库同时驱动3个步进电机.因此非常适合应用在运动控制项目.
@@ -37,6 +35,14 @@
<td>规格</td>
<td>参数</td>
</tr>
<tr>
<td>DC接口型号</td>
<td>XT30</td>
</tr>
<tr>
<td>电机接口型号</td>
<td>HY2.0-4P</td>
</tr>
<tr>
<td>净重</td>
<td>24g</td>
+142 -4
View File
@@ -3,12 +3,24 @@
>使用wifiCfg模块中的API, 配置设备WiFi连接。
```
```clike
import wifiCfg
//自动连接已经保存的WiFi
//自动连接已经保存的WiFi,屏幕显示连接UI
wifiCfg.autoConnect(lcdShow=True)
//连接指定的WiFi
wifiCfg.doConnect(ssid, pwd)
//连接指定的WiFi,并指定连接超时时间
wifiCfg.connect(ssid, pwd, timeout, block=False)
//WiFi重连
wifiCfg.reconnect()
//是否已经连接
print(wifiCfg.wlan_sta.isconnected())
```
# M5mqtt
@@ -73,7 +85,7 @@ m5mqtt.deinit()
>使用ESP-NOW技术,无线传输数据到其他ESP32主控设备
```
```clike
import espnow
//初始化
@@ -114,7 +126,7 @@ espnow.recv_cb(recv_cb)
>使用HTTP模块中的API, 向服务器发送HTTP请求,获取数据。
```
```clike
import urequests
//GET请求
@@ -149,4 +161,130 @@ print(req.json)
```
# NTP
>通过NTP服务器获取当前时间信息。
```clike
import ntptime
//设置NTP服务器
//eg:
//ntp = ntptime.client(host='jp.pool.ntp.org', timezone=8)
//ntp = ntptime.client(host='sg.pool.ntp.org', timezone=8)
//ntp = ntptime.client(host='tw.pool.ntp.org', timezone=8)
//ntp = ntptime.client(host='hk.pool.ntp.org', timezone=8)
//ntp = ntptime.client(host='tw.pool.ntp.org', timezone=8)
//ntp = ntptime.client(host='hk.pool.ntp.org', timezone=8)
//ntp = ntptime.client(host='us.pool.ntp.org', timezone=8)
//ntp = ntptime.client(host='de.pool.ntp.org', timezone=8)
ntp = ntptime.client(host='cn.pool.ntp.org', timezone=8)
//获取时间戳
ntp.getTimestamp()
//格式化日期
ntp.formatDate('-')
//格式化时间
ntp.formatTime('-')
//格式化日期&时间
ntp.formatDatetime('-', ':')
ntp.year()
ntp.month()
ntp.day()
ntp.hour()
ntp.minute()
ntp.second()
ntp.weekday()
```
# EEPROM
>通过EEPROM持久化保存数据。
```clike
import nvs
//写入数据
nvs.write_str(KEY, VALUE)
//读取数据
nvs.read_str(KEY)
```
# UART
>通过UART发送和接收数据。
```clike
//创建串口实例
uart1 = machine.UART(1, tx=1, rx=3)
//初始化串口
uart1.init(115200, bits=8, parity=None, stop=1)
//缓存区中是否有内容
uart1.any()
//读取缓存区中的内容
uart1.read()
//向串口写入内容
uart1.write('Hello')
//读/写案例
while True:
if uart1.any():
print(uart1.read())
uart1.write('Hello')
```
# SD-Card
```clike
import os
//读文件
with open('/sd/FileName.*', 'r') as fs:
print(fs.read())
//写文件
with open('/sd/test.txt', 'w+') as fs:
fs.write('Hello World')
//文件读写模式
w 以写方式打开,
w+ 以读写模式打开
r 以读模式打开
r+ 以读写模式打开
a 以追加模式打开
//设置文件光标
fs.seek(0)
//查看目录
os.listdir('/sd/DirectoryPath')
//判断路径是否为文件
os.stat('/sd/FilePath')[0] == 0x8000)
//判断路径是否为目录
os.stat('/sd/DirectoryPath')[0] == 0x4000)
//判断文件是否存在于指定目录
'FileName.*' in os.listdir('/sd/DirectoryPath')
```
+16 -1
View File
@@ -59,13 +59,28 @@ const unit = {
"id":"unit_api"
};
const advanced = {
'title':"Advanced",
'item':{
'WiFi':'#/zh_CN/mpy/advanced?id=wificfg',
'MQTT':'#/zh_CN/mpy/advanced?id=m5mqtt',
'ESP-NOW':'#/zh_CN/mpy/advanced?id=esp-now',
'HTTP':'#/zh_CN/mpy/advanced?id=http',
'NTP':'#/zh_CN/mpy/advanced?id=ntp',
'EEPROM':'#/zh_CN/mpy/advanced?id=eeprom',
'UART':'#/zh_CN/mpy/advanced?id=uart'
},
"id":"advanced_api"
};
var arduino_home_page = new Vue({
el:'#arduino_home_page',
data() {
return {
list: {
quickstart: quickstart,
unit: unit
unit: unit,
advanced: advanced
}
};
}