Good morning,
I wanted to ask you if anyone has any idea how to control Arduino_MKRIoTCarrier (what comes out on the display, how to select an option with one of the side buttons, how to turn the LED strip on/off etc...).
Do you also happen to have some code you can test?
A thousand thanks.
Hi @castorettino. You can learn about how to use the features of the MKR IoT Carrier Rev2 from the documentation here:
https://docs.arduino.cc/hardware/mkr-iot-carrier-rev2/
Give that a try and let us know if you have any questions or problems.
Error:
/usr/local/bin/arduino-cli compile --fqbn arduino:samd:mkrwifi1010 --build-cache-path /tmp --output-dir /tmp/5185238/build --build-path /tmp/arduino-build-70F948518AB3180085E64D191880154F --library /home/builder/opt/libraries/arduino_mkriotcarrier_2_0_4 --library /home/builder/opt/libraries/bsec_software_library_1_6_1480 --library /home/builder/opt/libraries/arduino_lsm6dsox_1_1_2 /tmp/5185238/Componenti_Serra_may03a
/tmp/5185238/Componenti_Serra_may03a/Componenti_Serra_may03a.ino: In function 'void Test()':
/tmp/5185238/Componenti_Serra_may03a/Componenti_Serra_may03a.ino:237:5: error: 'display' was not declared in this scope
display.print("Pulsante 0");
^~~~~~~
/tmp/5185238/Componenti_Serra_may03a/Componenti_Serra_may03a.ino:237:5: note: suggested alternatives:
In file included from /home/builder/opt/libraries/arduino_mkriotcarrier_2_0_4/src/Arduino_MKRIoTCarrier.h:25:0,
from /tmp/5185238/Componenti_Serra_may03a/Componenti_Serra_may03a.ino:13:
/home/builder/opt/libraries/arduino_mkriotcarrier_2_0_4/src/MKRIoTCarrierDefines.h:48:10: note: 'mkr_iot_carrier_rev1::display'
enum display {
^~~~~~~
/home/builder/opt/libraries/arduino_mkriotcarrier_2_0_4/src/MKRIoTCarrierDefines.h:71:10: note: 'mkr_iot_carrier_rev2::display'
enum display {
^~~~~~~
Multiple libraries were found for "Adafruit_ST7789.h"
Used: /home/builder/opt/libraries/adafruit_st7735_and_st7789_library_1_10_3
Not used: /home/builder/opt/libraries/vega_st7735_and_st7789_1_0_0
Multiple libraries were found for "ECCX08.h"
Used: /home/builder/opt/libraries/arduinoeccx08_1_3_8
Not used: /home/builder/opt/libraries/rak5814_atecc608a_1_0_0
Multiple libraries were found for "Wire.h"
Used: /home/builder/.arduino15/packages/arduino/hardware/samd/1.8.13/libraries/Wire
Not used: /home/builder/opt/libraries/flexwire_1_2_0
Multiple libraries were found for "Arduino_LSM6DSOX.h"
Used: /home/builder/opt/libraries/arduino_lsm6dsox_1_1_2
Not used: /home/builder/opt/libraries/arduino_lsm6dsox_1_1_2
Multiple libraries were found for "Arduino_MKRIoTCarrier.h"
Used: /home/builder/opt/libraries/arduino_mkriotcarrier_2_0_4
Not used: /home/builder/opt/libraries/arduino_mkriotcarrier_2_1_0
Multiple libraries were found for "Arduino_PMIC.h"
Used: /home/builder/opt/libraries/arduino_bq24195_0_9_2
Not used: /home/builder/opt/libraries/arduino_pf1550_0_3_0
Multiple libraries were found for "Adafruit_GFX.h"
Used: /home/builder/opt/libraries/adafruit_gfx_library_1_11_9
Not used: /home/builder/opt/libraries/dfrobot_rgbmatrix_1_0_1
Multiple libraries were found for "WiFiNINA.h"
Used: /home/builder/opt/libraries/wifinina_1_8_14
Not used: /home/builder/opt/libraries/betterwifinina_1_3_0
Not used: /home/builder/opt/libraries/vega_wifinina_1_0_1
Multiple libraries were found for "Adafruit_I2CDevice.h"
Used: /home/builder/opt/libraries/adafruit_busio_1_16_0
Not used: /home/builder/opt/libraries/vegaiot_busio_1_0_0
Multiple libraries were found for "SPI.h"
Used: /home/builder/.arduino15/packages/arduino/hardware/samd/1.8.13/libraries/SPI
Not used: /home/builder/opt/libraries/eventethernet_1_0_0
Error during build: exit status 1
Code
// Arduino_MKRIoTCarrier - Version: 2.0.4
// BSEC Software Library - Version: 1.6.1480
// Arduino_LSM6DSOX - Version: 1.1.2
// Adafruit GFX Library - Version: 1.11.9
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
#include <Arduino_LSM6DSOX.h>
#include "thingProperties.h"
#include <Arduino_MKRIoTCarrier.h>
#include <Grove_I2C_Motor_Driver.h>
MKRIoTCarrier carrier;
Bsec iaqSensor;
String output;
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
Wire.begin();
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(4);
ArduinoCloud.printDebugInfo();
iaqSensor.begin(BME680_I2C_ADDR_PRIMARY, Wire);
output = "\nBSEC library version " + String(iaqSensor.version.major) + "." + String(iaqSensor.version.minor) + "." + String(iaqSensor.version.major_bugfix) + "." + String(iaqSensor.version.minor_bugfix);
Serial.println(output);
checkIaqSensorStatus();
bsec_virtual_sensor_t sensorList[10] = {
BSEC_OUTPUT_RAW_TEMPERATURE,
// BSEC_OUTPUT_RAW_PRESSURE,
BSEC_OUTPUT_RAW_HUMIDITY,
// BSEC_OUTPUT_RAW_GAS,
// BSEC_OUTPUT_IAQ,
// BSEC_OUTPUT_STATIC_IAQ,
// BSEC_OUTPUT_CO2_EQUIVALENT,
// BSEC_OUTPUT_BREATH_VOC_EQUIVALENT,
// BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_TEMPERATURE,
// BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_HUMIDITY,
};
iaqSensor.updateSubscription(sensorList, 10, BSEC_SAMPLE_RATE_LP);
checkIaqSensorStatus();
//------------------------------------------------------
carrier.withCase();
carrier.begin();
carrier.leds.fill(carrier.leds.Color(255,100,255), 0, 5);
carrier.leds.show();
carrier.display.fillScreen(0x07E0);
carrier.display.setTextColor(0x0000);
carrier.display.setTextSize(2);
carrier.display.setCursor(2, 2);
//------------------------------------------------------
}
void loop() {
ArduinoCloud.update();
carrier.Buttons.update();
if (iaqSensor.run()) { // If new data is available
temperature = iaqSensor.rawTemperature;
humidity = iaqSensor.rawHumidity;
}
else {
checkIaqSensorStatus();
}
if(carrier.IMUmodule.accelerationAvailable()){
Open();
}
if (carrier.Buttons.onTouchDown(TOUCH0)){
Test();
}
/*
if(temperature>20){
fan=true;
onFanChange();
}
else{
fan=false;
onFanChange();
}
*/
/*
Serial.println("Temperature[°C] | relative humidity[%] |");
Serial.println(" ");
Serial.print(temperature);
Serial.println(" | ");
Serial.print(humidity);
Serial.println(" | ");
*/
}
void onFanChange() {
if (fan) {
Motor.speed(MOTOR2, 100);
}
else {
Motor.stop(MOTOR2);
}
}
void checkIaqSensorStatus(void){
if (iaqSensor.status != BSEC_OK) {
if (iaqSensor.status < BSEC_OK) {
output = "BSEC error code : " + String(iaqSensor.status);
Serial.println(output);
/* for (;;)
errLeds(); /* Halt in case of failure */
} else {
output = "BSEC warning code : " + String(iaqSensor.status);
Serial.println(output);
}
}
if (iaqSensor.bme680Status != BME680_OK) {
if (iaqSensor.bme680Status < BME680_OK) {
output = "BME680 error code : " + String(iaqSensor.bme680Status);
Serial.println(output);
/* for (;;)
errLeds(); /* Halt in case of failure */
} else {
output = "BME680 warning code : " + String(iaqSensor.bme680Status);
Serial.println(output);
}
}
}
void onMessageChange() {
if(message=="Spegni la ventola"){
fan=false;
Changes();
onFanChange();
}
if(message=="Accendi la ventola"){
fan=true;
Changes();
onFanChange();
}
if(message=="Controllo Manuale"){
Manual_Control();
}
if(message=="Controllo Automatico"){
Automatic_Control();
}
}
void onLedStripChange() {
if (led_strip) {
carrier.Relay1.open();
}
else {
carrier.Relay1.close();
}
}
void Changes(){
for(int i = 0; i<3; i++){
carrier.Relay1.open();
delay(1000);
carrier.Relay1.close();
delay(1000);
}
}
void Manual_Control(){
for(int i = 0; i<2; i++){
carrier.Relay1.open();
delay(2000);
carrier.Relay1.close();
delay(1000);
}
}
void Automatic_Control(){
carrier.Relay1.open();
delay(3000);
carrier.Relay1.close();
}
void Open(){
carrier.Relay1.open();
delay(5000);
carrier.Relay1.close();
}
void Test(){
carrier.Relay1.open();
display.print("Pulsante 0");
delay(5000);
display.print("Serra in Esecuzione");
carrier.Relay1.close();
}
/*
void errLeds(void)
{
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
delay(100);
digitalWrite(LED_BUILTIN, LOW);
delay(100);
}
*/
There is an error in the documentation. Instead of display.print
, it must be carrier.display.print
:
carrier.display.print("Pulsante 0");
delay(5000);
carrier.display.print("Serra in Esecuzione");
You can see a demonstration of the correct code here in the "Arduino_MKRIoTCarrier" library's "All_Features" example:
I've submitted a correction for the erroneous documentation:
Sorry,i am so distract...
Can i ask you if the version of the library is corrected?
// Arduino_LSM6DSOX - Version: 1.1.2
// Adafruit GFX Library - Version: 1.11.9
Yes, those library versions are fine.
everything works, perfect....
Do you happen to know how to clear the screen of all the words that have been written?
The most simple way to do it is to use carrier.display.fillScreen
.
I'll provide an example:
#include <Arduino_MKRIoTCarrier.h>
MKRIoTCarrier carrier;
unsigned int backgroundColor = 0x0000;
void setup() {
carrier.begin();
}
void loop() {
carrier.display.fillScreen(backgroundColor);
carrier.display.setCursor(80, 120);
carrier.display.print("Hello");
delay(1000);
carrier.display.fillScreen(backgroundColor);
carrier.display.setCursor(80, 120);
carrier.display.print("World!");
delay(1000);
}
Thank you so much
You are welcome. I'm glad if I was able to be of assistance.
Regards,
Per
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.