mirror of
https://github.com/m5stack/m5-docs.git
synced 2026-05-20 10:23:01 -07:00
add examples for some units
This commit is contained in:
@@ -34,11 +34,73 @@ Color是一个颜色传感器. 通过GROVE接口(I2C)与M5Core相连,能够识
|
||||
### 1. Arduino IDE
|
||||
|
||||
```arduino
|
||||
Adafruit_TCS34725 tcs;
|
||||
/*
|
||||
Color test
|
||||
hardware: M5Stack
|
||||
|
||||
please install the Adfruit TCS34725 library first ...
|
||||
*/
|
||||
|
||||
tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X);
|
||||
#include <Wire.h>
|
||||
#include <M5Stack.h>
|
||||
#include "Adafruit_TCS34725.h"
|
||||
|
||||
tcs.getRawData(&red, &green, &blue, &clear);//get rgb value
|
||||
// set to false if using a common cathode LED
|
||||
#define commonAnode true
|
||||
// our RGB -> eye-recognized gamma color
|
||||
byte gammatable[256];
|
||||
|
||||
static uint16_t color16(uint16_t r, uint16_t g, uint16_t b) {
|
||||
uint16_t _color;
|
||||
_color = (uint16_t)(r & 0xF8) << 8;
|
||||
_color |= (uint16_t)(g & 0xFC) << 3;
|
||||
_color |= (uint16_t)(b & 0xF8) >> 3;
|
||||
return _color;
|
||||
}
|
||||
|
||||
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS,TCS34725_GAIN_4X);
|
||||
|
||||
void setup() {
|
||||
delay(100);
|
||||
|
||||
M5.begin(true, false, false);
|
||||
Serial.begin(115200);
|
||||
Serial.println("Color View Test!");
|
||||
|
||||
if (tcs.begin()) {
|
||||
Serial.println("Found sensor");
|
||||
} else {
|
||||
Serial.println("No TCS34725 found ... check your connections");
|
||||
while (1); // halt!
|
||||
}
|
||||
tcs.setIntegrationTime(TCS34725_INTEGRATIONTIME_154MS);
|
||||
tcs.setGain(TCS34725_GAIN_4X);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
uint16_t clear, red, green, blue;
|
||||
|
||||
delay(60); // takes 50ms to read
|
||||
|
||||
tcs.getRawData(&red, &green, &blue, &clear);
|
||||
|
||||
Serial.print("C:\t"); Serial.print(clear);
|
||||
Serial.print("\tR:\t"); Serial.print(red);
|
||||
Serial.print("\tG:\t"); Serial.print(green);
|
||||
Serial.print("\tB:\t"); Serial.print(blue);
|
||||
|
||||
// Figure out some basic hex code for visualization
|
||||
uint32_t sum = clear;
|
||||
float r, g, b;
|
||||
r = red; r /= sum;
|
||||
g = green; g /= sum;
|
||||
b = blue; b /= sum;
|
||||
r *= 256; g *= 256; b *= 256;
|
||||
Serial.print("\t");
|
||||
Serial.print((int)r, HEX); Serial.print((int)g, HEX); Serial.println((int)b, HEX);
|
||||
uint16_t _color = color16((int)r, (int)g, (int)b);
|
||||
M5.Lcd.clear(_color);
|
||||
}
|
||||
```
|
||||
|
||||
具体例程请点击[这里](https://github.com/m5stack/M5-ProductExampleCodes/tree/master/Unit/COLOR/Arduino)。
|
||||
@@ -49,7 +111,7 @@ tcs.getRawData(&red, &green, &blue, &clear);//get rgb value
|
||||
|
||||
<img src="assets/img/product_pics/unit/unit_example/COLOR/example_unit_color_result_01.png">
|
||||
|
||||
### 2. UIFlow
|
||||
<!-- ### 2. UIFlow -->
|
||||
<!--
|
||||
<img src="assets/img/product_pics/unit/unit_example/example_unit_color_01.png" width="30%" height="30%"> <img src="assets/img/product_pics/unit/unit_example/example_unit_color_02.png" width="55%" height="55%">
|
||||
|
||||
@@ -62,6 +124,6 @@ tcs.getRawData(&red, &green, &blue, &clear);//get rgb value
|
||||
### 管脚映射
|
||||
|
||||
<table>
|
||||
<tr><td>M5Core(GROVE A)</td><td>GPIO22</td><td>GPIO21</td><td>5V</td><td>GND</td></tr>
|
||||
<tr><td>COLOR Unit</td><td>SCL</td><td>SDA</td><td>5V</td><td>GND</td></tr>
|
||||
<tr><td>M5Core(GROVE接口A)</td><td>GPIO22</td><td>GPIO21</td><td>5V</td><td>GND</td></tr>
|
||||
<tr><td>颜色传感器Unit</td><td>SCL</td><td>SDA</td><td>5V</td><td>GND</td></tr>
|
||||
</table>
|
||||
@@ -1,4 +1,4 @@
|
||||
# EARTH - 土壤湿度传感Unit
|
||||
# EARTH - 土壤湿度Unit
|
||||
|
||||
<img src="assets/img/product_pics/unit/M5GO_Unit_earth.png" width="30%" height="30%"><img src="assets/img/product_pics/unit/unit_earth_grove_b.png" width="30%" height="30%">
|
||||
|
||||
@@ -29,16 +29,28 @@ Unit可以输出0/1的数字信号,也可以直接输出被测物体反映的
|
||||
|
||||
### 1. Arduino IDE
|
||||
|
||||
*以下仅为用法示意,并不完整。如果需要完整例程请点击[这里](https://github.com/m5stack/M5-ProductExampleCodes/tree/master/Unit/EARTH/Arduino)。*
|
||||
|
||||
```arduino
|
||||
//disable the speak noise
|
||||
dacWrite(25, 0);
|
||||
#include <M5Stack.h>
|
||||
|
||||
void setup() {
|
||||
M5.begin();
|
||||
dacWrite(25, 0);//disable the speak noise
|
||||
|
||||
pinMode(26, INPUT);// set digital pin
|
||||
}
|
||||
|
||||
uint16_t analogRead_value = 0;
|
||||
uint16_t digitalRead_value = 0;
|
||||
|
||||
void loop() {
|
||||
analogRead_value = analogRead(36);// read analog value of EARTH
|
||||
digitalRead_value = digitalRead(26);// read digital value of EARTH
|
||||
}
|
||||
|
||||
analogRead_value = analogRead(36);
|
||||
digitalRead_value = digitalRead(26);
|
||||
```
|
||||
|
||||
具体例程请点击[这里](https://github.com/m5stack/M5-ProductExampleCodes/tree/master/Unit/EARTH/Arduino)。
|
||||
|
||||
### 2. UIFlow
|
||||
|
||||
<img src="assets/img/product_pics/unit/unit_example/EARTH/example_unit_earth_01.png" width="30%" height="30%"> <img src="assets/img/product_pics/unit/unit_example/EARTH/example_unit_earth_02.png" width="69%" height="69%">
|
||||
@@ -53,5 +65,5 @@ digitalRead_value = digitalRead(26);
|
||||
|
||||
<table>
|
||||
<tr><td>M5Core(GROVE B)</td><td>GPIO36</td><td>GPIO26</td><td>5V</td><td>GND</td></tr>
|
||||
<tr><td>EARTH Unit</td><td>Ain</td><td>Din</td><td>5V</td><td>GND</td></tr>
|
||||
<tr><td>土壤湿度Unit</td><td>模拟值输出引脚</td><td>数字值输出引脚</td><td>5V</td><td>GND</td></tr>
|
||||
</table>
|
||||
+33
-14
@@ -6,7 +6,9 @@
|
||||
|
||||
***
|
||||
|
||||
:memo:**[描述](#描述)** :octocat:**[例程](#例程)** :electric_plug:**[原理图](#原理图)** 🛒**[购买链接](https://item.taobao.com/item.htm?spm=a1z10.3-c.w4002-1172588106.66.159c425eoqBTTY&id=577874535012)**
|
||||
:memo:**[描述](#描述)** :octocat:**[例程](#例程)** 🛒**[购买链接](https://item.taobao.com/item.htm?spm=a1z10.3-c.w4002-1172588106.66.159c425eoqBTTY&id=577874535012)**
|
||||
|
||||
<!-- :memo:**[描述](#描述)** :octocat:**[例程](#例程)** :electric_plug:**[原理图](#原理图)** 🛒**[购买链接](https://item.taobao.com/item.htm?spm=a1z10.3-c.w4002-1172588106.66.159c425eoqBTTY&id=577874535012)** -->
|
||||
|
||||
## 描述
|
||||
|
||||
@@ -32,17 +34,34 @@ Joystick Unit同样也是与M5Core相连之后,通过PORT A(I2C)控制,其I2
|
||||
### 1. Arduino IDE
|
||||
|
||||
```arduino
|
||||
#define JOY_ADDR 0x52
|
||||
#include <M5Stack.h>
|
||||
#include "Wire.h"
|
||||
|
||||
//disable the speak noise
|
||||
dacWrite(25, 0);
|
||||
Wire.begin(21, 22, 400000);
|
||||
Wire.requestFrom(JOY_ADDR);
|
||||
while(Wire.available())
|
||||
{
|
||||
x_data = Wire.read();//x
|
||||
y_data = Wire.read();//x
|
||||
button_data = Wire.read();//x
|
||||
#define JOY_ADDR 0x52
|
||||
void setup() {
|
||||
M5.begin();
|
||||
M5.Lcd.clear();
|
||||
//disable the speak noise
|
||||
dacWrite(25, 0);
|
||||
|
||||
Wire.begin(21, 22, 400000);
|
||||
}
|
||||
|
||||
uint8_t x_data;
|
||||
uint8_t y_data;
|
||||
uint8_t button_data;
|
||||
char data[100];
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
Wire.requestFrom(JOY_ADDR, 3);
|
||||
if (Wire.available()) {
|
||||
x_data = Wire.read();
|
||||
y_data = Wire.read();
|
||||
button_data = Wire.read();
|
||||
sprintf(data, "x:%d y:%d button:%d\n", x_data, y_data, button_data);
|
||||
Serial.print(data);
|
||||
}
|
||||
delay(200);
|
||||
}
|
||||
```
|
||||
|
||||
@@ -54,13 +73,13 @@ while(Wire.available())
|
||||
|
||||
具体例程请点击[这里](https://github.com/m5stack/M5-ProductExampleCodes/tree/master/Unit/JOYSTICK/UIFlow)。
|
||||
|
||||
## 原理图
|
||||
<!-- ## 原理图 -->
|
||||
|
||||
<!-- <img src="assets/img/product_pics/unit/joystick_sch.JPG"> -->
|
||||
|
||||
### 管脚映射
|
||||
|
||||
<table>
|
||||
<tr><td>M5Core(GROVE A)</td><td>GPIO22</td><td>GPIO21</td><td>5V</td><td>GND</td></tr>
|
||||
<tr><td>JOYSTICK Unit</td><td>SCL</td><td>SDA</td><td>5V</td><td>GND</td></tr>
|
||||
<tr><td>M5Core(GROVE接口A)</td><td>GPIO22</td><td>GPIO21</td><td>5V</td><td>GND</td></tr>
|
||||
<tr><td>摇杆Unit</td><td>SCL</td><td>SDA</td><td>5V</td><td>GND</td></tr>
|
||||
</table>
|
||||
@@ -27,16 +27,28 @@
|
||||
|
||||
### 1. Arduino IDE
|
||||
|
||||
*以下仅为用法示意,并不完整。如果需要完整例程请点击[这里](https://github.com/m5stack/M5-ProductExampleCodes/tree/master/Unit/LIGHT/Arduino)。*
|
||||
|
||||
```arduino
|
||||
//disable the speak noise
|
||||
dacWrite(25, 0);
|
||||
#include <M5Stack.h>
|
||||
|
||||
analogRead_value = analogRead(36);//get analog value of LIGHT(0-4095)
|
||||
digitalRead_value = digitalRead(26);//0: sense the ligth 1: do not sense
|
||||
void setup() {
|
||||
M5.begin();
|
||||
dacWrite(25, 0);// disable the speak noise
|
||||
|
||||
pinMode(26, INPUT);// set LIGHT Pin
|
||||
}
|
||||
|
||||
uint16_t analogRead_value = 0;
|
||||
uint16_t digitalRead_value = 0;
|
||||
|
||||
void loop() {
|
||||
analogRead_value = analogRead(36);// read analog value of LIGHT
|
||||
digitalRead_value = digitalRead(26);// read digital value of LIGHT
|
||||
delay(10);
|
||||
}
|
||||
```
|
||||
|
||||
具体例程请点击[这里](https://github.com/m5stack/M5-ProductExampleCodes/tree/master/Unit/LIGHT/Arduino)。
|
||||
|
||||
### 2. UIFlow
|
||||
|
||||
<img src="assets/img/product_pics/unit/unit_example/LIGHT/example_unit_light_01.png" width="30%" height="30%"> <img src="assets/img/product_pics/unit/unit_example/LIGHT/example_unit_light_02.png" width="69%" height="69%">
|
||||
@@ -51,5 +63,5 @@ digitalRead_value = digitalRead(26);//0: sense the ligth 1: do not sense
|
||||
|
||||
<table>
|
||||
<tr><td>M5Core(GROVE B)</td><td>GPIO36</td><td>GPIO26</td><td>5V</td><td>GND</td></tr>
|
||||
<tr><td>LIGHT Unit</td><td>Ain</td><td>Din</td><td>5V</td><td>GND</td></tr>
|
||||
<tr><td>光线传感Unit</td><td>模拟值输出引脚</td><td>数字值输出引脚</td><td>5V</td><td>GND</td></tr>
|
||||
</table>
|
||||
@@ -1,4 +1,4 @@
|
||||
# NCIR - 单点红外检测Unit
|
||||
# NCIR - 单点红外测温Unit
|
||||
|
||||
<img src="assets/img/product_pics/unit/M5GO_Unit_ncir.png" width="30%" height="30%"><img src="assets/img/product_pics/unit/unit_ncir_grove_a.png" width="30%" height="30%">
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
## 描述
|
||||
|
||||
<mark>NCIR</mark>是一款可以测量人体体温和人体走动的Unit,它内置了MLX90641传感器。它与Thermal Unit的区别,主要是NCIR Unit做表面单点温度测量,而Thermal Unit做大面积范围的温度测量。
|
||||
<mark>NCIR</mark>是一款可以测量人体体温和人体走动的Unit,它内置了**MLX90641传感器**。它与Thermal Unit的区别,主要是NCIR Unit做表面单点温度测量,而Thermal Unit做大面积范围的温度测量。
|
||||
|
||||
## 特性
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
|
||||
- **数据手册** - [MLX90614](https://pdf1.alldatasheet.com/datasheet-pdf/view/218977/ETC2/MLX90614.html)
|
||||
|
||||
## 例程
|
||||
<!-- ## 例程 -->
|
||||
|
||||
<!-- ### 1. Arduino IDE
|
||||
|
||||
@@ -58,6 +58,6 @@ float pressure = bme.readPressure();//pressure
|
||||
### 管脚映射
|
||||
|
||||
<table>
|
||||
<tr><td>M5Core(GROVE A)</td><td>GPIO22</td><td>GPIO21</td><td>5V</td><td>GND</td></tr>
|
||||
<tr><td>NCIR Unit</td><td>SCL</td><td>SDA</td><td>5V</td><td>GND</td></tr>
|
||||
<tr><td>M5Core(GROVE接口A)</td><td>GPIO22</td><td>GPIO21</td><td>5V</td><td>GND</td></tr>
|
||||
<tr><td>红外测温Unit</td><td>SCL</td><td>SDA</td><td>5V</td><td>GND</td></tr>
|
||||
</table>
|
||||
Reference in New Issue
Block a user