Working code on original spark core doesn't work with my new core

Why can’t u put my spark account web ice on original firmware push to core? It was working for me then and that’s what put me into buying more to finish the project…

@MartyMart, when the production web IDE is updated, there is no other version running to “go back to”. If you are not locally compiling it may be somewhat onerous for you learn. Nonetheless, you can learn how to setup a local compile environment here and get version 2.1 of the firmware here.

Fixing the RAM issue is a present (as in now) priority and is one of the key goals of the current Sprint. Each Sprint lasts 2-3 weeks so if you will wait a bit more, the IDE RAM issues will be resolved. :smile:

1 Like

Hi @peekay123,

I was wondering if a similar solution could be applied to my code. The difference is it uses an unsigned int (well actually, several of them). It’s the IR code for an air conditioner :

unsigned int acTemp27[148] = {4400,4300,550,1600,550,1550,600,1550,600,1550,600,500,550,500,600,1550,550,500,600,500,600,450,600,450,600,500,600,1550,550,1600,550,500,600,1550,550,500,600,500,550,500,600,450,600,500,600,450,600,1550,600,1550,600,1550,550,1600,550,1550,600,1550,600,1550,600,1550,600,450,600,500,550,500,600,500,550,500,600,450,600,500,600,450,600,500,550,1600,550,1550,600,500,550,1600,550,500,600,450,600,500,600,450,600,500,550,500,600,500,550,500,600,450,600,500,550,500,550,550,550,1550,600,500,600,450,600,500,550,500,600,500,550,500,600,450,600,500,550,1600,550,500,600,1550,550,500,600,500,550,500,600,500,550,500,600}; 

How would i go about this? static const unsigned int ?

Thanks,
Rehaan.

@Rehaan, if these are arrays of constants then YES, that is exactly what you do. You may also want to cast your array as uint16_t which are unsigned 16-bit integers since “int” is a 4-bytes variable. The “const” will commit the arrays to flash and the unint16_t will take half the space. :slight_smile:

1 Like

Thanks @peekay123,

However i tried changing those lines to the following:

static const unsigned int acTemp27[148] = {4400,4300,, ,,, ,,

and

static const uint16_t acTemp27[148] = {4400,4300,, ,,, ,,

And both of them threw errors (that i couldn’t completely understand).

My full code can be seen here : https://gist.github.com/anonymous/0d71d59e9c0597906b78

@kennethlimcp was nice enough to check and let me know that I’m facing problems because of RAM usage:

Other than shortening my code - I’m rather clueless as how to proceed…

Thanks a ton for the help!
Rehaan.

@Rehaan, I found the reason the “const” declaration won’t work. The way you wrote your code, you pass entire arrays to sendRaw:

void IRsend::sendRaw(unsigned int buf[], int len, int hz)

This puts the entire data structure on the stack when calling the function! A more standard approach is to pass a pointer to the array instead, reducing the stack and memory overhead:

void IRsend::sendRaw(unsigned int *buf, int len, int hz)

This would mean minor adjustments to your code to handle the pointer to the array instead of the array itself.

Also of note is that you use unsigned int values (4 bytes) where unint16_t values (2 bytes) would work as well.

If you need any help, let me know. :smile:

3 Likes

Hi @peekay123,

Thanks again.

I understand the gist of what you’re saying, but i really don’t know how to correctly apply it in practice.

The code is actually from the IRremote library I’m using from here : https://github.com/qwertzguy/Spark-Core-IRremote
(It seems to be a spark-core adaptation of a popular arduino IR library - maybe someone with skills could add it to the spark-build “library” collection?)

If i make the *buf change you’ve provided in your post above (ignoring the part about unint16_t for now) – what other adjustments would i need to make in my code, like you’ve mentioned?

Thanks!
R

EDIT : Okay I’m playing around and it seems to be working with the *buf change so far!

Using uint16_t throws an error…

1 Like

@Rehaan, I’ll take a shot at optimizing it and get back to you :smile:

UPDATE: I updated the code with the changes and put it on my github here. Give it a shot and let me know how it goes. :smile:

3 Likes

Woohoo… thanks a ton @peekay123!

Works like a charm, and for the first time i could actually load up several of the IR commands (vs just 1 or 2).

Question: How come you didn’t use “static” ?

Thanks again,
R

@Rehaan, there seems to be confusion in the community in regards to how to specify a variable be placed in flash. Using “static” tells the compiler to make the specified object available only to the compile unit (file) where it is found (ie not global for example). The “const” specifier tells the compiler that the object will not change in value therefore can be placed in flash. In you code, adding static will work fine but is not necessary. :slight_smile:

2 Likes