You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/hardware/01.mkr/03.carriers/mkr-iot-carrier/tutorials/mkr-iot-carrier-01-technical-reference/mkr-iot-carrier-01-technical-reference.md
+92-63Lines changed: 92 additions & 63 deletions
Original file line number
Diff line number
Diff line change
@@ -76,13 +76,13 @@ The MKR IoT Carrier comes with **three grove connectors** (2 analog and 1 I2C) t
76
76
77
77
## Carrier Library
78
78
79
-
To program the MKR IoT Carrier, the **Arduino_MKRIoTCarrier** library needs to be included. This library allows us to control and read all the components of the MKR IoT Carrier. Setting up the MKRIoTCarrier library requires an addition of few code lines in the **initialization** and **setup**. Practically speaking, the code used in the initialization and setup is rarely changed, and it is required in every sketch.
79
+
To program the MKR IoT Carrier, the **[Arduino_MKRIoTCarrier](https://www.arduino.cc/reference/en/libraries/arduino_mkriotcarrier/)** library needs to be included. This library allows us to control and read all the components of the MKR IoT Carrier. Setting up the MKRIoTCarrier library requires an addition of few code lines in the **initialization** and **setup**. Practically speaking, the code used in the initialization and setup is rarely changed, and it is required in every sketch.
80
80
81
81
### Initialization
82
82
83
83
In the initialization (the very top) of every sketch, the **MKRIoTCarrier** library needs to be included, which includes the individual libraries of the components mounted onto the carrier.
84
84
85
-
Next, an object, which is always named `carrier` needs to be added.
85
+
Next, an object of type `MKRIoTCarrier` needs to be created. We'll call it `carrier` for simplicity.
86
86
87
87
```arduino
88
88
#include <Arduino_MKRIoTCarrier.h>
@@ -91,15 +91,29 @@ MKRIoTCarrier carrier;
91
91
92
92
### Setup
93
93
94
-
Inside the `setup()` of every sketch that created, 2 lines of code needs to added:
94
+
Inside the `setup()` of every sketch that created, 2 lines of code needs to added.
95
95
96
-
The boolean `CARRIER_CASE` refers to the **plastic casing** in the kit, and the capacitive buttons on the carrier. It is set to `true` when the plastic casing is used, and to `false` when not. This is not mandatory, as it is set to `false` by default.
96
+
First, we need to tell the library whether the carrieris being used inside the **plastic enclosure** included in the Oplà IoT Kit or not. The library uses this information in order to calibrate the sensitivity of the capacitive buttons.
97
97
98
-
The `carrier.begin();` command is essential to initializing the carrier and must be added.
98
+
If you use the plastic enclosure, add this line:
99
+
100
+
```
101
+
carrier.withCase();
102
+
```
103
+
104
+
Otherwise, add this line:
105
+
106
+
```
107
+
carrier.noCase();
108
+
```
109
+
110
+
After that, the `carrier.begin();` command is needed. Final example is:
99
111
100
112
```arduino
101
-
CARRIER_CASE = false;
113
+
void setup() {
114
+
carrier.noCase();
102
115
carrier.begin();
116
+
}
103
117
```
104
118
105
119
## Humidity & Temperature Sensor
@@ -110,26 +124,16 @@ The **HTS221 Humidity Sensor** is mounted on the top side of the carrier under t
110
124
111
125
### Code
112
126
113
-
The **ArduinoHTS221** library is included in the **MKRIoTCarrier**, meaning that it does not need to include it separately. The values from the **temperature** and **humidity** sensors can be stored in **float** variables as shown below.
127
+
The values from the **temperature** and **humidity** sensors can be retrieved and stored in **float** variables as shown below.
114
128
115
129
```arduino
116
130
float temperature = carrier.Env.readTemperature();
117
131
float humidity = carrier.Env.readHumidity();
118
132
```
119
133
120
-
The following methods can be used to get the temperature and humidity values:
121
-
122
-
```arduino
123
-
carrier.Env.readTemperature();
124
-
```
125
-
126
-
Returns temperature value in Celsius.
127
-
128
-
```arduino
129
-
carrier.Env.readHumidity();
130
-
```
134
+
Temperature is returned in degrees Celsius, while relative humidity is returned in percentage.
131
135
132
-
Returns relative humidity (rH) in percentage.
136
+
The underlying library used to read the sensor is **[Arduino_HTS221](https://www.arduino.cc/reference/en/libraries/arduino_hts221/)**.
133
137
134
138
## Pressure Sensor
135
139
@@ -139,29 +143,23 @@ The **LPS22HBTR Pressure Sensor** is mounted on the top side of the carrier unde
139
143
140
144
### Code
141
145
142
-
The **ArduinoLPS22HB** library is included in the **MKRIoTCarrier**, meaning that it does not need to include it separately. The values from the **pressure** sensor can be stored in **float**variables as shown below.
146
+
The value from the **pressure** sensor, expressed in kiloPascal (kPa) can be retrieved and stored in a **float**variable as shown below.
143
147
144
148
```arduino
145
149
float pressure = carrier.Pressure.readPressure();
146
150
```
147
151
148
-
The following methods can be used to get the pressure values:
149
-
150
-
```arduino
151
-
carrier.Pressure.readPressure();
152
-
```
153
-
154
-
Returns pressure value in Kilopascal (kPa).
152
+
The underlying library used to read the sensor is **[Arduino_LPS22HB](https://www.arduino.cc/reference/en/libraries/arduino_lps22hb/)**.
155
153
156
154
## IMU Accelerometer & Gyroscope Sensors
157
155
158
156

159
157
160
-
The **LSM6DS3** from STM is an IMU (Inertial Measurement Unit) that features a 3D digital accelerometer and a 3D digital gyroscope.
158
+
The carrier includes a **LSM6DS3**sensor from STM which is an IMU (Inertial Measurement Unit) featuring a 3D digital accelerometer and a 3D digital gyroscope.
161
159
162
160
### Code
163
161
164
-
To access the data from the **LSM6DS3 module**, the **MKRIoTCarrier** library needs to be included. The carrier's library includes the **Arduino_LSM6DS3** and functions similarly. The 3-axis values from the **accelerometer** and **gyroscope** sensors can be stored in **float** variables as shown below:
162
+
The 3-axis values from the **accelerometer** and **gyroscope** sensors can be retrieved and stored in **float** variables as shown below:
165
163
166
164
```arduino
167
165
float x, y, z;
@@ -188,7 +186,9 @@ Returns 0 if no new acceleration data sample is available, 1 if new acceleration
188
186
carrier.IMUmodule.readAcceleration(x, y, z);
189
187
```
190
188
191
-
Allows as to access the acceleration data on the three axis (x, y & z).
189
+
Reads acceleration data from the sensor on the three axis and assigns it to the provided variables.
190
+
191
+
The underlying library used to read the sensor is **[Arduino_LSM6DS3](https://www.arduino.cc/reference/en/libraries/arduino_lsm6ds3/)**.
192
192
193
193
## RGB and Gesture Sensor
194
194
@@ -198,7 +198,7 @@ The MKR IoT Carrier contains a Broadcom **APDS-9660 RGB and Gesture sensors**, s
198
198
199
199
### Code
200
200
201
-
The **ArduinoAPDS9960** library is included in the **MKRIoTCarrier**, meaning that it does not need to include it separately. The color values from the **RGB** sensor can be stored in **int** variables as shown below.
201
+
The color values from the **RGB** sensor can be retrieved and stored in **int** variables as shown below.
202
202
203
203
The `carrier.Light.readColor(r, g, b);` method can be used to detect colors.
204
204
@@ -255,6 +255,8 @@ The code example below shows the gesture value in a fixed width integer `uint8_t
255
255
256
256
```
257
257
258
+
The underlying library used to read the sensor is **[Arduino_APDS9960](https://www.arduino.cc/reference/en/libraries/arduino_apds9960/)**.
259
+
258
260
## Relays
259
261
260
262

@@ -304,27 +306,37 @@ The screen on the MKR IoT Carrier is a **rounded 1.3” TFT display**, with a 24
304
306
305
307
#### Code
306
308
307
-
The display is controlled through the Adafruit-ST7735-Library, which is included in the carrier's library, meaning that it does not need to be added it separately.
309
+
The display is controlled through the `carrier.display` object which is an instance of the **Adafruit_ST7789** class, based on the more general **Adafruit_GFX** interface. Most tutorials mentioning **Adafruit_GFX** should be usable on your MKR IoT Carrier.
308
310
309
-
Below are some methods to configure the MKR IoT Carrier's display, these include basic configurations, background and text colors, font size, position of the cursor and a loading animation.
311
+
To get started, check the [Adafruit_GFX documentation](https://learn.adafruit.com/adafruit-gfx-graphics-library)and see the examples included in the Arduino_MKTIoTCarrier library.
310
312
311
-
```arduino
312
-
carrier.display.fillScreen(color);
313
-
```
314
313
315
-
This method sets the color of the background of the display using hex codes.
314
+
315
+
](https://www.arduino.cc/reference/en/libraries/adafruit-st7735-and-st7789-library/), which is included in the carrier's library, meaning that it does not need to be added it separately.
316
+
317
+
We'll list here some of the most useful methods to configure the MKR IoT Carrier's display, including basic configurations, background and text colors, font size, position of the cursor and a loading animation.
316
318
317
319
```arduino
318
-
carrier.display.setRotation(0);
320
+
carrier.display.fillScreen(color);
319
321
```
320
322
321
-
This method sets the angle of the screen, 0 is the starting position with no rotation.The screen can only be rotated 90, 180 or 270 degrees by replacing the 0 with 1, 2 or 3.
323
+
This method sets the color of the background of the display using hex codes. Example values are:
324
+
325
+
*`0xFFFF` for white
326
+
*`0x0000` for black
327
+
*`0xF800` for red
328
+
*`0x07E0` for green
329
+
*`0x001F` for blue
330
+
*`0x07FF` for cyan
331
+
*`0xF81F` for magenta
332
+
*`0xFFE0` for yellow
333
+
*`0xFC00` for orange
322
334
323
335
```arduino
324
-
display.print("text");
336
+
carrier.display.setRotation(0);
325
337
```
326
338
327
-
This method will print the text inside the string at the current cursor position.
339
+
This method sets the angle of the screen. 0 is the starting position with no rotation.The screen can only be rotated 90, 180 or 270 degrees by replacing the 0 with 1, 2 or 3.
328
340
329
341
```arduino
330
342
carrier.display.drawBitmap(x, y, bitmap_visual, w, h, color);
This method is very important, as it indicates where on the printing starts on the display. It is indicated by pixels, so, if **0, 0** are used for example, it will start printing in the top left corner.
352
364
365
+
```arduino
366
+
display.print("text");
367
+
```
368
+
369
+
This method will print the text inside the string at the current cursor position.
370
+
371
+
#### More Resources
372
+
373
+
In order to develop a graphical user interface with the MKR IoT Carrier, the **[Arduino_OplaUI](https://www.arduino.cc/reference/en/libraries/arduino_oplaui/)** library can be used. This library uses the color LEDs, the buzzer and the touch buttons to build an interactive user interface featuring multiple pages. It also includes a few predefined gauges to display values. See the library examples to get started.
The carrier has five **capacitive qTouch buttons** on its top side, numbered from 00 to 04. The buttons are sensitive to direct touch and detect wireless touch.
379
+
The carrier has five **capacitive touch buttons** on its top side, numbered from 0 to 4. The buttons are sensitive to direct touch and can also detect wireless touch.
358
380
359
381
#### Code
360
382
361
-
The **Button class** can be controlled using the following methods:
362
-
363
383
```arduino
364
-
Buttons.update();
384
+
carrier.Buttons.update();
365
385
```
366
386
367
387
Reads the state of the pads and save them to be used in the different types of touch events.
368
388
369
389
```arduino
370
-
Buttons.getTouch(TOUCHX);
390
+
carrier.Buttons.getTouch(TOUCH0);
371
391
```
372
392
373
393
Get if the pad is getting touched, true until it gets released.
374
394
375
395
```arduino
376
-
Buttons.onTouchDown(TOUCHX);
396
+
carrier.Buttons.onTouchDown(TOUCH0);
377
397
```
378
398
379
399
Get when have been a touch down.
380
400
381
401
```arduino
382
-
Buttons.onTouchUp(TOUCHX);
402
+
carrier.Buttons.onTouchUp(TOUCH0);
383
403
```
384
404
385
405
Get when the button has been released.
386
406
387
407
```arduino
388
-
Buttons.onTouchChange(TOUCHX);
408
+
carrier.Buttons.onTouchChange(TOUCH0);
389
409
```
390
410
391
411
Get both, touched and released.
392
412
393
-
`TOUCH0`, `TOUCH1`, `TOUCH2`, `TOUCH3`, `TOUCH4`can be used to access each individual button. The code example below shows how the status of a button can be checked.
413
+
Replace `TOUCH0` with `TOUCH1`, `TOUCH2`, `TOUCH3`, `TOUCH4`in the examples above to access the other buttons. The code example below shows how the status of a button can be checked.
@@ -480,48 +500,57 @@ The MKR IoT Carrier is equipped with a **sound buzzer** on the bottom side of th
480
500
The buzzer can be controlled with the following methods:
481
501
482
502
```arduino
483
-
carrier.Buzzer.sound(freq)
503
+
carrier.Buzzer.sound(freq);
484
504
```
485
505
486
506
Equivalent to tone(), it will make the tone with the selected frequency.
487
507
488
508
```arduino
489
-
carrier.Buzzer.noSound()
509
+
carrier.Buzzer.noSound();
490
510
```
491
511
492
512
Equivalent to noTone(), it will stop the tone signal.
493
513
514
+
```arduino
515
+
carrier.Buzzer.beep();
516
+
carrier.Buzzer.beep(800, 20);
517
+
```
518
+
519
+
This method is a handy shortcut generating a beep. The two arguments are optional and can be set to customize the frequency and the duration (in milliseconds);
520
+
494
521
## Memory
495
522
496
-
The MKR IoT Carrier contains a **SD Card slot** that accepts a Micro SD, which allows for three times the amount of data storage locally.
523
+
The MKR IoT Carrier contains a **SD card slot** that accepts a Micro SD.
497
524
498
525
### Code
499
526
500
-
The memory can be used with the SD library commands that is already included in the `MKRIoTCarrier` library
527
+
The memory can be used with the SD library commands that is already included in the `MKRIoTCarrier` library.
501
528
502
-
The SD class initialized in the main `carrier.begin()`. In order to save our data on a specific file, the method `SD.open("file-name", FILE_WRITE))` can be used. The code below demonstrates how to save data on a file on a SD card.
529
+
The SD class initialized in the main `carrier.begin()` so you don't need to do it yourself. The code below demonstrates how to save data on a file on a SD card.
503
530
504
531
```arduino
505
532
#include <Arduino_MKRIoTCarrier.h>
506
533
MKRIoTCarrier carrier;
507
534
508
535
File myFile;
509
536
510
-
setup(){
511
-
CARRIER_CASE = false;
537
+
void setup(){
538
+
carrier.noCase();
512
539
carrier.begin(); //SD card initialized here
513
540
514
541
myFile = SD.open("test.txt", FILE_WRITE);
515
542
}
516
543
```
517
544
545
+
In order to learn more, check any of the many tutorials about using the `SD` library on Arduino.
546
+
518
547
## Power
519
548
520
549

521
550
522
-
The MKR IoT Carrier can be either powered through a USB cable connected to the mounted MKR board, or through a battery. The battery used should be a LI-ION 18650 3.7 v battery, which can be mounted to the carrier via the battery holder on the bottom side.
551
+
The MKR IoT Carrier can be either powered through a USB cable connected to the mounted MKR board, or through a battery. The battery used should be a LI-ION 18650 3.7v battery, which can be mounted to the carrier via the battery holder on the bottom side.
523
552
524
-
A cable with JST connectors on both ends are needed to connect the MKR IoT Carrier and the MKR board. The Battery can then be recharged via a USB connection through the MKR Board (Runs up to 48h with a 3.7v 2500mAh).
553
+
In order to use the USB power to charge the battery, a little cable with JST connectors on both ends is needed between the MKR IoT Carrier and the MKR board. The bBattery can then be recharged via a USB connection through the MKR Board (runs up to 48h with a 3.7v 2500mAh).
0 commit comments