Arduino Nano only printing out first 2 letters of String

My Arduino Nano Board only prints out first two letters of String.
My Code:

#include <ArduinoSTL.h>
#include <map>
#include <vector>
#include <utility>
#include <initializer_list>
#include <RTClib.h>
#include <Wire.h>
#include <Adafruit_NeoPixel.h>

RTC_DS1307 rtc;
Adafruit_NeoPixel strip(114, 6, NEO_GRB + NEO_KHZ800);

std::vector<int> make_vector(const std::initializer_list<int> &init_list)
{
  std::vector<int> *vec = new std::vector<int>;
  for (int *i = init_list.begin(); i != init_list.end(); i++)
  {
    vec->push_back(*i);
  }
  return *vec;
}

std::map<uint8_t, std::vector<int>> minutes, hours;
std::vector<int> single_mins, es_ist, uhr, startup_leds;

void setup_vars() {
  minutes = {
    std::make_pair(5, make_vector({1, 2, 3, 4, 42, 43, 44, 45})),
    std::make_pair(10, make_vector({13, 14, 15, 16, 42, 43, 44, 45})),
    std::make_pair(15, make_vector({24, 25, 26, 27, 28, 29, 30, 42, 43, 44, 45})),
    std::make_pair(20, make_vector({17, 18, 19, 20, 21, 22, 23, 42, 43, 44, 45})),
    std::make_pair(25, make_vector({1, 2, 3, 4, 35, 36, 37, 53, 54, 55, 56})),
    std::make_pair(30, make_vector({53, 54, 55, 56})),
    std::make_pair(35, make_vector({1, 2, 3, 4, 42, 43, 44, 45, 53, 54, 55, 56})),
    std::make_pair(40, make_vector({17, 18, 19, 20, 21, 22, 23, 35, 36, 37})),
    std::make_pair(45, make_vector({34, 33, 32, 31, 24, 25, 26, 27, 28, 29, 30})),
    std::make_pair(50, make_vector({13, 14, 15, 16, 35, 36, 37})),
    std::make_pair(55, make_vector({1, 2, 3, 4, 35, 36, 37}))};

    hours = {
    std::make_pair(1, make_vector({57, 58, 59, 60})),
    std::make_pair(2, make_vector({64, 65, 66, 67})),
    std::make_pair(3, make_vector({75, 76, 77, 78})),
    std::make_pair(4, make_vector({68, 69, 70, 71})),
    std::make_pair(5, make_vector({46, 47, 48, 49})),
    std::make_pair(6, make_vector({79, 80, 81, 82, 83})),
    std::make_pair(7, make_vector({95, 96, 97, 98, 99, 100})),
    std::make_pair(8, make_vector({86, 87, 88, 89})),
    std::make_pair(9, make_vector({105, 106, 107, 108})),
    std::make_pair(10, make_vector({102, 103, 104, 105})),
    std::make_pair(11, make_vector({49, 50, 51})),
    std::make_pair(12, make_vector({90, 91, 92, 93, 94}))};

    single_mins = make_vector({12, 0, 113, 101});

    es_ist = make_vector({11, 10, 8, 7, 6});

    uhr = make_vector({110, 111, 112});
    
    startup_leds = make_vector({87, 50, 36, 81, 109, 8, 2, 62});
}

String time_to_string(DateTime time) {
  return String((char *)time.hour()) + ":" + String((char *)time.minute()) + ":" + String((char *)time.second()) + " " + String((char *)time.dayOfTheWeek()) + " " + String((char *)time.year());
}

void setup() {
  Serial.begin(9600);

  for (int i = 10; i > 0; i--) {
    Serial.println(i);
    delay(500);
  }
  
  Serial.println("This is a test");

  setup_vars();

  if (!rtc.begin())
  {
    Serial.println("Couldn't find RTC");
    while (1)
      ;
  }
  if (!rtc.isrunning())
  {
    Serial.println("RTC is NOT running!");
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }

  Serial.println("test");
  Serial.println(time_to_string(rtc.now()));
}

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

}

Anyone knows what the problem is?

char text[] = "Das ist ein Test";

Didn't change anything. Saw that my code was wrong version. Updated version above. Didn't change anything either.

Start a separate sketch. Just make the string and print it. See what happens. Post results.

Prints out the full String.

Did you modify the code in the original post after I replied to it?

After your first reply.

