Code error on camera JPEG ttl sketch

Hi

I bought this camera:

http://www.tinyosshop.com/index.php?route=product/product&filter_name=camera&filter_description=true&filter_sub_category=true&product_id=586

Its a generic jpeg ttl serial camera. The linked sketch is this:

http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Sensors/LightImaging/LinkSprite_cam_IR.zip

Im trying to use the code but I get a BYTE not declared in this scope error message. In the code, BYTE is used quite frequently like so:

void SendTakePhotoCmd()
{
      mySerial.print(0x56, BYTE);
      mySerial.print(0x00, BYTE);
      mySerial.print(0x36, BYTE);
      mySerial.print(0x01, BYTE);
      mySerial.print(0x00, BYTE);  
}

Basically every one of those BYTE instances throw the same error.

BYTE is supposed to be a constant, isnt it? I definitely dont see a definition for it anywhere. What can I do?

In the code, BYTE is used quite frequently like so:

That used to be valid, but no longer is. Chang print() to write(), and get rid of the , BYTE from each statement.

Did you consult the documentation for the print method?

Thanks so much! I did so. Then it asked me to use the new SoftwareSerial library so I had to change NewSoftSerial to SoftwareSerial.

Now Im getting this error:

LinkSprite_cam_IR.ino: In function 'void SendResetCmd()':
LinkSprite_cam_IR.ino:71:26: error: call of overloaded 'write(int)' is ambiguous
LinkSprite_cam_IR.ino:71:26: note: candidates are:
In file included from LinkSprite_cam_IR.ino:3:0:
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SoftwareSerial/SoftwareSerial.h:100:18: note: virtual size_t SoftwareSerial::write(uint8_t)
virtual size_t write(uint8_t byte);

Im not sure I understand that at all. Could you help me on that as well?

I have this JPEG Camera Serial IR and I cant get data from it. The place where I bought it has this

Here is the wiring suggested & followed:

Here is the actual wiring:

But the results in the Serial Monitor are just:

00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00
00 00 00 00 00
00 00 00 00 00 00
00 00 00 00
00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00

How can I debug why the camera is getting 0 data?

Here is the sketch:

//*******************************************************
//              www.linksprite.com
// Note:
// 1. SD must be formated to FAT16
// 2. As the buffer of softserial has 64 bytes,
//    so the code read 32 bytes each time
// 3. Please add the libaray to the lib path
//
// * SD card attached to SPI bus as follows:
// * MOSI - pin 11
// * MISO - pin 12
// * CLK - pin 13
// * CS - pin 4
//*******************************************************
#include <SoftwareSerial.h>
#include <SPI.h>
#include <SD.h>
 
SoftwareSerial mySerial(5,6);          // Set Arduino pin 4 and 5 as softserial
 
byte ZERO = 0x00;
byte incomingbyte;
long int j=0,k=0,count=0,i=0x0000;
uint8_t MH,ML;
boolean EndFlag=0;
File  myFile;
 
void SendResetCmd()
{
    mySerial.write(0x56);
    mySerial.write(ZERO);
    mySerial.write(0x26);
    mySerial.write(ZERO);
}
 
/*************************************/
/* Set ImageSize :
/* <1> 0x22 : 160*120
/* <2> 0x11 : 320*240
/* <3> 0x00 : 640*480
/* <4> 0x1D : 800*600
/* <5> 0x1C : 1024*768
/* <6> 0x1B : 1280*960
/* <7> 0x21 : 1600*1200
/************************************/
void SetImageSizeCmd(byte Size)
{
    mySerial.write(0x56);
    mySerial.write(ZERO);  
    mySerial.write(0x54);
    mySerial.write(0x01);
    mySerial.write(Size);
}
 
/*************************************/
/* Set BaudRate :
/* <1>¡¡0xAE  :   9600
/* <2>¡¡0x2A  :   38400
/* <3>¡¡0x1C  :   57600
/* <4>¡¡0x0D  :   115200
/* <5>¡¡0xAE  :   128000
/* <6>¡¡0x56  :   256000
/*************************************/
void SetBaudRateCmd(byte baudrate)
{
    mySerial.write(0x56);
    mySerial.write(ZERO);
    mySerial.write(0x24);
    mySerial.write(0x03);
    mySerial.write(0x01);
    mySerial.write(baudrate);
}
 
