HD44780 Problems

Posted on
  • Hi,

    I used Espruino a while ago and had both mt STMVL and STM32F4 boards happily driving a 16x2 LCD display in 4 bit mode.

    I have since updated to the latest version and started to use the WebIDE. No matter what I try I cannot get any output on the LCD.

    I have tried different pin combinations and even different LCD modules. The LCD modules work fine on my Raspberry Pi but for the life of me I cannot get them to work as set out in the examples..

    var lcd = require("HD44780").connect(A0,A1,C0,C1,C­2,C3);
    lcd.print("Hello World");
    

    Can anyone shed any light?

    Cheers

    Dan

  • Hi Dan, that's a bit strange... I have tested the module not that long ago at all (and it's only using simple GPIO), so I'd be pretty sure it works.

    Does the display show the usual solid bar of pixels? If not, it could be you're running it off 3.3v instead of VBat? Also I've found that unless I connect RW up to GND, it tends not to work.

    Finally, those pins are the ones for the Espruino board. A0 is shared with BTN1 on those 2 boards and might be causing you problems - the others might be shared too. Check out your boards at the top of http://www.espruino.com/Reference to see what's free.

  • Hi Gordon,

    Yes it displays a solid bar on one line on a 2 line display. Its definitely hooked up to the +5v on the STM32F4 board and RW is connected to ground.

    I have tried other pin combinations already with no success at all. All that seems to happen is the solid bar of pixels dims ever so slightly when the code has been run which happens whatever pins I choose.

    Ill double check everything again.

    Thanks for your help.

    Regards

    Dan

  • The dimming sounds odd - like there's a bad electrical connection. The only thing that should change how dim those pixels are is the voltage on VCC and the Contrast wires.

  • Hi Gordon, Dan ... Encountering exact same symptoms here, STM32F4Discovery board, (A0,A1,C0,C1,C2,C3 wiring) ... including the 'ever so slight' dimming on running the code. A DS18B20 on A2 runs perfectly. Have double-checked wiring, tried 1.62 and 1.63 . Changed 'rs' from A0 to A3 in case it was a button conflict, but no joy. Just a single bar of blank chars ... Any ideas?
    Cheers, Jon

  • @RFPlus I'm not sure what to suggest apart from re-checking the wiring and making sure that RW is grounded.

    The display doesn't use any special hardware, it's just simple IO - so if OneWire works, it should definitely go.

    If you find out what the problem is, can you let us know? It might be something confusing in the documentation...

  • Thanks, Gordon ... I'll try to track it down. I've tried another display and rewired. Tested each path end-to-end with a conductivity tester. Pulsed all pins using digitalWrite() and these appear on the LCD connector, according to my trusty HP545A probe. No shorts between pins, RW grounded. So electrically it appears sound. Now I'd like to understand which code is being called. There seem to be several functions in code/lcd.js .. is there any documentation on how/what is called? And could I try driving the display directly, using digitalWrite() for example, to troubleshoot this? ... Cheers, Jon

  • Actually the code/lcd.js file is misleading - I should really remove all of those from the repo.

    The module that's loaded is: http://www.espruino.com/modules/HD44780.­js (or syntax highlighted)

    The code's really quite basic, so you could copy it out and try it line by line if you wanted.

  • I think I've understood the problem ... it's a speed/timing issue. Maybe my LCDs are running a little slow, certainly the processor at 168MHz is fast. I started getting a response from the LCD when I built a small init routine in the IDE.

    After some playing I moved the HD44780.js module into the IDE right-hand pane and it worked(!) essentially unmodified. However, after a save() and restart, the display corrupted. I think it's because the timing on the write() routine is too quick for the LCD interface when it's minified. I changed the digitalWrite() to digitalPulse() on the 'en' line and it now works fairly reliably, even standalone after a save().

    It's a hack ... that it works at all is probably coincidental. There's work to be done on ensuring the timing constraints on the HD44780 are always met, regardless of processor speed.

    var exports={};
    function HD44780J(write) {
      // initialise
      write(0x33,1);
      write(0x32,1);
      write(0x28,1);
      write(0x0C,1);
      write(0x06,1);
      write(0x01,1);
      // add functions
      return {
        write : write,
        // clear screen
        clear : function() { write(0x01,1); },
        // print text
        print : function(str) {
          for (var i=0;i<str.length;i++)
            write(str.charCodeAt(i));
        },
        // set cursor pos, top left = 0,0
        setCursor : function(x,y) { var l=[0x00,0x40,0x14,0x54];write(0x80|(l[y]­+x),1); }
      };
    }
    
    
    exports.connect = function(_rs,_en,_d4,_d5,_d6,_d7)  {
      var data = [_d7,_d6,_d5,_d4];
      var rs = _rs;
      var en = _en;
      digitalWrite(rs, 1);
      digitalWrite([rs,en], 0);
      var write = function(x, c) 
        {
        digitalWrite(rs, !c);
        digitalWrite(data, x>>4);
    //    digitalWrite(en, 1);     Original pulse
    //    digitalWrite(en, 0);
        digitalPulse(en,1,1);    // 1ms timed pulse
        digitalPulse(en,1,0);    // wait for pulse end
        digitalWrite(data, x);
    //    digitalWrite(en, 1);       Original  pulse
    //    digitalWrite(en, 0);
        digitalPulse(en,1,1);     // 1ms timed pulse
        digitalPulse(en,1,0);    // wait for pulse end
        };
      return new HD44780J(write);
      };
    
    var lcd;
    var sensor;
    
    setInterval(function()  {
      //lcd.clear();
      lcd.setCursor(7,1);
      lcd.print(" "+sensor.getTemp());
      }, 1000);
    
    function onInit()  {
      // Set up display and sensor
      lcd = exports.connect(A3,A1,C0,C1,C2,C3);
      lcd.clear();
      lcd.setCursor(1,1);
      lcd.print("Temp =");
      lcd.setCursor(14,1);
      lcd.print("C");
      lcd.setCursor(0,0);
      lcd.print("* RFPlus  2014 *");
        
      var ow = new OneWire(A2);
      sensor = require("DS18B20").connect(ow);
      sensor.setRes(10);  // 10 bit mode
      }
    
    
    onInit();
    
  • That's great - thanks for all the debugging work!

    When JavaScript code isn't minified, it runs more slowly - so that explains how the HD44780 starts working I guess! I'll have a look at the driver, but your digitalPulse solution seems pretty good.

    For now, anyone having this problem could change the 'Module Extensionsitem in the Web IDE settings from.min.js|.jsto.js|.min.js`. That'll then load in unminified modules, which should be slow enough to make the LCD start working.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

HD44780 Problems

Posted by Avatar for danhans42 @danhans42

Actions