Skip to content

Commit c062f70

Browse files
authored
Merge pull request #567 from alranel/mkriotcarrier
Misc improvements to MKR IoT Carrier cheat sheet
2 parents 7225bd9 + 5d35ca5 commit c062f70

File tree

1 file changed

+92
-63
lines changed

1 file changed

+92
-63
lines changed

content/hardware/01.mkr/03.carriers/mkr-iot-carrier/tutorials/mkr-iot-carrier-01-technical-reference/mkr-iot-carrier-01-technical-reference.md

Lines changed: 92 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ The MKR IoT Carrier comes with **three grove connectors** (2 analog and 1 I2C) t
7676

7777
## Carrier Library
7878

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.
8080

8181
### Initialization
8282

8383
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.
8484

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.
8686

8787
```arduino
8888
#include <Arduino_MKRIoTCarrier.h>
@@ -91,15 +91,29 @@ MKRIoTCarrier carrier;
9191

9292
### Setup
9393

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.
9595

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 carrier is 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.
9797

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:
99111

100112
```arduino
101-
CARRIER_CASE = false;
113+
void setup() {
114+
carrier.noCase();
102115
carrier.begin();
116+
}
103117
```
104118

105119
## Humidity & Temperature Sensor
@@ -110,26 +124,16 @@ The **HTS221 Humidity Sensor** is mounted on the top side of the carrier under t
110124

111125
### Code
112126

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.
114128

115129
```arduino
116130
float temperature = carrier.Env.readTemperature();
117131
float humidity = carrier.Env.readHumidity();
118132
```
119133

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.
131135

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/)**.
133137

134138
## Pressure Sensor
135139

@@ -139,29 +143,23 @@ The **LPS22HBTR Pressure Sensor** is mounted on the top side of the carrier unde
139143

140144
### Code
141145

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.
143147

144148
```arduino
145149
float pressure = carrier.Pressure.readPressure();
146150
```
147151

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/)**.
155153

156154
## IMU Accelerometer & Gyroscope Sensors
157155

158156
![The IMU on the MKR IoT Carrier](assets/mkrIotCarrier-sensor-imu.png)
159157

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.
161159

162160
### Code
163161

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:
165163

166164
```arduino
167165
float x, y, z;
@@ -188,7 +186,9 @@ Returns 0 if no new acceleration data sample is available, 1 if new acceleration
188186
carrier.IMUmodule.readAcceleration(x, y, z);
189187
```
190188

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/)**.
192192

193193
## RGB and Gesture Sensor
194194

@@ -198,7 +198,7 @@ The MKR IoT Carrier contains a Broadcom **APDS-9660 RGB and Gesture sensors**, s
198198

199199
### Code
200200

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.
202202

203203
The `carrier.Light.readColor(r, g, b);` method can be used to detect colors.
204204

@@ -255,6 +255,8 @@ The code example below shows the gesture value in a fixed width integer `uint8_t
255255
256256
```
257257

258+
The underlying library used to read the sensor is **[Arduino_APDS9960](https://www.arduino.cc/reference/en/libraries/arduino_apds9960/)**.
259+
258260
## Relays
259261

260262
![The relays on the MKR IoT Carrier](assets/mkrIotCarrier-relays-01.png)
@@ -304,27 +306,37 @@ The screen on the MKR IoT Carrier is a **rounded 1.3” TFT display**, with a 24
304306

305307
#### Code
306308

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.
308310

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.
310312

311-
```arduino
312-
carrier.display.fillScreen(color);
313-
```
314313

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.
316318

317319
```arduino
318-
carrier.display.setRotation(0);
320+
carrier.display.fillScreen(color);
319321
```
320322

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
322334

323335
```arduino
324-
display.print("text");
336+
carrier.display.setRotation(0);
325337
```
326338

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.
328340

329341
```arduino
330342
carrier.display.drawBitmap(x, y, bitmap_visual, w, h, color);
@@ -350,47 +362,55 @@ carrier.display.setCursor(x, y);
350362

