Flashes red after green after flashing with my code no RAM

So Im trying to make a remote IR blaster for my AC but when I flash the code via the web IDE the core flashes green then red and doesnt connect. Is it running out of RAM or flash, how would I optimize this code?

/* FIRMWARE */
#include "IRSend.h"

// IR Code Settings
const int IR_LED_PIN = 7;
const int MESSAGE_LENGTH = 68;
const int IR_FREQ = 38;  // In kHz
// Create an instance of the IR remote
IRSend IRremote = IRSend(IR_LED_PIN);

// IR Codes for LG window AC
unsigned int pwrCmd[MESSAGE_LENGTH] = { 
    8700, 4280, 620, 1540, 600, 480, 600, 480, 600, 480, 600, 480, 600, 460, 620, 460, 620, 1540, 600, 480, 600, 1560, 600, 1560, 600, 460, 620, 460, 620, 1540, 620, 1540, 600, 480, 600, 1560, 600, 480, 600, 480, 600, 480, 600, 460, 600, 480, 600, 480,600, 1560, 600, 480, 600, 1540, 620, 1560, 580, 1560, 600, 1560, 600, 1560, 600, 1560, 600, 480, 600, 0 };
unsigned int tmpDownCmd[MESSAGE_LENGTH] = { 
    8700, 4280, 600, 1560, 600, 480, 600, 480, 600, 480, 600, 480, 600, 460, 600, 480, 600, 1560, 600, 480, 600, 1560, 600, 1560, 600, 460, 620, 460, 600, 1560, 600, 1560, 600, 480, 600, 480, 600, 1540, 620, 460, 620, 1540, 600, 480, 600, 480, 600, 480, 600, 1560, 600, 1540, 620, 460, 600, 1560, 600, 480, 600, 1560, 600, 1560, 600, 1560, 600, 460, 620, 0 };
unsigned int tmpUpCmd[MESSAGE_LENGTH] = {
    8700, 4300, 600, 1560, 600, 460, 600, 480, 600, 480, 580, 500, 600, 480, 600, 480, 580, 1560, 580, 500, 600, 1560, 600, 1560, 600, 480, 600, 480, 560, 1600, 600, 1540, 600, 480, 600, 1560, 580, 500, 600, 1560, 600, 480, 600, 480, 580, 500, 560, 500, 580, 1580, 600, 480, 600, 1560, 600, 480, 580, 1580, 580, 1580, 580, 1560, 600, 1560, 600, 480, 600, 0 };
unsigned int fanCmd[MESSAGE_LENGTH] = {
    8700, 4280, 620, 1540, 620, 460, 600, 480, 600, 480, 600, 480, 600, 480, 600, 480, 580, 1560, 600, 480, 600, 1560, 600, 1560, 600, 480, 600, 480, 580, 1560, 620, 1540, 600, 480, 600, 1560, 600, 480, 600, 480, 580, 1580, 600, 1560, 580, 480, 600, 480, 600, 1560, 600, 480, 600, 1560, 600, 1560, 580, 480, 600, 480, 600, 1560, 600, 1560, 600, 480, 600, 0 };
unsigned int tmrCmd[MESSAGE_LENGTH] = {
    8660, 4320, 600, 1560, 600, 460, 600, 480, 600, 480, 600, 480, 600, 480, 600, 480, 580, 1580, 580, 480, 600, 1560, 600, 1560, 600, 480, 600, 480, 600, 1560, 580, 1580, 580, 480, 600, 1560, 600, 1560, 600, 1560, 600, 1560, 600, 1560, 600, 480, 580, 480, 600, 1560, 600, 480, 600, 480, 600, 480, 600, 480, 580, 480, 620, 1540, 600, 1560, 600, 480, 600, 0 };
unsigned int mdeCmd[MESSAGE_LENGTH] = {
    8700, 4280, 600, 1560, 600, 480, 580, 500, 600, 480, 600, 480, 600, 460, 600, 480, 600, 1560, 600, 480, 600, 1560, 600, 1560, 560, 520, 560, 500, 600, 1560, 600, 1560, 560, 520, 580, 1580, 600, 1560, 600, 460, 580, 1580, 600, 1560, 600, 480, 600, 480, 560, 1600, 600, 480, 600, 460, 600, 1560, 580, 500, 600, 480, 600, 1560, 600, 1560, 560, 520, 580, 0 };

// REST Points
int ac(String command) {
    unsigned int *irCode;
    String substring = command.substring(0,3);
    if(substring == "PWR") irCode = pwrCmd;
    else if(substring == "FAN") irCode = fanCmd;
    else if(substring == "TMR") irCode = tmrCmd;
    else if(substring == "MDE") irCode = mdeCmd;
    else if(substring == "TMP") {
        if(command.substring(4) == "DOWN")
            irCode = tmpDownCmd;
        else if(command.substring(4) == "UP")
            irCode = tmpUpCmd;
        else
            return -2;
    }
    else return -1;

    // Send IR command 
    IRremote.sendRaw(irCode, MESSAGE_LENGTH, IR_FREQ);

    return 1;
}

int tinkerDigitalWrite(String command)
{
	bool value = 0;
	//convert ascii to integer
	int pinNumber = command.charAt(1) - '0';
	//Sanity check to see if the pin numbers are within limits
	if (pinNumber< 0 || pinNumber >7) return pinNumber;

	if(command.substring(3,7) == "HIGH") value = 1;
	else if(command.substring(3,6) == "LOW") value = 0;
	else return -2;

	if(command.startsWith("D"))
	{
		pinMode(pinNumber, OUTPUT);
		digitalWrite(pinNumber, value);
		return 1;
	}
	else if(command.startsWith("A"))
	{
		pinMode(pinNumber+10, OUTPUT);
		digitalWrite(pinNumber+10, value);
		return 1;
	}
	else return -3;
}


/* FIRMWARE */
void setup()
{
  Spark.function("digitalwrite", tinkerDigitalWrite);
  Spark.function("ac", ac);
}

/* This function loops forever --------------------------------------------*/
void loop()
{
	//This will run in a loop
}

Can you post the contents of IRSend.h as well?

We’re planning on releasing some updates after this sprint (ends on Friday) that should free up more ram, so hopefully that will help quite a bit!

Thanks,
David

1 Like

@Dave - Isn’t flashing green then red a connectivity issue? Or could it be either/or?

Hmm… flashing green would indicate a connection to the wifi network… Flashing red before cyan could indicate a networking problem (can’t connect to server IP, etc), or depending on the code could be an out-of-memory error, or maybe a server key error methinks.

Thanks,
David

@arduima, I would suggest that all your large arrays (that don’t seem to be modified anywhere) be cast as const unsigned int to put then in flash instead of RAM. See if that helps. :smile:

It looks like it was the issue or running out of memory.

Peekay I tried changing it to const but it was com playing because I was assigning it to a non const pointer later on.

I modified my array and the code to hold bytes instead of ints corresponding to either a short (0) or a long (1) pause pulse and removed the on pulse from the arrays because it was always the same.

1 Like