Cannot use RGB shield & env shield together

Hi all,

I just bought the MKR 1010 with an RGB shield and an ENV shield.

I stacked them together and tried to modify the ENV sample to display the temperature using the RGB shield. It doesn't work, I get nothing displayed on the shield and nothing displayed on the console either. I played around and noticed that all the MATRIX calls work fine until I try to read the ENV sensors which seems to make the loop() function hanging.

I've not yet digged into the libraries but I've checked both schemas and there are no pin shared between the two shields so I don't known why it hangs like this :(

Does someone have an idea about this ?



I’ve had mixed results combining MKR shields as well (e.g. ENV + GPS).

How is your setup supplied? USB (std port ~500mA max draw) or do you have a LiPo supporting the main board as well? Is the RGB shield supplied with an additional 5V source as well? Apparently the RGB shield draws a lot of current.

I came across an I2C scanner sketch (Google), which prints out the connected I2C devices’ addresses in serial monitor. Not sure if there’s a clash between RGB and ENV there?

Would be helpful if you share your full sketch as wel.



Thank you for your answer.

My setup is supplied by the USB port.
The RGB shield is set to a low brightness so it shouldn’t matter.

I’ve investigated more and found the issue and a (quick & dirty) fix :slight_smile:
The problem actually comes from the Wire library having the endTransmission() hanging.
As stated in this post, I’ve added explicit calls to ENV.begin() and MATRIX.begin() before calling their functions in the loop() method and now my sketch works as expected.

I don’t really understand why those two libraries, using different protocols (ENV uses I2C & RGB uses SPI) are conflicting like this but I guess there must be an explanation somewhere…

Here is the (working) code:

  MKR ENV Shield - Read Sensors

  This example reads the sensors on-board the MKR ENV shield
  and prints them to the Serial Monitor once a second.

  The circuit:
  - Arduino MKR board
  - Arduino MKR ENV Shield attached

  This example code is in the public domain.
#include <ArduinoGraphics.h> // Arduino_MKRRGB depends on ArduinoGraphics
#include <Arduino_MKRRGB.h>
#include <Arduino_MKRENV.h>

void setup() {
  while (!Serial);

  if (!ENV.begin()) {
    Serial.println("Failed to initialize MKR ENV shield!");
    while (1);
  } else {
    Serial.println("MKR ENV shield initialized");

    // initialize the display
  if (!MATRIX.begin()) {
    Serial.println("Failed to initialize MKR RGB shield!");
    while (1);
  } else {
    Serial.println("MKR RGB shield initialized");

  // set the brightness, supported values are 0 - 255

  // configure the text scroll speed

    // display some short text without scrolling
  MATRIX.beginText(0, 0, 0, 0, 127); // X, Y, then R, G, B
  MATRIX.print("Init complete");
  Serial.println("Init complete");


void loop() {

  // read all the sensor values
  Serial.println("Reading temperature");
  float temperature = ENV.readTemperature();
  Serial.println("Reading humidity");  
  float humidity    = ENV.readHumidity();
  Serial.println("Reading pressure");
  float pressure    = ENV.readPressure();
  Serial.println("Reading illuminance");
  float illuminance = ENV.readIlluminance();
  Serial.println("Reading uva");
  float uva         = ENV.readUVA();
  Serial.println("Reading uvb");
  float uvb         = ENV.readUVB();
  Serial.println("Reading uvIndex");
  float uvIndex     = ENV.readUVIndex();

  // print each of the sensor values
  Serial.print("Temperature = ");
  Serial.println(" °C");

  MATRIX.beginText(0, 0); // use the same color as before
  MATRIX.println(" °c");
  MATRIX.endText(); // SCROLL_LEFT parameter here to configure scrolling left

  Serial.print("Humidity    = ");
  Serial.println(" %");

  Serial.print("Pressure    = ");
  Serial.println(" kPa");

  Serial.print("Illuminance = ");
  Serial.println(" lx");

  Serial.print("UVA         = ");

  Serial.print("UVB         = ");

  Serial.print("UV Index    = ");

  // print an empty line

  // wait 1 second to print again

Ok, i've found the explanation i was looking for :)

The RGB shield uses SPI but not on the standard pins. Its library created the SPI interface using sercom0 which is used by the default I2C.

You may find explanations about SERCOM here.

If i've read well the table in variants file (see source code here), the pins A3 & A4 used by the RGB shield may only be used by sercom0.

I should then move I2C to sercom2 but sercom2 is used by the Wifi SPI, which could then be moved to sercom4.

It seems like a lot of hassle just to print temperature on the leds :confused:

But, at least, now i know why it doesn't work!