Weird Messenger library

Please i need someone to tell me why this is not working: I'm having a sketch that receives a command via serial (Messenger Library) and afterwards pulses a IR Led corresponding to the received message.

The following works fine:

// Create the callback function
void messageReady() 
{
  msgToProcess = 0;
  
        if (message.checkString("on"))
          blinkLed(on, sizeof(on)/sizeof(long));

        if (message.checkString("off"))
          blinkLed(off, sizeof(off)/sizeof(long));

        if (message.checkString("white"))
          blinkLed(white, sizeof(white)/sizeof(long));

        if (message.checkString("red"))
          blinkLed(red, sizeof(red)/sizeof(long));
          
        if (message.checkString("green"))
          blinkLed(green, sizeof(green)/sizeof(long));
          
        if (msgToProcess == 0)
        {
          Serial.println("UNKNOWN CMD");
          message.readInt();  
        }
}

But as soon as i add one more message like

        if (message.checkString("blue"))
          blinkLed(blue, sizeof(blue)/sizeof(long));

the whole sketch stops working but the IR Leds always blinks (i know this because i'm using Pin 13 as Output pin which has a normal led attached on my board) but without any data sent to Arduino via Serial connection. :astonished:

Whats wrong with this ****?

Post your code.

Whole sketch is this (i attached it as the forum just allows too less chars)

In fact all i need is one serial message for each array (those that are defined in the beginning of the sketch).

ir_steuerung2.pde (9.58 KB)

I'm guessing RAM, as in "not enough"

I haven't looked closely, but do those numbers have to be "long"s?

Edit: I think they all end in zero, so I guess that's a rheotorical "no"

Hint: sizeof(green)/sizeof(green[0]));
and a simple macro could save you a lot of typing.

hmm yes i need the arrays to be long, as some values are > than the 32.xxx of int

hmm..

But all the entries appear to be integer multiples of ten.
A fairly quick statistical analysis of the distribution of of the pulse lengths, and a further short look up table could reduce your pulse tables to byte size or smaller.
Just thinking aloud.

Ok.
Is there a way to find out how many RAM is used / if there is too much used?

Count the total number of entries in all your tables and multiply by four.
PROGMEM would help too.

hmm ok :frowning:
But it's very hard to reprogram this sketch if it's not really clear where the problem is...

IS there a different possiblity for implementing my needs? (maybe with different library / without library?)
I can't imagine it's not possible reacting on let's say 24 different messages that Arduino should get via serial.

Is there a way to find out how many RAM is used / if there is too much used?

There is also a FreeMemory() function that you can add a call to to your code.
That will report how much SRAM is being used.

IS there a different possiblity for implementing my needs?

Yes. PROGMEM was mentioned.

I can't imagine it's not possible reacting on let's say 24 different messages that Arduino should get via serial.

Of course it is. Just get rid of all those arrays.

What is the result of the array size calculation?
The probem is very easy to solve, in several different ways.
Some will require lots of changes, some very few.
Probably the simplest short term fix would be to change all the longs into unsigned ints.

PaulS:
Of course it is. Just get rid of all those arrays.

How would you implement it without using arrays?
How would you implement the serial communication part (with messenger library or something different?)

AWOL:
Probably the simplest short term fix would be to change all the longs into unsigned ints.

Can you give me an example of how to do this?

No, I don't think that is necessary.
Be sure to change the sizeof calculations though.

The first step is to confirm that you are out of memory. Come on back when you know how much you are using.

So i checked free RAM with the first method of this page http://www.arduino.cc/playground/Code/AvailableMemory

Outcome:
3 IF's=> 510 free
4 IF's => 218 free

4 IF's=> Arduino not working anymore

One more time.
Change the 'long' array declarations to 'unsigned int'.
Change the sizeof calculation to use unsigned int instead of long (a macro would be useful here).
Job done, for now.

Job done, for now.

At least it is if FreeMemory() reports enough memory remains as you continue adding more code.

Yeah, I know, but at least something will have been learned.
More strings to your bow, and all that.

AWOL:
One more time.
Change the 'long' array declarations to 'unsigned int'.
Change the sizeof calculation to use unsigned int instead of long (a macro would be useful here).
Job done, for now.

ok i did this now.
Now i had a bit more free space and could add 5 more IF's.
But now i'm again stuck only 79 free..

So, go for the PROGMEM solution.
Or go for the factoring and look up table solution.
Sorry, there is no free lunch.