udpate api en ja

This commit is contained in:
塩入孔章
2019-02-28 15:56:00 +08:00
parent 874752e6cb
commit 2e3f1afe90
8 changed files with 429 additions and 384 deletions
+4 -4
View File
@@ -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 <M5Stack.h>
@@ -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 <M5Stack.h>
@@ -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 <M5Stack.h>
@@ -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 <M5Stack.h>
+69 -58
View File
@@ -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:**
<mark>fillScreen(uint16_t color);</mark> // 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 <M5Stack.h>
@@ -30,15 +33,15 @@ from m5ui import *
lcd.fillScreen(lcd.RED)
``` -->
* * *
<!-- ### ```arduinolcd.setColor(color [, background_color])</mark> -->
## setTextColor()
<!-- ### <mark>lcd.setColor(color [, background_color])</mark> -->
### setTextColor()
**Syntax:**
**Function prototype:**
<mark>setTextColor(uint16_t color, uint16_t backgroundcolor);</mark> // 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 <M5Stack.h>
@@ -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);
```
<mark>setCursor(uint16_t x0, uint16_t y0);</mark> // for arduino
<!-- <mark>setCursor(x0, y0)</mark> # for micropython -->
<!-- ```arduinosetCursor(x0, y0)</mark> # for micropython -->
**Function: Move the cursor to (x0, y0).**
**Example:**
```arduino
#include <M5Stack.h>
@@ -95,13 +100,13 @@ from m5ui import *
lcd.drawPixel(22,22,lcd.RED)
``` -->
* * *
## drawPixel()
### drawPixel()
**Syntax:**
**Function prototype:**
<mark>drawPixel(int16_t x, int16_t y, uint16_t color);</mark> // 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 <M5Stack.h>
@@ -127,13 +133,13 @@ from m5ui import *
lcd.drawPixel(22,22,lcd.RED)
``` -->
* * *
## drawLine()
### drawLine()
**Syntax:**
**Function prototype:**
<mark>drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);</mark> // 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 <M5Stack.h>
@@ -159,13 +166,13 @@ from m5ui import *
lcd.drawLine(0,0,12,12,lcd.WHITE)
``` -->
* * *
## drawTriangle()
### drawTriangle()
**Syntax:**
**Function prototype:**
<mark>drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);</mark> // 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 <M5Stack.h>
@@ -191,13 +199,13 @@ from m5ui import *
lcd.drawLine(0,0,12,12,lcd.WHITE)
``` -->
* * *
## fillTriangle()
### fillTriangle()
**Syntax:**
**Function prototype:**
<mark>fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);</mark> // 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 <M5Stack.h>
@@ -223,13 +232,13 @@ from m5ui import *
lcd.drawLine(0,0,12,12,lcd.WHITE)
``` -->
* * *
## drawRect()
### drawRect()
**Syntax:**
**Function prototype:**
<mark>drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);</mark> // 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 <M5Stack.h>
@@ -257,13 +267,13 @@ from m5ui import *
lcd.drawLine(0,0,12,12,lcd.WHITE)
``` -->
* * *
## fillRect()
### fillRect()
**Syntax:**
**Function prototype:**
<mark>fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);</mark> // 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 <M5Stack.h>
@@ -291,13 +302,13 @@ from m5ui import *
lcd.drawLine(0,0,12,12,lcd.WHITE)
``` -->
* * *
## drawRoundRect()
### drawRoundRect()
**Syntax:**
**Function prototype:**
<mark>drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color);</mark> // 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 <M5Stack.h>
@@ -326,19 +338,20 @@ from m5ui import *
lcd.drawLine(0,0,12,12,lcd.WHITE)
``` -->
* * *
## print()
### print()
**Syntax:**
**Function prototype:**
<mark>print();</mark> // 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 <M5Stack.h>
@@ -354,9 +367,7 @@ from m5ui import *
lcd.drawLine(0,0,12,12,lcd.WHITE)
``` -->
* * *
### Usage {docsify-ignore}
## Usage {docsify-ignore}
```arduino
#include <M5Stack.h>
+167 -151
View File
@@ -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:**
<mark>void initMPU9250();</mark>
```arduino
void initMPU9250();
```
<!-- <mark>fillScreen(color)</mark> # for micropython -->
**Description:**
**功能:初始化 MPU6500 芯片。**
This function initialize MPU6500 chip.
**Example:**
**例程:**
```arduino
#include <M5Stack.h>
#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:**
<mark>void initAK8963(float * destination);</mark>
```arduino
void initAK8963(float * destination);
```
<!-- <mark>fillScreen(color)</mark> # for micropython -->
**Description:**
**功能:初始化 AK8963 芯片。**
This function initialize AK8963 chip.
| 参数 | 描述 |
| --- | --- |
| destination | 出厂预设于 AK8963 芯片内缺省值的数组指针 |
| Argument | Description | Type |
| --- | --- | -- |
| destination | for AK8963 Calibration Value | float * |
**Example:**
**例程:**
```arduino
#include <M5Stack.h>
#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:**
<mark>void calibrateMPU9250(float * gyroBias, float * accelBias);</mark>
```arduino
void calibrateMPU9250(float * gyroBias, float * accelBias);
```
<!-- <mark>fillScreen(color)</mark> # for micropython -->
**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 <M5Stack.h>
#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:**
<mark>uint8_t readByte(uint8_t address, uint8_t subAddress);</mark>
```arduino
uint8_t readByte(uint8_t address, uint8_t subAddress);
```
<!-- <mark>fillScreen(color)</mark> # for micropython -->
**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 <M5Stack.h>
#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:**
<mark>void readGyroData(int16_t * destination);</mark>
```arduino
void readGyroData(int16_t * destination);
```
<!-- <mark>fillScreen(color)</mark> # for micropython -->
**Description:**
**功能:读取三个方向的陀螺仪值。**
This function reads the value of 3-axis gyro sensor.
| 参数 | 描述 |
| --- | --- |
| destination | 保存陀螺仪值的数组的地址 |
| Argument | Description | Type |
| --- | --- | -- |
| destination | read gyro values | int16_t * |
**Example:**
**例程:**
```arduino
#include <M5Stack.h>
#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:**
<mark>void readAccelData(int16_t * destination);</mark>
```arduino
void readAccelData(int16_t * destination);
```
<!-- <mark>fillScreen(color)</mark> # for micropython -->
**Description:**
**功能:读取三个方向的加速度值。**
This function reads the value of 3-axis accelerate sensor.
| 参数 | 描述 |
| --- | --- |
| destination | 保存加速度值的数组的地址 |
| Argument | Description | Type |
| --- | --- | -- |
| destination | read accelerate values | int16_t * |
**Example:**
**例程:**
```arduino
#include <M5Stack.h>
#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);
}
```
+13 -13
View File
@@ -2,25 +2,25 @@
### tone
**Function prototype:**
**Syntax:**
<mark>tone(uint16_t freq);</mark> // for arduino
```arduino
tone(uint16_t freq, [uint32_t duration]);
```
<mark>tone(uint16_t freq, uint32_t duration);</mark> // for arduino
<!-- <mark>fillScreen(color)</mark> # for micropython -->
**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 <M5Stack.h>
M5.begin();
M5.Speaker.tone(900, 1000);
void setup() {
M5.begin();
M5.Speaker.tone(900, 1000);
}
```
+3 -3
View File
@@ -34,7 +34,7 @@ void M5Stack::begin(bool LCDEnable, bool SDEnable, bool SerialEnable) {
}
```
**Sample:**
**Example:**
```arduino
#include <M5Stack.h>
@@ -71,7 +71,7 @@ void M5Stack::update() {
}
```
**Sample:**
**Example:**
```arduino
#include <M5Stack.h>
@@ -121,7 +121,7 @@ void M5Stack::powerOFF() {
}
```
**Sample:**
**Example:**
```arduino
#include <M5Stack.h>
+2 -2
View File
@@ -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 <M5Stack.h>
@@ -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
/*
+167 -151
View File
@@ -1,259 +1,275 @@
# 姿态传感器 MPU9250
# IMU Sensor MPU9250
*姿态传感器 MPU9250 是一款多芯片模块,集成两个芯片,一个芯片是 MPU6500,由 3 轴陀螺仪和 3 轴加速度计组成,另外一个是 AK8963 是 3 轴磁力计*
*IMUとして搭載されているMPU9250は2種類のチップを1つのモジュールに統合しています。ひとつはMPU6500という3軸のジャイロセンサーと3軸の加速度センサーのチップです。もうひとつはAK8963という3軸地磁気センサーのチップです*
## initMPU9250()
**函数原型:**
**構文:**
<mark>void initMPU9250();</mark>
```arduino
void initMPU9250();
```
<!-- <mark>fillScreen(color)</mark> # for micropython -->
**説明:**
**功能:初始化 MPU6500 芯片。**
MPU6500チップを初期化します。
**使用例:**
**例程:**
```arduino
#include <M5Stack.h>
#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()
**函数原型:**
**構文:**
<mark>void initAK8963(float * destination);</mark>
```arduino
void initAK8963(float * destination);
```
<!-- <mark>fillScreen(color)</mark> # for micropython -->
**説明:**
**功能:初始化 AK8963 芯片。**
AK8963チップを初期化します。
| 数 | 描述 |
| --- | --- |
| destination | 出厂预设于 AK8963 芯片内缺省值的数组指针 |
| 数 | 説明 | 型 |
| --- | --- | -- |
| destination | AK8963補正用の値を保存する変数 | float * |
**使用例:**
**例程:**
```arduino
#include <M5Stack.h>
#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()
**函数原型:**
**構文:**
<mark>void calibrateMPU9250(float * gyroBias, float * accelBias);</mark>
```arduino
void calibrateMPU9250(float * gyroBias, float * accelBias);
```
<!-- <mark>fillScreen(color)</mark> # for micropython -->
**説明:**
**功能:初始化芯片后,执行该函数以读取静止状态下的陀螺仪和加速度值偏移,并保存到各自的偏移寄存器。**
ジャイロと加速度センサーの補正値を計算します。
| 数 | 描述 |
| --- | --- |
| gyroBias | 保存静止下陀螺仪值的数组的地址 |
| accelBias | 保存静止下加速度值的数组的地址 |
| 数 | 説明 | 型 |
| --- | --- | -- |
| gyroBias | gyro オフセット | float * |
| accelBias | accel オフセット | float * |
**使用例:**
**例程:**
```arduino
#include <M5Stack.h>
#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()
**函数原型:**
**構文:**
<mark>uint8_t readByte(uint8_t address, uint8_t subAddress);</mark>
```arduino
uint8_t readByte(uint8_t address, uint8_t subAddress);
```
<!-- <mark>fillScreen(color)</mark> # for micropython -->
**説明:**
**功能:读取指定寄存器内数据。返回值:寄存器值,长度为8 位。**
MPU9250の指定のレジスタから1バイト分のデータを取得します。
| 数 | 描述 |
| --- | --- |
| address | 芯片 (MPU9250/AK8963)地址 |
| subAddress | 芯片内寄存器地址 |
| 数 | 説明 | 型 |
| --- | --- | -- |
| address | (MPU9250/AK8963) I2Cアドレス | uint8_t |
| subAddress | レジスタアドレス | uint8_t |
**使用例:**
**例程:**
```arduino
#include <M5Stack.h>
#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()
**函数原型:**
**構文:**
<mark>void readGyroData(int16_t * destination);</mark>
```arduino
void readGyroData(int16_t * destination);
```
<!-- <mark>fillScreen(color)</mark> # for micropython -->
**説明:**
**功能:读取三个方向的陀螺仪值。**
3軸ジャイロセンサーの値を取得します。
| 数 | 描述 |
| --- | --- |
| destination | 保存陀螺仪值的数组的地址 |
| 数 | 説明 | 型 |
| --- | --- | -- |
| destination | ジャイロセンサーの値 | int16_t * |
**使用例:**
**例程:**
```arduino
#include <M5Stack.h>
#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()
**函数原型:**
**構文:**
<mark>void readAccelData(int16_t * destination);</mark>
```arduino
void readAccelData(int16_t * destination);
```
<!-- <mark>fillScreen(color)</mark> # for micropython -->
**説明:**
**功能:读取三个方向的加速度值。**
3軸加速度センサーから値を取得します。
| 数 | 描述 |
| --- | --- |
| destination | 保存加速度值的数组的地址 |
| 数 | 説明 | 型 |
| --- | --- | -- |
| destination | 加速度センサーの値 | int16_t * |
**使用例:**
**例程:**
```arduino
#include <M5Stack.h>
#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);
}
```
+4 -2
View File
@@ -22,8 +22,10 @@ tone(uint16_t freq, [uint32_t duration]);
```arduino
#include <M5Stack.h>
M5.begin();
M5.Speaker.tone(900, 1000);
void setup() {
M5.begin();
M5.Speaker.tone(900, 1000);
}
```
<!--