how to add commas to array?

I am working on a project involving raw IR codes, which I store in the EEPROM and later read back.

In theory I should be able to retrieve the IR codes to send it to my IR led. However, when i retrieve it, I get the following data:

Recieved IR Raw data from the EEPROM:
1000910044507005507005507001650700550700550700550700550700550700165070016507005507001650700165070016507001650700165070016507001650700550700165070055070055070055070055070055070055070016507005507001650700165070016507001650

Expected IR Raw Data from EEPROM:1000, 9100,4450, 700,550, 700,550, 700,1650, 700,550, 700,550, 700,550, 700,550, 700,550, 700,1650, 700,1650, 700,550, 700,1650, 700,1650, 700,1650, 700,1650, 700,1650, 700,1650, 700,1650, 700,550, 700,1650, 700,550, 700,550, 700,550, 700,550, 700,550, 700,550, 700,1650, 700,550, 700,1650, 700,1650, 700,1650, 700,1650

The only difference is that the expected has commas inbetween each element of the array.

This is the code, which I used to retrive the data:

[i]void sendIR()
{
 int startIndex = currentCode * (RAWBUF + 1);
 int len = EEPROM.read(startIndex);
 unsigned int code[RAWBUF];
 for (int i=0; i<len; ++i)
 {
 int pulseLen = EEPROM.read(startIndex + i + 1);
 
 code[i] = pulseLen * USECPERTICK ;
 Serial.print(code[i]);
  if ( i <len-1 ) Serial.print(","); // ',' not needed on last one
    if (!(i & 1))  Serial.print(" ");
 }

  irsend.sendRaw(code, len, 38);
 Serial.print("Send Code Length: ");

 Serial.println(len);
}[/i][/i][/i]

The only difference is that the expected has commas inbetween each element of the array.

That would be a difference in how the data is printed. You are not storing the data one digit per EEPROM address, are you?

This is the code, which I used to retrive the data

That code is useless without knowing how you saved the data.

This is how I have stored the data:

void storeCode()
{
//Write the code to EEPROM, first byte contains the length
//Write the code to EEPROM, first byte contains the length
int startIndex = currentCode * (RAWBUF + 1);
int len = results.rawlen - 1;
EEPROM.write(startIndex, (unsigned byte)len);
for (int i = 0; i<len; ++i)
{
if (results.rawbuf[i] > 255)
{
EEPROM.write(startIndex + i + 1, 255);
} else {
EEPROM.write(startIndex + i + 1, results.rawbuf[i]);
Serial.print(results.rawbuf[i] * USECPERTICK);

}
}
Serial.print("Saved code, length: ");
Serial.println(len);
EEPROM.commit();

}

Please read the post at the top of this Forum on the proper way to post source code. Before you post it, with the cursor in the source code window of the IDE, use Ctrl-T to format the code into a common C style. Then use code tags to post it here. It makes it easier for us to read.

EEPROM.write(startIndex, (unsigned byte)len);

Are you POSITIVE that this cast is valid?

I know that your code does NOT look like that. Read the stickies at the top of the forum - the ones you were supposed to read BEFORE you posted here. Post your code properly - ALL of it.

@PaulS. Yes I am sure it is valid as it outputs the length of the raw ir code correctly when read.

A unsigned byte? Are you aware of how a byte is defined?

typedef uint8_t byte;

Also, why are you using a cast at all? You made len an int yourself:

 int len = EEPROM.read(startIndex);

I am using a cast because the EEPROM write only accepts byte and also I need that to define the length of the IR code when I read it.

qwerty12883848384:
I am using a cast because the EEPROM write only accepts byte and also I need that to define the length of the IR code when I read it.

Then why not give it what it needs, byte? You can either cast to a byte, or make len a byte and cast results.rawlen to it.

Oh ok! Is there any way to add those commas to the array?

Oh ok! Is there any way to add those commas to the array?

No, because doing so makes no sense.

You are writing 255 to EEPROM whenever the value in rawbuf[n] is greater than 255. That appears, from the sample data shown, to be every time. Please explain why you are doing that.

qwerty12883848384:
Oh ok! Is there any way to add those commas to the array?

Wouldn’t it be easier to throw away the commas you receive since you don’t need them?

Wouldn't it be easier to throw away the commas you receive since you don't need them?

He's not receiving any commas.

this is because the maximum byte that eeprom can take is 255, so if it is more thana 255 it cannot store so in place it just stores 255.

PaulS:
He's not receiving any commas.

He wrote The only difference is that the expected has commas inbetween each element of the array. which apparently is what is being retrieved from the EEPROM. Don't know.
Hence my suggestion in throwing the commas away when comparing to "raw" data.

If not, simply add 0x2C wherever and whenever needed.

this is because the maximum byte that eeprom can take is 255, so if it is more thana 255 it cannot store so in place it just stores 255.

How many values in

1000, 9100,4450, 700,550, 700,550, 700,1650, 700,550, 700,550, 700,550, 700,550, 700,550, 700,1650, 700,1650, 700,550, 700,1650, 700,1650, 700,1650, 700,1650, 700,1650, 700,1650, 700,1650, 700,550, 700,1650, 700,550, 700,550, 700,550, 700,550, 700,550, 700,550, 700,1650, 700,550, 700,1650, 700,1650, 700,1650, 700,1650

are below 255?

You REALLY need to store the high order byte AND the low order byte for every value. Then, when reading the data, you reconstruct the int from the high order byte and the low order byte.

I'd be inclined to factor the values - that way, the high byte would be irrelevant

I guess it should have been results.rawlen rather than results.rawbuf*. Sorry for that error. However, I think the problem lies with the way I recieve by rawbuf. Cause I just checked with serial.print, I found that the raw data recieved by the IR reciever is the same as the output from the read function. Is there a way to modify my rawbuf as I put it in the function to get the desired output?*

I guess it should have been results.rawlen rather than results.rawbuf.

What should have been?

However, I think the problem lies with the way I recieve by rawbuf.

What does "receive by rawbuf" mean? If you mean that you think that the problem is the way you get rawbuf, show the complete code that does that. It is unlikely that there is anything wrong with the way you get rawbuf, because you didn't write that code.

Cause I just checked with serial.print, I found that the raw data recieved by the IR reciever is the same as the output from the read function.

Show that code, because the statement does not make sense.

Is there a way to modify my rawbuf as I put it in the function to get the desired output?

No.

Sorry if I used the wrong terminology. I wanted to say that the output from the IR reciever is the same as the EEPROM read.