初始化提交

This commit is contained in:
王立帮
2024-07-20 22:09:06 +08:00
commit c247dd07a6
6876 changed files with 2743096 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
#include <M5StickCPlus.h>
#include "AXP192.h"
TFT_eSprite tftSprite = TFT_eSprite(&M5.Lcd);
void setup() {
M5.begin();
M5.Lcd.setRotation(3);
tftSprite.createSprite(160, 80);
tftSprite.setRotation(3);
M5.Axp.EnableCoulombcounter();
}
void loop() {
tftSprite.fillSprite(BLACK);
tftSprite.setCursor(0, 0, 1);
tftSprite.printf("AXP Temp: %.1fC \r\n", M5.Axp.GetTempInAXP192());
tftSprite.setCursor(0, 10);
tftSprite.printf("Bat:\r\n V: %.3fv I: %.3fma\r\n", M5.Axp.GetBatVoltage(), M5.Axp.GetBatCurrent());
tftSprite.setCursor(0, 30);
tftSprite.printf("USB:\r\n V: %.3fv I: %.3fma\r\n", M5.Axp.GetVBusVoltage(), M5.Axp.GetVBusCurrent());
tftSprite.setCursor(0, 50);
tftSprite.printf("5V-In:\r\n V: %.3fv I: %.3fma\r\n", M5.Axp.GetVinVoltage(), M5.Axp.GetVinCurrent());
tftSprite.setCursor(0, 70);
tftSprite.printf("Bat power %.3fmw", M5.Axp.GetBatPower());
tftSprite.pushSprite(40, 20);
// 0x01 long press(1s), 0x02 press
if(M5.Axp.GetBtnPress() == 0x02)
{
esp_restart();
}
if(M5.BtnA.wasPressed())
{
// close tft voltage output
M5.Axp.SetLDO2(false);
}
if(M5.BtnB.wasPressed())
{
// close tft voltage output
M5.Axp.SetLDO2(true);
}
// M5.Axp.SetChargeCurrent(CURRENT_100MA);
M5.update();
delay(100);
}

View File

@@ -0,0 +1,47 @@
#include <M5StickCPlus.h>
// the setup routine runs once when M5StickC starts up
void setup() {
// initialize the M5StickC object
M5.begin();
// Lcd display
M5.Lcd.fillScreen(WHITE);
delay(500);
M5.Lcd.fillScreen(RED);
delay(500);
M5.Lcd.fillScreen(GREEN);
delay(500);
M5.Lcd.fillScreen(BLUE);
delay(500);
M5.Lcd.fillScreen(BLACK);
delay(500);
// text print
M5.Lcd.fillScreen(BLACK);
M5.Lcd.setCursor(0, 10);
M5.Lcd.setTextColor(WHITE);
M5.Lcd.setTextSize(1);
M5.Lcd.printf("Display Test!");
// draw graphic
delay(1000);
M5.Lcd.drawRect(15, 55, 50, 50, BLUE);
delay(1000);
M5.Lcd.fillRect(15, 55, 50, 50, BLUE);
delay(1000);
M5.Lcd.drawCircle(40, 80, 30, RED);
delay(1000);
M5.Lcd.fillCircle(40, 80, 30, RED);
delay(1000);
}
// the loop routine runs over and over again forever
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();
}

View File

@@ -0,0 +1,58 @@
#include <M5StickCPlus.h>
float accX = 0.0F;
float accY = 0.0F;
float accZ = 0.0F;
float gyroX = 0.0F;
float gyroY = 0.0F;
float gyroZ = 0.0F;
float pitch = 0.0F;
float roll = 0.0F;
float yaw = 0.0F;
void setup() {
// put your setup code here, to run once:
M5.begin();
M5.IMU.Init();
M5.Lcd.setRotation(3);
M5.Lcd.fillScreen(BLACK);
M5.Lcd.setTextSize(1);
M5.Lcd.setCursor(80, 15);
M5.Lcd.println("IMU TEST");
M5.Lcd.setCursor(30, 30);
M5.Lcd.println(" X Y Z");
M5.Lcd.setCursor(30, 70);
M5.Lcd.println(" Pitch Roll Yaw");
}
float temp = 0;
/*****************************************
M5.IMU.getGyroData(&gyroX,&gyroY,&gyroZ);
M5.IMU.getAccelData(&accX,&accY,&accZ);
M5.IMU.getAhrsData(&pitch,&roll,&yaw);
M5.IMU.getTempData(&temp);
*****************************************/
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(30, 40);
M5.Lcd.printf("%6.2f %6.2f %6.2f ", gyroX, gyroY, gyroZ);
M5.Lcd.setCursor(170, 40);
M5.Lcd.print("o/s");
M5.Lcd.setCursor(30, 50);
M5.Lcd.printf(" %5.2f %5.2f %5.2f ", accX, accY, accZ);
M5.Lcd.setCursor(170, 50);
M5.Lcd.print("G");
M5.Lcd.setCursor(30, 80);
M5.Lcd.printf(" %5.2f %5.2f %5.2f ", pitch, roll, yaw);
M5.Lcd.setCursor(30, 95);
M5.Lcd.printf("Temperature : %.2f C", temp);
delay(100);
}

View File