351363
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.
352364

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.
374+
353375
### Buttons
354376

355377
![The MKR IoT Carrier's buttons](assets/mkrIotCarrier-buttons.png)
356378

357-
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.
358380

359381
#### Code
360382

361-
The **Button class** can be controlled using the following methods:
362-
363383
```arduino
364-
Buttons.update();
384+
carrier.Buttons.update();
365385
```
366386

367387
Reads the state of the pads and save them to be used in the different types of touch events.
368388

369389
```arduino
370-
Buttons.getTouch(TOUCHX);
390+
carrier.Buttons.getTouch(TOUCH0);
371391
```
372392

373393
Get if the pad is getting touched, true until it gets released.
374394

375395
```arduino
376-
Buttons.onTouchDown(TOUCHX);
396+
carrier.Buttons.onTouchDown(TOUCH0);
377397
```
378398

379399
Get when have been a touch down.
380400

381401
```arduino
382-
Buttons.onTouchUp(TOUCHX);
402+
carrier.Buttons.onTouchUp(TOUCH0);
383403
```
384404

385405
Get when the button has been released.
386406

387407
```arduino
388-
Buttons.onTouchChange(TOUCHX);
408+
carrier.Buttons.onTouchChange(TOUCH0);
389409
```
390410

391411
Get both, touched and released.
392412

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.
394414

395415
```arduino
396416
@@ -428,13 +448,13 @@ carrier.leds.setPixelColor(index, red, green, blue);
428448
Sets the color of the index’s LED.
429449

430450
```arduino
431-
carrier.leds.setBrightness(0-255)
451+
carrier.leds.setBrightness(255);
432452
```
433453

434454
Set the overall brightness, from 0 (no brightness) to 255 (maximum brightness).
435455

436456
```arduino
437-
carrier.leds.clear()
457+
carrier.leds.clear();
438458
```
439459

440460
Clear the buffer of the LEDs.
@@ -460,8 +480,8 @@ MKRIoTCarrier carrier;
460480
461481
uint32_t myCustomColor = carrier.leds.Color(255,100,50);
462482
463-
void setup(){
464-
CARRIER_CASE = false;
483+
void setup() {
484+
carrier.noCase();
465485
carrier.begin();
466486
carrier.leds.fill(myCustomColor, 0, 5);
467487
carrier.leds.show();
@@ -480,48 +500,57 @@ The MKR IoT Carrier is equipped with a **sound buzzer** on the bottom side of th
480500
The buzzer can be controlled with the following methods:
481501

482502
```arduino
483-
carrier.Buzzer.sound(freq)
503+
carrier.Buzzer.sound(freq);
484504
```
485505

486506
Equivalent to tone(), it will make the tone with the selected frequency.
487507

488508
```arduino
489-
carrier.Buzzer.noSound()
509+
carrier.Buzzer.noSound();
490510
```
491511

492512
Equivalent to noTone(), it will stop the tone signal.
493513

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+
494521
## Memory
495522

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.
497524

498525
### Code
499526

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.
501528

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.
503530

504531
```arduino
505532
#include <Arduino_MKRIoTCarrier.h>
506533
MKRIoTCarrier carrier;
507534
508535
File myFile;
509536
510-
setup(){
511-
CARRIER_CASE = false;
537+
void setup() {
538+
carrier.noCase();
512539
carrier.begin(); //SD card initialized here
513540
514541
myFile = SD.open("test.txt", FILE_WRITE);
515542
}
516543
```
517544

545+
In order to learn more, check any of the many tutorials about using the `SD` library on Arduino.
546+
518547
## Power
519548

520549
![JST battery connector on the MKR IoT Carrier.](assets/mkriotcarrier-battery.png)
521550

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.
523552

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).
525554

526555
<video width="100%" controls="true">
527556
<source src="assets/mkrIoTCarrier-battery-assembly.mp4" type="video/mp4"/>

0 commit comments

Comments
 (0)