Variables to LCD1602 RGB

Copy of file attached as discussed
Trying to write a variable on the screen.
A complete list of all the commands would also be very helpful.

2 Likes

Hey Rudi,

It appears that your code didn’t link (you likely didn’t have the required permission to be able to post it onto the forum)

Could you please copy the content of your code as an ino into the forum text and format it using ``` on either side of the code block?

Also, can you add a link to the LCD that you’re using with it?

Thanks

1 Like

Hi Bryce,
I am using your LCD1602-RGB display
Processing: LCD_2.ino…
Cannot copy or upload my code to this forum.

1 Like

Hey Rudi,

Sorry about the fuss with attachments! New users can’t attach things by default to make sure no spam makes it in with malicious files. I’ve upgraded your permissions so you should be able to attach it now.

As Bryce said, you can use three backticks (```) to denote the start of code, paste the code, and use 3 backticks again to signal the end, such that it formats it correctly, it should look like this if you do it right:

void loop(){
    Serial.println()
}
1 Like

James,
I still can’t attach my *.ino file
Which I have actually already sent in my previous Email
Processing: LCD_2.ino…
I assume you do not want me to type this into this message

1 Like

Hi Rudi,

It looks like you’re trying to upload a file it’s actually easier to copy paste the code into the forum post.

You can either surround your code with the tthree backticks manually as James mentioned, like this:

```
Your code here = x
Some more = code
and some more
```

Or you can make sure it’s surrounded by empty lines and use the code block button: image

Your code here = x
Some more = code
and some more

Here’s what it looks like on your end:

Even if it’s a large amount of code, don’t worry as the forum will take care of all the formatting, and make it nice and neat.

2 Likes

WHY is this all so hard ???

I sent you a my *.ino file 3 days ago

Is that not sufficient ? Surely that is the easiest way for everybody.

This Forum seems an extreme waste of everybody’s time.

If I buy a product and need help I don’t want to wait for 3 or 4 days

to continue with my project.

If this is easier then –

#include <Wire.h>
#include "Waveshare_LCD1602_RGB.h"

uint8_t Load;
Waveshare_LCD1602_RGB lcd(16,2); //16 characters and 2 lines of show
int r,g,b,t=0;

void setup() {
Serial.begin(9600);
lcd.init();// initialize
r=100; //set colour
g=0;
b=0;
lcd.stopBlink();
lcd.setRGB(r,g,b);
lcd.setCursor(0,0);
lcd.send_string("Nett");
lcd.setCursor(12,0);
lcd.send_string("Kg.");
lcd.setCursor(0,1);
lcd.send_string("Tared");
}

void loop() {
Load=21;
Serial.println(Load);
lcd.setCursor(6,0);
//lcd.send_string("xx.xx");
//lcd.write_char(Load);
lcd.send(Load,3);
delay(500);
//lcd.clear();
//r = (abs(sin(3.14*t/180)))*255;
//g = (abs(sin(3.14*(t + 60)/180)))*255;
//b = (abs(sin(3.14*(t + 120)/180)))*255;
//t = t + 3;
}

Regards
Rudi Broekhuizen

1 Like

Hi Rudi,

The forum is an excellent spot so the community can step in and help out. Also writing and email directly to someone doesnt allow to share the knowledge to other makers. Usually the guys at Core are super fast in getting back to you once all of the documentation has been sent through.

From the code it looks like you are using this screen here: https://core-electronics.com.au/lcd1602-rgb-module-16x2-characters-lcd-rgb-backlight-3-3v-5v-i2c-bus.html

Waveshare dont have an API on their modules but you can take a look through the .cpp file in the demo file

The send_string command actually needs a char array rather than a string. to convert from an integer (the data type used for the load variable) I’d take a look at using the itoa() function.
Once you have the char array from the function you can then use the send_string() function to display it.

The micropython guide also looks really good if you have a RPi Pico on hand.

PS: Replying via email keeps the footer of your email open for the public to see. I’d head over to the forum to edit the post :smiley:

4 Likes

Thank you Liam.

I agree it is good to share information with others

I have tried to use the Forum a couple of times but without any success

For one the upload function does not work when I try to share a file.

Regards

Rudi Broekhuizen

