Skip to content

Commit 6f5366c

Browse files
committed
Update README
1 parent 531bc2a commit 6f5366c

File tree

2 files changed

+192
-10
lines changed

2 files changed

+192
-10
lines changed

README.ja.md

Lines changed: 96 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@ lib_deps=m5stack/M5Unit-foo ;使用したいユニットのライブラリ
4444

4545
## 使い方
4646

47-
各ユニットのレポジトリの例も参照のこと
47+
各ユニットのリポジトリの例も参照のこと
4848

4949
### Unit コンポーネントを UnitUnified とともに使用する (標準的な使用法)
5050

51+
#### Wire 使用のユニット
52+
5153
```cpp
5254
// 他のユニットを使用する場合、インクルードファイル (*1)、インスタンス (*2)、値の取得 (*3) を変更する
5355
#include <M5Unified.h>
@@ -74,15 +76,107 @@ void setup() {
7476
}
7577

7678
void loop() {
79+
M5.update();
80+
Units.update();
81+
if (unit.updated()) {
82+
// *3 ユニット固有の計測値の取得
83+
M5.Log.printf("CO2:%u Temp:%f Hum:%f\n", unit.co2(), unit.temperature(), unit.humidity());
84+
}
85+
}
86+
```
87+
88+
#### GPIO 使用のユニット
89+
90+
```cpp
91+
// 他のユニットを使用する場合、インクルードファイル (*1)、インスタンス (*2)、値の取得 (*3) を変更する
92+
#include <M5Unified.h>
93+
#include <M5UnitUnified.h>
94+
#include <M5UnitUnifiedTUBE.h> // *1 使用するユニットのヘッダ
95+
96+
m5::unit::UnitUnified Units;
97+
m5::unit::UnitTubePressure unit; // *2 使用するユニットのインスタンス
98+
99+
void setup()
100+
{
77101
M5.begin();
102+
103+
// PortB if available, PortA if not
104+
auto pin_num_gpio_in = M5.getPin(m5::pin_name_t::port_b_in);
105+
auto pin_num_gpio_out = M5.getPin(m5::pin_name_t::port_b_out);
106+
if (pin_num_gpio_in < 0 || pin_num_gpio_out < 0) {
107+
M5_LOGW("PortB is not available");
108+
Wire.end();
109+
pin_num_gpio_in = M5.getPin(m5::pin_name_t::port_a_pin1);
110+
pin_num_gpio_out = M5.getPin(m5::pin_name_t::port_a_pin2);
111+
}
112+
113+
if (!Units.add(unit, pin_num_gpio_in, pin_num_gpio_out) // Add unit to UnitUnified manager
114+
|| !Units.begin()) { // Begin each unit
115+
M5_LOGE("Failed to add/begin");
116+
}
117+
}
118+
119+
void loop()
120+
{
121+
M5.update();
78122
Units.update();
79123
if (unit.updated()) {
80124
// *3 ユニット固有の計測値の取得
81-
M5_LOGI("CO2:%u Temp:%f Hum:%f", unit.co2(), unit.temperature(), unit.humidity());
125+
M5.Log.printf("Pressure:%.2f\n", unit.pressure());
82126
}
83127
}
84128
```
85129

130+
#### UART(Serial) 使用のユニット
131+
132+
```cpp
133+
// 他のユニットを使用する場合、インクルードファイル (*1)、インスタンス (*2)、API呼び出し (*3) を変更する
134+
#include <M5Unified.h>
135+
#include <M5UnitUnified.h>
136+
#include <M5UnitUnifiedFINGER.h> // *1 使用するユニットのヘッダ
137+
138+
m5::unit::UnitUnified Units;
139+
m5::unit::UnitFinger unit; // *2 使用するユニットのインスタンス
140+
141+
void setup()
142+
{
143+
M5.begin();
144+
145+
// PortC if available, PortA if not
146+
auto pin_num_in = M5.getPin(m5::pin_name_t::port_c_rxd);
147+
auto pin_num_out = M5.getPin(m5::pin_name_t::port_c_txd);
148+
if (pin_num_in < 0 || pin_num_out < 0) {
149+
M5_LOGW("PortC is not available");
150+
Wire.end();
151+
pin_num_in = M5.getPin(m5::pin_name_t::port_a_pin1);
152+
pin_num_out = M5.getPin(m5::pin_name_t::port_a_pin2);
153+
}
154+
155+
#if SOC_UART_NUM > 2
156+
auto& s = Serial2;
157+
#elif SOC_UART_NUM > 1
158+
auto& s = Serial1;
159+
#else
160+
#error "Not enough Serial"
161+
#endif
162+
s.end();
163+
// 備考: ユニットによって初期化パラメータは異なる
164+
s.begin(19200, SERIAL_8N1, pin_num_in, pin_num_out);
165+
166+
if (!Units.add(unit, s) // Add unit to UnitUnified manager
167+
|| !Units.begin()) { // Begin each unit
168+
M5_LOGE("Failed to begin");
169+
}
170+
}
171+
172+
void loop() {
173+
M5.update();
174+
Units.update();
175+
// *3 任意の API 呼び出し...
176+
}
177+
178+
```
179+
86180
- 標準外の使い方
87181
- [自分でユニットの更新を行う例](examples/Basic/SelfUpdate)
88182
- [UnitUnified マネージャを使用せず、コンポーネントのみでの例](examples/Basic/ComponentOnly)

README.md

Lines changed: 96 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ See also examples for each unit repositry too.
4848

4949
### UnitComponent with UnitUnified (Standard usage)
5050

