M5stack으로 기압 측정
개요
M5stack에 초고성능의 절대압 및 온도 센서를 연결하여 기압과 온도를 측정하여 그래프 표시합니다.
장치
사용한 것은 이쪽

스위치 사이언스에서 구입했습니다. Arduino용 라이브러리도 공개되어 있으며 구매 페이지에서 다운로드할 수 있습니다.
구매 페이지
이 센서는 Grove 케이블로 쉽게 M5stack에 연결할 수 있습니다.
이런 느낌

실행 결과
이것을 이용하여 만든 것이 여기

흰색은 기압, 녹색은 온도입니다. 계단을 오르내리면 기압의 변화를 알 수 있습니다.
프로그램
#include "Omron2SMPB02E.h"
#include <M5Stack.h>
Omron2SMPB02E prs;
#define WIDTH 320//横サイズ
#define HEIGHT 240//縦サイズ
#define GRAPH_X 25 //グラフ描画領域X座標
#define GRAPH_Y 50 //グラフ描画領域Y座標
#define GRAPH_SPACE 2
#define GRAPH_W WIDTH - GRAPH_X - GRAPH_SPACE
#define GRAPH_H HEIGHT - GRAPH_Y - GRAPH_SPACE
//絶対圧の下限と上限を設定
#define GRAPH_A_MAX 103000
#define GRAPH_A_MIN 101000
// 温度の下限と上限を設定
#define GRAPH_B_MAX 40
#define GRAPH_B_MIN 0
/* 色の定義 */
#define RED 0xf800
#define REDd 0xf800
#define GREEN 0x07e0
#define BLUE 0x001f
#define BLACK 0x0000
#define WHITE 0xffff
#define GRAY 0x8c51
#define YELLOW 0xFFE0
#define CYAN 0x07FF
#define PURPLR 0xF81F
uint16_t GraphBuff_A[int(GRAPH_W)] = {0};
uint16_t GraphBuff_B[int(GRAPH_W)] = {0};
// グラフの最大値と最小値を変数にする
uint32_t Graph_A_Max;
uint32_t Graph_A_Min;
uint32_t Graph_B_Max;
uint32_t Graph_B_Min;
// グラフ開始ポイントを設定
uint16_t graphStartPos[2] = {
GRAPH_X + 1,
GRAPH_Y - 1 + int(GRAPH_H)
};
/* 描画用バッファ領域をずらす*/
void slideBuff(uint16_t buff[], uint16_t size){
for(int i = size - 1; i > 0; i--) buff[i] = buff[i - 1];
}
/* テキスト描画 */
void drawText(uint32_t x, uint32_t y, String text, uint32_t color , uint8_t size){
M5.Lcd.setTextColor(color);
M5.Lcd.setTextSize(size);
M5.Lcd.setCursor(x, y);
M5.Lcd.print(text);
}
/*グラフ描画 */
void updateGraph(uint16_t color,uint16_t *GraphBuff,uint16_t count){
for(int i = 0; i < count; i++){
M5.Lcd.drawPixel(graphStartPos[0] + i, graphStartPos[1] - *GraphBuff++, color);
}
}
void setup()
{
prs.begin();
Serial.begin(9600);
M5.begin();
prs.set_mode(MODE_NORMAL);
delay(300);
//範囲選定用に1回読み込む
float tmp = prs.read_temp();
float pressure = prs.read_pressure();
Graph_A_Max = (uint32_t)pressure + 1000;
Graph_A_Min = (uint32_t)pressure - 1000;
Graph_B_Max = (uint32_t)tmp + 10;
Graph_B_Min = (uint32_t)tmp - 10;
}
// 何回読んだかのカウント
uint16_t count =1;
void loop()
{
//気圧と温度を読み込む
float tmp = prs.read_temp();
float pressure = prs.read_pressure();
Serial.println(pressure);
M5.Lcd.fillRect(0, 0, 120, 20, BLACK);//文字領域クリア
//気圧と温度を表示する
drawText(0, 0, "pressure: " + String(pressure), WHITE, 1);
drawText(0, 10, "TEMP: " + String(tmp),GREEN, 1);
M5.Lcd.fillRect(GRAPH_X + 1, GRAPH_Y + 1, GRAPH_W - GRAPH_SPACE, GRAPH_H - GRAPH_SPACE, 0);//グラフ領域をいったんクリアする
//気圧を描画する
slideBuff(GraphBuff_A, sizeof(GraphBuff_A) / 2);
GraphBuff_A[0] = map(pressure, Graph_A_Min, Graph_A_Max, 0, GRAPH_H - 2);
updateGraph(WHITE,GraphBuff_A,count);
//温度を描画する
slideBuff(GraphBuff_B, sizeof(GraphBuff_B) / 2);
GraphBuff_B[0] = map(tmp, Graph_B_Min, Graph_B_Max, 0, GRAPH_H - 2);
updateGraph(GREEN,GraphBuff_B,count);
if(count >= GRAPH_W){
count = GRAPH_W;
}
else {
count ++;
}
delay(100);
}
Reference
이 문제에 관하여(M5stack으로 기압 측정), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/hirowo/items/84f932429bc569e03062
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
사용한 것은 이쪽

