Is the UART output buffered?

I need to pull a pin up, while writing to UART, and bring it down otherwise. Is the UART buffered? If I pull a pin high, right, and bring it low again, is it going to be high while the bits are written out? If not, is there a way to do that?

The UART is buffered; the only way in the current release to do what you describe is to raise the pin, write to the UART, imp.sleep() for the right amount of time, and then lower the pin again. A future release will add blocking/flushing semantics to the UART.


Is there a magical time I can wait?

It should be something like imp.sleep(1.0/(BaudRate/8)) I believe but it may be slightly more depending on what the imp is doing (of course if there is some processing happening somewhere in the imp before this call is fired then this sleep could last too long and you may miss the beginning of your message - so its somewhat hairy)

There’s a start bit and at least one stop bit per character (depending how you configured the UART), so it’s at least imp.sleep(nchars*1.0/(BaudRate/10)). But hopefully in your application it isn’t a big problem to err slightly on the generous side?