# Constant string in the middle of a program changed

**URL:** <https://forum.arduino.cc/t/constant-string-in-the-middle-of-a-program-changed/1310910>\
**Category:** Programming\
**Created:** [October 13, 2024, 5:12pm UTC](https://forum.arduino.cc/t/constant-string-in-the-middle-of-a-program-changed/1310910 "2024-10-13T17:12:44Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ArchHasher](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/archhasher/32/315701_2.png) [@ArchHasher](https://forum.arduino.cc/u/ArchHasher)\
**Post date:** [October 13, 2024, 5:12pm UTC](https://forum.arduino.cc/t/constant-string-in-the-middle-of-a-program-changed/1310910/1 "2024-10-13T17:12:44Z")

</div>

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

```arduino
#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.

```arduino
#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](https://forum.arduino.cc/uploads/short-url/caDaUKAVXzpcuss3Q5fv36uMUbf.cpp) (4.4 KB)  
[TroykaTextLCD.h](https://forum.arduino.cc/uploads/short-url/4eq6Rv8q9cS0PY097xbPz40Zb4u.h) (4.2 KB)

[LTArmoury\_1\_4.ino](https://forum.arduino.cc/uploads/short-url/f0zPF2q0xdKOurPEYB51lt97Ewq.ino) (13.5 KB)  
[mlt\_core.cpp](https://forum.arduino.cc/uploads/short-url/xEkcfAzsaDSjI0lASvH6ddOAoQd.cpp) (6.7 KB)  
[mlt\_core.h](https://forum.arduino.cc/uploads/short-url/1axEVbo5WlCBAYZsSnU1jdQ7K4Q.h) (3.1 KB)

---

<div class="post-metadata">

**Author:** ![anon94801460](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon94801460](https://forum.arduino.cc/u/anon94801460)\
**Post date:** [October 13, 2024, 5:15pm UTC](https://forum.arduino.cc/t/constant-string-in-the-middle-of-a-program-changed/1310910/2 "2024-10-13T17:15:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![david\_2018](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/david_2018/32/1013044_2.png) [@david\_2018](https://forum.arduino.cc/u/david_2018)\
**Post date:** [October 13, 2024, 5:20pm UTC](https://forum.arduino.cc/t/constant-string-in-the-middle-of-a-program-changed/1310910/3 "2024-10-13T17:20:08Z")

</div>

> [@ArchHasher](#):
>
> Text is already changed in the beginning of the `setup()`, so none of my code could do it.

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.

---

<div class="post-metadata">

**Author:** ![markd833](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/markd833/32/1186928_2.png) [@markd833](https://forum.arduino.cc/u/markd833)\
**Post date:** [October 13, 2024, 5:22pm UTC](https://forum.arduino.cc/t/constant-string-in-the-middle-of-a-program-changed/1310910/4 "2024-10-13T17:22:29Z")

</div>

> [@ArchHasher](#):
>
> Serial.println("Touch the reader");

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.

---

<div class="post-metadata">

**Author:** ![ArchHasher](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/archhasher/32/315701_2.png) [@ArchHasher](https://forum.arduino.cc/u/ArchHasher)\
**Post date:** [October 13, 2024, 5:24pm UTC](https://forum.arduino.cc/t/constant-string-in-the-middle-of-a-program-changed/1310910/5 "2024-10-13T17:24:21Z")

</div>

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:

```arduino
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.

---

<div class="post-metadata">

**Author:** ![ArchHasher](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/archhasher/32/315701_2.png) [@ArchHasher](https://forum.arduino.cc/u/ArchHasher)\
**Post date:** [October 13, 2024, 5:24pm UTC](https://forum.arduino.cc/t/constant-string-in-the-middle-of-a-program-changed/1310910/6 "2024-10-13T17:24:58Z")

</div>

Added 100ms delay - same issue ☹

---

<div class="post-metadata">

**Author:** ![david\_2018](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/david_2018/32/1013044_2.png) [@david\_2018](https://forum.arduino.cc/u/david_2018)\
**Post date:** [October 13, 2024, 5:25pm UTC](https://forum.arduino.cc/t/constant-string-in-the-middle-of-a-program-changed/1310910/7 "2024-10-13T17:25:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ArchHasher](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/archhasher/32/315701_2.png) [@ArchHasher](https://forum.arduino.cc/u/ArchHasher)\
**Post date:** [October 13, 2024, 5:27pm UTC](https://forum.arduino.cc/t/constant-string-in-the-middle-of-a-program-changed/1310910/8 "2024-10-13T17:27:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ArchHasher](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/archhasher/32/315701_2.png) [@ArchHasher](https://forum.arduino.cc/u/ArchHasher)\
**Post date:** [October 13, 2024, 5:29pm UTC](https://forum.arduino.cc/t/constant-string-in-the-middle-of-a-program-changed/1310910/9 "2024-10-13T17:29:02Z")

</div>

Thank you, added the code.

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [October 13, 2024, 5:29pm UTC](https://forum.arduino.cc/t/constant-string-in-the-middle-of-a-program-changed/1310910/10 "2024-10-13T17:29:37Z")

</div>

> [@ArchHasher](#):
>
> I can post the whole program

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

```arduino
void setup() {
 // empty
}

void loop() {
  // empty
}

```

---

<div class="post-metadata">

**Author:** ![anon94801460](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon94801460](https://forum.arduino.cc/u/anon94801460)\
**Post date:** [October 13, 2024, 5:30pm UTC](https://forum.arduino.cc/t/constant-string-in-the-middle-of-a-program-changed/1310910/11 "2024-10-13T17:30:07Z")

</div>

> [@ArchHasher](#):
>
> I am not sure any external hardware ... can impact the _constant_ string.

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

---

<div class="post-metadata">

**Author:** ![ArchHasher](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/archhasher/32/315701_2.png) [@ArchHasher](https://forum.arduino.cc/u/ArchHasher)\
**Post date:** [October 13, 2024, 5:31pm UTC](https://forum.arduino.cc/t/constant-string-in-the-middle-of-a-program-changed/1310910/12 "2024-10-13T17:31:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ArchHasher](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/archhasher/32/315701_2.png) [@ArchHasher](https://forum.arduino.cc/u/ArchHasher)\
**Post date:** [October 13, 2024, 5:32pm UTC](https://forum.arduino.cc/t/constant-string-in-the-middle-of-a-program-changed/1310910/13 "2024-10-13T17:32:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anon94801460](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon94801460](https://forum.arduino.cc/u/anon94801460)\
**Post date:** [October 13, 2024, 5:33pm UTC](https://forum.arduino.cc/t/constant-string-in-the-middle-of-a-program-changed/1310910/14 "2024-10-13T17:33:23Z")

</div>

> [@ArchHasher](#):
>
> Program is too big for that.

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

---

<div class="post-metadata">

**Author:** ![anon94801460](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon94801460](https://forum.arduino.cc/u/anon94801460)\
**Post date:** [October 13, 2024, 5:34pm UTC](https://forum.arduino.cc/t/constant-string-in-the-middle-of-a-program-changed/1310910/15 "2024-10-13T17:34:19Z")

</div>

> [@ArchHasher](#):
>
> if I touch it, glitch goes somewhere else

Unstable wiring.

---

<div class="post-metadata">

**Author:** ![ArchHasher](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/archhasher/32/315701_2.png) [@ArchHasher](https://forum.arduino.cc/u/ArchHasher)\
**Post date:** [October 13, 2024, 5:35pm UTC](https://forum.arduino.cc/t/constant-string-in-the-middle-of-a-program-changed/1310910/16 "2024-10-13T17:35:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anon94801460](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon94801460](https://forum.arduino.cc/u/anon94801460)\
**Post date:** [October 13, 2024, 5:36pm UTC](https://forum.arduino.cc/t/constant-string-in-the-middle-of-a-program-changed/1310910/17 "2024-10-13T17:36:19Z")

</div>

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

Goodbye.

---

<div class="post-metadata">

**Author:** ![ArchHasher](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/archhasher/32/315701_2.png) [@ArchHasher](https://forum.arduino.cc/u/ArchHasher)\
**Post date:** [October 13, 2024, 5:39pm UTC](https://forum.arduino.cc/t/constant-string-in-the-middle-of-a-program-changed/1310910/18 "2024-10-13T17:39:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [October 13, 2024, 5:40pm UTC](https://forum.arduino.cc/t/constant-string-in-the-middle-of-a-program-changed/1310910/19 "2024-10-13T17:40:15Z")

</div>

> [@ArchHasher](#):
>
> Cannot be.

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.

---

<div class="post-metadata">

**Author:** ![ArchHasher](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/archhasher/32/315701_2.png) [@ArchHasher](https://forum.arduino.cc/u/ArchHasher)\
**Post date:** [October 13, 2024, 5:49pm UTC](https://forum.arduino.cc/t/constant-string-in-the-middle-of-a-program-changed/1310910/20 "2024-10-13T17:49:49Z")

</div>

Added code blocks to the original question

[Next page](https://forum.arduino.cc/t/constant-string-in-the-middle-of-a-program-changed/1310910.md?page=2)