That's a faux pas. It now means that my reply makes no sense, and this post can' help others in the future. Always post updated code in new replies.

If the sketch without all the other stuff works as expected, then the problem lies in the other stuff. Add it in one piece at a time until you figure out what causes the issue. It will be much easier to handle then.

What happens if you comment out setup_vars(); in setup()? My guess is that you are using more dynamic memory than is available.. All your vectors and pairs use "int" as data type whereas all values fit into a "char" or "uint8_t" and that would use half the memory.

EDIT: Oh, and the usage of "String" in time_to_string is also a bummer..

If I comment this line it prints: "This is a test" and after that "test" and ":aaaaa:"

Just that happens...
How would I be able to fix this?

This is absolutely a bug:

return String((char *)time.hour()) + ":" + String((char *)time.minute()) + ":" + String((char *)time.second()) + " " + String((char *)time.dayOfTheWeek()) + " " + String((char *)time.year());

You are casting numeric values to char pointers, that is absolutely going to crap out on you..

Ok yeah this can be fixed easily. But how am I able to use less space in setup_vars()?

Do not use a 16bit integer for small numbers, use an 8bit instead..

std::vector<uint8_t> make_vector(const std::initializer_list<uint8_t> &init_list)
...
std::map<uint8_t, std::vector<uint8_t>> minutes, hours;
std::vector<uint8_t> single_mins, es_ist, uhr, startup_leds;
...


After that the output looks like this...

⸮10
9
8
7
6
5
4
3
2
1
T⸮ZLj
9
8
7
6
5
4
3
2
1
Thi10
9
8
7
6
5
4
3
2
1
Th⸮

Not quite right

My glasses aren't either cus I cannot se your updated code..

Ah sorry forgot to add it.

#include <ArduinoSTL.h>
#include <map>
#include <vector>
#include <utility>
#include <initializer_list>
#include <RTClib.h>
#include <Wire.h>
#include <Adafruit_NeoPixel.h>

RTC_DS1307 rtc;
Adafruit_NeoPixel strip(114, 6, NEO_GRB + NEO_KHZ800);

const char date_format[] = "hh:mm:ss";

std::vector<uint8_t> make_vector(const std::initializer_list<uint8_t> &init_list)
{
  std::vector<uint8_t> *vec = new std::vector<uint8_t>;
  for (uint8_t *i = init_list.begin(); i != init_list.end(); i++)
  {
    vec->push_back(*i);
  }
  return *vec;
}

std::map<uint8_t, std::vector<uint8_t>> minutes, hours;
std::vector<uint8_t> single_mins, es_ist, uhr, startup_leds;

void setup_vars() {
  minutes = {
    std::make_pair(5, make_vector({1, 2, 3, 4, 42, 43, 44, 45})),
    std::make_pair(10, make_vector({13, 14, 15, 16, 42, 43, 44, 45})),
    std::make_pair(15, make_vector({24, 25, 26, 27, 28, 29, 30, 42, 43, 44, 45})),
    std::make_pair(20, make_vector({17, 18, 19, 20, 21, 22, 23, 42, 43, 44, 45})),
    std::make_pair(25, make_vector({1, 2, 3, 4, 35, 36, 37, 53, 54, 55, 56})),
    std::make_pair(30, make_vector({53, 54, 55, 56})),
    std::make_pair(35, make_vector({1, 2, 3, 4, 42, 43, 44, 45, 53, 54, 55, 56})),
    std::make_pair(40, make_vector({17, 18, 19, 20, 21, 22, 23, 35, 36, 37})),
    std::make_pair(45, make_vector({34, 33, 32, 31, 24, 25, 26, 27, 28, 29, 30})),
    std::make_pair(50, make_vector({13, 14, 15, 16, 35, 36, 37})),
    std::make_pair(55, make_vector({1, 2, 3, 4, 35, 36, 37}))};

    hours = {
    std::make_pair(1, make_vector({57, 58, 59, 60})),
    std::make_pair(2, make_vector({64, 65, 66, 67})),
    std::make_pair(3, make_vector({75, 76, 77, 78})),
    std::make_pair(4, make_vector({68, 69, 70, 71})),
    std::make_pair(5, make_vector({46, 47, 48, 49})),
    std::make_pair(6, make_vector({79, 80, 81, 82, 83})),
    std::make_pair(7, make_vector({95, 96, 97, 98, 99, 100})),
    std::make_pair(8, make_vector({86, 87, 88, 89})),
    std::make_pair(9, make_vector({105, 106, 107, 108})),
    std::make_pair(10, make_vector({102, 103, 104, 105})),
    std::make_pair(11, make_vector({49, 50, 51})),
    std::make_pair(12, make_vector({90, 91, 92, 93, 94}))};

    single_mins = make_vector({12, 0, 113, 101});

    es_ist = make_vector({11, 10, 8, 7, 6});

    uhr = make_vector({110, 111, 112});
    
    startup_leds = make_vector({87, 50, 36, 81, 109, 8, 2, 62});
}

