add PUSH 6060 example

This commit is contained in:
vany5921
2019-10-09 11:26:59 +08:00
parent 6059e11a29
commit 51aefe01e2
4 changed files with 135 additions and 64 deletions
+4 -61
View File
@@ -4,7 +4,7 @@
***
:memo:**[Description](#Description)**      🛒**[Purchase](https://m5stack.com/collections/m5-application/products/m5stack-6060-push)**
:memo:**[Description](#Description)**      :octocat:**[Example](#Example)**      🛒**[Purchase](https://m5stack.com/collections/m5-application/products/m5stack-6060-push)**
<!--
:octocat:**[Code](#Code)**&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
-->
@@ -34,71 +34,14 @@ Product Feature:
- 3D printer
- Linear motion
## Example
<a href="#en\uiflow\RS485.md">Example Code</a>
## Links
- **Datasheet** - [Mega328P](http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-7810-Automotive-Microcontrollers-ATmega328P_Datasheet.pdf)
<!--## Schematic
<img src="assets/img/product_pics/hat/dac_hat/dac_hat_04.jpg" width="80%" height="80%">
-->
<!--
## EasyLoader
<img src="https://m5stack.oss-cn-shenzhen.aliyuncs.com/image/EasyLoader_logo.png" width="100px" style="margin-top:20px">
<a href="https://m5stack.oss-cn-shenzhen.aliyuncs.com/EasyLoader/HAT/DAC/EasyLoader_DAC_HAT.exe"><button type="button" class="btn btn-primary">click to download EasyLoader</button></a>
>1.EasyLoader is a simple and fast program burner, and each product page has a product-related case program for EasyLoader.
>2.After downloading the software, double-click to run the application, connect the M5 device to the computer via the data cable, select the port parameters, and click **"Burn"** to start burning.
## Code
### 1. Arduino IDE
*To get complete code, please click [here](https://github.com/m5stack/M5StickC/blob/master/examples/Hat/DAC).*
```arduino
#include <M5StickC.h>
#include <Wire.h>
#include "Adafruit_MCP4725.h"
#define DAC_ADDR
Adafruit_MCP4725 dac;
void setup(void) {
M5.begin(true,true,false);
dac.begin(0x60);
dac.setVoltage(2048, false);
}
void loop(void) {
// 12bit value , false mean not write EEPROM
dac.setVoltage(1024, false);
dac.setVoltage(2048, false);
}
```
-->
<!--
### Pin Map
<table>
<tr><td>M5StickC</td><td>GPIO0</td><td>GPIO26</td><td>5V</td><td>GND</td></tr>
<tr><td>HAT ADC</td><td>SDA</td><td>SCL</td><td>5V</td><td>GND</td></tr>
</table>
-->
<!--## Video
**Demo**
<video width="500" height="500" controls>
<source src="https://m5stack.oss-cn-shenzhen.aliyuncs.com/video/Product_example_video/HAT/ADC-DAC-HAT.mp4" type="video/mp4" >
</video>
-->
+128
View File
@@ -0,0 +1,128 @@
# RS485 {docsify-ignore-all}
<img src="assets/img/product_pics/unit/unit_rs485_01.png" width="20%" height="20%"><img src="assets\img\product_pics\hat\rs485_hat\rs485_hat_01.jpg" width="20%" height="20%">
<img src="assets\img\product_pics\1515\6060-push\6060_push_01.jpg" width="20%" height="20%"> <img src="assets\img\product_pics\app\ac_socket\ac_socket_01.jpg" width="20%" height="20%">
**[1. Introduction&nbsp;to&nbsp;RS485&nbsp;use](#RS485&nbsp;Introduction)**
**[2. RS485&nbsp;Example](#RS485&nbsp;Example)**
**[3. PUSH6060&nbsp;Example](#PUSH6060&nbsp;Example)**
## RS485&nbsp;Introduction
>RS485 is a data transmission standard. Its basic usage is the same as that of the serial port. It defines the RX and TX ports, communication baud rate and data bits for communication. Usually configured as (9600, Serial_8N1, RX_PIN, TX_PIN), 9600 baud rate, 8 data bits, no parity, 1 stop bit
## RS485&nbsp;example
>1. Serial port 2 is defined during program initialization. Normally, the serial port of M5Stack is 16 (RX_PIN) and 17 (TX_PIN), the serial port of M5StickC is 33 (RX_PIN) and 32 (TX_PIN), and the HAT serial port is 26 (RX_PIN) and 0 (TX_PIN).
Serial2.begin(115200, SERIAL_8N1, RX_PIN, TX_PIN);
>2. Send data can use Serial2.print ("x") or Serial.write ("x"). For the difference between the two, please refer to the use of Serial in Arduino.
Serial2.print("97");或者Serial2.write("97");
>3. Read data can be read from the buffer using Serial2.read().
if(Serial2.available()){
char c = Serial2.read();
}
> *The following basic code is for reference only
```arduino
#include <M5Stack.h>
#define RX_PIN 16
#define TX_PIN 17
void setup() {
M5.begin();
Serial2.begin(9600, SERIAL_8N1, RX_PIN, TX_PIN); //Serial port 2 initialization
}
void loop() {
if(M5.BtnA.wasPressed()){ //If button A is pressed
Serial2.print("hello,from RS485\r\n"); //Send data through serial port 2
}
if(Serial2.available()){ //If the serial port has data to read and print
char c = Serial2.read();
Serial.print(c);
}
M5.update(); //Button status refresh
}
```
>UIFlow Useage
<img src="image\Advanced module\RS485.png" width="40%" height="40%">
## PUSH6060&nbsp;Example
>Refer to the RS485 example for specific details. The following is the sample code.
```arduino
#include <M5Stack.h>
#define RX_PIN 16
#define TX_PIN 17
#define X_LOCAL 40
#define Y_LOCAL 40
#define X_OFF 160
#define Y_OFF 30
int distance = 0; //步进电机移动步进值
void header(const char *string, uint16_t color){ //Title
M5.Lcd.fillScreen(color);
M5.Lcd.setTextSize(1);
M5.Lcd.setTextColor(TFT_MAGENTA, TFT_BLUE);
M5.Lcd.fillRect(0, 0, 320, 30, TFT_BLUE);
M5.Lcd.setTextDatum(TC_DATUM);
M5.Lcd.drawString(string, 160, 3, 4);
}
void setup() {
M5.begin();
M5.Power.begin();
header("PUSH 6060", TFT_BLACK);
M5.Lcd.setTextFont(2);
M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK);
Serial2.begin(9600, SERIAL_8N1, RX_PIN, TX_PIN); //Configure serial port 2
delay(500);
Serial2.print("ID=123\r\n"); //Serial port 2 output ID=123\r\n, configuration 6060 motor ID is 123
}
void loop() {
if(M5.BtnA.wasPressed()){ //Press button A to send ID\r\n to view 6060 motor ID.
Serial2.print("ID\r\n");
}
if(M5.BtnB.wasPressed()){ //Press button B to send the ID123: X%d\r\n to control the absolute travel, where %d is the variable distance
if(distance < 50){
distance +=10;
Serial2.printf("ID123:X%d\r\n",distance);
}
}
if(M5.BtnC.wasPressed()){ //Press C to send ID123Z\r\n and the motor returns to the origin.
Serial2.print("ID123Z\r\n");
}
if(Serial2.available()){ //Serial port 2 receives the message returned by 6060 and prints
char c = Serial2.read();
Serial.print(c);
}
M5.update();
}
```
+1 -1
View File
@@ -4,7 +4,7 @@
***
:memo:**[描述](#描述)**&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:octocat:**[例程](#例)**&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:electric_plug:**[原理图](#原理图)**&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;🛒**[购买链接](https://m5stack.com/collections/m5-application/products/m5stack-6060-push)**&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:clapper:**[相关视频](#相关视频)**&nbsp;&nbsp;&nbsp;<img src="https://m5stack.oss-cn-shenzhen.aliyuncs.com/image/EasyLoader_logo-min.jpg">**[EasyLoader](#EasyLoader)**
:memo:**[描述](#描述)**&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:octocat:**[例程](#RS485示)**&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:🛒**[购买链接](https://m5stack.com/collections/m5-application/products/m5stack-6060-push)**&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="https://m5stack.oss-cn-shenzhen.aliyuncs.com/image/EasyLoader_logo-min.jpg">**[EasyLoader](#EasyLoader)**
## 描述
+2 -2
View File
@@ -5,7 +5,7 @@
**[1. RS485使用介绍](#RS485使用介绍)**
**[2. RS485例](#RS485使用示例)**
**[2. RS485使用Arduino示](#RS485使用Arduino示例)**
**[3. PUSH6060例程](#PUSH6060例程)**
@@ -65,7 +65,7 @@ void loop() {
<img src="image\Advanced module\RS485.png" width="40%" height="40%">
## PUSH6060例程
## PUSH6060例程
>具体细节参考RS485示例,以下为示范代码