'Problem with BME280 and char arrays on Arduino

I am trying to fill a char array with 1800 characters from digital pin 7 (data from a rain gauge) before reading the air pressure from a BME280 using Ardino UNO. The results are printed with Serial.println over USB.

#include <Adafruit_BME280.h>
#define DATA 7

Adafruit_BME280 bme;

void setup() 
{
    Serial.begin(9600);
    bme.begin(0x76);
    pinMode(DATA, INPUT);  
}

void loop() 
{ 
   int rmax = 1800;      //1460
   char r[rmax+1];       // changed from r[rmax]
   int i;
   for (i = 0; i < rmax; i++)
   {
      if (digitalRead(DATA) == 1)
         r[i] = '1';
      else
         r[i] = '0';
   }
   r[rmax] = '\0';
   Serial.println(r);
   Serial.println(bme.readPressure());
   delay(1000);
}

If the size of the array is greater than 1460, the data is not read from BME280, and array is printed without lineshift. Can anybody tell me why, and what can be done to get succeeded if the size of the array is 1800?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source