Go Down

Topic: Problems with I2C LCD on Slave connected to Master UNO (Read 485 times) previous topic - next topic


first of all sorry if this is not the correct Board for this problem... I could not identify one that would fit...

I am trying to achieve controlling a Stepper Motor (Nema17 + A4988 Driver Board) using different states and routines for different purposes.
So far everything works great.
At one point I decided I want to seperate the tasks and split them onto 2 Arduino UNOs.

What already works:
The Master UNO:

The Master UNO Controls the states and routines of the current setup and thereby decides how the motor behaves.
He sets the states, prints out the menu and current settings on a I2C Display, listens to an IR Reveiver for Remote Control Input and sends data like Motor Speed and Acceleration to the Slave UNO. Also the Master UNO handles the ENABLE Pin of the A4988 driver board (to turn it off while setup or while the state and routine are a setup one).
Also the Master UNO uses some Timer Structs I implemented to help managing the tasks and giving every task the interval it needs.

The Slave UNO:

The Slave UNO receives 2 char arrays from the Master UNO, containing speed and acceleration of the motor settings. Also it controls the direct motor movement.

What does not work:

The Slave UNO should also print information about the steps of the motor on a debug I2C LCD.
This works for the Master without any problem.
But on the Slave UNO, as soon as I set a cursor for the display and try to print the Slave UNO gets stuck and stops executing the loop...

More info:

The Slave and Master are connected through the SCL and SDA pins of the UNOs.
The 2 displays are connected to the A4 and A5 pins of the UNOs.
I do not call methods of the LiquidCrystal_I2C.h inside the registered Wire.onReceive receiver method.

The Slave Code:
I think it is enough to provide the simple slave code due to the fact that the problem also persists without the master being attached...

#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <AccelStepper.h>

/* -- Initialization -- */

/*----- Display -----*/
LiquidCrystal_I2C lcd(0x27, 20, 4);
char *lcdLineOne;
char lcdLineTwo[20];
char lcdLineThree[20];
char lcdLineFour[20];
bool writeToLCD = false;

/*----- Transmission -----*/
volatile long speedX;
volatile long accelX;
char* trString;

/*----- Stepper -----*/
int stepP = 3; // A4988 step pin
int dir = 4; // A4988 dir pin
long totalSteps = 0;
long lastDistance = 0;
bool firstLoop = true;
AccelStepper sliderStepper(1, stepP, dir);
int motorSpeed = 1200;
int motorAccel = 1000;

/*----- Setup -----*/
void setup()
    Wire.begin( 8 );               
    Serial.println("Setup Motor Runner Complete");

/*----- Count Total Steps done so far -----*/
void setTotalStepsDone(){


/*----- Update the LCD -----*/
void updateLCD(){

    lcdLineOne = "Motor Slider";
    sprintf(lcdLineTwo,"%ld", speedX);
    sprintf(lcdLineThree,"%ld", accelX);
    sprintf(lcdLineFour,"%ld", totalSteps);

    // here the slave UNO stops executing.... Everything works fine if I do not print on the LCD...
    lcd.setCursor(0, 0);
    lcd.setCursor(0, 1);
    lcd.setCursor(0, 2);
    lcd.setCursor(0, 3);

/*----- loop -----*/
void loop()


/*----- receive event -----*/
void receiveEvent(int bytes) {


I left out some unimportant parts of the code marked with "...".

Is there a problem with the slave because of listening to data using <Wire> and at the same time trying to print via <LiquidCrystal_I2C> ?

Why doesn't the Master have any problem with sending and printing simultaneously?

Thank you for any help!

Go Up