Merge pull request #253 from Tinyu-Zhao/master

Changed some files
This commit is contained in:
Sean Kwok
2021-07-16 12:07:10 +08:00
committed by GitHub
14 changed files with 264 additions and 10553 deletions
+21 -25
View File
@@ -1,39 +1,35 @@
/*
Name: button.ino
Created: 2018/9/21 14:06:15
Author: sakabin
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with M5Core sample source code
* Visit the website for more informationhttps://docs.m5stack.com/en/products
*
* describeButton example
* date2021/7/15
*******************************************************************************
*/
#include <M5Stack.h>
// The setup() function runs once each time the micro-controller starts
// After M5Core is started or reset
// the program in the setUp () function will be run, and this part will only be run once.
void setup() {
// init lcd, serial, but don't init sd card
M5.begin(true, false, true);
/*
Power chip connected to gpio21, gpio22, I2C device
Set battery charging voltage and current
If used battery, please call this function in your project
*/
M5.Power.begin();
M5.begin(); //Init M5Core
M5.Power.begin();//Init Power module
M5.Lcd.clear(BLACK);
M5.Lcd.setTextColor(YELLOW);
M5.Lcd.setTextSize(2);
M5.Lcd.setCursor(65, 10);
M5.Lcd.println("Button example");
M5.Lcd.setTextColor(YELLOW); // Set the font color to yellow
M5.Lcd.setTextSize(2); // Set the font size
M5.Lcd.setCursor(65, 10); //Move the cursor position to (x, y)
M5.Lcd.println("Button example"); //The screen prints the formatted string and wraps the line
M5.Lcd.setCursor(3, 35);
M5.Lcd.println("Press button B for 700ms");
M5.Lcd.println("to clear screen.");
M5.Lcd.setTextColor(RED);
}
// Add the main program code into the continuous loop() function
//After the program in setup() runs, it runs the program in loop()
//The loop() function is an infinite loop in which the program runs repeatedly
void loop() {
// update button state
M5.update();
// if you want to use Releasefor("was released for"), use .wasReleasefor(int time) below
M5.update(); //Read the press state of the key
//Returns 1 if key A is released or pressed longer than the specified time
if (M5.BtnA.wasReleased() || M5.BtnA.pressedFor(1000, 200)) {
M5.Lcd.print('A');
} else if (M5.BtnB.wasReleased() || M5.BtnB.pressedFor(1000, 200)) {
@@ -41,7 +37,7 @@ void loop() {
} else if (M5.BtnC.wasReleased() || M5.BtnC.pressedFor(1000, 200)) {
M5.Lcd.print('C');
} else if (M5.BtnB.wasReleasefor(700)) {
M5.Lcd.clear(BLACK);
M5.Lcd.clear(WHITE); // Clear the screen and set white to the background color
M5.Lcd.setCursor(0, 0);
}
}
+29 -30
View File
@@ -1,21 +1,23 @@
/*
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with M5Core sample source code
* Visit the website for more informationhttps://docs.m5stack.com/en/products
*
* describeDisplay Example
* date2021/7/15
*******************************************************************************
*/
#include <M5Stack.h>
// the setup routine runs once when M5Stack starts up
// After M5Core is started or reset
// the program in the setUp () function will be run, and this part will only be run once.
void setup() {
// initialize the M5Stack object
M5.begin();
M5.begin(); //Init M5Core
M5.Power.begin(); //Init Power module
/*
Power chip connected to gpio21, gpio22, I2C device
Set battery charging voltage and current
If used battery, please call this function in your project
*/
M5.Power.begin();
// Lcd display
M5.Lcd.fillScreen(WHITE);
delay(500);
M5.Lcd.fillScreen(WHITE); // Set the screen background color to white
delay(500); //Delay 500ms
M5.Lcd.fillScreen(RED);
delay(500);
M5.Lcd.fillScreen(GREEN);
@@ -25,34 +27,31 @@ void setup() {
M5.Lcd.fillScreen(BLACK);
delay(500);
// text print
M5.Lcd.fillScreen(BLACK);
M5.Lcd.setCursor(10, 10);
M5.Lcd.setTextColor(WHITE);
M5.Lcd.setTextSize(1);
M5.Lcd.printf("Display Test!");
M5.Lcd.setCursor(10, 10); // Move the cursor position to (x,y)
M5.Lcd.setTextColor(WHITE); // Set the font color to white,
M5.Lcd.setTextSize(1); // Set the font size
M5.Lcd.printf("Display Test!"); // Serial output format string
// draw graphic
delay(1000);
M5.Lcd.drawRect(100, 100, 50, 50, BLUE);
M5.Lcd.drawRect(100, 100, 50, 50, BLUE); // Draw a 50x50 blue rectangle wireframe at (x,y)
delay(1000);
M5.Lcd.fillRect(100, 100, 50, 50, BLUE);
M5.Lcd.fillRect(100, 100, 50, 50, BLUE); // Draw a blue rectangle 50x50 at (x,y)
delay(1000);
M5.Lcd.drawCircle(100, 100, 50, RED);
M5.Lcd.drawCircle(100, 100, 50, RED); // Draw a red circle of radius 50 at (x,y)
delay(1000);
M5.Lcd.fillCircle(100, 100, 50, RED);
M5.Lcd.fillCircle(100, 100, 50, RED); //Draw a red circle of radius 50 at (x,y)
delay(1000);
M5.Lcd.drawTriangle(30, 30, 180, 100, 80, 150, YELLOW);
M5.Lcd.drawTriangle(30, 30, 180, 100, 80, 150, YELLOW); // Make a triangle wireframe with (x1,y1) (x2,y2) (x3,y3) as the vertices
delay(1000);
M5.Lcd.fillTriangle(30, 30, 180, 100, 80, 150, YELLOW);
M5.Lcd.fillTriangle(30, 30, 180, 100, 80, 150, YELLOW); // Construct a triangle with (x1,y1) (x2,y2) (x3,y3) as its vertices
}
// the loop routine runs over and over again forever
//After the program in setup() runs, it runs the program in loop()
//The loop() function is an infinite loop in which the program runs repeatedly
void loop(){
//rand draw
M5.Lcd.fillTriangle(random(M5.Lcd.width()-1), random(M5.Lcd.height()-1), random(M5.Lcd.width()-1), random(M5.Lcd.height()-1), random(M5.Lcd.width()-1), random(M5.Lcd.height()-1), random(0xfffe));
M5.update();
M5.update(); //Read the press state of the key
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
+20 -15
View File
@@ -1,23 +1,28 @@
/*
*******************************************************************************
*Copyright (c) 2021 by M5Stack
* Equipped with M5Core sample source code
*Visit the website for more informationhttps://docs.m5stack.com/en/products
*
* describeHello World
* date2021/7/15
*******************************************************************************
*/
#include <M5Stack.h>
// the setup routine runs once when M5Stack starts up
// After M5Core is started or reset
// the program in the setUp () function will be run, and this part will only be run once.
void setup(){
M5.begin(); //Init M5Core
M5.Power.begin(); /*Power chip connected to gpio21, gpio22, I2C device
Set battery charging voltage and current
If used battery, please call this function in your project*/
// Initialize the M5Stack object
M5.begin();
/*
Power chip connected to gpio21, gpio22, I2C device
Set battery charging voltage and current
If used battery, please call this function in your project
*/
M5.Power.begin();
// LCD display
M5.Lcd.print("Hello World");
M5.Lcd.print("Hello World"); // Print text on the screen (string)
}
// the loop routine runs over and over again forever
//After the program in setup() runs, it runs the program in loop()
//The loop() function is an infinite loop in which the program runs repeatedly
void loop() {
}
}
+50 -43
View File
@@ -1,12 +1,17 @@
// define must ahead #include <M5Stack.h>
#define M5STACK_MPU6886
// #define M5STACK_MPU9250
// #define M5STACK_MPU6050
// #define M5STACK_200Q
/*
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with M5Core sample source code
* Visit the website for more informationhttps://docs.m5stack.com/en/products
*
* describeMPU6886 example
* date2021/7/15
*******************************************************************************
*/
#define M5STACK_MPU6886
#include <M5Stack.h>
float accX = 0.0F;
float accX = 0.0F; // Define variables for storing inertial sensor data
float accY = 0.0F;
float accZ = 0.0F;
@@ -20,47 +25,49 @@ float yaw = 0.0F;
float temp = 0.0F;
// the setup routine runs once when M5Stack starts up
// After M5Core is started or reset
// the program in the setUp () function will be run, and this part will only be run once.
void setup(){
// Initialize the M5Stack object
M5.begin();
/*
Power chip connected to gpio21, gpio22, I2C device
Set battery charging voltage and current
If used battery, please call this function in your project
*/
M5.Power.begin();
M5.begin(); //Init M5Core
M5.Power.begin(); //Init Power module
M5.IMU.Init();
M5.IMU.Init(); //Init IMU sensor
M5.Lcd.fillScreen(BLACK);
M5.Lcd.setTextColor(GREEN , BLACK);
M5.Lcd.setTextSize(2);
M5.Lcd.fillScreen(BLACK); // Set the screen background color to black
M5.Lcd.setTextColor(GREEN , BLACK); // Sets the foreground color and background color of the displayed text
M5.Lcd.setTextSize(2); // Set the font size
}
// the loop routine runs over and over again forever
//After the program in setup() runs, it runs the program in loop()
//The loop() function is an infinite loop in which the program runs repeatedly
void loop() {
// put your main code here, to run repeatedly:
M5.IMU.getGyroData(&gyroX,&gyroY,&gyroZ);
M5.IMU.getAccelData(&accX,&accY,&accZ);
M5.IMU.getAhrsData(&pitch,&roll,&yaw);
M5.IMU.getTempData(&temp);
M5.Lcd.setCursor(0, 20);
M5.Lcd.printf("%6.2f %6.2f %6.2f ", gyroX, gyroY, gyroZ);
M5.Lcd.setCursor(220, 42);
M5.Lcd.print(" o/s");
M5.Lcd.setCursor(0, 65);
M5.Lcd.printf(" %5.2f %5.2f %5.2f ", accX, accY, accZ);
M5.Lcd.setCursor(220, 87);
M5.Lcd.print(" G");
M5.Lcd.setCursor(0, 110);
M5.Lcd.printf(" %5.2f %5.2f %5.2f ", pitch, roll, yaw);
M5.Lcd.setCursor(220, 132);
M5.Lcd.print(" degree");
M5.Lcd.setCursor(0, 155);
M5.IMU.getGyroData(&gyroX,&gyroY,&gyroZ); // Stores the triaxial gyroscope data of the inertial sensor to the relevant variable
M5.IMU.getAccelData(&accX,&accY,&accZ); // Stores the triaxial accelerometer data of the inertial sensor to the relevant variable
M5.IMU.getAhrsData(&pitch,&roll,&yaw); // Stores the inertial sensor attitude to the relevant variable
M5.IMU.getTempData(&temp); // Stores the inertial sensor temperature to temp
// The M5Core screen is 320x240 pixels, starting at the top left corner of the screen (0,0).
// gyroscope output related
M5.Lcd.setCursor(0, 20); // Move the cursor position to (x,y)
M5.Lcd.printf("gyroX, gyroY, gyroZ"); // Screen printingformatted string
M5.Lcd.setCursor(0, 42);
M5.Lcd.printf("%6.2f %6.2f%6.2f o/s", gyroX, gyroY, gyroZ);
// Accelerometer output is related
M5.Lcd.setCursor(0, 70);
M5.Lcd.printf("accX, accY, accZ");
M5.Lcd.setCursor(0, 92);
M5.Lcd.printf("%5.2f %5.2f %5.2f G", accX, accY, accZ);
// Pose output is related
M5.Lcd.setCursor(0, 120);
M5.Lcd.printf("pitch, roll, yaw");
M5.Lcd.setCursor(0, 142);
M5.Lcd.printf("%5.2f %5.2f %5.2f deg", pitch, roll, yaw);
// Inertial sensor temperature output related
M5.Lcd.setCursor(0, 175);
M5.Lcd.printf("Temperature : %.2f C", temp);
delay(1);
}
delay(1000); // Delay 1000ms (1 sec)
}
+23 -23
View File
@@ -1,30 +1,30 @@
/*
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with M5Core sample source code
* Visit the website for more informationhttps://docs.m5stack.com/en/products
*
* describePower Management Example
* date2021/7/15
*******************************************************************************
*/
#include <M5Stack.h>
// the setup routine runs once when M5Stack starts up
// After M5Core is started or reset
// the program in the setUp () function will be run, and this part will only be run once.
void setup(){
M5.begin(); //Init M5Core
M5.Power.begin(); //Init Power module
M5.Power.lightSleep(SLEEP_SEC(5));
M5.Lcd.setTextSize(2); // Set the font size
M5.Lcd.print("press ButtonA: shutdown, use power button to turn back on");// Screen printing the formatted string
}
// initialize the M5Stack object
M5.begin();
/*
Power chip connected to gpio21, gpio22, I2C device
Set battery charging voltage and current
If used battery, please call this function in your project
*/
M5.Power.begin();
// Lcd display
M5.Lcd.setTextSize(2);
M5.Lcd.println("Software Power-OFF Demo");
M5.Lcd.println("Press Button A ...");
}
// the loop routine runs over and over again forever
//After the program in setup() runs, it runs the program in loop()
//The loop() function is an infinite loop in which the program runs repeatedly
void loop() {
if(M5.BtnA.wasPressed()) {
M5.Power.powerOFF();
M5.update(); //Read the press state of the key
if(M5.BtnA.wasPressed()) { // Check if the key is pressed
M5.Power.powerOFF(); //Turn off power
}
M5.update();
}
+31 -30
View File
@@ -1,47 +1,48 @@
/*
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with M5Core sample source code
* Visit the website for more informationhttps://docs.m5stack.com/en/products
*
* describeSleep example
* date2021/7/15
*******************************************************************************
*/
#include <M5Stack.h>
// After M5Core is started or reset
// the program in the setUp () function will be run, and this part will only be run once.
void setup() {
M5.begin();
M5.begin(); //Init M5Core
M5.Power.begin(); //Init Power module
/*
Power chip connected to gpio21, gpio22, I2C device
Set battery charging voltage and current
If used battery, please call this function in your project
*/
M5.Power.begin();
M5.Lcd.setBrightness(200);
M5.Power.setWakeupButton(BUTTON_A_PIN);
if(!M5.Power.canControl()) {
M5.Lcd.printf("IP5306 is not i2c version\n");
}
M5.Power.setWakeupButton(BUTTON_A_PIN); // Set the screen wake-up button to A
M5.Lcd.setBrightness(200); // Set the screen brightness to 200 nits
}
//After the program in setup() runs, it runs the program in loop()
//The loop() function is an infinite loop in which the program runs repeatedly
void loop() {
M5.update();
bool c=M5.Power.isResetbyPowerSW();
bool d=M5.Power.isResetbyDeepsleep();
M5.update(); //Read the press state of the key
bool c=M5.Power.isResetbyPowerSW(); // Determine if M5Core is started when powered on
bool d=M5.Power.isResetbyDeepsleep(); // Determine if M5Core starts after deep sleep
M5.Lcd.printf("<<Sleep test>>\n");
M5.Lcd.printf("power-on triggered at:%s%s\n\n",c?"POWER-SW":"",d?"DeepSleep-end":"");
M5.Lcd.println("<Sleep test>"); // Print the formatted string and wrap it
M5.Lcd.printf("power-on triggered at:%s%s\n\n",(c) ? ("POWER-SW") : (""),(d) ? ("DeepSleep-end") : (""));
M5.Lcd.printf("Go lightSleep (5s or press buttonA wake up)\n");
delay(2500);
// Calling this function will disable the power button
// To restore power btn please call M5.Power.setPowerBoostKeepOn(false)
M5.Power.lightSleep(SLEEP_SEC(5));
delay(2500); //delay 2500ms
M5.Power.lightSleep(SLEEP_SEC(10)); /*/Restart after 10 seconds of light sleep and continue from the next line
Calling this function will disable the power button to restore the power button
Please call M5.Power.setPowerBoostKeepOn(false)*/
M5.Lcd.printf("Go lightSleep (press buttonA wake up)\n");
delay(2500);
// Calling this function will disable the power button
// To restore power btn please call M5.Power.setPowerBoostKeepOn(false)
M5.Power.lightSleep(0);
M5.Lcd.printf("resume.\n\nGo deepSleep (press buttonA wake up) ");
delay(2500);
// Calling this function will disable the power button
// To restore power btn please call M5.Power.setPowerBoostKeepOn(false)
M5.Power.deepSleep(0);
M5.Power.deepSleep(0); /*After waking up from deep sleep for 0 seconds,
the CPU will restart and the program will be executed from the beginning
Calling this function will disable the power button to restore the power button
Please call M5.Power.setPowerBoostKeepOn(false)*/
}
+28 -22
View File
@@ -1,5 +1,16 @@
/*
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with M5Core sample source code
* Visit the website for more informationhttps://docs.m5stack.com/en/products
*
* describeSpeaker example
* date2021/7/15
*******************************************************************************
*/
#include <M5Stack.h>
// Set the frequency of the speaker
#define NOTE_D0 -1
#define NOTE_D1 294
#define NOTE_D2 330
@@ -25,32 +36,27 @@
#define NOTE_DH6 990
#define NOTE_DH7 112
// After M5Core is started or reset
// the program in the setUp () function will be run, and this part will only be run once.
void setup() {
// Initialize the M5Stack object
M5.begin();
/*
Power chip connected to gpio21, gpio22, I2C device
Set battery charging voltage and current
If used battery, please call this function in your project
*/
M5.Power.begin();
M5.Lcd.printf("M5Stack Speaker test:\r\n");
M5.begin(); //Init M5Core
M5.Power.begin(); //Init Power module
M5.Lcd.println("M5Stack Speaker test"); // Print the formatted string and wrap it
}
//After the program in setup() runs, it runs the program in loop()
//The loop() function is an infinite loop in which the program runs repeatedly
void loop() {
if(M5.BtnA.wasPressed()) {
M5.Lcd.printf("A wasPressed \r\n");
M5.Speaker.beep(); //beep
}
M5.update(); //Read the press state of the key
if(M5.BtnB.wasPressed())
{
M5.Lcd.printf("B wasPressed \r\n");
M5.Speaker.tone(NOTE_DH2, 200); //frequency 3000, with a duration of 200ms
if(M5.BtnA.wasPressed()) { //Check if the key is pressed
M5.Lcd.println("A wasPressed");
M5.Speaker.tone(NOTE_DH2, 200); // Set the speaker to ring at 661Hz for 200ms
}else if(M5.BtnB.wasPressed()){
M5.Lcd.println("B wasPressed");
M5.Speaker.tone(NOTE_DH7); // Set the horn to continuously sound at 112Hz
}else if(M5.BtnC.wasPressed()){
M5.Lcd.println("C wasPressed");
M5.Speaker.end(); // Turn off the speaker
}
M5.update();
}
+1 -1
View File
@@ -622,7 +622,7 @@ int8_t bmm150_soft_reset(const struct bmm150_dev *dev)
}
/*!
* @brief This API is used to set the power mode of the sensor.
* @brief
*/
int8_t bmm150_set_op_mode(struct bmm150_dev *dev)
{
+59 -83
View File
@@ -1,10 +1,13 @@
/*
* @Author: Sorzn
* @Date: 2019-11-21 19:58:40
* @LastEditTime: 2019-11-22 20:36:35
* @Description: M5Stack project
* @FilePath: /bmm150/bmm150.ino
*/
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with M5Core sample source code
* Visit the website for more informationhttps://docs.m5stack.com/en/products
*
* describebmm150--Magnetometer example
* date2021/7/15
*******************************************************************************
*/
#include <Arduino.h>
#include <Wire.h>
@@ -17,135 +20,110 @@
Preferences prefs;
struct bmm150_dev dev;
bmm150_mag_data mag_offset;
bmm150_mag_data mag_offset; // Compensation magnetometer float data storage
bmm150_mag_data mag_max;
bmm150_mag_data mag_min;
TFT_eSprite img = TFT_eSprite(&M5.Lcd);
int8_t i2c_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *read_data, uint16_t len)
{
if(M5.I2C.readBytes(dev_id, reg_addr, len, read_data))
{
int8_t i2c_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *read_data, uint16_t len){
if(M5.I2C.readBytes(dev_id, reg_addr, len, read_data)){ // Check whether the device ID, address, data exist
return BMM150_OK;
}
else
{
}else{
return BMM150_E_DEV_NOT_FOUND;
}
}
int8_t i2c_write(uint8_t dev_id, uint8_t reg_addr, uint8_t *read_data, uint16_t len)
{
if(M5.I2C.writeBytes(dev_id, reg_addr, read_data, len))
{
int8_t i2c_write(uint8_t dev_id, uint8_t reg_addr, uint8_t *read_data, uint16_t len){
if(M5.I2C.writeBytes(dev_id, reg_addr, read_data, len)){ //Writes data of length len to the specified device address
return BMM150_OK;
}
else
{
}else{
return BMM150_E_DEV_NOT_FOUND;
}
}
int8_t bmm150_initialization()
{
int8_t bmm150_initialization(){
int8_t rslt = BMM150_OK;
/* Sensor interface over SPI with native chip select line */
dev.dev_id = 0x10;
dev.intf = BMM150_I2C_INTF;
dev.read = i2c_read;
dev.write = i2c_write;
dev.delay_ms = delay;
dev.dev_id = 0x10; // Device address setting
dev.intf = BMM150_I2C_INTF; //SPI or I2C interface setup
dev.read = i2c_read; // Read the bus pointer
dev.write = i2c_write; // Write the bus pointer
dev.delay_ms = delay;
/* make sure max < mag data first */
// Set the maximum range range
mag_max.x = -2000;
mag_max.y = -2000;
mag_max.z = -2000;
/* make sure min > mag data first */
// Set the minimum range
mag_min.x = 2000;
mag_min.y = 2000;
mag_min.z = 2000;
rslt = bmm150_init(&dev);
dev.settings.pwr_mode = BMM150_NORMAL_MODE;
rslt |= bmm150_set_op_mode(&dev);
rslt = bmm150_init(&dev); // Memory chip ID
dev.settings.pwr_mode = BMM150_NORMAL_MODE;
rslt |= bmm150_set_op_mode(&dev); // Set the sensor power mode
dev.settings.preset_mode = BMM150_PRESETMODE_ENHANCED;
rslt |= bmm150_set_presetmode(&dev);
rslt |= bmm150_set_presetmode(&dev); // Set the preset mode of the sensor
return rslt;
}
void bmm150_offset_save()
{
void bmm150_offset_save(){ //Store the data
prefs.begin("bmm150", false);
prefs.putBytes("offset", (uint8_t *)&mag_offset, sizeof(bmm150_mag_data));
prefs.end();
}
void bmm150_offset_load()
{
if(prefs.begin("bmm150", true))
{
void bmm150_offset_load(){ //load the data
if(prefs.begin("bmm150", true)){
prefs.getBytes("offset", (uint8_t *)&mag_offset, sizeof(bmm150_mag_data));
prefs.end();
Serial.printf("bmm150 load offset finish.... \r\n");
}
else
{
Serial.printf("bmm150 load offset failed.... \r\n");
Serial.println("bmm150 load offset finish....");
}else{
Serial.println("bmm150 load offset failed....");
}
}
void setup()
{
M5.begin(true, false, true, false);
M5.Power.begin();
Wire.begin(21, 22, 400000);
void setup() {
M5.begin(true, false, true, false); //Init M5Core(Initialize LCD, serial port)
M5.Power.begin(); //Init Power module
Wire.begin(21, 22, 400000); //Set the frequency of the SDA SCL
img.setColorDepth(1);
img.setTextColor(TFT_WHITE);
img.createSprite(320, 240);
img.setBitmapColor(TFT_WHITE, 0);
img.setColorDepth(1); // Set bits per pixel for colour
img.setTextColor(TFT_WHITE); //Set the font foreground colour (background is
img.createSprite(320, 240); // Create a sprite (bitmap) of defined width and height
img.setBitmapColor(TFT_WHITE, 0); //Set the foreground and background colour
if(bmm150_initialization() != BMM150_OK)
{
img.fillSprite(0);
img.drawCentreString("BMM150 init failed", 160, 110, 4);
img.pushSprite(0, 0);
for(;;)
{
delay(100);
if(bmm150_initialization() != BMM150_OK){
img.fillSprite(0); //Fill the whole sprite with defined colour
img.drawCentreString("BMM150 init failed", 160, 110, 4); //draw string centred on 160
img.pushSprite(0, 0); //Push the sprite to the TFT at 0, 0
for(;;){
delay(100); //delay 100ms
}
}
bmm150_offset_load();
}
void bmm150_calibrate(uint32_t calibrate_time)
{
void bmm150_calibrate(uint32_t calibrate_time){ //bbm150 data calibrate
uint32_t calibrate_timeout = 0;
calibrate_timeout = millis() + calibrate_time;
Serial.printf("Go calibrate, use %d ms \r\n", calibrate_time);
Serial.printf("Go calibrate, use %d ms \r\n", calibrate_time); //The serial port outputs formatting characters
Serial.printf("running ...");
while (calibrate_timeout > millis())
{
bmm150_read_mag_data(&dev);
if(dev.data.x)
{
while (calibrate_timeout > millis()){
bmm150_read_mag_data(&dev); //read the magnetometer data from registers
if(dev.data.x){
mag_min.x = (dev.data.x < mag_min.x) ? dev.data.x : mag_min.x;
mag_max.x = (dev.data.x > mag_max.x) ? dev.data.x : mag_max.x;
}
if(dev.data.y)
{
if(dev.data.y){
mag_max.y = (dev.data.y > mag_max.y) ? dev.data.y : mag_max.y;
mag_min.y = (dev.data.y < mag_min.y) ? dev.data.y : mag_min.y;
}
if(dev.data.z)
{
if(dev.data.z){
mag_min.z = (dev.data.z < mag_min.z) ? dev.data.z : mag_min.z;
mag_max.z = (dev.data.z > mag_max.z) ? dev.data.z : mag_max.z;
}
@@ -163,10 +141,9 @@ void bmm150_calibrate(uint32_t calibrate_time)
Serial.printf("z_max: %.2f z_min: %.2f \r\n", mag_max.z, mag_min.z);
}
void loop()
{
void loop() {
char text_string[100];
M5.update();
M5.update(); //Read the press state of the key
bmm150_read_mag_data(&dev);
float head_dir = atan2(dev.data.x - mag_offset.x, dev.data.y - mag_offset.y) * 180.0 / M_PI;
Serial.printf("Magnetometer data, heading %.2f\n", head_dir);
@@ -175,7 +152,7 @@ void loop()
img.fillSprite(0);
sprintf(text_string, "MAG X: %.2f", dev.data.x);
img.drawString(text_string, 10, 20, 4);
img.drawString(text_string, 10, 20, 4); //draw string with padding
sprintf(text_string, "MAG Y: %.2f", dev.data.y);
img.drawString(text_string, 10, 50, 4);
sprintf(text_string, "MAG Z: %.2f", dev.data.z);
@@ -185,8 +162,7 @@ void loop()
img.drawCentreString("Press BtnA enter calibrate", 160, 150, 4);
img.pushSprite(0, 0);
if(M5.BtnA.wasPressed())
{
if(M5.BtnA.wasPressed()){
img.fillSprite(0);
img.drawCentreString("Flip + rotate core calibration", 160, 110, 4);
img.pushSprite(0, 0);
+1 -1
View File
@@ -10,7 +10,7 @@
"type": "git",
"url": "https://github.com/m5stack/m5stack.git"
},
"version": "0.3.2",
"version": "0.3.3",
"framework": "arduino",
"platforms": "espressif32"
}
+1 -1
View File
@@ -1,5 +1,5 @@
name=M5Stack
version=0.3.2
version=0.3.3
author=M5Stack
maintainer=Zibin Zheng <bin@m5stack.com>
sentence=Library for M5Stack Core development kit