@@ -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
7976void 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
106194See also [ Wiki] ( https://github.com/m5stack/M5UnitUnified/wiki/ )
0 commit comments