51-
Simple example of the UnitCO2
52-
UnitCO2 is started with default settings in Units.begin(), and loop() print logs measurement data.
53-
51+
#### Unit using Wire
5452
```cpp
5553
// If you use other units, change include files(*1), instances(*2), and get values(*3)
5654
#include <M5Unified.h>
@@ -66,24 +64,115 @@ void setup() {
6664
auto pin_num_sda = M5.getPin(m5::pin_name_t::port_a_sda);
6765
auto pin_num_scl = M5.getPin(m5::pin_name_t::port_a_scl);
6866
M5_LOGI("getPin: SDA:%u SCL:%u", pin_num_sda, pin_num_scl);
67+
Wire.end();
6968
Wire.begin(pin_num_sda, pin_num_scl, 400 * 1000U);
7069

71-
M5.Display.clear(TFT_DARKGREEN);
7270
if (!Units.add(unit, Wire) // Add unit to UnitUnified manager
7371
|| !Units.begin()) { // Begin each unit
7472
M5_LOGE("Failed to add/begin");
75-
M5.Display.clear(TFT_RED);
7673
}
7774
}
7875

7976
void loop() {
77+
M5.update();
78+
Units.update();
79+
if (unit.updated()) {
80+
// *3 Obtaining unit-specific measurements
81+
M5.Log.printf("CO2:%u Temp:%f Hum:%f\n", unit.co2(), unit.temperature(), unit.humidity());
82+
}
83+
}
84+
```
85+
86+
#### Unit using GPIO
87+
88+
```cpp
89+
// If you use other units, change include files(*1), instances(*2), and get values(*3)
90+
#include <M5Unified.h>
91+
#include <M5UnitUnified.h>
92+
#include <M5UnitUnifiedTUBE.h> // *1 Include the header of the unit to be used
93+
94+
m5::unit::UnitUnified Units;
95+
m5::unit::UnitTubePressure unit; // *2 Instance of the unit
96+
97+
void setup()
98+
{
8099
M5.begin();
100+
101+
// PortB if available, PortA if not
102+
auto pin_num_gpio_in = M5.getPin(m5::pin_name_t::port_b_in);
103+
auto pin_num_gpio_out = M5.getPin(m5::pin_name_t::port_b_out);
104+
if (pin_num_gpio_in < 0 || pin_num_gpio_out < 0) {
105+
M5_LOGW("PortB is not available");
106+
Wire.end();
107+
pin_num_gpio_in = M5.getPin(m5::pin_name_t::port_a_pin1);
108+
pin_num_gpio_out = M5.getPin(m5::pin_name_t::port_a_pin2);
109+
}
110+
111+
if (!Units.add(unit, pin_num_gpio_in, pin_num_gpio_out) // Add unit to UnitUnified manager
112+
|| !Units.begin()) { // Begin each unit
113+
M5_LOGE("Failed to add/begin");
114+
}
115+
}
116+
117+
void loop()
118+
{
119+
M5.update();
81120
Units.update();
82121
if (unit.updated()) {
83122
// *3 Obtaining unit-specific measurements
84-
M5_LOGI("CO2:%u Temp:%f Hum:%f", unit.co2(), unit.temperature(), unit.humidity());
123+
M5.Log.printf("Pressure:%.2f\n", unit.pressure());
124+
}
125+
}
126+
```
127+
128+
#### Unit using UART(Serial)
129+
130+
```cpp
131+
// If you use other units, change include files(*1), instances(*2), and call any API(*3)
132+
#include <M5Unified.h>
133+
#include <M5UnitUnified.h>
134+
#include <M5UnitUnifiedFINGER.h> // *1 Include the header of the unit to be used
135+
136+
m5::unit::UnitUnified Units;
137+
m5::unit::UnitFinger unit; // *2 Instance of the unit
138+
139+
void setup()
140+
{
141+
M5.begin();
142+
143+
// PortC if available, PortA if not
144+
auto pin_num_in = M5.getPin(m5::pin_name_t::port_c_rxd);
145+
auto pin_num_out = M5.getPin(m5::pin_name_t::port_c_txd);
146+
if (pin_num_in < 0 || pin_num_out < 0) {
147+
M5_LOGW("PortC is not available");
148+
Wire.end();
149+
pin_num_in = M5.getPin(m5::pin_name_t::port_a_pin1);
150+
pin_num_out = M5.getPin(m5::pin_name_t::port_a_pin2);
151+
}
152+
153+
#if SOC_UART_NUM > 2
154+
auto& s = Serial2;
155+
#elif SOC_UART_NUM > 1
156+
auto& s = Serial1;
157+
#else
158+
#error "Not enough Serial"
159+
#endif
160+
s.end();
161+
// Note that the argument varies depending on the target unit
162+
s.begin(19200, SERIAL_8N1, pin_num_in, pin_num_out);
163+
164+
if (!Units.add(unit, s) // Add unit to UnitUnified manager
165+
|| !Units.begin()) { // Begin each unit
166+
M5_LOGE("Failed to begin");
85167
}
86168
}
169+
170+
void loop() {
171+
M5.update();
172+
Units.update();
173+
// *3 Arbitrary API calls to the unit...
174+
}
175+
87176
```
88177

89178
- Nonstandard usage
@@ -99,8 +188,7 @@ Support ESP-IDF with M5HAL in the future.
99188
### Supported connection
100189
- I2C with TwoWire
101190
- GPIO (Currently only functions required for the units are included)
102-
103-
Support UART in the future.
191+
- UART with HardwareSerial
104192

105193
### Supported devices, units
106194
See also [Wiki](https://github.com/m5stack/M5UnitUnified/wiki/)

0 commit comments

Comments
 (0)