HD44780 connected over RP2040 (RPi Pico)

Hi,

i’m trying to get my HD44780 working which I’ve connected to an RPi Pico.

I just got wrong output shown on the display.

The HD44780 seam to initialized correctly, I can see that it switches to 4 lines, and also I can see some outputs which were correct, but arround there is some wrong stuff printed.

[mcu rp_pico]
serial: /dev/serial/by-id/usb-Klipper_rp2040_E6611C08CB077322-if00
baud: 250000
restart_method: rpi_usb

[output_pin pico_led]
pin: rp_pico:gpio25


[display]
lcd_type: hd44780
rs_pin: rp_pico:gpio0
e_pin: rp_pico:gpio1
d4_pin: rp_pico:gpio5
d5_pin: rp_pico:gpio4
d6_pin: rp_pico:gpio3
d7_pin: rp_pico:gpio2
hd44780_protocol_init: True
line_length: 20
display_group: static_text_grp

#click_pin: rp_pico:gpio9
#up_pin: rp_pico:gpio7
#down_pin: rp_pico:gpio8
#kill_pin: rp_pico:gpio6

[display_data static_text_grp static_text1]
position: 1,1
text: 01234

I tried to reduce the outputs that should been printed out to the display by setting a custom defined text group, that just prints out 01234. Or at least I think i’ve done that.

Can someone confirm that this configuration should print out 01234 on the second line, beginning at the second column?

The wiring is correct, I confirmed that by programming the pi pico from my desktop machine using the same gpios, and its working.

When I use the klipper firmware for RPI pico and configure it like shown above, i got the following output on the display.

If i’m not using my static_text_grp i got a very similar behaviour, a few characters shown on the display were correct, but other were just some jibber.

Any idea, what do to further investigate whats going on?

A logic analyzer is connected to the pins so i can show the signals on the pins of the HD44780 if anyone need them.

Kind Regards,
Sebastian

I finally got the Display working on the RP2040.

I report back with more details when I finished my tests.

Basically in my constellation the LCD2004A that I used needed much lower frequencies.

If this is caused trough the TSX108 Level converter I use, needs to be tested.

I’ll report back with more details.

Here now the patch for using the LCD2004A with an TXS0108E on the RPi Pico:

diff --git a/src/lcd_hd44780.c b/src/lcd_hd44780.c
index 0afca915..bd142d58 100644
--- a/src/lcd_hd44780.c
+++ b/src/lcd_hd44780.c
@@ -45,7 +45,6 @@ static __always_inline void
 hd44780_xmit_bits(uint8_t toggle, struct gpio_out e, struct gpio_out d4
                   , struct gpio_out d5, struct gpio_out d6, struct gpio_out d7)
 {
-    gpio_out_toggle(e);
     if (toggle & 0x10)
         gpio_out_toggle(d4);
     if (toggle & 0x20)
@@ -54,8 +53,14 @@ hd44780_xmit_bits(uint8_t toggle, struct gpio_out e, struct gpio_out d4
         gpio_out_toggle(d6);
     if (toggle & 0x80)
         gpio_out_toggle(d7);
-    ndelay(230);
-    gpio_out_toggle(e);
+    
+    const uint32_t delay = 12000;
+    
+    ndelay(delay);
+    gpio_out_write(e, 0);
+    ndelay(delay);
+    gpio_out_write(e, 1);
+    ndelay(delay);
 }
 
 // Transmit 8 bits to the chip
@@ -94,7 +99,7 @@ command_config_hd44780(uint32_t *args)
 {
     struct hd44780 *h = oid_alloc(args[0], command_config_hd44780, sizeof(*h));
     h->rs = gpio_out_setup(args[1], 0);
-    h->e = gpio_out_setup(args[2], 0);
+    h->e = gpio_out_setup(args[2], 1);
     h->d4 = gpio_out_setup(args[3], 0);
     h->d5 = gpio_out_setup(args[4], 0);
     h->d6 = gpio_out_setup(args[5], 0);
@@ -126,6 +131,7 @@ command_hd44780_send_cmds(uint32_t *args)
     gpio_out_write(h->rs, 0);
     uint8_t len = args[1], *cmds = command_decode_ptr(args[2]);
     hd44780_xmit(h, len, cmds);
+    ndelay(3000);
 }
 DECL_COMMAND(command_hd44780_send_cmds, "hd44780_send_cmds oid=%c cmds=%*s");
 
@@ -136,6 +142,7 @@ command_hd44780_send_data(uint32_t *args)
     gpio_out_write(h->rs, 1);
     uint8_t len = args[1], *data = command_decode_ptr(args[2]);
     hd44780_xmit(h, len, data);
+    ndelay(3000);
 }
 DECL_COMMAND(command_hd44780_send_data, "hd44780_send_data oid=%c data=%*s");

For the next I’ll try to it completly on 3.3V and if it works, i’ll report back.

I looked again at source code base and found another better solution. Instead of tweaking the MCU code, the controlling python script does now add the proper delays to the commands issued to the MCU.

I integrated that and created a PR.

See hd44780: Make delays configurable by user. by seho85 · Pull Request #5318 · Klipper3d/klipper · GitHub

Kind regards,
Sebastian