Hi Rudi,

Thanks for persisting - we got there in the end. Now we’re over that hurdle, let’s get stuck in! :slight_smile:

@Liam120347 has got you off to a pretty good start, though before that you’ll want to make sure your wiring’s correct:

You’ll also need to make sure you’ve installed the Waveshare Ardunio library correctly. Here’s the official guide on how to do that: Arduino - Libraries

Just note that the zip you need is actually a few folders deep within the zip from waveshare (as that contains libraries for a few different systems).
image

Before trying your own code, I’d recommend trying out one of the included examples to make sure all your wiring is correct. It looks like that’s what you’ve based your code on, but did you manage to get it running first?

It should print:

Waveshare
Hello,World!

And cycle the backlight through a range of colours.

Once that’s working, you should dive into customizing it. To get a list of all the functions available in a library, you’ll want to open up the header file - in this case Waveshare_LCD1602_RGB.h - and have a look at the public: section for the class. I’ve copied it out for you here for convenience:

class Waveshare_LCD1602_RGB
{
public:
	Waveshare_LCD1602_RGB(uint8_t lcd_cols,uint8_t lcd_rows);
	
	void init();
	void home();
	void display();
	void command(uint8_t);
	void send(uint8_t *data, uint8_t len);
	void setReg(uint8_t addr, uint8_t data);
	void setRGB(uint8_t r, uint8_t g, uint8_t b);
	void setCursor(uint8_t col, uint8_t row);
	void clear();
	void BlinkLED();
	void noBlinkLED();
	void write_char(uint8_t value);
	void send_string(const char *str);
	void stopBlink();
	void blink();
	void noCursor();
	void cursor();
	void scrollDisplayLeft();
	void scrollDisplayRight();
	void leftToRight();
	void rightToLeft();
	void noAutoscroll();
	void autoscroll();
	void customSymbol(uint8_t location, uint8_t charmap[]);
	void setColorWhite(){setRGB(255, 255, 255);}

As you can see, the send() function (fifth from the top) is expecting a memory address (or pointer), not the value of a variable. At present, you are passing it a variable value with lcd.send(Load,3);

I suspect changing it to: lcd.send(&Load,3); should do the trick to get your code working the way you expect, though you might need to change that static 3 to a function that calculates the length of the number you’re sending dynamically. If not though, you can then dive into the .cpp file which has the actual code for that function in it, to get a better understanding of how it works and what it expects.

Understanding pointers (and hence arrays and strings) is a really important fundamental when programming in any C based language - like the version of C++ used for Arduino sketches - so reading up on this will really help you out.

A quick google has brought up this article which looks to be a pretty good intro to understanding pointers:

Alternately, you can use the approach @Liam120347 suggested and stick with the send_string() function by first converting your Load integer value to a string using the itoa() function.


PS.

It looks like you replied by email and left your signature on though, so I’ve removed your personal details and formatted your code while I was at it.

FYI, the reason we prefer the forum for technical support is it greatly expands the brains trust from just a single member of our support team, to the whole team at Core (including our design engineers like @Michael) as well as helpful community members like @Liam120347 - so you’ll sometimes even get answers to your questions outside business hours!

It also means that the solution to your problem is not locked up in emails. Someone else will undoubtedly run into the same issue in the future (and more than once you’ll run into an issue someone else has had) so this way we can build on past knowledge and experience as we learn from one another.

If you need private one on one support though, there are engineering consultancies that provide that service. Engineering support for a custom application like this is quite expensive, but it is sometimes a better option for commercial applications where you’ll make a return on that investment.

4 Likes

Hi guysProcessing: Loadcell_T2.ino… - Still can’t attach file.
I need to know how to set the address for the LCD1602 so I can send a variable to it

// R.Broekhuize - Load display
// Hardware - Teensy 2.0, LCD1602_RGB, HX711

#include <Wire.h>
#include "Waveshare_LCD1602_RGB.h"
#include <stdio.h>
#include <stdlib.h>

  uint8_t Load;+-
  a
  Waveshare_LCD1602_RGB lcd(16,2);  //16 characters and 2 lines of show
  int r,g,b,t=0;
  
