From 26a71cf48798dcbf8f9ae5f29e7660d5449face6 Mon Sep 17 00:00:00 2001 From: LiHuashen <854410664@qq.com> Date: Thu, 27 Dec 2018 09:51:54 +0800 Subject: [PATCH] add examples for some units --- docs/zh_CN/unit/color.md | 74 ++++++++++++++++++++++++++++++++++--- docs/zh_CN/unit/earth.md | 28 ++++++++++---- docs/zh_CN/unit/joystick.md | 47 ++++++++++++++++------- docs/zh_CN/unit/light.md | 26 +++++++++---- docs/zh_CN/unit/ncir.md | 10 ++--- 5 files changed, 145 insertions(+), 40 deletions(-) diff --git a/docs/zh_CN/unit/color.md b/docs/zh_CN/unit/color.md index 76d65ea9..ccd8982c 100644 --- a/docs/zh_CN/unit/color.md +++ b/docs/zh_CN/unit/color.md @@ -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 +#include +#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 -### 2. UIFlow + ## 描述 @@ -32,17 +34,34 @@ Joystick Unit同样也是与M5Core相连之后,通过PORT A(I2C)控制,其I2 ### 1. Arduino IDE ```arduino -#define JOY_ADDR 0x52 +#include +#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)。 -## 原理图 + ### 管脚映射 - - + +
M5Core(GROVE A)GPIO22GPIO215VGND
JOYSTICK UnitSCLSDA5VGND
M5Core(GROVE接口A)GPIO22GPIO215VGND
摇杆UnitSCLSDA5VGND
\ No newline at end of file diff --git a/docs/zh_CN/unit/light.md b/docs/zh_CN/unit/light.md index 26f7048e..3967412a 100644 --- a/docs/zh_CN/unit/light.md +++ b/docs/zh_CN/unit/light.md @@ -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 -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 @@ -51,5 +63,5 @@ digitalRead_value = digitalRead(26);//0: sense the ligth 1: do not sense - +
M5Core(GROVE B)GPIO36GPIO265VGND
LIGHT UnitAinDin5VGND
光线传感Unit模拟值输出引脚数字值输出引脚5VGND
\ No newline at end of file diff --git a/docs/zh_CN/unit/ncir.md b/docs/zh_CN/unit/ncir.md index e7a3d8c8..3f516380 100644 --- a/docs/zh_CN/unit/ncir.md +++ b/docs/zh_CN/unit/ncir.md @@ -1,4 +1,4 @@ -# NCIR - 单点红外检测Unit +# NCIR - 单点红外测温Unit @@ -8,7 +8,7 @@ ## 描述 -NCIR是一款可以测量人体体温和人体走动的Unit,它内置了MLX90641传感器。它与Thermal Unit的区别,主要是NCIR Unit做表面单点温度测量,而Thermal Unit做大面积范围的温度测量。 +NCIR是一款可以测量人体体温和人体走动的Unit,它内置了**MLX90641传感器**。它与Thermal Unit的区别,主要是NCIR Unit做表面单点温度测量,而Thermal Unit做大面积范围的温度测量。 ## 特性 @@ -30,7 +30,7 @@ - **数据手册** - [MLX90614](https://pdf1.alldatasheet.com/datasheet-pdf/view/218977/ETC2/MLX90614.html) -## 例程 +