Help with Arduino Cloud

Hi, I'm totally newby with arduino. I'm trying to create a marquee for a person who has Alzheimer. The Idea is that his daughter should be able to activate a marquee which is controlled with a dashboard. The main problem that I have is that sometimes the state of the arduino side and the dashboard are out of sync. The dashboard only have a switch to turn on the marquee and a led to know if the marquee are running. But if I activate the marque using the mobile app sometime when reload the app the switch appear off while the arduino marquee is running, so it's impossible to know the real state of the arduino side. The code:

#include "arduino_secrets.h"
// Adafruit NeoMatrix - Version: Latest 
#include <Adafruit_NeoMatrix.h>
#include <gamma.h>

#define PIN 4

Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(32, 8, PIN,
  NEO_MATRIX_TOP     + NEO_MATRIX_RIGHT +
  NEO_MATRIX_COLUMNS + NEO_MATRIX_PROGRESSIVE,
  NEO_GRB            + NEO_KHZ800); 
  
  const uint16_t colors[] = {
  matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(0, 0, 255) };


#include "thingProperties.h"

bool enviando;
char *message;
int x;
int textlength;
int matrixWidth;

void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(115200);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500); 

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(4);
  ArduinoCloud.printDebugInfo();
  
  matrix.begin();
  matrix.setTextWrap(false);
  matrix.setBrightness(50);
  matrix.setTextColor(colors[0]);
  enviando = false;
  indicador = false;   
  message = "Papa llamame";
  matrix.setBrightness(40);
  x = matrix.width();
  textlength = strlen(message);
  matrixWidth = textlength * 5 + textlength;
  matrix.setCursor(0, 0);
}



void loop() {
  ArduinoCloud.update();
  indicador = 0;
}



void onEnviarChange()  {
  // Add your code here int counter = 0
  if (enviar == HIGH){
    matrix.setCursor(0, 0);
    while(enviar == HIGH){
          Serial.println("ON");
          matrix.fillScreen(0);
          matrix.setCursor(x, 0);
          matrix.print(message);
          if(--x < -matrixWidth) {
            x = matrix.width();      
          }
          matrix.show();
          delay(70);
          indicador = 1;
          ArduinoCloud.update();
  };
  return;
  }else{
    indicador = 0;
    Serial.println("OFF");
    matrix.fillScreen(0);
    matrix.setCursor(0, 0);
    matrix.print(" ");
    matrix.show();
  }
}

void onIndicadorChange()  {
  Serial.println("LED");
  
}

Hi!

Thanks for sharing your project. It looks really interesting and it is great to hear from people who create projects to help people with problems.

In order to help you, it would be interesting to get more details about your setup.
What board are you using? What peripherals? How do you connect it to internet? WIFI?

If I understand correctly your use case, the disabled person will be wearing or have at hand a device with a display, that will be activated from the cloud when the switch in the dashboard is turned on. Is that right?

Hi! Sorry for the delay answering. It's a esp8266 with 4 8*8 matrix led. The device is a marquee that we will install on the top of the TV.

Hi!
You shouldn't have a "while" clause inside onEnviarChange. That function should be used to process the event and execute the one-shot actions.
If you want to do some action while a variable has certain value, you should put an "if" clause in the loop() function. Bear in mind that the loop() function is being called continuously.
Without digging too much in your code, I think that you should move your while (enviar == HIGH) clause to the loop() function, replacing the condition with an if (enviar == HIGH).

void loop() {
   ArduinoCloud.update();
   ...
   if (enviar == HIGH) {
      ...
   }
}

and remove the ArduinoCloud.update() call from inside the clause.

I hope this helps.

1 Like

Thanks!! (Again, sorry for the delay). The device it's working like a charm and doing the job!

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.