Serial UART Communication

Posted on
  • Hello Gordon,

    I have a few questions regarding serial communication.

    Serial1.setup is not working with parity 'none'. I got the following error:

    INTERNAL ERROR: Unsupported serial parity mode.

    'even' works:


    Is null also 'none' ?

    Second question. I'm a bit confused about the UART/USART pins. What is the difference between UART and USART ?

    On the pinout reference for example "USART1 TX" is labeled on pin B06 and A09.
    Thus this mean, that i can choose which pin i would like to use ?

    Many thanks


  • Ahh - thanks. I'll change that. For now, just do parity:0 (or leave it out). parity:null works for no parity too, as you suggest.

    UART/USART are actually because of the STM32 chip that's being used. A USART has a CK (clock) pin, and a UART doesn't. There's no support for the CK pin in Espruino right now, so you can actually safely assume that both UART and USART are the same.

    And with the pins - yes, on Espruino you've usually got a choice of which pin you put which peripheral on. However you can't put rx on one pin and tx on the other - both rx and tx have to be on pins 'next' to each other - eg . use B6+B7 or A9+A10, not B6+A10

  • Many thanks Gordon.

  • this is probably a basic question:
    how do I read from Serial1 when the data that arrives is not a letter or number but for example has the value 0x08 (BS)?
    I am interfacing to a gadget that sends out bytes not text and need to take action depending on the data received.

  • I would expect it to be returned as an escaped string (ie, "\x08") - does it not do that?

  • 8-)
    even if it did, I would have no clue what to do to capture that escaped string... I am trying to learn

  • Ok, I figured out a way. There must be more elegant ways to do this, but at least now I can see what I am receiving and I can take some actions depending on the messages.

    Serial1.onData(function (e) { 
      var tr=(;
      switch (p)
        case 80 :
          var s = "CV,1.6A to 3A"; 
        case 96 :
          var s2 = "CV, < 1.6A"; 
        case 85 :
        default :
          var s3="*";
  • Using charCodeAt is the right way of doing it if you need a number...

  • Hello,
    I have a Espruino board v 1.3 and I'm using the SD card and Uarts 1 to 4 already but I still need to use one more uart. So my plan is to use uart5/serial5 but that shares a pin with the SD (CS) so my initial thought was to setup serial5 to different pins.

    So I tried to set up Serial5 to two of my available pins (B1 and B0) as

    but it does not seem to work.

    Do I need to recompile the firmware to assign serial5 to B1 and B0?

    Any info is appreciated.

  • That's a lotta serials...

    The allowable pins for each peripheral are determined by the chip, not the software - the UARTs and SPI's and I2C's shown on the reference are bits of silicon in the chip, and can only be connected to certain pins.

    If you need 5 serials, I'm afraid your options are to either wait for Gordon to implement software serial (this emulates serial in software, working on any pins - he's talked about doing this in other thread:­257119/?offset=25#comment11957278 ), or hack your Espruino board and get a wire onto D2. That would take out the SD card though (there are plans for a change to let you set the pins for SD card, but then you'd have to cut a trace and run another wire).

  • You do have another option, which is that if you don't need serial inputs at the same time, you can use Serial1.setup() to dynamically swap between A9/A10 and B6/B7 as you need it.

    Also, In the next few weeks I should be adding support for swapping the SD card to other pins. That means you could potentially cut the trace for D2 and then use another pin for the SD card...

    Finally you could always use an SPI/I2C USART chip, so you can add extra UARTs that way.

  • Thanks for both answers.
    Then will cut the trace for D2 so I can use it for UART5 RX

    When the new changes are done to assign the SD card pins, are there any restrictions what pin I could use for the SD CS, for example can I use B0 ?


  • When changing the SD card pins is done, you should be able to use any pin for CS. The only restriction would be on using a hardware SPI port (although that may change at some point too).

  • thank you for your explanation.

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

Serial UART Communication

Posted by Avatar for Sacha @Sacha