• I have determined what needs to be done to make the PCD8544 display actually work, and not cut off the first two bytes: every line needs the extra two bytes on the end, otherwise the display gets confused (I have no idea why - It doesn't look like it should be necessary from the datasheet...). The extra two bytes on the last line overwrite the first two bytes of the first line. Hence, the last two bytes need to be set to the first two bytes of line one.

    This sounds easy enough, but my code isn't working:

      LCD.flip = function () {
        for (var i=0;i<6;i++) {
          digitalWrite(dc,0); // cmd
          spi.send(0x40|i, ce); // Y addr
          spi.send(0x80, ce); // X addr
          digitalWrite(dc,1); // data
          if (i==5) {
            var last=new Uint8Array(this.buffer,i*84,84+2);
            console.log(this.buffer[0]);
            console.log(this.buffer[1]);
            last[84]=this.buffer[0];
            console.log(last[84]);
            last[85]=this.buffer[1];
            console.log(last[85]);
            console.log(last);
            spi.send(last, ce); 
          } else {
            spi.send(new Uint8Array(this.buffer,i*84,84+2), ce);
          }
        }
      };
    
    12
    130
    0
    0
    new Uint8Array([0,0,0,0,62,42,20,0,0,0,0,0,0­,0,28,34,20,0,0,0,0,0,0,0,0,62,24,62,0,0­,0,0,0,0,0,14,56,14,0,0,0,0,0,0,62,18,12­,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0­,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])­
    

    What the heck is going on there? Why aren't those values in the array being set?

    If I manually define the array I want it to be sending for the last line and send that, the screen renders correctly, with the first two bytes displayed.

    var magic=Uint8Array([0,0,0,0,62,42,20,0,0,0­,0,0,0,0,28,34,20,0,0,0,0,0,0,0,0,62,24,­62,0,0,0,0,0,0,0,14,56,14,0,0,0,0,0,0,62­,18,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0­,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0­,12,130]);
    
      LCD.flip = function () {
        for (var i=0;i<6;i++) {
          digitalWrite(dc,0); // cmd
          spi.send(0x40|i, ce); // Y addr
          spi.send(0x80, ce); // X addr
          digitalWrite(dc,1); // data
          if (i==5) {
            spi.send(magic, ce);    
          } else {
            spi.send(new Uint8Array(this.buffer,i*84,84+2), ce);
          }
        }
      };
    

    But yeah - I don't know why I can't set those values in the array....

    Using v59.

  • It's because the Uint8Array is a 'view' of the original array rather than a new array. You're trying to make it go past the end of the existing array, so if you set bytes in it they're ignored.

    I guess the best you could do is:

    var last=new Uint8Array(84+2);
    last.set(new Uint8Array(this.buffer,i*84,84+2));
    last[84]=this.buffer[0];
    last[85]=this.buffer[1];
    spi.send(last, ce); 
    

    Or, you could set CE manually, which is probably better (in fact you may not even have to bother):

    ce.reset();
    spi.send(new Uint8Array(this.buffer,i*84,84+2)); 
    spi.send(new Uint8Array(this.buffer,0,2)); 
    ce.set();
    

    Looks like this isn't 100% JS compliant though - in proper JS there seems to be a difference between:

    new Uint8Array(uint8Array,i*84,84+2) // silently ignores first and second arguments, returns a *copy* of uint8Array
    new Uint8Array(uint8Array.buffer,i*84,84+2) // does what Espruino does - creates a view
    

    I guess I should probably change the drivers over and then tweak Espruino's implementation - I prefer my version though ;)

    By the way, on my LCD it works great without the extra 2 bytes, so I wonder whether it's just some driver chips that have the issue - or maybe it's something to do with initialisation.

  • Umm... So I tried your new module - and yes, it's completely broken.

    But the code that I had before (without the extra 2 bytes at the end at all) works perfectly on software SPI. Perhaps it's actually an issue with Espruino's SPI and how quickly it raises the CE line after sending.

    Try:

      LCD.flip = function () {
        ce.reset();
        for (var i=0;i<6;i++) {
          digitalWrite(dc,0); // cmd
          spi.send(0x40|i); // Y addr
          spi.send(0x80); // X addr
          digitalWrite(dc,1); // data
          spi.send(new Uint8Array(this.buffer,i*84,84));
        }
        ce.set();
      };
    
  • Actually I could be wrong, but at least for me, this works now:

      LCD.flip = function () {
        ce.reset();
        digitalWrite(dc,0); // cmd
        spi.send([0x40,0x80]); // Y addr
        digitalWrite(dc,1); // data
        spi.send(this.buffer);
        ce.set();
      };
    
  • Actually it's a big SPI issue. I'm trying to figure out why it's happening, but it seems that it gets confused about when it's finished sending data.

  • Ok, that's now fixed in GitHub. This also explains the problems people were having with resetting the displays. I'm still not sure why I never had this issue myself :)

    Just a note about uint8arrays:

    >var a = new ArrayBuffer(10)
    >b = new Uint8Array(a)
    =[object Uint8Array]{
    0: 0,
    1: 0,
    2: 0,
    3: 0,
    4: 0,
    5: 0,
    6: 0,
    7: 0,
    8: 0,
    9: 0
    }
    >for (i in b) b[i]=i;
    > c = new Uint8Array(b,5,5)
    = [object Uint8Array]{
    0: 0,
    1: 1,
    2: 2,
    3: 3,
    4: 4,
    5: 5,
    6: 6,
    7: 7,
    8: 8,
    9: 9
    }
    > c = new Uint8Array(a,5,5)
    = [object Uint8Array]{
    0: 5,
    1: 6,
    2: 7,
    3: 8,
    4: 9
    }
    

    It's a bit crazy really.

    Graphics in Espruino uses ArrayBuffer, not Uint8Array, so actually in this case it's behaving perfectly - the only issue is that it doesn't error out when you give it range that extends past the end of the array - that that's actually pretty useful :)

  • Hi!
    Can you give me your LCD library for Nokia 5110?

    thanks

  • This is the Espruino one that seems to work pretty well at the moment?

    http://www.espruino.com/PCD8544
    http://www.espruino.com/modules/PCD8544.­js

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

PCD8544 - attempts to fix module running into strange js behavior

Posted by Avatar for DrAzzy @DrAzzy

Actions