@@ -0,0 +1,42 @@
#include <M5StickCPlus.h>
float accX = 0;
float accY = 0;
float accZ = 0;
float gyroX = 0;
float gyroY = 0;
float gyroZ = 0;
float temp = 0;
void setup() {
// put your setup code here, to run once:
M5.begin();
M5.Lcd.setRotation(3);
M5.Lcd.fillScreen(BLACK);
M5.Lcd.setTextSize(1);
M5.Lcd.setCursor(50, 15);
M5.Lcd.println("MPU6886 TEST");
M5.Lcd.setCursor(30, 30);
M5.Lcd.println(" X Y Z");
M5.Imu.Init();
}
void loop() {
// put your main code here, to run repeatedly:
M5.Imu.getGyroData(&gyroX,&gyroY,&gyroZ);
M5.Imu.getAccelData(&accX,&accY,&accZ);
M5.Imu.getTempData(&temp);
M5.Lcd.setCursor(30, 45);
M5.Lcd.printf("%.2f %.2f %.2f ", gyroX, gyroY,gyroZ);
M5.Lcd.setCursor(170, 45);
M5.Lcd.print("o/s");
M5.Lcd.setCursor(30, 60);
M5.Lcd.printf("%.2f %.2f %.2f ",accX * 1000,accY * 1000, accZ * 1000);
M5.Lcd.setCursor(185, 60);
M5.Lcd.print("mg");
M5.Lcd.setCursor(30, 75);
M5.Lcd.printf("Temperature : %.2f C", temp);
delay(100);
}

View File

@@ -0,0 +1,79 @@
#include <M5StickCPlus.h>
#include <driver/i2s.h>
#define PIN_CLK 0
#define PIN_DATA 34
#define READ_LEN (2 * 256)
#define GAIN_FACTOR 3
uint8_t BUFFER[READ_LEN] = {0};
uint16_t oldy[160];
int16_t *adcBuffer = NULL;
void showSignal(){
int y;
for (int n = 0; n < 160; n++){
y = adcBuffer[n] * GAIN_FACTOR;
y = map(y, INT16_MIN, INT16_MAX, 10, 70);
M5.Lcd.drawPixel(n, oldy[n],WHITE);
M5.Lcd.drawPixel(n,y,BLACK);
oldy[n] = y;
}
}
void mic_record_task (void* arg)
{
size_t bytesread;
while(1){
i2s_read(I2S_NUM_0,(char*) BUFFER, READ_LEN, &bytesread, (100 / portTICK_RATE_MS));
adcBuffer = (int16_t *)BUFFER;
showSignal();
vTaskDelay(100 / portTICK_RATE_MS);
}
}
void i2sInit()
{
i2s_config_t i2s_config = {
.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_PDM),
.sample_rate = 44100,
.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT, // is fixed at 12bit, stereo, MSB
.channel_format = I2S_CHANNEL_FMT_ALL_RIGHT,
.communication_format = I2S_COMM_FORMAT_I2S,
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
.dma_buf_count = 2,
.dma_buf_len = 128,
};
i2s_pin_config_t pin_config;
pin_config.bck_io_num = I2S_PIN_NO_CHANGE;
pin_config.ws_io_num = PIN_CLK;
pin_config.data_out_num = I2S_PIN_NO_CHANGE;
pin_config.data_in_num = PIN_DATA;
i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL);
i2s_set_pin(I2S_NUM_0, &pin_config);
i2s_set_clk(I2S_NUM_0, 44100, I2S_BITS_PER_SAMPLE_16BIT, I2S_CHANNEL_MONO);
}
void setup() {
M5.begin();
M5.Lcd.setRotation(3);
M5.Lcd.fillScreen(WHITE);
M5.Lcd.setTextColor(BLACK, WHITE);
M5.Lcd.println("mic test");
i2sInit();
xTaskCreate(mic_record_task, "mic_record_task", 2048, NULL, 1, NULL);
}
void loop() {
printf("loop cycling\n");
vTaskDelay(1000 / portTICK_RATE_MS); // otherwise the main task wastes half of the cpu cycles
}

View File

@@ -0,0 +1,39 @@
#include <M5StickCPlus.h>
RTC_TimeTypeDef RTC_TimeStruct;
RTC_DateTypeDef RTC_DateStruct;
void setup() {
// put your setup code here, to run once:
M5.begin();
M5.Lcd.setRotation(3);
M5.Lcd.fillScreen(BLACK);
M5.Lcd.setTextSize(1);
M5.Lcd.setCursor(60, 10, 2);
M5.Lcd.println("RTC TEST");
RTC_TimeTypeDef TimeStruct;
TimeStruct.Hours = 18;
TimeStruct.Minutes = 56;
TimeStruct.Seconds = 10;
M5.Rtc.SetTime(&TimeStruct);
RTC_DateTypeDef DateStruct;
DateStruct.WeekDay = 3;
DateStruct.Month = 3;
DateStruct.Date = 22;
DateStruct.Year = 2019;
M5.Rtc.SetData(&DateStruct);
}
void loop() {
// put your main code here, to run repeatedly:
M5.Rtc.GetTime(&RTC_TimeStruct);
M5.Rtc.GetData(&RTC_DateStruct);
M5.Lcd.setCursor(30, 35);
M5.Lcd.printf("Data: %04d-%02d-%02d\n",RTC_DateStruct.Year, RTC_DateStruct.Month,RTC_DateStruct.Date);
M5.Lcd.setCursor(30, 55);
M5.Lcd.printf("Week: %d\n",RTC_DateStruct.WeekDay);
M5.Lcd.setCursor(30, 75);
M5.Lcd.printf("Time: %02d : %02d : %02d\n",RTC_TimeStruct.Hours, RTC_TimeStruct.Minutes, RTC_TimeStruct.Seconds);
delay(500);
}