Print serial communication with lcd.setCursor

Hi everyone;

I am going to communicate 2 arduinos via serial communication, Arduino 1 and Arduino 2.
Arduino 2 is connected with i2c LCD , Arduino 1 has 2 push buttons for counter variables.

*The thing is that I would like to print those variables in my i2c LCD connected to Arduino 2.
*I need you help for the i2c lcd code at Arduino 2 to print with columns and rows, maybe my code isnt´the best way to do that.
Image attach
Image explanation
Here is my Code for Serial Display modified for i2c LCD


#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);  //

void setup() {
  lcd.init();
  lcd.backlight();  
  Serial.begin(9600);
}

void loop() {
  // when characters arrive over the serial port...
  if (Serial.available()) {
    // wait a bit for the entire message to arrive
    delay(100);
    // clear the screen
    lcd.clear();
    // read all the available characters
    while (Serial.available() > 0) {
      // display each character to the LCD
      lcd.write(Serial.read());
    }
  }
}

I use Ldmicro ladder software for my projects, I know I can use Arduino IDE but I am more familiar with ladder and doesn´t support parallel lcd only serial lcd, so here I am looking for information that nobody asks

What do you mean? Can you draw a picture of what you would like the LCD display to look like and post that.

yes I posted a picture , here it is:

Picture explanation URL

OK so you just need to keep track of how many time each button is pressed and display on the LCD?

if button 1 is pressed you send '1'
if button 2 is pressed you send '2'

Then in your receiver you have something like...

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);  

int counter1, counter2;

void setup() 
{
  lcd.init();
  lcd.backlight();  
  Serial.begin(9600);
}

void loop() 
{
  if (Serial.available() > 0) 
  {
    char c = Serial.read();
    
    if (c == '1')
    {
      counter1++;
      lcd.setCursor(0,0);
      lcd.print(counter1);
    }
    else if (c == '2')
    {
      counter2++;
      lcd.setCursor(0,1);
      lcd.print(counter2);
    }
  }
}

Thank you very much for your help

yeah, It is close to what I want, Every time I press button 1 the counter1 encreases, like a normal counter, what I would like to achieve is to print the number of counter1 on the Arduino_2 lcd, no matter what number is, the same for button 2 with counter2 in another cursor position

Doesn't the code above do that?

yeah, but
*the counting procces is in Arduino 1 which is programmed with ladder
*The code I need is just for printing in Arduino 2 the values sent by Arduino 1

For example I send values with Arduino 1 like this: "counting_value\2\r\n
but I can´t set a cursor with my Arduino Code, I need this position because I could mix another values at LCD

When you add 1 to counter1 on Uno 1, send a ‘1’ to Uno 2… the count can also be keep there?

Hi, @parksplit
How far apart are the UNOs?

Why can't you just run three wires from the LCD UNO to the two buttons?

Or is this an experiment/project for school?

@parksplit circuit

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

thanks for yotu reply, it is because the arduino with buttons is programmed with ldmicro, a ladder software IDE, this ldmicro only support serial lcd communication. that´s why I am trying to use another arduino as a serial reader adapter to print values on lcd.

thanks for your reply, I have made this code for 2 buttons, it prints the numbers I send with each button, but I cant manage to print with set.Cursor, button 1 overlaps the value from button 2 or vice versa.


#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);  //

void setup() {
    lcd.init();
    lcd.backlight();
    Serial.begin(9600);
}

void loop() {
    if (Serial.available()) {
        String serialData = Serial.readStringUntil('\n');
        int commaIndex = serialData.indexOf(",");
        int counter1 = serialData.substring(0, commaIndex).toInt();
        int counter2 = serialData.substring(commaIndex + 1).toInt();
        lcd.clear(); // Limpiar el LCD antes de escribir un nuevo valor
        lcd.setCursor(0, 0);
        lcd.print("Counter 1: ");
        lcd.print(counter1);
        lcd.setCursor(0, 1);
        lcd.print("Counter 2: ");
        lcd.print(counter2);
    }
}

Got a picture?

Why use the Idmicro software at all?
Or is the Idmicro doing other things apart from reading two buttons?

If you need to use two UNOs, not just connect two of the first UNO's digital outputs to two of the second UNO's digital inputs.?
No comms protocol needed, press button ONE and OUTPUT representing button one goes HIGH.
Likewise for the othe button, still uses the same number, 3, of interconnecting wires.

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

I uploaded a 30 seconds video demostration of overlap on youtube, I used an ESP32 instead of arduino 2 because I lent it to my friend, watch it please:

All my project are done with ldmicro, It is easy for me ladder language, for example, this is a comparison for debounce button between ldmicro and arduino:

All my logic process is en arduino 1 made with ladder, I want to print values from my ladder logic to lcd, but as ldmicro doesn´t support parallel lcd only supports serial lcd i have to use a serial reader, another arduino (arduino 2).

Please show us the format of the message being sent by the first Arduino to the second Arduino. Is there just one message per button push or is there a single message with both button push totals?

Hi,
Have you Googled;

Ldmicro arduino I2c

This channel seems to have some thing.

Tom... :smiley: :+1: :coffee: :australia:

Thanks for your reply, Mr Onostech have helped us with ldmicro many times ,Yes I have, It doesn´t work for many people, It seems there is something messing at high level coding, I made my own vide tutorial years ago but it doesn´t work with new releases:

Thanks for your reply. Yes, this is the format message from first Arduino, I use ldmicro as I said before:

Counter1= starts at 1 resets at 11 (CTC: Circular Counter)
Counter2= starts at 1 resets at 6 (CTC: Circular Counter)
OSR = One Shot Rising
{"\2\n"} = Formatted String Over UART (sends "Counters" values)
[TON 41 ms] = Timer On Delay 41 ms (used for debounce buttons)

How will the Arduino program determine which message refers to which counter?