You are reading a single comment by @Owen and its replies. Click here to read the full conversation.
  • Hi Gordon,
    I understand the idea but can't get it to work. It is outputting mostly random colours and the idx.length looks too small. My guess is it's receiving the data but doesn't know where the frame begins or perhaps the frame break "\1" is being included in the output.
    I've tweaked your code a bit to get it working but with the problems above.
    PS. I've been running this code on both the Pico and orgional Espruino with the same results on both.

    /**
    Glediator settings
    Driver: Glediator
    Baud 115200
    Colour order: GRB
    Pixel order:  HS_TL
    */
    var fps = 0,
        buf = new Uint8Array(15*15*3),
        bufIdx = 0,
        cmd = "";
    
    function onInit() {
      SPI1.setup({baud:3200000, mosi:A7});
      
      Serial1.setup(115200, {tx:B6,rx:B7});
      Serial1.on('data', function (data) {
        
        buf.set(data, bufIdx);
        bufIdx += data.length;
        
        if (data.indexOf("\1") >= 0) {
          var idx = bufIdx + data.indexOf("\1");
          var line = new Uint8Array(buf.buffer, 0, idx);
          console.log(idx);
          
          SPI1.send4bit(line, 0b0001, 0b0011);
          buf.set(new Uint8Array(buf.buffer, idx, bufIdx-idx), 0);
          bufIdx -= idx;
          fps++;
        }
      });
        
      var fps = setInterval(function() {
        console.log('fps: ' + fps);
        fps = 0;
      }, 1000);
    }
    
    onInit();
    

    This outputs the following:

      594  
      594  
      593  
      593  
      594  
      593  
      594  
      594  
      594  
      594  
      594  
      593  
      fps: 12  
      593  
      594  
      593  
      593  
      593  
      594  
      593  
      594  
      593  
      593  
      594  
      fps: 11  
    
About

Avatar for Owen @Owen started