arduino_mega2560_serial_issuce

hi all,
am new to arduino mega actually i need to receive a mega serial data. my aim is just receive 3072 byte data from pc continuously with out any delay between byte .i tried this but i cant get the correct data if i used a delay between every byte then i get correct value. am using 1 ms delay each byte actually this is long time that means the delay is very large. instead of 3072 byte i was used 1536 byte that time i get a correct data with out any delay so please kindly any one help me to solve this issue.

here i attach my code:

#include <Adafruit_GFX.h> // Core graphics library
#include <RGBmatrixPanel.h> // Hardware-specific library
#define OE 9
#define LAT 10
#define A A0
#define B A1
#define C A2
#define D A3 // Comment this line out if you’re using a 32x16
// CLK can be moved but must remain on PORTB(8, 9, 10, 11, 12, 13)
#define CLK 11 // MUST be on PORTB!
RGBmatrixPanel matrix(A, B, C, D, CLK, LAT, OE, false,64); // 32x32
// For 32x16 LED panels:
//RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false); // 32x16
int8_t cursorX = 0; // Cursor x position, initialize left
int8_t cursorY = 0; // Cursor y position, initialize top
int16_t oldColor = 0; // Keep track of color under cursor
int8_t red = 1; // Red paint value
int8_t blue = 1; // Blue paint value
int8_t green = 1; // Green paint value
uint8_t *ptrr;
// Enum shape drawing mode:
enum shapeMode {
NONE, // 0
LINE, // 1
CIRCLE, // 2
RECT // 3
};
int8_t activeDraw = NONE; // Keeps track of whether we’re drawing a shape
int16_t oldCenterColor; // For circle, keeps track of color under cursor
int8_t shapeX0; // x0 of line or box, center of circle
int8_t shapeY0; // y0 of line or box, center of circle
unsigned int integerValue=0;
#define EXIT_CHAR ‘`’
// Timing stuff:
#define BLINK_RATE 250 // blink rate in ms
void setup()
{
matrix.begin(); // Initialize the matrix.
blankEasel(); // Blank screen
loadBitmap();
Serial.begin(115200); // Start serial
}
void loop()
{

ptrr = matrix.backBuffer();

if (Serial.available())
{
int8_t c = Serial.read();
if(c ==1)
{
for(uint16_t i=0;i<3072;i++)
{

while(!Serial.available());
ptrr*= Serial.read();*

  • }*

  • }*
    }
    }
    void loadBitmap()
    {
    uint8_t *ptr = matrix.backBuffer(); // Get address of matrix data

  • oldColor = getPixelColor(cursorX, cursorY); *
    }
    void blankEasel()
    {

  • cursorX = 0;*

  • cursorY = 0;*

  • oldColor = 0;*

  • matrix.fillScreen(0); // Blank screen*
    }
    uint16_t getPixelColor(uint8_t x, uint8_t y)
    {
    uint8_t * ptr; // A movable pointer to read data from

  • uint16_t r=0, g=0, b=0; // We’ll store rgb values in these*

  • uint8_t nPlanes = 0; // 4 planes. This is static in the library*

  • uint8_t nRows = matrix.height()/2 ; // / 216 for 32 row, 8 for 16*
    uint8_t * buf = matrix.backBuffer();

  • // Data for upper half is stored in lower bits of each byte*

  • if (y < nRows)*

  • {*
    _ ptr = &buf[y * matrix.width() * (nPlanes - 1) + x];_

  • // get data from plane 0:*

  • if (ptr[64] & 0x01)*

  • r = 1;*

  • if (ptr[64] & 0x02)*

  • g = 1;*

  • if (ptr[32] & 0x01)*

  • b = 1;*

  • // get data from other planes:*

  • for (uint8_t i=2; i < (1<<nPlanes); i <<= 1)*

  • {*
    _ if (*ptr & 0x04)_

  • r |= i;*
    _ if (*ptr & 0x08)_

  • g |= i;*
    _ if (*ptr & 0x10)_

  • b |= i;*

  • ptr += matrix.width();*

  • }*

  • }*

  • else*

  • {*
    _ ptr = &buf[(y - nRows) * matrix.width() * (nPlanes - 1) + x];_

  • // get data from plane 0*

  • if (ptr[32] & 0x02)*

  • r = 1;*
    _ if (*ptr & 0x01)_

  • g = 1;*
    _ if (*ptr & 0x02)_

  • b = 1;*

  • for (uint8_t i=2; i < (1<<nPlanes); i <<= 1)*

  • {*
    _ if (*ptr & 0x20)_

  • r |= i;*
    _ if (*ptr & 0x40)_

  • g |= i;*
    _ if (*ptr & 0x80)_

  • b |= i;*

  • ptr += matrix.width();*

  • }*

  • }*

  • return (r << 12) | (g << 7) | (b << 1);*
    }

Please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum Your code is too long for me to study quickly without copying to a text editor.

You need a more robust way for receiving data. Have a look at the examples in Serial Input Basics

…R

sorry sir i will correct but please kindly give any suggestion for this issue

here i tell my exact issue
if (Serial.available())
{
int8_t c = Serial.read();
if(c ==1)
** {**
** for(uint16_t i=0;i<1536;i++)**
** {**

** while(!Serial.available());**
__ ptrr*= Serial.read();__
__
}__
__
} [/b]__
if i do this no issue instead of 1536 i changed to 3072 that time am not getting correct data.i will try with 1ms delay for every byte in from sender side(pc) then i get a data but this delay is very huge because for 3kb its take 3 seconds.but in a 1536 byte am not using any delay that time no issue plese any one give some suggestion.
video_and_image_checked_program.ino (3.23 KB)*

Send/receive your data in 128 byte packets.

Have you studied the code in the link I gave you?

Why are you still posting code (in Reply #2) without using the code button </> so your code looks like this

…R