• Using software serial moved me ahead a bit and may even be the solution...

    Minimal change of the routine I had for hardware serial:

    function receiveSOD() {
      var errs = true
        , serial = Serial1
        ;
      serial = new Serial();
      serial.setup(316, {rx:SOD, tx:SID, parity:"o", errors:errs });
      serial.on('data', function (data) { print(data); });
      if (errs) {
        serial.on('parity',  ()=>console.log('P'));
        serial.on('framing', ()=>console.log('F'));
      }
    }
    

    Console output for 0x0E byte sequence of:

    Byte# 0x## 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E
    Value 0x##: 00 01 02 04 08 10 20 40 80 FF 00 0F F0 55 AA
    VALUE dec.: 0 1 2 4 8 16 32 64 128 255 0 15 240 85 170

    var t=`
    >
    
    
    
    
     
    @
    
    ÿ
    
    ð
    U
    ª
    ü
    >
    `;
    

    With ü as being the CRC / checksum.

    Creating a version that prints the data in decimal to show non-printable
    characters - changing print(data); to print(data.charCodeAt(0)); -
    shows the expected (values in) console:

    var t=`
    >
    
    0
    1
    2
    4
    8
    16
    32
    64
    128
    255
    0
    15
    240
    85
    170
    252
    >
    `;
    

    But as @Gordon pointed out in USART / UART / Serial Port for software serial, there is not much processing cycles left for other things while communication is going on, such as my attempt to print the received data in hex using my generic approach, which also can handle reception of more than one byte at a time. Here the changes and the versatile (hex) output creation (complete, runnable code to load):

    // wire connections (in code use ums view names)
    //  ums=pico view | ums view || ums              pico
    var SOD=B7   // I | SOD   O  || serial output on USART1 SERIAL1 RX (B7) I
      , SID=B6   // O | SID   I  || serial input  on USART1 SERIAL1 TX (B6) O
      ;
    
    function setPinModes() {
      //      ums - pico view
      pinMode(SID,"output");
      pinMode(SOD,"input");
    }
    
    function hex(v) { return ((v>15) ?
      hex(v>>4) : "")+"0123456789ABCDEF".charAt(v&15); } // hex...
    function hep(v,ds) { // hex, digits (w/ blank padding up to ds)
      return ("        "+hex(v)).substr(-ds); }
    function lep(v,ds) { // hex, digits (w/ 0 padded up to ds)
      return ("00000000"+hex(v)).substr(-ds); }
    
    function receiveSOD() {
      var errs = true
        , serial = Serial1
        , opt
        ;
      serial = new Serial();
      serial.setup(316, {rx:SOD, tx:SID, parity:"o", errors:errs });
      opt = // 0 // 0 or any: just print as received (as initialy)
            // 1 // most unasumptional, flexibel hex output
            // 2 // assuming 1 byte at a time reception hex output
               3 // assuming 1 byte at a time charCode (dec) output
               ;
      serial.on('data'
        , (opt==1) ? (function(data){ 
           for (i=0; i++; i<data.length)
             print(lep(data.charCodeAt(i),2)); } )
        : (opt==2) ? (function(data){ 
             print(lep(data.charCodeAt(0),2)); } )
        : (opt==3) ? (function(data){ 
             print(data.charCodeAt(0)); } )
        : (function(data){ print(data); }) );
      if (errs) {
        serial.on('parity',  ()=>console.log('P'));
        serial.on('framing', ()=>console.log('F'));
      }
    }
    function onInit() {
      setPinModes();
      receiveSOD();
    }
    
    setTimeout(onInit,999); // dev only; remove before upload for save()
    

    With output option 1, the console output was absent... (a simpler implementation for 2-digit hex output may have worked, but was not done and tried).

    For that reason, I built a buffering into/around the code with a routine for visualization of the buffer... shown in a next post, including the Espruino js Bitbanging solution (not using any appliances (except the timer/interrupts... as is used by setWatch, setTimeout, setInterval for that purpose).

About

Avatar for allObjects @allObjects started