mLink Arduino library for mLink modules

Useful guides, libraries, and example sketches to support our Arduino based products.
RogerL
Posts: 35
Joined: Mon Apr 14, 2014 7:56 pm

Re: mLink Arduino library for mLink modules

Post by RogerL » Mon Feb 17, 2025 11:37 am

I got my mLink LCDs on Saturday and was able to do a little testing with my ESP32C3 board.

The basic Hello World sketch worked OK along with other fuctions like backlit brightness and clearing the display. This was using level shifters rather than modding the hardware. I had mixed success with printing numbers. The example code for printing integers in the Quick Start pdf (after I had added the missing semicolon) produced a flood of errors starting:

C:\Data\Roger_Hobby\Control_Systems\Arduino\Greenhouse_IoT\ESP32_Version\mLink_LCD_Int_test\mLink_LCD_Int_test.ino: In function 'void loop()':
C:\Data\Roger_Hobby\Control_Systems\Arduino\libraries\mLink/mLink.h:541:62: error: call of overloaded 'print(int, MLINK_CLCD_REGISTERS, int&)' is ambiguous
541 | #define cLCD_print(add, d) print(add, CLCD_PRINT, d)
C:\Data\Roger_Hobby\Control_Systems\Arduino\Greenhouse_IoT\ESP32_Version\mLink_LCD_Int_test\mLink_LCD_Int_test.ino:12:7: note: in expansion of macro 'cLCD_print'
12 | mLink.cLCD_print(I2C_ADD, number); // Print the number
| ^~~~~~~~~~
C:\Data\Roger_Hobby\Control_Systems\Arduino\libraries\mLink/mLink.h:1342:22: note: candidate: 'void mLink::print(uint8_t, uint8_t, char, boolean)'
1342 | void print(uint8_t add, uint8_t reg, char c, boolean wait = false);
| ^~~~~

The printFloat function worked OK providing I specified one or more decimal places:

float f;
f = 19.25;
mLink.cLCD_printFloat(I2C_ADD, f, 1); this prints 19.3 -the rounding-up is useful.
mLink.cLCD_printFloat(I2C_ADD, f, 0); this prints 19. -the trailing decimal point is not what I was hoping for.
mLink.cLCD_printFloat(I2C_ADD, f, 3); this prints 19.250

andrew
Site Admin
Posts: 1481
Joined: Sun Aug 05, 2012 4:15 pm

Re: mLink Arduino library for mLink modules

Post by andrew » Tue Feb 18, 2025 4:20 pm

Hi Roger,

I'm guessing your pico treats an int as a 32 bit number rather than a 16 bit number so I've updated the library to handle this.

Here's the link:

https://hobbycomponents.com/downloads/m ... V2_2_1.zip

Note, the version number is the same (V2.2.1)
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

RogerL
Posts: 35
Joined: Mon Apr 14, 2014 7:56 pm

Re: mLink Arduino library for mLink modules

Post by RogerL » Tue Feb 18, 2025 7:52 pm

Hi Andrew. Just to clarify, for the time being I have stopped testing with other microcontrollers and am concentrating on the ESP32 because that is what I am using for my current project.

The example program from the Quick start PDF now compiles for ESP32 and prints stuff to the display. However, like the printFloat function with 0 decimal places, it prints a decimal point after the number, so:

int number = -1234;
mLink.cLCD_print(I2C_ADD, number); // prints -1234.

I am guessing that this isn't what you intended. Apart from looking odd, the decimal point takes up a precious character position on the display.

andrew
Site Admin
Posts: 1481
Joined: Sun Aug 05, 2012 4:15 pm

Re: mLink Arduino library for mLink modules

Post by andrew » Wed Feb 19, 2025 10:02 am

he example program from the Quick start PDF now compiles for ESP32 and prints stuff to the display. However, like the printFloat function with 0 decimal places, it prints a decimal point after the number

Ah, it's a bug in the new function that was added. I've now uploaded the fix to the current version of the library.

I think in the rush to fix the library for your pico I'm just playing whack-a-mole so I'm going to find some time to do a thorough test with what boards I can. The current version should be fixed for any issue you've reported though.

I'm very grateful for your help and please do not go to any trouble, but if you spot anything else then just let me know and I'll fix it. If not, I'll push this version after I've done a proper test.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

RogerL
Posts: 35
Joined: Mon Apr 14, 2014 7:56 pm

Re: mLink Arduino library for mLink modules

Post by RogerL » Wed Feb 19, 2025 4:04 pm

andrew wrote:
Wed Feb 19, 2025 10:02 am
I'm very grateful for your help and please do not go to any trouble, but if you spot anything else then just let me know and I'll fix it. If not, I'll push this version after I've done a proper test.
I will give the new version a try this evening and get back to you.

