From 51aefe01e2bda6030ba37e2f1b20ca4fa47341c3 Mon Sep 17 00:00:00 2001 From: vany5921 <908744431@qq.com> Date: Wed, 9 Oct 2019 11:26:59 +0800 Subject: [PATCH] add PUSH 6060 example --- docs/en/1515/6060-push.md | 65 ++---------------- docs/en/uiflow/RS485.md | 128 +++++++++++++++++++++++++++++++++++ docs/zh_CN/1515/6060-push.md | 2 +- docs/zh_CN/uiflow/RS485.md | 4 +- 4 files changed, 135 insertions(+), 64 deletions(-) create mode 100644 docs/en/uiflow/RS485.md diff --git a/docs/en/1515/6060-push.md b/docs/en/1515/6060-push.md index 5d668091..4820106b 100644 --- a/docs/en/1515/6060-push.md +++ b/docs/en/1515/6060-push.md @@ -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)** @@ -34,71 +34,14 @@ Product Feature: - 3D printer - Linear motion +## Example + +Example Code ## Links - **Datasheet** - [Mega328P](http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-7810-Automotive-Microcontrollers-ATmega328P_Datasheet.pdf) - - - - - - diff --git a/docs/en/uiflow/RS485.md b/docs/en/uiflow/RS485.md new file mode 100644 index 00000000..4cd2611f --- /dev/null +++ b/docs/en/uiflow/RS485.md @@ -0,0 +1,128 @@ +# RS485 {docsify-ignore-all} + + + + +**[1. Introduction to RS485 use](#RS485 Introduction)** + +**[2. RS485 Example](#RS485 Example)** + +**[3. PUSH6060 Example](#PUSH6060 Example)** + + +## RS485 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 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 + +#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 + + + + +## PUSH6060 Example: + +>Refer to the RS485 example for specific details. The following is the sample code. + +```arduino + +#include +#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(); +} + +``` \ No newline at end of file diff --git a/docs/zh_CN/1515/6060-push.md b/docs/zh_CN/1515/6060-push.md index bfd82ee3..f3bfa4a5 100644 --- a/docs/zh_CN/1515/6060-push.md +++ b/docs/zh_CN/1515/6060-push.md @@ -4,7 +4,7 @@ *** -:memo:**[描述](#描述)**      :octocat:**[例程](#例程)**      :electric_plug:**[原理图](#原理图)**      🛒**[购买链接](https://m5stack.com/collections/m5-application/products/m5stack-6060-push)**      :clapper:**[相关视频](#相关视频)**   **[EasyLoader](#EasyLoader)** +:memo:**[描述](#描述)**      :octocat:**[例程](#RS485示例)**      :🛒**[购买链接](https://m5stack.com/collections/m5-application/products/m5stack-6060-push)**      **[EasyLoader](#EasyLoader)** ## 描述 diff --git a/docs/zh_CN/uiflow/RS485.md b/docs/zh_CN/uiflow/RS485.md index 552978ce..036565a9 100644 --- a/docs/zh_CN/uiflow/RS485.md +++ b/docs/zh_CN/uiflow/RS485.md @@ -5,7 +5,7 @@ **[1. RS485使用介绍](#RS485使用介绍)** -**[2. RS485例程](#RS485使用示例)** +**[2. RS485使用Arduino示例](#RS485使用Arduino示例)** **[3. PUSH6060例程](#PUSH6060例程)** @@ -65,7 +65,7 @@ void loop() { -## PUSH6060例程: +## PUSH6060例程 >具体细节参考RS485示例,以下为示范代码