void SendTakePhotoCmd()
{
    mySerial.write(0x56);
    mySerial.write(ZERO);
    mySerial.write(0x36);
    mySerial.write(0x01);
    mySerial.write(ZERO); 
}
 
void SendReadDataCmd()
{
    MH=i/0x100;
    ML=i%0x100;
    mySerial.write(0x56);
    mySerial.write(ZERO);
    mySerial.write(0x32);
    mySerial.write(0x0c);
    mySerial.write(ZERO);
    mySerial.write(0x0a);
    mySerial.write(ZERO);
    mySerial.write(ZERO);
    mySerial.write(MH);
    mySerial.write(ML);
    mySerial.write(ZERO);
    mySerial.write(ZERO);
    mySerial.write(ZERO);
    mySerial.write(0x20);
    mySerial.write(ZERO);
    mySerial.write(0x0a);
    i+=0x20;
}
 
void StopTakePhotoCmd()
{
    mySerial.write(0x56);
    mySerial.write(ZERO);
    mySerial.write(0x36);
    mySerial.write(0x01);
    mySerial.write(0x03);
}
 
void setup()
{
    Serial.begin(38400);
    while (!Serial)
    {
        ; // wait for serial port to connect. Needed for Leonardo only
    }
 
    Serial.print("Initializing SD card...");
    // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
    // Note that even if it's not used as the CS pin, the hardware SS pin
    // (10 on most Arduino boards, 53 on the Mega) must be left as an output
    // or the SD library functions will not work.
    pinMode(10, OUTPUT);
    if (!SD.begin(4))
    {
        Serial.println("initialization failed!");
        return;
    }
    Serial.println("initialization done.");
    Serial.println("please waiting ....");
 
    mySerial.begin(115200);
    delay(100);
    SendResetCmd();
    delay(2000);
    SetBaudRateCmd(0x2A);
    delay(500);
    mySerial.begin(38400);
    delay(100);
}
 
void loop()
{
    byte a[32];
    int ii;
 
    SendResetCmd();
    delay(2000);                            //Wait 2-3 second to send take picture command
    SendTakePhotoCmd();
    delay(1000);
    while(mySerial.available()>0)
    {
        incomingbyte=mySerial.read();
    }
 
    myFile = SD.open("pic.jpg", FILE_WRITE); //The file name should not be too long
 
    while(!EndFlag)
    {
        j=0;
        k=0;
        count=0;
        //mySerial.flush();
        SendReadDataCmd();
        delay(20);
        while(mySerial.available()>0)
        {
            incomingbyte=mySerial.read();
            k++;
            delay(1); //250 for regular
            if((k>5)&&(j<32)&&(!EndFlag))
            {
                a[j]=incomingbyte;
                if((a[j-1]==0xFF)&&(a[j]==0xD9))     //tell if the picture is finished
                {
                    EndFlag=1;
                }
                j++;
                count++;
            }
        }
 
        for(j=0;j<count;j++)
        {
            if(a[j]<0x10)  Serial.print("0");
            Serial.print(a[j],HEX);           // observe the image through serial port
            Serial.print(" ");
        }
 
        for(ii=0; ii<count; ii++)
        myFile.write(a[ii]);
        Serial.println();
    }
 
    myFile.close();
    Serial.print("Finished writing data to file");
    while(1);
}

Im not sure I understand that at all. Could you help me on that as well?

The write() takes either a byte or an array of bytes and a count.

Literals are interpreted as ints, in the absence of directives (or evidence) to the contrary. Some values can be interpreted more than one way, so the compiler needs help picking the right method.

You changed

      mySerial.print(0x00, BYTE);

to

      mySerial.write(0x00);

but that is one of the values that can be interpreted multiple ways. You need to help the compiler out:

      mySerial.write((byte)0x00);

Thanks, I got it working.

It compiles now. Unfortunately there seems to be an issue because all I get is blank data in the serial monitor. I mean the Serial Monitor just scrolls up indefinitely but with nothing on screen.

And of course the resulting file on the SD card is 0 bytes.

Here is the full sketch:

/* Linksprite */
//SPITS OUT WHITE SCREEN SERIAL MONITOR SCROLLING DOWN BUT NO DATA SAVED TO SD


