ArduinoJSON conflicts with SmartMatrix

Hello
I am getting a compile error when I use SmartMatrix and ArduinoJSON together, I am using PlatfromIO/VS Code as the IDE. According to a google search, the error I get seems to be related to when two things have been allocated the same memory by the compiler? or something. I don’t know enough details of C++, the error I get is:

In file included from .pio\libdeps\teensy41\ArduinoJson\src/ArduinoJson/Numbers/FloatTraits.hpp:14:0,
             from .pio\libdeps\teensy41\ArduinoJson\src/ArduinoJson/Numbers/convertNumber.hpp:18,
             from .pio\libdeps\teensy41\ArduinoJson\src/ArduinoJson/Variant/VariantData.hpp:9,
             from .pio\libdeps\teensy41\ArduinoJson\src/ArduinoJson/Variant/SlotFunctions.hpp:8,
             from .pio\libdeps\teensy41\ArduinoJson\src/ArduinoJson/Array/ArrayIterator.hpp:7,
             from .pio\libdeps\teensy41\ArduinoJson\src/ArduinoJson/Array/ArrayRef.hpp:8,
             from .pio\libdeps\teensy41\ArduinoJson\src/ArduinoJson.hpp:17,
             from .pio\libdeps\teensy41\ArduinoJson\src/ArduinoJson.h:9,
             from src\main.cpp:4:
.pio\libdeps\teensy41\ArduinoJson\src/ArduinoJson/Deserialization/DeserializationError.hpp:100:5: error: messages causes a section type conflict with lightPowerMap16bit
 ARDUINOJSON_DEFINE_STATIC_ARRAY(
 ^
In file included from .pio\libdeps\teensy41\SmartMatrix\src/SmartMatrix.h:50:0,
             from src\main.cpp:12:
.pio\libdeps\teensy41\SmartMatrix\src/MatrixCommon.h:387:31: note: 'lightPowerMap16bit' was declared here
 static const PROGMEM uint16_t lightPowerMap16bit[] = {
                           ^
*** [.pio\build\teensy41\src\main.cpp.o] Error 1

Here is the code I used to recreate this error, sorry its a bit long:

#include <Arduino.h>
#include <Wire.h>
#include <ArduinoJson.h>

// SmartMatrix Setup
#define USE_ADAFRUIT_GFX_LAYERS 
#define INCLUDE_FASTLED_BACKGROUND 
#include <MatrixHardware_Teensy4_ShieldV5.h>        // SmartLED Shield for Teensy 4 (V5)
#include <SmartMatrix.h>
#include <FastLED.h>
#define COLOR_DEPTH 24                  // Choose the color depth used for storing pixels in the layers: 24 or 48 (24 is good for most sketches - If the sketch uses type `rgb24` directly, COLOR_DEPTH must be 24)
const uint16_t kMatrixWidth = 64;       // Set to the width of your display, must be a multiple of 8
const uint16_t kMatrixHeight = 64;      // Set to the height of your display    
const uint8_t kRefreshDepth = 36;          
const uint8_t kDmaBufferRows = 6;   
const uint32_t kMatrixOptions = (SM_HUB75_OPTIONS_NONE);    
const uint8_t kScrollingLayerOptions = (SM_SCROLLING_OPTIONS_NONE);

SMARTMATRIX_ALLOCATE_BUFFERS(matrix, kMatrixWidth, kMatrixHeight, kRefreshDepth, kDmaBufferRows, kPanelType, kMatrixOptions);

const uint8_t kBackgroundLayerOptions = (SM_BACKGROUND_OPTIONS_NONE);
SMARTMATRIX_ALLOCATE_BACKGROUND_LAYER(backgroundLayer, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kBackgroundLayerOptions);

SMARTMATRIX_ALLOCATE_GFX_MONO_LAYER(messageLayer, kMatrixWidth, kMatrixHeight, kMatrixWidth*3, kMatrixHeight, COLOR_DEPTH, kScrollingLayerOptions);

const int defaultBrightness = (70*255)/100;         // dim: 15% brightness

char jsonData[] = "{'coord':{'lon':-1.4659,'lat':53.383}, "
      "'weather':[{'id':802,'main':'Clouds',"
      "'description':'scattered clouds','icon':'03n'}],'base':'stations',"
      "'main':{'temp':276.8,'feels_like':274.42,'temp_min':274.82,'temp_max':278.71,"
      "'pressure':1009,'humidity':86},'visibility':10000,"
      "'wind':{'speed':2.54,'deg':275,'gust':6.2},"
      "'clouds':{'all':36},'dt':1620248072,"
      "'sys':{'type':3,'id':2007943,'country':'GB','sunrise':1620188603,'sunset':1620243698},"
      "'timezone':3600,'id':2638077,'name':'Sheffield','cod':200}";

void setupDisplayLayers() {
  matrix.addLayer(&backgroundLayer); 
  matrix.addLayer(&messageLayer); 
  matrix.begin();

  matrix.setBrightness(defaultBrightness);
  messageLayer.setFont(font3x5);
  messageLayer.setOffsetFromTop(2);
  messageLayer.setColor(rgb24(0x07FF)); // cyan

  messageLayer.setMode((ScrollMode)3);
}

void setup() {
  Serial.begin(115200);
  while (!Serial) {
   ;
  }
  Serial.println("ready");
 
  setupDisplayLayers();
  messageLayer.fillScreen(0);
  messageLayer.drawString(3,6, 1, "Hello");
  messageLayer.drawString(3,12, 1, "World");
  messageLayer.swapBuffers();

  StaticJsonDocument<1024> doc;
  DeserializationError error = deserializeJson(doc, jsonData);
  // Test if parsing succeeds.
  if (error) {
    Serial.print(F("deserializeJson() failed: "));
    Serial.println(error.f_str());
    return;
  }

  char* weatherDescription = doc["weather"]["description"];
  Serial.println(weatherDescription);
}

void loop() {
  // put your main code here, to run repeatedly:
}

Any Ideas how this can be fixed?
Thanks
Karl

I’m not that familiar with PIO, so I compiled your code with Arduino IDE. It wouldn’t compile until I added a missing kPanelType definition:

const uint8_t kPanelType = SM_PANELTYPE_HUB75_64ROW_MOD32SCAN;

and this line was throwing an error so I just commented it out: //Serial.println(error.f_str());

It compiles successfully after that. Maybe it’s a PIO issue? Maybe you have a different version of ArduinoJSON?

Thanks for correctly using the code block formatting, it’s very rare that people do that :slight_smile:

Hello Louis
Thanks for the reply. Yes, it was to do with the version of ArduinoJSON, reverting to 6.15.2 from 6.17.3 fixed the problem on the test code, also when I was updating my main code, the version given was 6.18.0, released less than a day ago, so that one may have been faulty.

I must have forgotten the .kPanelType line when pasting the code.

Thanks
Karl