스위치 사이언스에서 구입했습니다. Arduino용 라이브러리도 공개되어 있으며 구매 페이지에서 다운로드할 수 있습니다.
구매 페이지
이 센서는 Grove 케이블로 쉽게 M5stack에 연결할 수 있습니다.
이런 느낌

실행 결과
이것을 이용하여 만든 것이 여기

흰색은 기압, 녹색은 온도입니다. 계단을 오르내리면 기압의 변화를 알 수 있습니다.
프로그램
#include "Omron2SMPB02E.h"
#include <M5Stack.h>
Omron2SMPB02E prs;
#define WIDTH 320//横サイズ
#define HEIGHT 240//縦サイズ
#define GRAPH_X 25 //グラフ描画領域X座標
#define GRAPH_Y 50 //グラフ描画領域Y座標
#define GRAPH_SPACE 2
#define GRAPH_W WIDTH - GRAPH_X - GRAPH_SPACE
#define GRAPH_H HEIGHT - GRAPH_Y - GRAPH_SPACE
//絶対圧の下限と上限を設定
#define GRAPH_A_MAX 103000
#define GRAPH_A_MIN 101000
// 温度の下限と上限を設定
#define GRAPH_B_MAX 40
#define GRAPH_B_MIN 0
/* 色の定義 */
#define RED 0xf800
#define REDd 0xf800
#define GREEN 0x07e0
#define BLUE 0x001f
#define BLACK 0x0000
#define WHITE 0xffff
#define GRAY 0x8c51
#define YELLOW 0xFFE0
#define CYAN 0x07FF
#define PURPLR 0xF81F
uint16_t GraphBuff_A[int(GRAPH_W)] = {0};
uint16_t GraphBuff_B[int(GRAPH_W)] = {0};
// グラフの最大値と最小値を変数にする
uint32_t Graph_A_Max;
uint32_t Graph_A_Min;
uint32_t Graph_B_Max;
uint32_t Graph_B_Min;
// グラフ開始ポイントを設定
uint16_t graphStartPos[2] = {
GRAPH_X + 1,
GRAPH_Y - 1 + int(GRAPH_H)
};
/* 描画用バッファ領域をずらす*/
void slideBuff(uint16_t buff[], uint16_t size){
for(int i = size - 1; i > 0; i--) buff[i] = buff[i - 1];
}
/* テキスト描画 */
void drawText(uint32_t x, uint32_t y, String text, uint32_t color , uint8_t size){
M5.Lcd.setTextColor(color);
M5.Lcd.setTextSize(size);
M5.Lcd.setCursor(x, y);
M5.Lcd.print(text);
}
/*グラフ描画 */
void updateGraph(uint16_t color,uint16_t *GraphBuff,uint16_t count){
for(int i = 0; i < count; i++){
M5.Lcd.drawPixel(graphStartPos[0] + i, graphStartPos[1] - *GraphBuff++, color);
}
}
void setup()
{
prs.begin();
Serial.begin(9600);
M5.begin();
prs.set_mode(MODE_NORMAL);
delay(300);
//範囲選定用に1回読み込む
float tmp = prs.read_temp();
float pressure = prs.read_pressure();
Graph_A_Max = (uint32_t)pressure + 1000;
Graph_A_Min = (uint32_t)pressure - 1000;
Graph_B_Max = (uint32_t)tmp + 10;
Graph_B_Min = (uint32_t)tmp - 10;
}
// 何回読んだかのカウント
uint16_t count =1;
void loop()
{
//気圧と温度を読み込む
float tmp = prs.read_temp();
float pressure = prs.read_pressure();
Serial.println(pressure);
M5.Lcd.fillRect(0, 0, 120, 20, BLACK);//文字領域クリア
//気圧と温度を表示する
drawText(0, 0, "pressure: " + String(pressure), WHITE, 1);
drawText(0, 10, "TEMP: " + String(tmp),GREEN, 1);
M5.Lcd.fillRect(GRAPH_X + 1, GRAPH_Y + 1, GRAPH_W - GRAPH_SPACE, GRAPH_H - GRAPH_SPACE, 0);//グラフ領域をいったんクリアする
//気圧を描画する
slideBuff(GraphBuff_A, sizeof(GraphBuff_A) / 2);
GraphBuff_A[0] = map(pressure, Graph_A_Min, Graph_A_Max, 0, GRAPH_H - 2);
updateGraph(WHITE,GraphBuff_A,count);
//温度を描画する
slideBuff(GraphBuff_B, sizeof(GraphBuff_B) / 2);
GraphBuff_B[0] = map(tmp, Graph_B_Min, Graph_B_Max, 0, GRAPH_H - 2);
updateGraph(GREEN,GraphBuff_B,count);
if(count >= GRAPH_W){
count = GRAPH_W;
}
else {
count ++;
}
delay(100);
}
Reference
이 문제에 관하여(M5stack으로 기압 측정), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/hirowo/items/84f932429bc569e03062
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
#include "Omron2SMPB02E.h"
#include <M5Stack.h>
Omron2SMPB02E prs;
#define WIDTH 320//横サイズ
#define HEIGHT 240//縦サイズ
#define GRAPH_X 25 //グラフ描画領域X座標
#define GRAPH_Y 50 //グラフ描画領域Y座標
#define GRAPH_SPACE 2
#define GRAPH_W WIDTH - GRAPH_X - GRAPH_SPACE
#define GRAPH_H HEIGHT - GRAPH_Y - GRAPH_SPACE
//絶対圧の下限と上限を設定
#define GRAPH_A_MAX 103000
#define GRAPH_A_MIN 101000
// 温度の下限と上限を設定
#define GRAPH_B_MAX 40
#define GRAPH_B_MIN 0
/* 色の定義 */
#define RED 0xf800
#define REDd 0xf800
#define GREEN 0x07e0
#define BLUE 0x001f
#define BLACK 0x0000
#define WHITE 0xffff
#define GRAY 0x8c51
#define YELLOW 0xFFE0
#define CYAN 0x07FF
#define PURPLR 0xF81F
uint16_t GraphBuff_A[int(GRAPH_W)] = {0};
uint16_t GraphBuff_B[int(GRAPH_W)] = {0};
// グラフの最大値と最小値を変数にする
uint32_t Graph_A_Max;
uint32_t Graph_A_Min;
uint32_t Graph_B_Max;
uint32_t Graph_B_Min;
// グラフ開始ポイントを設定
uint16_t graphStartPos[2] = {
GRAPH_X + 1,
GRAPH_Y - 1 + int(GRAPH_H)
};
/* 描画用バッファ領域をずらす*/
void slideBuff(uint16_t buff[], uint16_t size){
for(int i = size - 1; i > 0; i--) buff[i] = buff[i - 1];
}
/* テキスト描画 */
void drawText(uint32_t x, uint32_t y, String text, uint32_t color , uint8_t size){
M5.Lcd.setTextColor(color);
M5.Lcd.setTextSize(size);
M5.Lcd.setCursor(x, y);
M5.Lcd.print(text);
}
/*グラフ描画 */
void updateGraph(uint16_t color,uint16_t *GraphBuff,uint16_t count){
for(int i = 0; i < count; i++){
M5.Lcd.drawPixel(graphStartPos[0] + i, graphStartPos[1] - *GraphBuff++, color);
}
}
void setup()
{
prs.begin();
Serial.begin(9600);
M5.begin();
prs.set_mode(MODE_NORMAL);
delay(300);
//範囲選定用に1回読み込む
float tmp = prs.read_temp();
float pressure = prs.read_pressure();
Graph_A_Max = (uint32_t)pressure + 1000;
Graph_A_Min = (uint32_t)pressure - 1000;
Graph_B_Max = (uint32_t)tmp + 10;
Graph_B_Min = (uint32_t)tmp - 10;
}
// 何回読んだかのカウント
uint16_t count =1;
void loop()
{
//気圧と温度を読み込む
float tmp = prs.read_temp();
float pressure = prs.read_pressure();
Serial.println(pressure);
M5.Lcd.fillRect(0, 0, 120, 20, BLACK);//文字領域クリア
//気圧と温度を表示する
drawText(0, 0, "pressure: " + String(pressure), WHITE, 1);
drawText(0, 10, "TEMP: " + String(tmp),GREEN, 1);
M5.Lcd.fillRect(GRAPH_X + 1, GRAPH_Y + 1, GRAPH_W - GRAPH_SPACE, GRAPH_H - GRAPH_SPACE, 0);//グラフ領域をいったんクリアする
//気圧を描画する
slideBuff(GraphBuff_A, sizeof(GraphBuff_A) / 2);
GraphBuff_A[0] = map(pressure, Graph_A_Min, Graph_A_Max, 0, GRAPH_H - 2);
updateGraph(WHITE,GraphBuff_A,count);
//温度を描画する
slideBuff(GraphBuff_B, sizeof(GraphBuff_B) / 2);
GraphBuff_B[0] = map(tmp, Graph_B_Min, Graph_B_Max, 0, GRAPH_H - 2);
updateGraph(GREEN,GraphBuff_B,count);
if(count >= GRAPH_W){
count = GRAPH_W;
}
else {
count ++;
}
delay(100);
}
Reference
이 문제에 관하여(M5stack으로 기압 측정), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/hirowo/items/84f932429bc569e03062텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)