#include <SoftwareSerial.h>

byte incomingbyte;
SoftwareSerial mySerial(4,5);                     //Configure pin 4 and 5 as soft serial port
int a=0x0000,j=0,k=0,count=0;                    //Read Starting address       
uint8_t MH,ML;
boolean EndFlag=0;
                               
void SendResetCmd();
void SendTakePhotoCmd();
void SendReadDataCmd();
void StopTakePhotoCmd();

void setup(){ 
  Serial.begin(19200);
  mySerial.begin(38400);
}

void loop() {
     SendResetCmd();
     delay(4000);                               //After reset, wait 2-3 second to send take picture command
      
      SendTakePhotoCmd();

     while(mySerial.available()>0)
      {
        incomingbyte=mySerial.read();

      }   
      byte a[32];
      
      while(!EndFlag)
      {  
         j=0;
         k=0;
         count=0;
         SendReadDataCmd();

         delay(25);
          while(mySerial.available()>0)
          {
               incomingbyte=mySerial.read();
               k++;
               if((k>5)&&(j<32)&&(!EndFlag))
               {
               a[j]=incomingbyte;
               if((a[j-1]==0xFF)&&(a[j]==0xD9))      //Check if the picture is over
               EndFlag=1;                           
               j++;
	       count++;
               }
          }
         
          for(j=0;j<count;j++)
          {   if(a[j]<0x10)
              Serial.print("0");
              Serial.print(a[j],HEX);
              Serial.print(" ");
          }                                       //Send jpeg picture over the serial port
          Serial.println();
      }      
     while(1);
}

//Send Reset command
void SendResetCmd()
{
      mySerial.write((byte)0x56);
      mySerial.write((byte)0x00);
      mySerial.write((byte)0x26);
      mySerial.write((byte)0x00);
}

//Send take picture command
void SendTakePhotoCmd()
{
      mySerial.write((byte)0x56);
      mySerial.write((byte)0x00);
      mySerial.write((byte)0x36);
      mySerial.write((byte)0x01);
      mySerial.write((byte)0x00);  
}

//Read data
void SendReadDataCmd()
{
      MH=a/0x100;
      ML=a%0x100;
      mySerial.write((byte)0x56);
      mySerial.write((byte)0x00);
      mySerial.write((byte)0x32);
      mySerial.write((byte)0x0c);
      mySerial.write((byte)0x00); 
      mySerial.write((byte)0x0a);
      mySerial.write((byte)0x00);
      mySerial.write((byte)0x00);
      mySerial.write(MH);
      mySerial.write(ML);   
      mySerial.write((byte)0x00);
      mySerial.write((byte)0x00);
      mySerial.write((byte)0x00);
      mySerial.write((byte)0x20);
      mySerial.write((byte)0x00);  
      mySerial.write((byte)0x0a);
      a+=0x20;                            //address increases 32£¬set according to buffer size
}

void StopTakePhotoCmd(){
      mySerial.write((byte)0x56);
      mySerial.write((byte)0x00);
      mySerial.write((byte)0x36);
      mySerial.write((byte)0x01);
      mySerial.write((byte)0x03);        
}
     delay(4000);                               //After reset, wait 2-3 second to send take picture command

That is NOT what that statement does. Loose the stupid comment or make it right.

     while(mySerial.available()>0)
      {
        incomingbyte=mySerial.read();

      }

