1

When I try to run the following program it runs ok:

#include <modbus.h>
#include <modbusDevice.h>
#include <modbusRegBank.h>
#include <modbusSlave.h>
#include <LiquidCrystal.h>


LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
modbusDevice regBank;
modbusSlave slave;

void setup()
{
  lcd.begin(40, 2);
  regBank.setId(10);
  int numSet=0;
  for (int i=0; i <= 300; i++){
    if (numSet <= 8) {
      regBank.add(i);
    }
    if (numSet == 16) {
      numSet = 0;
    }
    numSet++;   
  }
  slave._device = &regBank;
  slave.setBaud(9600);
}

void loop() {
  int numSet=0;
  for (int i=0; i <= 300; i++){
    if (numSet <= 8) {
        if (regBank.get(i) >= 1) {
          lcd.setCursor(2, 0);
          lcd.print("test");                
        }
    }
    if (numSet == 16) {
      numSet = 0;
    }
    numSet++;   
  }
  slave.run();
}

But whenever I add more code, or raise the number of the loops, it starts failing to communicate over MODBUS.

Is it that some part of the Arduino can't handle the amount of work? It's confusing because it not only fails when adding more regBank.add() or regBank.get() actions, but also when adding more program code (for example add 40 lines of code to write to the LCD display).

  • 1
    Voting to close as this has been abandoned for a year without any specific information necessary to make it answerable ever being provided. – Chris Stratton May 24 '16 at 16:36
1

Before you decided to switch platforms, take the time to figure out what your resource usage is. After compiling you'll get a report of the amount of memory you're consuming, check that first.

After that, it would be helpful if you could describe more clearly what you're seeing when the code fails.

0

Those libraries use a fair bit of RAM and code space. I am not surprised that you are running out of space.

As dlu suggests in his/her answer, find out how much flash and RAM you are using by checking the output window after compiling.

I suggest using an Arduino Mega as it will give you more code space and RAM. Other alternatives are the Arduino Due and Arduino MKR Zero/1000/1010 but they may require level converters as they run at 3.3V.

  • But you could also use a Teensy3.2 (sparkfun.com/products/13736) it's cheaper and probably better. But might not be as easy to set-up. – Paul Mar 21 '16 at 18:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.