MKR Motor Carried Library error

Hi everyone,
bought an MKR Motor Carrier Board connected with an MKR WiFi1010.
Including the library in the sketch (tried version 1.0.5 and 1.0.4) cause the compiler to return with this:

Arduino: 1.8.12 (Mac OS X), Board: "Arduino MKR WiFi 1010"

In file included from /Users/KuzkaMac/Documents/Arduino/libraries/MKRMotorCarrier/src/MKRMotorShield.h:22:0,
from /Users/KuzkaMac/Documents/Arduino/libraries/MKRMotorCarrier/src/MKRMotorCarrier.h:1,
from /Users/KuzkaMac/Documents/Arduino/RV12-iS_RPM_Control/RV12-iS_RPM_Control.ino:3:
/Users/KuzkaMac/Documents/Arduino/libraries/MKRMotorCarrier/src/Battery.h:21:7: error: redefinition of 'class mc::Battery'
class Battery {
^~~~~~~
In file included from /Users/KuzkaMac/Documents/Arduino/RV12-iS_RPM_Control/RV12-iS_RPM_Control.ino:1:0:
/Users/KuzkaMac/Documents/Arduino/libraries/MKRMotorCarrier/src/Battery.h:21:7: note: previous definition of 'class mc::Battery'
class Battery {
^~~~~~~
In file included from /Users/KuzkaMac/Documents/Arduino/RV12-iS_RPM_Control/RV12-iS_RPM_Control.ino:4:0:
/Users/KuzkaMac/Documents/Arduino/libraries/MKRMotorCarrier/src/ServoMotor.h:21:7: error: redefinition of 'class mc::ServoMotor'
class ServoMotor {
^~~~~~~~~~
In file included from /Users/KuzkaMac/Documents/Arduino/libraries/MKRMotorCarrier/src/MKRMotorShield.h:24:0,
from /Users/KuzkaMac/Documents/Arduino/libraries/MKRMotorCarrier/src/MKRMotorCarrier.h:1,
from /Users/KuzkaMac/Documents/Arduino/RV12-iS_RPM_Control/RV12-iS_RPM_Control.ino:3:
/Users/KuzkaMac/Documents/Arduino/libraries/MKRMotorCarrier/src/ServoMotor.h:21:7: note: previous definition of 'class mc::ServoMotor'
class ServoMotor {
^~~~~~~~~~
In file included from /Users/KuzkaMac/Documents/Arduino/RV12-iS_RPM_Control/RV12-iS_RPM_Control.ino:6:0:
/Users/KuzkaMac/Documents/Arduino/libraries/MKRMotorCarrier/src/Common.h:17:6: error: multiple definition of 'enum Commands'
enum Commands {
^~~~~~~~
In file included from /Users/KuzkaMac/Documents/Arduino/libraries/MKRMotorCarrier/src/MKRMotorShield.h:26:0,
from /Users/KuzkaMac/Documents/Arduino/libraries/MKRMotorCarrier/src/MKRMotorCarrier.h:1,
from /Users/KuzkaMac/Documents/Arduino/RV12-iS_RPM_Control/RV12-iS_RPM_Control.ino:3:
/Users/KuzkaMac/Documents/Arduino/libraries/MKRMotorCarrier/src/Common.h:17:6: note: previous definition here
enum Commands {
^~~~~~~~
In file included from /Users/KuzkaMac/Documents/Arduino/RV12-iS_RPM_Control/RV12-iS_RPM_Control.ino:6:0:
/Users/KuzkaMac/Documents/Arduino/libraries/MKRMotorCarrier/src/Common.h:47:6: error: multiple definition of 'enum IRQCause'
enum IRQCause {
^~~~~~~~
In file included from /Users/KuzkaMac/Documents/Arduino/libraries/MKRMotorCarrier/src/MKRMotorShield.h:26:0,
from /Users/KuzkaMac/Documents/Arduino/libraries/MKRMotorCarrier/src/MKRMotorCarrier.h:1,
from /Users/KuzkaMac/Documents/Arduino/RV12-iS_RPM_Control/RV12-iS_RPM_Control.ino:3:
/Users/KuzkaMac/Documents/Arduino/libraries/MKRMotorCarrier/src/Common.h:47:6: note: previous definition here
enum IRQCause {
^~~~~~~~
exit status 1
Error compiling for board Arduino MKR WiFi 1010.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Any clue?
Thanks

Giovanni

The problem is that Sketch > Include Library > MKRMotorCarrier added #include directives for all the .h files of the library, thus the redefinition errors. You need to remove all those unnecessary #include directives other than the one for MKRMotorCarrier.h. So instead of this:

#include <Battery.h>
#include <Common.h>
#include <DCMotor.h>
#include <Encoder.h>
#include <MKRMotorCarrier.h>
#include <MKRMotorShield.h>
#include <MotorController.h>
#include <PID.h>
#include <ServoMotor.h>

you have only this:

#include <MKRMotorCarrier.h>

I forgot to mention that I just submitted a fix for this issue, which has already been merged!
https://github.com/arduino-libraries/MKRMotorCarrier/pull/22
so in the next release of the library this issue will no longer occur.

Thanks for your fast reply.

I'm now looking for more infos about analog inputs AIN 1 to AIN 4 but I cannot find any examples.

The pinout of the IN1-4 connectors on the MKR Motor Carrier is:

  • GND (denoted by white line on silkscreen)
  • SIG
  • 5V

The connections to the MKR board:

Carrier | MKR board

IN1 | A6
IN2 | A1
IN3 | A5
IN4 | A2

The SIG pins are connected to the analog pins on the MKR board via a level translator. Any voltage from 0-3.3 V on the SIG pin is passed directly to the MKR board's analog pin. Any voltage from 3.3 V to 5 V on the SIG pin is reduced to 3.3 V before being passed to the MKR board's analog pin.

Here's an example that prints the readings on the SIG pins of the IN1-4 connectors to the Serial Monitor or Serial Plotter:

void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.print(analogRead(A6)); // IN1
  Serial.print(',');
  Serial.print(analogRead(A1)); // IN2
  Serial.print(',');
  Serial.print(analogRead(A5)); // IN3
  Serial.print(',');
  Serial.println(analogRead(A2)); // IN4
}

Let me know if you have any questions.