Take a photo, then throw away random amounts of unread data. Sounds like a great idea. I wonder why more people don't do that.

         SendReadDataCmd();

         delay(25);
          while(mySerial.available()>0)
          {

25 milliseconds to get a response? Is that even in the same universe as reasonable?

          while(mySerial.available()>0)
          {
               incomingbyte=mySerial.read();
               k++;
               if((k>5)&&(j<32)&&(!EndFlag))
               {
               a[j]=incomingbyte;
               if((a[j-1]==0xFF)&&(a[j]==0xD9))      //Check if the picture is over
               EndFlag=1;                           
               j++;
	       count++;
               }
          }

I don't guess it matters whether there is room in the array.

Ok I changed the delay to 5 seconds

Its a hardware manufacturer's tutorial so i guess they dont bother with little things like checking for array space and as for throwing the data away, I have the data written to an SD card in my other sketch, but in both cases the data is simply not there. I have logged the incomingbyte like so:

            Serial.print(incomingbyte);

and I just get 0 for data.

Its a hardware manufacturer's tutorial so i guess they dont bother with little things like checking for array space

You can write to the manufacturer, and tell them that there code is crap, and wait for them to fix it, or fix it yourself.

and as for throwing the data away, I have the data written to an SD card in my other sketch

How can you write the random amounts of unread data to an SD card in another sketch?

We need to see the sketch where you "prove" that you are reading nothing but 0 from the camera, along with a schematic showing how the camera is connected, and a link to the camera.

Ok, as far as I know, this reads like so:

byte a[32]; // Create an array of 32 elements named a
int ii; // Create a variable named ii of int type

SendResetCmd(); // Send reset command to module
delay(2000); //Wait 2 second to send take picture command
SendTakePhotoCmd(); // Send take a picture command
delay(1000); // Wait 1 second after taking picture command
while(mySerial.available()>0) // while mySerial is available...
{
incomingbyte=mySerial.read(); // read serial incoming data & store it in "incomingbyte" which is a byte type
}

Can you point me a little closer?

Ok the wiring diagram is here:

Imgur

and the actual wiring is this one (it includes a tft shield for microSD storage:

Imgur

The other sketch, as I mentioned, also ends up writing 0 bytes to a file. I never said that I could prove it was getting written anywhere. You're getting all "politician" on me! :-). That sketch is here, but its the same one except that it contains a snippet for writing bytes into a file.

When I said "and as for throwing the data away, I have the data written to an SD card in my other sketch" what I meant was that as opposed to this original sketch, I wasnt just reading the data and throwing it away. I was reading it and then storing it in a file.

Here is that sketch. It is also a sketch from the manufacturer btw:

//*******************************************************
//              www.linksprite.com
// Note:
// 1. SD must be formated to FAT16
// 2. As the buffer of softserial has 64 bytes,
//    so the code read 32 bytes each time
// 3. Please add the libaray to the lib path
//
// * SD card attached to SPI bus as follows:
// * MOSI - pin 11
// * MISO - pin 12
// * CLK - pin 13
// * CS - pin 4
//*******************************************************
#include <SoftwareSerial.h>
#include <SPI.h>
#include <SD.h>
 
SoftwareSerial mySerial(5,6);          // 5,6 softserial
 
byte ZERO = 0x00;
byte incomingbyte;
int j=0,k=0,count=0,i=0x0000;
uint8_t MH,ML;
boolean EndFlag=0;
File  myFile;
 
void SendResetCmd()
{
    mySerial.write(0x56);
    mySerial.write(ZERO);
    mySerial.write(0x26);
    mySerial.write(ZERO);
}
 
/*************************************/
/* Set ImageSize :
/* <1> 0x22 : 160*120
/* <2> 0x11 : 320*240
/* <3> 0x00 : 640*480
/* <4> 0x1D : 800*600
/* <5> 0x1C : 1024*768
/* <6> 0x1B : 1280*960
/* <7> 0x21 : 1600*1200
/************************************/
void SetImageSizeCmd(byte Size)
{
    mySerial.write(0x56);
    mySerial.write(ZERO);  
    mySerial.write(0x54);
    mySerial.write(0x01);
    mySerial.write(Size);
}
 
/*************************************/
/* Set BaudRate :
/* <1>¡¡0xAE  :   9600
/* <2>¡¡0x2A  :   38400
/* <3>¡¡0x1C  :   57600
/* <4>¡¡0x0D  :   115200
/* <5>¡¡0xAE  :   128000
/* <6>¡¡0x56  :   256000
/*************************************/
void SetBaudRateCmd(byte baudrate)
{
    mySerial.write(0x56);
    mySerial.write(ZERO);
    mySerial.write(0x24);
    mySerial.write(0x03);
    mySerial.write(0x01);
    mySerial.write(baudrate);
}
 
void SendTakePhotoCmd()
{
    mySerial.write(0x56);
    mySerial.write(ZERO);
    mySerial.write(0x36);
    mySerial.write(0x01);
    mySerial.write(ZERO); 
}
 
void SendReadDataCmd()
{
    MH=i/0x100;
    ML=i%0x100;
    mySerial.write(0x56);
    mySerial.write(ZERO);
    mySerial.write(0x32);
    mySerial.write(0x0c);
    mySerial.write(ZERO);
    mySerial.write(0x0a);
    mySerial.write(ZERO);
    mySerial.write(ZERO);
    mySerial.write(MH);
    mySerial.write(ML);
    mySerial.write(ZERO);
    mySerial.write(ZERO);
    mySerial.write(ZERO);
    mySerial.write(0x20);
    mySerial.write(ZERO);
    mySerial.write(0x0a);
    i+=0x20;
}
 
void StopTakePhotoCmd()
{
    mySerial.write(0x56);
    mySerial.write(ZERO);
    mySerial.write(0x36);
    mySerial.write(0x01);
    mySerial.write(0x03);
}
 
void setup()
{
    Serial.begin(38400);
    while (!Serial)
    {
        ; // wait for serial port to connect. Needed for Leonardo only
    }
 
    Serial.print("Initializing SD card...");
    // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
    // Note that even if it's not used as the CS pin, the hardware SS pin
    // (10 on most Arduino boards, 53 on the Mega) must be left as an output
    // or the SD library functions will not work.
    pinMode(10, OUTPUT);
    if (!SD.begin(4))
    {
        Serial.println("initialization failed!");
        return;
    }
    Serial.println("initialization done.");
    Serial.println("please wait for picture....");
 
    mySerial.begin(115200);
    delay(100);
    SendResetCmd();
    delay(2000);
    SetBaudRateCmd(0x2A);
    delay(500);
    mySerial.begin(38400);
    delay(100);
}
 
void loop()
{
    byte a[32];
    int ii;
 
    SendResetCmd();
    delay(2000);                            //Wait 2-3 second to send take picture command
    SendTakePhotoCmd();
    delay(1000);
    while(mySerial.available()>0)
    {
        incomingbyte=mySerial.read();
    }
 
    myFile = SD.open("pic.jpg", FILE_WRITE); //The file name should not be too long
 
    while(!EndFlag)
    {
        j=0;
        k=0;
        count=0;
        //mySerial.flush();
        SendReadDataCmd();
        delay(2000);
        while(mySerial.available()>0)
        {
            incomingbyte=mySerial.read();
            Serial.print("incoming...");
            Serial.print(incomingbyte);
            k++;
            delay(1); //250 for regular
            if((k>5)&&(j<32)&&(!EndFlag))
            {
                a[j]=incomingbyte;
                if((a[j-1]==0xFF)&&(a[j]==0xD9))     //tell if the picture is finished
                {
                    EndFlag=1;
                }
                j++;
                count++;
            }
        }
 
        for(j=0;j<count;j++)
        {
            if(a[j]<0x10)  Serial.print("0");
            Serial.print(a[j],HEX);           // observe the image through serial port
            Serial.print(" ");
        }
 
        for(ii=0; ii<count; ii++)
        myFile.write(a[ii]);
        Serial.println();
    }
 
    myFile.close();
    Serial.print("Finished writing data to file");
    while(1);
}
    SendTakePhotoCmd();
    delay(1000);
    while(mySerial.available()>0)
    {
        incomingbyte=mySerial.read();
    }

Tell the camera to take a picture. Wait some time. Throw away random amounts of unread data.

I can't figure out why you are doing that. If the camera told you to stuff it, why don't you care?

        SendReadDataCmd();
        delay(2000);

Do you have any idea how much serial data can be sent in 2 seconds, at 38400 bits per second? Nearly 7800 bytes. Are your pictures even that large?

            delay(1); //250 for regular

What does that mean?

You are already blocking because it takes longer to send "incoming..." and a multi-digit number at 115200 than it does to receive one byte.

More thumb twiddling is not needed.

Does the camera module/breakout board have any lights that indicate it is actually doing anything?

Ok please explain to me why you say this throws away the data?

while(mySerial.available()>0)
    {
        incomingbyte=mySerial.read();
    }

Isnt it storing it in incomingbyte?

==============

delay(2000);

Ok in 2 seconds at 38,400 bps, I get 38,400 x 2 = 76,800 bits / 8 = 9,600 bytes. I dont know about this stuff but I guess there is a header and terminal bunch of bits/bytes that are required for messaging which take up 9,600 - 7,800 = 1,800 bytes to get to the 7,800 you mentioned. But ok, so Im taking pictures at 160x120 pixels = 19,200 pixels. Each color pixel takes 24 bits, = 460,800 bits or 57,600 bytes or 57kb.

If I have 2 second delay that would be too short? So I should increase it to 9x that?

===============

What do you mean by:

"You are already blocking because it takes longer to send "incoming..." and a multi-digit number at 115200 than it does to receive one byte."

My addition of the log line incoming... should be removed? But I added that as a debug, the problem was already there. But yes, Ill remove it. I just wanted to see if I could visualize any byte numbers in the serial monitor to make sure "something" or "anything" was coming in.

===============

No the board doesnt have any leds except for the IR leds. But I was looking at the Tx/Rx on the UNO and I saw only the Tx blinking, not the Rx one. So I dont think its receiving anything from the Camera module.

Ok please explain to me why you say this throws away the data?

How many times do you read? How many bytes end up in incomingbyte? If the answers are not the same, what happens to the data that is not in incomingbyte?

Ok in 2 seconds at 38,400 bps, I get 38,400 x 2 = 76,800 bits / 8 = 9,600 bytes.

There are start and stop bits, so sending a byte requires 10 intervals, not 8.

If I have 2 second delay that would be too short? So I should increase it to 9x that?

The delay is not too short. It is 2 seconds too long. Start reading serial data as soon as it arrives.

What do you mean by:

"You are already blocking because it takes longer to send "incoming..." and a multi-digit number at 115200 than it does to receive one byte."

Surely you don't think that sending serial data takes no time. Serial data is written to a buffer, which is very fast, UNTIL the buffer gets full. Then, print() blocks until data has been shifted out. THAT takes time.

My addition of the log line incoming... should be removed?

For debugging purposes, it is fine. In the end, it has to go.

But I was looking at the Tx/Rx on the UNO and I saw only the Tx blinking, not the Rx one. So I dont think its receiving anything from the Camera module.

The TX and RX LEDs are involved when Serial is sending/receiving data, not the SoftwareSerial instance.

I understand everyone comments on that. But later on, in the loop() method, the sketch does this:

while(!EndFlag)
    {
        j=0;
        k=0;
        count=0;
        //mySerial.flush();
        SendReadDataCmd();
        delay(20);
        while(mySerial.available()>0)
        {
            incomingbyte=mySerial.read();
            k++;
            delay(1); //250 for regular
            if((k>5)&&(j<32)&&(!EndFlag))
            {
                a[j]=incomingbyte;
                if((a[j-1]==0xFF)&&(a[j]==0xD9))     //tell if the picture is finished
                {
                    EndFlag=1;
                }
                j++;
                count++;
            }
        }
 
        for(j=0;j<count;j++)
        {
            if(a[j]<0x10)  Serial.print("0");
            Serial.print(a[j],HEX);           // observe the image through serial port
            Serial.print(" ");
        }
 
        for(ii=0; ii<count; ii++)
        myFile.write(a[ii]);
        Serial.println();
    }

Where you can see incomingbyte is put into the a[j] and spat into the monitor and then written into the file.

Isnt it?

This is the linksprite sketch. If you see up top of the sketch their name is there. The sketch is here:

http://linksprite.com/wiki/index.php5?title=JPEG_Color_Camera_Serial_Interface_with_Built-in_Infrared_(RS232_level)

but the SD card was added later, because of this:

Still the data should be logged onto the serial monitor and it isn't.

@Marciokoko, you have been here long enough to know ... DO NOT CROSS-POST. Threads merged.

Yes, codingbadly, I know but it wasnt my intent.

Originally the problem was that I was getting compile errors because of an outdated coding format. This issue was actually solved. Later the problem became 00 as bytes. Sorry but I guess I wanted to leave the original post as notice that the code was outdated for anyone who ran into the problem.

But you're right, I did keep that old thread going until it merged with this one. I apologize.

Delta. I agree that if you look at just that part of the code it seems that way. But later in the sketch it reads the serial again and this time stores it into the array. The complete sketch is here:

Ok, so what I should do is:

  1. Eliminate the first while{}
  2. Append the incoming data to the array?

You haven't really been able to understand the replies. So you have to either study the program and learn a lot more about C++ at the same time, or start with some easier projects.