I am currently working on a project that will make extensive use of both 16x6 and 20x4 mLink displays, not only in writing a variety of information in different formats to the displays but also using backlight intensity as part of the alert notification mechanism. I expect to be giving the library quite a workout, so I am highly motivated to help you iron-out any issues!

RogerL
Posts: 35
Joined: Mon Apr 14, 2014 7:56 pm

Re: mLink Arduino library for mLink modules

Post by RogerL » Wed Feb 19, 2025 6:11 pm

Hi Andrew. OK, integers and floats are both displaying as expected. Thanks for sorting that out for me.

There is something else I have fallen foul of that is possibly not an issue with the current library, but may be a candidate for a future addition. When using the 20x4 display, I have had a situation where I have a program running on the microcontroller that is continually writing to the LCD and when I download an updated program the new version does not display as it should. To get everything to work I have to power cycle the LCD and microcontroller together and then everything is OK. This is only an issue while developing software as its only the action of downloading a new program that causes the problem. I have tried to reproduce this on the 16x2 display and so far failed.

In the SmartLCD library there is a command to initialise the display and return it to the power-on state. Having something similar in the mLink library would hopefully overcome this issue. Would this be a possibility?

andrew
Site Admin
Posts: 1481
Joined: Sun Aug 05, 2012 4:15 pm

Re: mLink Arduino library for mLink modules

Post by andrew » Thu Feb 20, 2025 11:16 am

In the SmartLCD library there is a command to initialise the display and return it to the power-on state. Having something similar in the mLink library would hopefully overcome this issue. Would this be a possibility?

It is a good point. I'll put a note in the firmware to an init in a future firmware revision. Tbh, the clear function should do part of that in clearing the screen and moving the cursor back to the top left.

When using the 20x4 display, I have had a situation where I have a program running on the microcontroller that is continually writing to the LCD and when I download an updated program the new version does not display as it should....

This is only an issue while developing software as its only the action of downloading a new program that causes the problem.

This might be a querk of the Arduino IDE. As I'm sure you know, by default whenever the serial interface is first opened, it resets the Arduino. As I understand the process, when uploading a sketch, the IDE first uploads the sketch then resets the Arduino. It then reopens serial communication which in-turn resets the Arduino a second time. In-between these two resets the Arduino can start to run the first few lines of your sketch before the second reset kicks in.

Maybe that could be the issue? You could try putting a one or two second delay as the first line of the setup() function to see if that fixes it.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

RogerL
Posts: 35
Joined: Mon Apr 14, 2014 7:56 pm

Re: mLink Arduino library for mLink modules

Post by RogerL » Thu Feb 20, 2025 7:56 pm

Hi Andrew. I tried delays up to 10 seconds, but that didn't work. Then I swapped out the mLink LCD in my circuit with a new one out of the bag and all worked fine. Then I reconnected my initial display and that now works fine too. So, I am beginning to think the problem may be with my breadboard set-up. Maybe a slightly iffy jumper cable or a breadboard glitch. Anyway, all is working now, so I hope you haven't wasted any time on this.

andrew
Site Admin
Posts: 1481
Joined: Sun Aug 05, 2012 4:15 pm

Re: mLink Arduino library for mLink modules

Post by andrew » Fri Feb 21, 2025 9:51 am

. So, I am beginning to think the problem may be with my breadboard set-up. Maybe a slightly iffy jumper cable or a breadboard glitch. Anyway, all is working now, so I hope you haven't wasted any time on this.
Ah ok, and no problem at all. I'll get the updates to this library and the smart LCD library pushed sometime next week. Anymore issues and just let me know.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

RogerL
Posts: 35
Joined: Mon Apr 14, 2014 7:56 pm

Re: mLink Arduino library for mLink modules

Post by RogerL » Fri Feb 21, 2025 10:50 am

Needless to say, as soon as I sent the message to say it was working OK, it stopped working OK. So, I have been digging around trying to better understand the problem.

I initially just said that the text wasn't displaying correctly. What was actually happening is that the program was supposed to display text on the screen starting at column 0 and when I downloaded a new program only the first character was being displayed. I assumed this was becasue the rest of the text was being dropped or the screen somehow blanked. This turned out to be a rash assumption. What is actually happening is that when the new program is being downloaded the cursor direction is flipping. So, the first character of the text is printed at column zero and the rest of the text is exiting stage left. This cursor direction reversal was confirmed when I changed the program to start printing in the middle of the row. When I add the command to setup() to set the cursor direction to 0, everything displays OK immediately after program download. My initial program wasn't doing any cursor direction changing, so this isn't a case of a non-default setting 'hanging over' from the previous program.

I have done further testing with both of my displays. Although display #1 has worked without issue for a couple of short periods, most of the time it exhibits the problem. I have also tested display #2, but so far that has always worked as expected. All this testing was done with an ESP32C3 board.

Post Reply

Return to “Arduino”