void setup() {
  Serial.begin(9600);

  for (int i = 10; i > 0; i--) {
    Serial.println(i);
    delay(500);
  }
  
  Serial.println("This is a test");

  setup_vars();

  if (!rtc.begin())
  {
    Serial.println("Couldn't find RTC");
    while (1)
      ;
  }
  if (!rtc.isrunning())
  {
    Serial.println("RTC is NOT running!");
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }

  Serial.println("test");
  Serial.println(rtc.now().toString(date_format));
}

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

}

Casting bug got fixed by using a given method I didn't notice.

The output you posted in #15 did not come from the posted code, did it?

Something different is that you create a dynamically allocated vector in make_vector() and then you return a static reference to it:

std::vector<uint8_t> make_vector(const std::initializer_list<uint8_t> &init_list)
{
  std::vector<uint8_t> *vec = new std::vector<uint8_t>; //Dynamic allocation
  for (uint8_t *i = init_list.begin(); i != init_list.end(); i++)
  {
    vec->push_back(*i);
  }
  return *vec; //Dereferenced pointer
}

You should return the pointer vec instead:

std::map<uint8_t, std::vector<uint8_t>*> minutes, hours;
...
std::vector<uint8_t>* make_vector(const std::initializer_list<uint8_t> &init_list)
{
  ..
  return vec;
}

EDIT: If I where you I would not use map and vector at all, simple arrays would do just fine..

The thing is that I want to use the time I'm getting from the RTC to display different pixels on a matrix which is easier code if I use maps.

Maps and vectors pull in a lot of std code, if it works for you that's fine. But it is not really simpler than declaring static arrays to handle it:

struct PIXEL_LIST
{
	uint8_t ident; //Minute or hour
	uint8_t size; //Number of indicies in pixels[]
	uint8_t pixels[]; //Array of pixel indicies
};

//PIXEL_LIST - Minutes
const PIXEL_LIST m5 = {5, 8, {1, 2, 3, 4, 42, 43, 44, 45}};
const PIXEL_LIST m10 = {10, 8, {13, 14, 15, 16, 42, 43, 44, 45}};
const PIXEL_LIST m15 = {15, 11, {24, 25, 26, 27, 28, 29, 30, 42, 43, 44, 45}};

//Minutes array for easy iteration
const uint8_t MINUTES_SIZE = 3;
const PIXEL_LIST* MINUTES[MINUTES_SIZE] = { &m5, &m10, &m15 };

//PIXEL_LIST - Hours
const PIXEL_LIST h1 = {1, 4, {57, 58, 59, 60}};
const PIXEL_LIST h2 = {2, 4, {64, 65, 66, 67}};
const PIXEL_LIST h3 = {3, 4, {75, 76, 77, 78}};

//Hours array for easy iteration
const uint8_t HOURS_SIZE = 3;
const PIXEL_LIST* HOURS[HOURS_SIZE] = { &h1, &h2, &h3 };


void dump_pixel_list(const char* name, const PIXEL_LIST **pl, uint8_t size)
{
	Serial.print(name);
	Serial.println(":");
	for (uint8_t i = 0; i < size; i++)
	{
		Serial.print("  ");
		Serial.print(pl[i]->ident);
		Serial.print(" :");
		for (uint8_t ii = 0; ii < pl[i]->size; ii++)
		{
			Serial.print(" ");
			Serial.print(pl[i]->pixels[ii]);
		}
		Serial.println();
	}
}

void setup()
{
	dump_pixel_list("Minutes", MINUTES, MINUTES_SIZE);
	dump_pixel_list("Hours", HOURS, HOURS_SIZE);
}

void loop()
{
}

By doing it like this, you will know during compile time how much memory the arrays consume.