Go Down

Topic: Cannot use RGB shield & env shield together (Read 70 times) previous topic - next topic

malhadeff

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 ?

Thanks,

Mikael

RELTD

#1
Jan 24, 2020, 08:53 am Last Edit: Jan 24, 2020, 09:19 am by RELTD
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.

Regards

malhadeff

Hi,

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  :)
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:
Code: [Select]

/*
  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() {
  Serial.begin(9600);
  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
  MATRIX.brightness(10);

  // configure the text scroll speed
  MATRIX.textScrollSpeed(125);

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

  delay(2000);
}

void loop() {

  ENV.begin();
 
  // 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.print(temperature);
  Serial.println(" °C");

  MATRIX.begin();
  MATRIX.brightness(10);
  MATRIX.textScrollSpeed(125);
  MATRIX.beginText(0, 0); // use the same color as before
  MATRIX.print(temperature);
  MATRIX.println(" °c");
  MATRIX.endText(); // SCROLL_LEFT parameter here to configure scrolling left

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

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

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

  Serial.print("UVA         = ");
  Serial.println(uva);

  Serial.print("UVB         = ");
  Serial.println(uvb);

  Serial.print("UV Index    = ");
  Serial.println(uvIndex);

  // print an empty line
  Serial.println();

  // wait 1 second to print again
  delay(1000);
}

malhadeff

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  :smiley-confuse:

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

Regards,

Mikael

Go Up