Adding LCD stops IoT updates

It's been awhile and I have to re-educate myself on developing IoT stuff, so I started with baby steps.

The first code is very simple and runs fine. My dashboard is a switch and a messenger.

/* 
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"
  https://create.arduino.cc/cloud/things/95a72fb1-1b43-4f84-bba8-2cddc7e88cd6 

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  String test_msg;
  bool test_switch;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"

void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // 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(2);
  ArduinoCloud.printDebugInfo();
}

void loop() {
  ArduinoCloud.update();
  // Your code here 
  
  
}


/*
  Since TestSwitch is READ_WRITE variable, onTestSwitchChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onTestSwitchChange()  {
  // Add your code here to act upon TestSwitch change
  if (test_switch) test_msg = "Switch On";
  if (!test_switch) test_msg = "Switch Off";
}

/*
  Since TestMsg is READ_WRITE variable, onTestMsgChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onTestMsgChange()  {
  // Add your code here to act upon TestMsg change
}



But as soon as I add the LCD unit, the IoT remote no longer updates. Anyone know why?

/* 
  AA :a simple code to check connection and LCD updates

  The following variables are automatically generated and updated when changes are made to the Thing

  String test_msg;
  bool test_switch;
*/

#include "Wire.h"
#include "hd44780.h"
#include "hd44780ioClass/hd44780_I2Cexp.h"

#include "thingProperties.h"

//create LCD object
hd44780_I2Cexp lcd;

//LCD geometry
const int LCD_COLS = 20;
const int LCD_ROWS = 4;


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

  // Defined in thingProperties.h
  initProperties();

  // initialize LCD
  int LCD_status;
  LCD_status = lcd.begin(LCD_COLS, LCD_ROWS);
  if (LCD_status) {hd44780::fatalError(LCD_status);}
  
  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
  
  //setup LCD
  lcd.clear();
  lcd.setCursor(1,2); //col,row
  lcd.write("Ready...");
  
  test_msg = "Ready.";
  
}

void loop() {
  ArduinoCloud.update();
  // Your code here 
  
}

/*
  Since TestMsg is READ_WRITE variable, onTestMsgChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onTestMsgChange()  {
  // Add your code here to act upon TestMsg change
}
/*
  Since TestSwitch is READ_WRITE variable, onTestSwitchChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onTestSwitchChange()  {
  // Add your code here to act upon TestSwitch change
  lcd.setCursor(0,0);
  if (test_switch) {
    lcd.write("On ");
    test_msg = "Switch On";
  }
  if (!test_switch) {
    lcd.write("Off");
    test_msg = "Switch Off";
  }
}

Yes, I know my IF statements can be IF/ELSE. I was just doing some dirty code to test.

Thanks in advance.

Maybe the code isn't getting past this point? Have you added some serial debug to figure out what code is getting executed?

1 Like

I failed to mention, I am getting the initial "Ready" message on the LCD.

Hi @cptadventure. Please try this troubleshooting procedure and then then report back here with the results:


:exclamation: This procedure is not intended to solve the problem. The purpose is to gather more information.


  1. Connect the Arduino board to your computer with a USB cable.
  2. If you are not already, log in to your Arduino account:
    https://login.arduino.cc/login
  3. Click the following link to open the list of your Arduino Cloud Things in the web browser:
    https://app.arduino.cc/things
  4. Click the name of the Thing.
    The "Setup" page for the Thing will open.
  5. Select the "Sketch" tab at the top of the page.
    The "Sketch" page for the Thing will open.
  6. Make sure the serial port of the Arduino board is selected on the sketch editor toolbar.
    Some Devices produce an "Over-the-Air" port and a serial port. In this case, there will be a menu on the toolbar that allows you to select either one. The serial port must be used for this procedure.
  7. Click the icon that looks like a magnifying glass ("Open Serial Monitor") on the sketch editor toolbar.
    A new browser window will open.
  8. Make sure the correct port is shown on the toolbar in the window.
  9. Select "9600" from the menu at the bottom of the window.
  10. Press and release the reset button on the Arduino board.

You should now see information about the progress of the Thing initialization printed in the window.

If the board is able to connect to your Wi-Fi access point, you should see a message like this:

Connected to "some-ssid"

After that, if the board is able to connect through the Internet to the Arduino Cloud servers, you should see this message:

Connected to Arduino IoT Cloud

Was the Thing initialization successful as I described? Did you see any error messages or other output that indicated a problem printed in the serial monitor?

Try commenting out all code lines related to the LCD. Does it still function correctly?

If so, un-comment the LCD lines, each in turn, beginning from the top of the code, and re-test after each one, to see at what point it stops working.

Firstly, thanks for your suggestion.
The only difference between the two pieces of code I listed is the LCD lines. And those few lines are easily recognizable as initialization, and two sections that output messages to the LCD. And one of those messages (the first one "Ready") displays...so somewhere after that something goes wrong. But the code is almost a mirror...I think it's actually going wrong within the LCD library itself.....its colliding with some 'cloud' signal....I don't know...I'm reaching here. I'm gonna get the serial output from @ptillisch and see what that shows me.

The serial monitor showed:

**** Arduino IoT Cloud - configuration info *****
Device ID: 4b3cfd62-1596-4b29-8cd3-8c934f964bbc
MQTT Broker: iot.arduino.cc:8883
WiFi.status(): 0
Current WiFi Firmware: 1.5.0
Connection to "----------" failed
Retrying in "500" milliseconds
Connected to "----------"
Connected to Arduino IoT Cloud
Thing ID: de1d86c8-c504-4b8b-9a4e-8f52d3921c52

So , no error messages

I don't know anything about how that IOT stuff works, like how/when those callbacks are called, but if those callbacks (that are attempting to print on the LCD) are called at ISR context, then calling the LCD code will lock up the system since you can't call into the Wire library at ISR level and the Wire code will get stuck spinning in a loop waiting for an ISR that won't ever happen.

Note:
There is an ugly hack in the Serial code that allows output to still get out when the serial code is called at ISR level.

--- bill

Which Arduino board are you using as your Arduino Cloud Device for this Thing @cptadventure?

The board I am using is a MKR1010.

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