Constant string in the middle of a program changed

Hi
I have some text in the middle of a program, such as
Serial.println("Touch the reader");

At some point I realizes it prints "To}ch the reader" instead.
After playing with different characters and program sequences I established that

  1. Text is already changed in the beginning of the setup(), so none of my code could do it.
  2. What actually happens with this character is the binary OR with the number 0x1D (???)
  3. Issue is not random - if I recompile or reboot, it stays. If I rearrange the code, it may happen to another string, but will be stable again.

None of my code could do it - it is pretty basic, no pointers or other dynamic memory thingies. The libraries I use are

#include <Pushbutton.h>
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_PN532.h>
#include <TroykaTextLCD.h>

Board is vanilla Leonardo.
Does anybody came across similar issues? Are any of these libraries are known to do weird things with memory?
P.S.

#include <Pushbutton.h>
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_PN532.h>
#include <TroykaTextLCD.h>
//some static initializers

void setup() {
  Serial.begin(9600);
  //commented out everything that was there
  drawDisplay();
  //more code
}

void drawDisplay() {
  //commented out all previous operations
  Serial.println("Touch the sensor");
  delay(100000);
  //some code continues
}

void loop() {
//some code that program never really gets to
}

Expected result in the console
Touch the sensor

visible result in the console
To{ch the sensor

P.P.S. Adding the code and some custom library I use
TroykaTextLCD.cpp (4.4 KB)
TroykaTextLCD.h (4.2 KB)

LTArmoury_1_4.ino (13.5 KB)
mlt_core.cpp (6.7 KB)
mlt_core.h (3.1 KB)

The problem could be in the hardware, which you forgot to describe, or in the code, which you forgot to post.

Please have a look at the instructions in the "How to get the best out of this forum" post, linked at the head of every forum category.

Actually the code after the Serial.print() could be corrupting the serial buffer, by the time you see text in the serial monitor the code is well past that point in the sketch, unless you have a delay() or Serial.flush() to slow things down.

If your text is defined like the above, then I think the text is copied from ROM to RAM before setup. Your code could be stomping on the area of RAM when the text resides after startup.

Thank you for a quick response. I am not sure any external hardware (NFC reader, LCD display, buttons, LEDs etc) can impact the constant string.

As for the software, the disruption apparently happens before the first (after Serial.begin()) line of setup, so only static initializers are executed so far. Placing some of the initializers below:

Adafruit_PN532 nfc(PIN_PN532_IRQ, 100);
char lines[SHOP_POSITIONS][11] = {
  "Dam",
  "HP",
  "Mag"
};

I can post the whole program, just did not want to use too much of your guys' time.

Added 100ms delay - same issue :frowning:

Post the entire code, it will take much less time to solve your problem when we can see that.

Yes, something definitely overwrites this character, unless my Arduino caught a kind of evel gremlin :slight_smile: I am trying to find what could do this |=0x1D . None of my code is doing such an operation.

Thank you, added the code.

This is always preferred.... but in < CODE > blocks...

void setup() {
 // empty
}

void loop() {
  // empty
}

Obviously, a malfunctioning LCD could display the string incorrectly. For help, post the requested material.

Updated the code. Line is following:
Serial.println("Touch the reader"); //THIS ONE
LCD gets same constant and displays same erroneous character.

Program is too big for that. And if I touch it, glitch goes somewhere else, to some other constant string.

Unlikely. Use code tags for thousands of lines. Or, post the minimum code that demonstrates the problem.

Unstable wiring.

Cannot be. I recompiled and restarted many times, glitch is in the same place. I move code around - glitch moves, but stays stable through the recompiles.

Until you supply the requested details, you are wasting everyone's time.

Goodbye.

Sorry for confusion. I attached all relevant files to the original question.

You are saying "Not the hardware, not the software and not me." You must not assume these.

Post your code in < CODE > blocks, post your drawing. Describe what you expect. Describe what you observe.

Added code blocks to the original question