You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • It means that Espruino isn't able to process the data that's coming in fast enough, and it's had to drop some of it.

    Your best bet would be to reduce the Serial baud rate from 1000000 to something a bit slower - then Espruino should be able to deal with the data as it comes in.

    If you need that baus rate you might also be able to reduce the amount of characters you check for \1 (for instance you could check data rather than cmd) - if you've got 15*15*3=675 bytes, repeatedly scanning it for \1 will probably take a while.

    Potentially you could also dump that into an array rather than appending to a string...

    var buf = new Uint8Array(1000);
    var bufIdx = 0;
    
      Serial1.on('data', function (data) {
        buf.set(data, bufIdx);
        var idx = bufIdx+data.indexOf("\1");
        bufIdx += data.length;
        if (idx>=0) {
          var line = new Uint8Array(buf.buffer, 0, idx);
          console.log(idx);
          SPI2.send4bit(line, 0b0001, 0b0011);
          buf.set(new Uint8Array(buf.buffer, idx, bufIdx-idx), 0);
          bufIdx -= idx;
        }
      });
    

    Not tested, but something like that might be quicker.

About

Avatar for Gordon @Gordon started