  int i;
  char buffer [5];

void setup() {
    Serial.begin(9600);
    lcd.init();// initialize
    r=100; //set colour
    g=0;
    b=0;
    
    lcd.stopBlink();
    lcd.setRGB(r,g,b);
    lcd.setCursor(0,0);
    lcd.send_string("Nett");
    lcd.setCursor(12,0);
    lcd.send_string("Kg.");
    lcd.setCursor(0,1);
    lcd.send_string("Tared");
}

void loop() {
  
    Load=45;
    i=Load;
    scanf ("%d",&i);
    itoa (i,buffer,10);
    printf ("decimal: %s\n",buffer);
    
    Serial.println(buffer);
    lcd.setCursor(6,0);
    lcd.send_string(buffer);
    
    delay(500);
        
    //r = (abs(sin(3.14*t/180)))*255;
    //g = (abs(sin(3.14*(t + 60)/180)))*255;
    //b = (abs(sin(3.14*(t + 120)/180)))*255;
    //t = t + 3;
   
   
   }

Regards Rudi

4 Likes

Hi Rudi,

I find copy and pasting code with three ``` before and after the code to be far easier.

Are you getting any error messages when compiling? According to the documentation all of your function calls are correct from a quick glance.
All of the addresses can be found in the Arduino Libraries header file (Waveshare_LCD1602_RGB.h).

Here’s a copy for reference (From Waveshares demo code):

 *   Device I2C Arress
 */
#define LCD_ADDRESS     (0x7c>>1)
#define RGB_ADDRESS     (0xc0>>1)


/*!
 *  color define
 */ 
#define WHITE           0
#define RED             1
#define GREEN           2
#define BLUE            3

#define REG_RED         0x04        // pwm2
#define REG_GREEN       0x03        // pwm1
#define REG_BLUE        0x02        // pwm0

#define REG_MODE1       0x00
#define REG_MODE2       0x01
#define REG_OUTPUT      0x08

/*!
 *   commands
 */
#define LCD_CLEARDISPLAY 0x01
#define LCD_RETURNHOME 0x02
#define LCD_ENTRYMODESET 0x04
#define LCD_DISPLAYCONTROL 0x08
#define LCD_CURSORSHIFT 0x10
#define LCD_FUNCTIONSET 0x20
#define LCD_SETCGRAMADDR 0x40
#define LCD_SETDDRAMADDR 0x80

/*!
 *   flags for display entry mode
 */
#define LCD_ENTRYRIGHT 0x00
#define LCD_ENTRYLEFT 0x02
#define LCD_ENTRYSHIFTINCREMENT 0x01
#define LCD_ENTRYSHIFTDECREMENT 0x00

/*!
 *   flags for display on/off control
 */
#define LCD_DISPLAYON 0x04
#define LCD_DISPLAYOFF 0x00
#define LCD_CURSORON 0x02
#define LCD_CURSOROFF 0x00
#define LCD_BLINKON 0x01
#define LCD_BLINKOFF 0x00

/*!
 *   flags for display/cursor shift
 */
#define LCD_DISPLAYMOVE 0x08
#define LCD_CURSORMOVE 0x00
#define LCD_MOVERIGHT 0x04
#define LCD_MOVELEFT 0x00

/*!
 *   flags for function set
 */
#define LCD_8BITMODE 0x10
#define LCD_4BITMODE 0x00
#define LCD_2LINE 0x08
#define LCD_1LINE 0x00
#define LCD_5x8DOTS 0x00```
4 Likes

Hi Liam,

Thanks very much,

How/where do I specify the address/addresses? As I already have a HX711 on the I2C bus.

Regards

Rudi Broekhuizen

2 Likes

Hi Rudi,

In short the library handles it all for you, there is a send command baked into the library with the LCD and RGB’s addresses already defined.

{
    Wire.beginTransmission(LCD_ADDRESS);        // transmit to device #4
    for(int i=0; i<len; i++) {
        Wire.write(data[i]);
		delay(5);
    }
    Wire.endTransmission();                     // stop transmitting
}

PS: for those that want a crash course on I2C Michael had a great explanation on the latest
Factory Ep: The Factory | How We Make Custom I2C Modules: A Deep Dive - YouTube

3 Likes