From 2e3f1afe90fb3ffd0a94d8056566c3336f9d7ddf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A1=A9=E5=85=A5=E5=AD=94=E7=AB=A0?= Date: Thu, 28 Feb 2019 15:56:00 +0800 Subject: [PATCH] udpate api en ja --- docs/en/api/button.md | 8 +- docs/en/api/lcd.md | 127 ++++++++-------- docs/en/api/mpu9250.md | 318 ++++++++++++++++++++++------------------- docs/en/api/speaker.md | 26 ++-- docs/en/api/system.md | 6 +- docs/en/api/tf.md | 4 +- docs/ja/api/mpu9250.md | 318 ++++++++++++++++++++++------------------- docs/ja/api/speaker.md | 6 +- 8 files changed, 429 insertions(+), 384 deletions(-) diff --git a/docs/en/api/button.md b/docs/en/api/button.md index fbd797ea..c95d78c5 100644 --- a/docs/en/api/button.md +++ b/docs/en/api/button.md @@ -12,7 +12,7 @@ uint8_t read(); This function returns reading the state of the button directly. 1: pressed, 0: released. -**Sample:** +**Example:** ```arduino #include @@ -40,7 +40,7 @@ uint8_t isPressed(); This function returns the state of the button the last time Button.read() was called. 1: pressed, 0: released. -**Sample:** +**Example:** ```arduino #include @@ -72,7 +72,7 @@ uint8_t wasPressed(); This function returns 1 only once each time the button is pressed. 1: pressed, 0: released. -**Sample:** +**Example:** ```arduino #include @@ -108,7 +108,7 @@ This function returns 1 if button has been pressed for more than specified time. | --- | --- | -- | | ms | pressing time (ms) | uint32_t | -**Sample:** +**Example:** ```arduino #include diff --git a/docs/en/api/lcd.md b/docs/en/api/lcd.md index cb2d7aa3..eaac0729 100644 --- a/docs/en/api/lcd.md +++ b/docs/en/api/lcd.md @@ -2,11 +2,13 @@ *The screen pixel is 320x240, with the top left corner of the screen as the origin (0,0)* -### fillScreen() +## fillScreen() -**Function prototype:** +**Syntax:** -fillScreen(uint16_t color); // for arduino +```arduino +fillScreen(uint16_t color); +``` **Function: Fill the entire screen with the specified color.** @@ -15,6 +17,7 @@ | color | the color to be filled | **Example:** + ```arduino #include @@ -30,15 +33,15 @@ from m5ui import * lcd.fillScreen(lcd.RED) ``` --> -* * * + +## setTextColor() - -### setTextColor() +**Syntax:** -**Function prototype:** - -setTextColor(uint16_t color, uint16_t backgroundcolor); // for arduino +```arduino +setTextColor(uint16_t color, uint16_t backgroundcolor); +``` **Function: Set the foreground color and background color of the displayed text.** @@ -50,6 +53,7 @@ lcd.fillScreen(lcd.RED) *If backgroundcolor is not given, current background color is used* **Example:** + ```arduino #include @@ -66,19 +70,20 @@ lcd.setTextColor(lcd.RED) lcd.setTextColor(lcd.ORANGE, lcd.DARKCYAN) ``` --> -* * * +## setCursor() -### setCursor() +**Syntax:** -**Function prototype:** +```arduino +setCursor(uint16_t x0, uint16_t y0); +``` -setCursor(uint16_t x0, uint16_t y0); // for arduino - - + **Function: Move the cursor to (x0, y0).** **Example:** + ```arduino #include @@ -95,13 +100,13 @@ from m5ui import * lcd.drawPixel(22,22,lcd.RED) ``` --> -* * * +## drawPixel() -### drawPixel() +**Syntax:** -**Function prototype:** - -drawPixel(int16_t x, int16_t y, uint16_t color); // for arduino +```arduino +drawPixel(int16_t x, int16_t y, uint16_t color); +``` **Function: Draw a point at position (x, y).** @@ -112,6 +117,7 @@ lcd.drawPixel(22,22,lcd.RED) *If color is not given, current background color is used* **Example:** + ```arduino #include @@ -127,13 +133,13 @@ from m5ui import * lcd.drawPixel(22,22,lcd.RED) ``` --> -* * * +## drawLine() -### drawLine() +**Syntax:** -**Function prototype:** - -drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color); // for arduino +```arduino +drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color); +``` **Function: Draw the line from point (x,y) to point (x1,y1).** @@ -144,6 +150,7 @@ lcd.drawPixel(22,22,lcd.RED) *If color is not given, current background color is used* **Example:** + ```arduino #include @@ -159,13 +166,13 @@ from m5ui import * lcd.drawLine(0,0,12,12,lcd.WHITE) ``` --> -* * * +## drawTriangle() -### drawTriangle() +**Syntax:** -**Function prototype:** - -drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color); // for arduino +```arduino +drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color); +``` **Function: Draw the triangel between points (x,y), (x1,y1) and (x2,y2).** @@ -176,6 +183,7 @@ lcd.drawLine(0,0,12,12,lcd.WHITE) *If color is not given, current background color is used* **Example:** + ```arduino #include @@ -191,13 +199,13 @@ from m5ui import * lcd.drawLine(0,0,12,12,lcd.WHITE) ``` --> -* * * +## fillTriangle() -### fillTriangle() +**Syntax:** -**Function prototype:** - -fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color); // for arduino +```arduino +fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color); +``` **Function: Fill the triangel between points (x,y), (x1,y1) and (x2,y2).** @@ -208,6 +216,7 @@ lcd.drawLine(0,0,12,12,lcd.WHITE) *If color is not given, current background color is used* **Example:** + ```arduino #include @@ -223,13 +232,13 @@ from m5ui import * lcd.drawLine(0,0,12,12,lcd.WHITE) ``` --> -* * * +## drawRect() -### drawRect() +**Syntax:** -**Function prototype:** - -drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color); // for arduino +```arduino +drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color); +``` **Function: Draw the rectangle from the upper left point at (x,y) and width and height.** @@ -242,6 +251,7 @@ lcd.drawLine(0,0,12,12,lcd.WHITE) *If color is not given, current background color is used* **Example:** + ```arduino #include @@ -257,13 +267,13 @@ from m5ui import * lcd.drawLine(0,0,12,12,lcd.WHITE) ``` --> -* * * +## fillRect() -### fillRect() +**Syntax:** -**Function prototype:** - -fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color); // for arduino +```arduino +fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color); +``` **Function: Fill the rectangle from the upper left point at (x,y) and width and height.** @@ -276,6 +286,7 @@ lcd.drawLine(0,0,12,12,lcd.WHITE) *If color is not given, current background color is used* **Example:** + ```arduino #include @@ -291,13 +302,13 @@ from m5ui import * lcd.drawLine(0,0,12,12,lcd.WHITE) ``` --> -* * * +## drawRoundRect() -### drawRoundRect() +**Syntax:** -**Function prototype:** - -drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color); // for arduino +```arduino +drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color); +``` **Function: Draw the rectangle with rounded corners from the upper left point at (x,y) and width and height. Corner radius is given by radius argument.** @@ -311,6 +322,7 @@ lcd.drawLine(0,0,12,12,lcd.WHITE) *If color is not given, current background color is used* **Example:** + ```arduino #include @@ -326,19 +338,20 @@ from m5ui import * lcd.drawLine(0,0,12,12,lcd.WHITE) ``` --> -* * * +## print() -### print() +**Syntax:** -**Function prototype:** - -print(); // for arduino +```arduino +print(); +``` **Function: Start printing text at the current position of the screen.** *The specified content is printed in the foreground color by default.* **Example:** + ```arduino #include @@ -354,9 +367,7 @@ from m5ui import * lcd.drawLine(0,0,12,12,lcd.WHITE) ``` --> -* * * - -### Usage {docsify-ignore} +## Usage {docsify-ignore} ```arduino #include diff --git a/docs/en/api/mpu9250.md b/docs/en/api/mpu9250.md index e3590a54..dd3c740a 100644 --- a/docs/en/api/mpu9250.md +++ b/docs/en/api/mpu9250.md @@ -1,259 +1,275 @@ -# 姿态传感器 MPU9250 +# IMU Sensor MPU9250 -*姿态传感器 MPU9250 是一款多芯片模块,集成两个芯片,一个芯片是 MPU6500,由 3 轴陀螺仪和 3 轴加速度计组成,另外一个是 AK8963 是 3 轴磁力计。* +*IMU The MPU9250 is a multi-chip module that integrates two chips. One chip is the MPU6500, which consists of a 3-axis gyroscope and a 3-axis accelerometer. The other is the AK8963 is a 3-axis magnetometer.* ## initMPU9250() -**函数原型:** +**Syntax:** -void initMPU9250(); +```arduino +void initMPU9250(); +``` - +**Description:** -**功能:初始化 MPU6500 芯片。** +This function initialize MPU6500 chip. + +**Example:** -**例程:** ```arduino #include #include "utility/MPU9250.h" MPU9250 IMU; // new a MPU9250 object -void setup(){ - M5.begin(); - Serial.begin(115200); +void setup() { + M5.begin(); + Wire.begin(); + IMU.initMPU9250(); // this line must be after Wire.begin() +} - IMU.initMPU9250(); - byte c = IMU.readByte(MPU9250_ADDRESS, WHO_AM_I_MPU9250); - Serial.print("MPU9250 "); Serial.print("I AM "); Serial.print(c, HEX); +void loop() { } ``` ## initAK8963() -**函数原型:** +**Syntax:** -void initAK8963(float * destination); +```arduino +void initAK8963(float * destination); +``` - +**Description:** -**功能:初始化 AK8963 芯片。** +This function initialize AK8963 chip. -| 参数 | 描述 | -| --- | --- | -| destination | 出厂预设于 AK8963 芯片内缺省值的数组指针 | +| Argument | Description | Type | +| --- | --- | -- | +| destination | for AK8963 Calibration Value | float * | + +**Example:** -**例程:** ```arduino #include #include "utility/MPU9250.h" MPU9250 IMU; // new a MPU9250 object -void setup(){ - M5.begin(); - Serial.begin(115200); +void setup() { + M5.begin(); + Wire.begin(); - // "magCalibration[3] = {0};" was defined at file "MPU9250.h" - IMU.initAK8963(IMU.magCalibration); - Serial.println("AK8963 initialized for active data mode...."); - if (Serial) - { - // Serial.println("Calibration values: "); - Serial.print("X-Axis sensitivity adjustment value "); - Serial.println(IMU.magCalibration[0], 2); - Serial.print("Y-Axis sensitivity adjustment value "); - Serial.println(IMU.magCalibration[1], 2); - Serial.print("Z-Axis sensitivity adjustment value "); - Serial.println(IMU.magCalibration[2], 2); - } + IMU.initAK8963(IMU.magCalibration); + M5.Lcd.println("AK8963 initialized for active data mode...."); + if (Serial) + { + M5.Lcd.println("Calibration values: "); + M5.Lcd.print("X-Axis sensitivity adjustment value "); + M5.Lcd.println(IMU.magCalibration[0], 2); + M5.Lcd.print("Y-Axis sensitivity adjustment value "); + M5.Lcd.println(IMU.magCalibration[1], 2); + M5.Lcd.print("Z-Axis sensitivity adjustment value "); + M5.Lcd.println(IMU.magCalibration[2], 2); + } +} + +void loop() { } ``` ## calibrateMPU9250() -**函数原型:** +**Syntax:** -void calibrateMPU9250(float * gyroBias, float * accelBias); +```arduino +void calibrateMPU9250(float * gyroBias, float * accelBias); +``` - +**Description:** -**功能:初始化芯片后,执行该函数以读取静止状态下的陀螺仪和加速度值偏移,并保存到各自的偏移寄存器。** +This function calcurate offset values of gyro and accelerometer. -| 参数 | 描述 | -| --- | --- | -| gyroBias | 保存静止下陀螺仪值的数组的地址 | -| accelBias | 保存静止下加速度值的数组的地址 | +| Argument | Description | Type | +| --- | --- | -- | +| gyroBias | gyro offset | float * | +| accelBias | accel offset | float * | + +**Example:** -**例程:** ```arduino #include #include "utility/MPU9250.h" MPU9250 IMU; // new a MPU9250 object -void setup(){ - M5.begin(); - Serial.begin(115200); +void setup() { + M5.begin(); + Wire.begin(); - IMU.initMPU9250(); - byte c = IMU.readByte(MPU9250_ADDRESS, WHO_AM_I_MPU9250); - Serial.print("MPU9250 "); Serial.print("I AM "); Serial.print(c, HEX); - // "gyroBias[3] = {0};" was defined at file "MPU9250.h" - // "accelBias[3] = {0};" was defined at file "MPU9250.h" - IMU.calibrateMPU9250(IMU.gyroBias, IMU.accelBias); - M5.Lcd.fillScreen(BLACK); - M5.Lcd.setTextSize(1); - M5.Lcd.setCursor(0, 0); M5.Lcd.print("MPU9250 bias"); - M5.Lcd.setCursor(0, 16); M5.Lcd.print(" x y z "); + IMU.initMPU9250(); + IMU.calibrateMPU9250(IMU.gyroBias, IMU.accelBias); + M5.Lcd.fillScreen(BLACK); + M5.Lcd.setTextSize(1); + M5.Lcd.setCursor(0, 0); M5.Lcd.print("MPU9250 bias"); + M5.Lcd.setCursor(0, 16); M5.Lcd.print(" x y z "); - M5.Lcd.setCursor(0, 32); M5.Lcd.print((int)(1000*IMU.accelBias[0])); - M5.Lcd.setCursor(32, 32); M5.Lcd.print((int)(1000*IMU.accelBias[1])); - M5.Lcd.setCursor(64, 32); M5.Lcd.print((int)(1000*IMU.accelBias[2])); - M5.Lcd.setCursor(96, 32); M5.Lcd.print("mg"); + M5.Lcd.setCursor(0, 32); M5.Lcd.print((int)(1000 * IMU.accelBias[0])); + M5.Lcd.setCursor(32, 32); M5.Lcd.print((int)(1000 * IMU.accelBias[1])); + M5.Lcd.setCursor(64, 32); M5.Lcd.print((int)(1000 * IMU.accelBias[2])); + M5.Lcd.setCursor(96, 32); M5.Lcd.print("mg"); - M5.Lcd.setCursor(0, 48); M5.Lcd.print(IMU.gyroBias[0], 1); - M5.Lcd.setCursor(32, 48); M5.Lcd.print(IMU.gyroBias[1], 1); - M5.Lcd.setCursor(64, 48); M5.Lcd.print(IMU.gyroBias[2], 1); - M5.Lcd.setCursor(96, 48); M5.Lcd.print("o/s"); + M5.Lcd.setCursor(0, 48); M5.Lcd.print(IMU.gyroBias[0], 1); + M5.Lcd.setCursor(32, 48); M5.Lcd.print(IMU.gyroBias[1], 1); + M5.Lcd.setCursor(64, 48); M5.Lcd.print(IMU.gyroBias[2], 1); + M5.Lcd.setCursor(96, 48); M5.Lcd.print("o/s"); } -void loop(){ - +void loop() { } ``` ## readByte() -**函数原型:** +**Syntax:** -uint8_t readByte(uint8_t address, uint8_t subAddress); +```arduino +uint8_t readByte(uint8_t address, uint8_t subAddress); +``` - +**Description:** -**功能:读取指定寄存器内数据。返回值:寄存器值,长度为8 位。** +This function reads a byte data from specified register of MPU9250. -| 参数 | 描述 | -| --- | --- | -| address | 芯片 (MPU9250/AK8963)地址 | -| subAddress | 芯片内寄存器地址 | +| Argument | Description | Type | +| --- | --- | -- | +| address | (MPU9250/AK8963) I2C address | uint8_t | +| subAddress | register address | uint8_t | + +**Example:** -**例程:** ```arduino #include #include "utility/MPU9250.h" MPU9250 IMU; // new a MPU9250 object -void setup(){ - M5.begin(); - Serial.begin(115200); +void setup() { + M5.begin(); + Wire.begin(); - byte c = IMU.readByte(MPU9250_ADDRESS, WHO_AM_I_MPU9250); - Serial.print("MPU9250 "); Serial.print("I AM "); Serial.print(c, HEX); + uint8_t id = IMU.readByte(MPU9250_ADDRESS, WHO_AM_I_MPU9250); + M5.Lcd.print("MPU9250 I AM 0x"); M5.Lcd.print(id, HEX); +} + +void loop() { } ``` ## readGyroData() -**函数原型:** +**Syntax:** -void readGyroData(int16_t * destination); +```arduino +void readGyroData(int16_t * destination); +``` - +**Description:** -**功能:读取三个方向的陀螺仪值。** +This function reads the value of 3-axis gyro sensor. -| 参数 | 描述 | -| --- | --- | -| destination | 保存陀螺仪值的数组的地址 | +| Argument | Description | Type | +| --- | --- | -- | +| destination | read gyro values | int16_t * | + +**Example:** -**例程:** ```arduino #include #include "utility/MPU9250.h" MPU9250 IMU; // new a MPU9250 object -void setup(){ - M5.begin(); - Serial.begin(115200); - - IMU.initMPU9250(); - byte c = IMU.readByte(MPU9250_ADDRESS, WHO_AM_I_MPU9250); - Serial.print("MPU9250 "); Serial.print("I AM "); Serial.print(c, HEX); - IMU.calibrateMPU9250(IMU.gyroBias, IMU.accelBias); +void setup() { + M5.begin(); + Wire.begin(); + IMU.initMPU9250(); + IMU.calibrateMPU9250(IMU.gyroBias, IMU.accelBias); } -void loop(){ - // If intPin goes high, all data registers have new data - // On interrupt, check if data ready interrupt - if (IMU.readByte(MPU9250_ADDRESS, INT_STATUS) & 0x01) - { - // "gyroCount[3] = {0};" was defined at file "MPU9250.h" - IMU.readGyroData(IMU.gyroCount); // Read the x/y/z adc values - IMU.getGres(); // get Gyro scales saved to "gRes" - IMU.gx = (float)IMU.gyroCount[0]*IMU.gRes; - IMU.gy = (float)IMU.gyroCount[1]*IMU.gRes; - IMU.gz = (float)IMU.gyroCount[2]*IMU.gRes; - Serial.print("X-gyro rate: "); Serial.print(IMU.gx, 3); - Serial.print(" degrees/sec "); - Serial.print("Y-gyro rate: "); Serial.print(IMU.gy, 3); - Serial.print(" degrees/sec "); - Serial.print("Z-gyro rate: "); Serial.print(IMU.gz, 3); - Serial.println(" degrees/sec"); - } +void loop() { + // If intPin goes high, all data registers have new data + // On interrupt, check if data ready interrupt + if (IMU.readByte(MPU9250_ADDRESS, INT_STATUS) & 0x01) + { + M5.Lcd.clear(); + M5.Lcd.setCursor(0, 0); + IMU.readGyroData(IMU.gyroCount); // Read the x/y/z adc values + IMU.getGres(); // get Gyro scales saved to "gRes" + IMU.gx = (float)IMU.gyroCount[0] * IMU.gRes; + IMU.gy = (float)IMU.gyroCount[1] * IMU.gRes; + IMU.gz = (float)IMU.gyroCount[2] * IMU.gRes; + M5.Lcd.print("X-gyro rate: "); M5.Lcd.print(IMU.gx, 3); + M5.Lcd.println(" degrees/sec "); + M5.Lcd.print("Y-gyro rate: "); M5.Lcd.print(IMU.gy, 3); + M5.Lcd.println(" degrees/sec "); + M5.Lcd.print("Z-gyro rate: "); M5.Lcd.print(IMU.gz, 3); + M5.Lcd.println(" degrees/sec"); + } + delay(500); } ``` ## readAccelData() -**函数原型:** +**Syntax:** -void readAccelData(int16_t * destination); +```arduino +void readAccelData(int16_t * destination); +``` - +**Description:** -**功能:读取三个方向的加速度值。** +This function reads the value of 3-axis accelerate sensor. -| 参数 | 描述 | -| --- | --- | -| destination | 保存加速度值的数组的地址 | +| Argument | Description | Type | +| --- | --- | -- | +| destination | read accelerate values | int16_t * | + +**Example:** -**例程:** ```arduino #include #include "utility/MPU9250.h" MPU9250 IMU; // new a MPU9250 object -void setup(){ - M5.begin(); - Serial.begin(115200); - - IMU.initMPU9250(); - byte c = IMU.readByte(MPU9250_ADDRESS, WHO_AM_I_MPU9250); - Serial.print("MPU9250 "); Serial.print("I AM "); Serial.print(c, HEX); - IMU.calibrateMPU9250(IMU.gyroBias, IMU.accelBias); +void setup() { + M5.begin(); + Wire.begin(); + IMU.initMPU9250(); + IMU.calibrateMPU9250(IMU.gyroBias, IMU.accelBias); } -void loop(){ - // If intPin goes high, all data registers have new data - // On interrupt, check if data ready interrupt - if (IMU.readByte(MPU9250_ADDRESS, INT_STATUS) & 0x01) - { - // "accelCount[3] = {0};" was defined at file "MPU9250.h" - IMU.readAccelData(IMU.accelCount); - IMU.getAres(); // get accelerometer scales saved to "aRes" - IMU.ax = (float)IMU.accelCount[0]*IMU.aRes; // - accelBias[0]; - IMU.ay = (float)IMU.accelCount[1]*IMU.aRes; // - accelBias[1]; - IMU.az = (float)IMU.accelCount[2]*IMU.aRes; // - accelBias[2]; - Serial.print("X-acceleration: "); Serial.print(1000*IMU.ax); - Serial.print(" mg "); - Serial.print("Y-acceleration: "); Serial.print(1000*IMU.ay); - Serial.print(" mg "); - Serial.print("Z-acceleration: "); Serial.print(1000*IMU.az); - Serial.println(" mg "); - } +void loop() { + // If intPin goes high, all data registers have new data + // On interrupt, check if data ready interrupt + if (IMU.readByte(MPU9250_ADDRESS, INT_STATUS) & 0x01) + { + M5.Lcd.clear(); + M5.Lcd.setCursor(0, 0); + IMU.readAccelData(IMU.accelCount); + IMU.getAres(); // get accelerometer scales saved to "aRes" + IMU.ax = (float)IMU.accelCount[0] * IMU.aRes; // - accelBias[0]; + IMU.ay = (float)IMU.accelCount[1] * IMU.aRes; // - accelBias[1]; + IMU.az = (float)IMU.accelCount[2] * IMU.aRes; // - accelBias[2]; + M5.Lcd.print("X-acceleration: "); M5.Lcd.print(1000 * IMU.ax); + M5.Lcd.println(" mg "); + M5.Lcd.print("Y-acceleration: "); M5.Lcd.print(1000 * IMU.ay); + M5.Lcd.println(" mg "); + M5.Lcd.print("Z-acceleration: "); M5.Lcd.print(1000 * IMU.az); + M5.Lcd.println(" mg "); + } + delay(500); } ``` \ No newline at end of file diff --git a/docs/en/api/speaker.md b/docs/en/api/speaker.md index 4d79b799..a94bcb0a 100644 --- a/docs/en/api/speaker.md +++ b/docs/en/api/speaker.md @@ -2,25 +2,25 @@ ### tone -**Function prototype:** +**Syntax:** -tone(uint16_t freq); // for arduino +```arduino +tone(uint16_t freq, [uint32_t duration]); +``` -tone(uint16_t freq, uint32_t duration); // for arduino - +**Description: Set the pitch of speaker.** -**Function: Set the pitch of speaker.** - -| Param | Description | -| --- | --- | -| freq | frequency | -| duration | duration (unit: millisecond) | +| Param | Description | type | +| --- | --- | -- | +| freq | frequency | uint16_t | +| duration | duration (unit: millisecond) | uint16_t | **Example** ```arduino #include -M5.begin(); - -M5.Speaker.tone(900, 1000); +void setup() { + M5.begin(); + M5.Speaker.tone(900, 1000); +} ``` \ No newline at end of file diff --git a/docs/en/api/system.md b/docs/en/api/system.md index d7881e83..f254a47a 100644 --- a/docs/en/api/system.md +++ b/docs/en/api/system.md @@ -34,7 +34,7 @@ void M5Stack::begin(bool LCDEnable, bool SDEnable, bool SerialEnable) { } ``` -**Sample:** +**Example:** ```arduino #include @@ -71,7 +71,7 @@ void M5Stack::update() { } ``` -**Sample:** +**Example:** ```arduino #include @@ -121,7 +121,7 @@ void M5Stack::powerOFF() { } ``` -**Sample:** +**Example:** ```arduino #include diff --git a/docs/en/api/tf.md b/docs/en/api/tf.md index 0f9acb1d..5512bd5a 100644 --- a/docs/en/api/tf.md +++ b/docs/en/api/tf.md @@ -16,7 +16,7 @@ This function initialize TF card. | --- | --- | -- | | cspin | chip select line (defaults SS line of SPI bus) | uint8_t | -**Sample:** +**Example:** ```arduino #include @@ -43,7 +43,7 @@ This function open the file. | filepath | path to file | const char * | | mode | read / write / rw (optional) | uint8_t | -**Sample:** +**Example:** ```arduino /* diff --git a/docs/ja/api/mpu9250.md b/docs/ja/api/mpu9250.md index e3590a54..a36526a2 100644 --- a/docs/ja/api/mpu9250.md +++ b/docs/ja/api/mpu9250.md @@ -1,259 +1,275 @@ -# 姿态传感器 MPU9250 +# IMU Sensor MPU9250 -*姿态传感器 MPU9250 是一款多芯片模块,集成两个芯片,一个芯片是 MPU6500,由 3 轴陀螺仪和 3 轴加速度计组成,另外一个是 AK8963 是 3 轴磁力计。* +*IMUとして搭載されているMPU9250は2種類のチップを1つのモジュールに統合しています。ひとつはMPU6500という3軸のジャイロセンサーと3軸の加速度センサーのチップです。もうひとつはAK8963という3軸地磁気センサーのチップです。* ## initMPU9250() -**函数原型:** +**構文:** -void initMPU9250(); +```arduino +void initMPU9250(); +``` - +**説明:** -**功能:初始化 MPU6500 芯片。** +MPU6500チップを初期化します。 + +**使用例:** -**例程:** ```arduino #include #include "utility/MPU9250.h" MPU9250 IMU; // new a MPU9250 object -void setup(){ - M5.begin(); - Serial.begin(115200); +void setup() { + M5.begin(); + Wire.begin(); + IMU.initMPU9250(); // this line must be after Wire.begin() +} - IMU.initMPU9250(); - byte c = IMU.readByte(MPU9250_ADDRESS, WHO_AM_I_MPU9250); - Serial.print("MPU9250 "); Serial.print("I AM "); Serial.print(c, HEX); +void loop() { } ``` ## initAK8963() -**函数原型:** +**構文:** -void initAK8963(float * destination); +```arduino +void initAK8963(float * destination); +``` - +**説明:** -**功能:初始化 AK8963 芯片。** +AK8963チップを初期化します。 -| 参数 | 描述 | -| --- | --- | -| destination | 出厂预设于 AK8963 芯片内缺省值的数组指针 | +| 引数 | 説明 | 型 | +| --- | --- | -- | +| destination | AK8963補正用の値を保存する変数 | float * | + +**使用例:** -**例程:** ```arduino #include #include "utility/MPU9250.h" MPU9250 IMU; // new a MPU9250 object -void setup(){ - M5.begin(); - Serial.begin(115200); +void setup() { + M5.begin(); + Wire.begin(); - // "magCalibration[3] = {0};" was defined at file "MPU9250.h" - IMU.initAK8963(IMU.magCalibration); - Serial.println("AK8963 initialized for active data mode...."); - if (Serial) - { - // Serial.println("Calibration values: "); - Serial.print("X-Axis sensitivity adjustment value "); - Serial.println(IMU.magCalibration[0], 2); - Serial.print("Y-Axis sensitivity adjustment value "); - Serial.println(IMU.magCalibration[1], 2); - Serial.print("Z-Axis sensitivity adjustment value "); - Serial.println(IMU.magCalibration[2], 2); - } + IMU.initAK8963(IMU.magCalibration); + M5.Lcd.println("AK8963 initialized for active data mode...."); + if (Serial) + { + M5.Lcd.println("Calibration values: "); + M5.Lcd.print("X-Axis sensitivity adjustment value "); + M5.Lcd.println(IMU.magCalibration[0], 2); + M5.Lcd.print("Y-Axis sensitivity adjustment value "); + M5.Lcd.println(IMU.magCalibration[1], 2); + M5.Lcd.print("Z-Axis sensitivity adjustment value "); + M5.Lcd.println(IMU.magCalibration[2], 2); + } +} + +void loop() { } ``` ## calibrateMPU9250() -**函数原型:** +**構文:** -void calibrateMPU9250(float * gyroBias, float * accelBias); +```arduino +void calibrateMPU9250(float * gyroBias, float * accelBias); +``` - +**説明:** -**功能:初始化芯片后,执行该函数以读取静止状态下的陀螺仪和加速度值偏移,并保存到各自的偏移寄存器。** +ジャイロと加速度センサーの補正値を計算します。 -| 参数 | 描述 | -| --- | --- | -| gyroBias | 保存静止下陀螺仪值的数组的地址 | -| accelBias | 保存静止下加速度值的数组的地址 | +| 引数 | 説明 | 型 | +| --- | --- | -- | +| gyroBias | gyro オフセット | float * | +| accelBias | accel オフセット | float * | + +**使用例:** -**例程:** ```arduino #include #include "utility/MPU9250.h" MPU9250 IMU; // new a MPU9250 object -void setup(){ - M5.begin(); - Serial.begin(115200); +void setup() { + M5.begin(); + Wire.begin(); - IMU.initMPU9250(); - byte c = IMU.readByte(MPU9250_ADDRESS, WHO_AM_I_MPU9250); - Serial.print("MPU9250 "); Serial.print("I AM "); Serial.print(c, HEX); - // "gyroBias[3] = {0};" was defined at file "MPU9250.h" - // "accelBias[3] = {0};" was defined at file "MPU9250.h" - IMU.calibrateMPU9250(IMU.gyroBias, IMU.accelBias); - M5.Lcd.fillScreen(BLACK); - M5.Lcd.setTextSize(1); - M5.Lcd.setCursor(0, 0); M5.Lcd.print("MPU9250 bias"); - M5.Lcd.setCursor(0, 16); M5.Lcd.print(" x y z "); + IMU.initMPU9250(); + IMU.calibrateMPU9250(IMU.gyroBias, IMU.accelBias); + M5.Lcd.fillScreen(BLACK); + M5.Lcd.setTextSize(1); + M5.Lcd.setCursor(0, 0); M5.Lcd.print("MPU9250 bias"); + M5.Lcd.setCursor(0, 16); M5.Lcd.print(" x y z "); - M5.Lcd.setCursor(0, 32); M5.Lcd.print((int)(1000*IMU.accelBias[0])); - M5.Lcd.setCursor(32, 32); M5.Lcd.print((int)(1000*IMU.accelBias[1])); - M5.Lcd.setCursor(64, 32); M5.Lcd.print((int)(1000*IMU.accelBias[2])); - M5.Lcd.setCursor(96, 32); M5.Lcd.print("mg"); + M5.Lcd.setCursor(0, 32); M5.Lcd.print((int)(1000 * IMU.accelBias[0])); + M5.Lcd.setCursor(32, 32); M5.Lcd.print((int)(1000 * IMU.accelBias[1])); + M5.Lcd.setCursor(64, 32); M5.Lcd.print((int)(1000 * IMU.accelBias[2])); + M5.Lcd.setCursor(96, 32); M5.Lcd.print("mg"); - M5.Lcd.setCursor(0, 48); M5.Lcd.print(IMU.gyroBias[0], 1); - M5.Lcd.setCursor(32, 48); M5.Lcd.print(IMU.gyroBias[1], 1); - M5.Lcd.setCursor(64, 48); M5.Lcd.print(IMU.gyroBias[2], 1); - M5.Lcd.setCursor(96, 48); M5.Lcd.print("o/s"); + M5.Lcd.setCursor(0, 48); M5.Lcd.print(IMU.gyroBias[0], 1); + M5.Lcd.setCursor(32, 48); M5.Lcd.print(IMU.gyroBias[1], 1); + M5.Lcd.setCursor(64, 48); M5.Lcd.print(IMU.gyroBias[2], 1); + M5.Lcd.setCursor(96, 48); M5.Lcd.print("o/s"); } -void loop(){ - +void loop() { } ``` ## readByte() -**函数原型:** +**構文:** -uint8_t readByte(uint8_t address, uint8_t subAddress); +```arduino +uint8_t readByte(uint8_t address, uint8_t subAddress); +``` - +**説明:** -**功能:读取指定寄存器内数据。返回值:寄存器值,长度为8 位。** +MPU9250の指定のレジスタから1バイト分のデータを取得します。 -| 参数 | 描述 | -| --- | --- | -| address | 芯片 (MPU9250/AK8963)地址 | -| subAddress | 芯片内寄存器地址 | +| 引数 | 説明 | 型 | +| --- | --- | -- | +| address | (MPU9250/AK8963) I2Cアドレス | uint8_t | +| subAddress | レジスタアドレス | uint8_t | + +**使用例:** -**例程:** ```arduino #include #include "utility/MPU9250.h" MPU9250 IMU; // new a MPU9250 object -void setup(){ - M5.begin(); - Serial.begin(115200); +void setup() { + M5.begin(); + Wire.begin(); - byte c = IMU.readByte(MPU9250_ADDRESS, WHO_AM_I_MPU9250); - Serial.print("MPU9250 "); Serial.print("I AM "); Serial.print(c, HEX); + uint8_t id = IMU.readByte(MPU9250_ADDRESS, WHO_AM_I_MPU9250); + M5.Lcd.print("MPU9250 I AM 0x"); M5.Lcd.print(id, HEX); +} + +void loop() { } ``` ## readGyroData() -**函数原型:** +**構文:** -void readGyroData(int16_t * destination); +```arduino +void readGyroData(int16_t * destination); +``` - +**説明:** -**功能:读取三个方向的陀螺仪值。** +3軸ジャイロセンサーの値を取得します。 -| 参数 | 描述 | -| --- | --- | -| destination | 保存陀螺仪值的数组的地址 | +| 引数 | 説明 | 型 | +| --- | --- | -- | +| destination | ジャイロセンサーの値 | int16_t * | + +**使用例:** -**例程:** ```arduino #include #include "utility/MPU9250.h" MPU9250 IMU; // new a MPU9250 object -void setup(){ - M5.begin(); - Serial.begin(115200); - - IMU.initMPU9250(); - byte c = IMU.readByte(MPU9250_ADDRESS, WHO_AM_I_MPU9250); - Serial.print("MPU9250 "); Serial.print("I AM "); Serial.print(c, HEX); - IMU.calibrateMPU9250(IMU.gyroBias, IMU.accelBias); +void setup() { + M5.begin(); + Wire.begin(); + IMU.initMPU9250(); + IMU.calibrateMPU9250(IMU.gyroBias, IMU.accelBias); } -void loop(){ - // If intPin goes high, all data registers have new data - // On interrupt, check if data ready interrupt - if (IMU.readByte(MPU9250_ADDRESS, INT_STATUS) & 0x01) - { - // "gyroCount[3] = {0};" was defined at file "MPU9250.h" - IMU.readGyroData(IMU.gyroCount); // Read the x/y/z adc values - IMU.getGres(); // get Gyro scales saved to "gRes" - IMU.gx = (float)IMU.gyroCount[0]*IMU.gRes; - IMU.gy = (float)IMU.gyroCount[1]*IMU.gRes; - IMU.gz = (float)IMU.gyroCount[2]*IMU.gRes; - Serial.print("X-gyro rate: "); Serial.print(IMU.gx, 3); - Serial.print(" degrees/sec "); - Serial.print("Y-gyro rate: "); Serial.print(IMU.gy, 3); - Serial.print(" degrees/sec "); - Serial.print("Z-gyro rate: "); Serial.print(IMU.gz, 3); - Serial.println(" degrees/sec"); - } +void loop() { + // If intPin goes high, all data registers have new data + // On interrupt, check if data ready interrupt + if (IMU.readByte(MPU9250_ADDRESS, INT_STATUS) & 0x01) + { + M5.Lcd.clear(); + M5.Lcd.setCursor(0, 0); + IMU.readGyroData(IMU.gyroCount); // Read the x/y/z adc values + IMU.getGres(); // get Gyro scales saved to "gRes" + IMU.gx = (float)IMU.gyroCount[0] * IMU.gRes; + IMU.gy = (float)IMU.gyroCount[1] * IMU.gRes; + IMU.gz = (float)IMU.gyroCount[2] * IMU.gRes; + M5.Lcd.print("X-gyro rate: "); M5.Lcd.print(IMU.gx, 3); + M5.Lcd.println(" degrees/sec "); + M5.Lcd.print("Y-gyro rate: "); M5.Lcd.print(IMU.gy, 3); + M5.Lcd.println(" degrees/sec "); + M5.Lcd.print("Z-gyro rate: "); M5.Lcd.print(IMU.gz, 3); + M5.Lcd.println(" degrees/sec"); + } + delay(500); } ``` ## readAccelData() -**函数原型:** +**構文:** -void readAccelData(int16_t * destination); +```arduino +void readAccelData(int16_t * destination); +``` - +**説明:** -**功能:读取三个方向的加速度值。** +3軸加速度センサーから値を取得します。 -| 参数 | 描述 | -| --- | --- | -| destination | 保存加速度值的数组的地址 | +| 引数 | 説明 | 型 | +| --- | --- | -- | +| destination | 加速度センサーの値 | int16_t * | + +**使用例:** -**例程:** ```arduino #include #include "utility/MPU9250.h" MPU9250 IMU; // new a MPU9250 object -void setup(){ - M5.begin(); - Serial.begin(115200); - - IMU.initMPU9250(); - byte c = IMU.readByte(MPU9250_ADDRESS, WHO_AM_I_MPU9250); - Serial.print("MPU9250 "); Serial.print("I AM "); Serial.print(c, HEX); - IMU.calibrateMPU9250(IMU.gyroBias, IMU.accelBias); +void setup() { + M5.begin(); + Wire.begin(); + IMU.initMPU9250(); + IMU.calibrateMPU9250(IMU.gyroBias, IMU.accelBias); } -void loop(){ - // If intPin goes high, all data registers have new data - // On interrupt, check if data ready interrupt - if (IMU.readByte(MPU9250_ADDRESS, INT_STATUS) & 0x01) - { - // "accelCount[3] = {0};" was defined at file "MPU9250.h" - IMU.readAccelData(IMU.accelCount); - IMU.getAres(); // get accelerometer scales saved to "aRes" - IMU.ax = (float)IMU.accelCount[0]*IMU.aRes; // - accelBias[0]; - IMU.ay = (float)IMU.accelCount[1]*IMU.aRes; // - accelBias[1]; - IMU.az = (float)IMU.accelCount[2]*IMU.aRes; // - accelBias[2]; - Serial.print("X-acceleration: "); Serial.print(1000*IMU.ax); - Serial.print(" mg "); - Serial.print("Y-acceleration: "); Serial.print(1000*IMU.ay); - Serial.print(" mg "); - Serial.print("Z-acceleration: "); Serial.print(1000*IMU.az); - Serial.println(" mg "); - } +void loop() { + // If intPin goes high, all data registers have new data + // On interrupt, check if data ready interrupt + if (IMU.readByte(MPU9250_ADDRESS, INT_STATUS) & 0x01) + { + M5.Lcd.clear(); + M5.Lcd.setCursor(0, 0); + IMU.readAccelData(IMU.accelCount); + IMU.getAres(); // get accelerometer scales saved to "aRes" + IMU.ax = (float)IMU.accelCount[0] * IMU.aRes; // - accelBias[0]; + IMU.ay = (float)IMU.accelCount[1] * IMU.aRes; // - accelBias[1]; + IMU.az = (float)IMU.accelCount[2] * IMU.aRes; // - accelBias[2]; + M5.Lcd.print("X-acceleration: "); M5.Lcd.print(1000 * IMU.ax); + M5.Lcd.println(" mg "); + M5.Lcd.print("Y-acceleration: "); M5.Lcd.print(1000 * IMU.ay); + M5.Lcd.println(" mg "); + M5.Lcd.print("Z-acceleration: "); M5.Lcd.print(1000 * IMU.az); + M5.Lcd.println(" mg "); + } + delay(500); } ``` \ No newline at end of file diff --git a/docs/ja/api/speaker.md b/docs/ja/api/speaker.md index cf698fd4..c36d8025 100644 --- a/docs/ja/api/speaker.md +++ b/docs/ja/api/speaker.md @@ -22,8 +22,10 @@ tone(uint16_t freq, [uint32_t duration]); ```arduino #include -M5.begin(); -M5.Speaker.tone(900, 1000); +void setup() { + M5.begin(); + M5.Speaker.tone(900, 1000); +} ```