2019-12-02 05:58:26 +01:00
# read Buffer
Read available serial data into a buffer.
```sig
serial.readBuffer(64);
```
## Parameters
* **length**: the [number ](/types/number ) of characters of serial data to read.
2022-08-10 18:36:19 +02:00
Use ``0`` to return the available buffered data.
2019-12-02 05:58:26 +01:00
## Returns
* a [buffer ](/types/buffer ) containing input from the serial port. The length of the buffer may be smaller than the requested length.
2022-08-10 18:36:19 +02:00
The length is 0 if any error occurs.
2019-12-02 05:58:26 +01:00
## ~hint
**Pause for more data**
If the desired number of characters are available, **readBuffer** returns a buffer with the expected size. If not, the calling fiber (the part of your program calling the **readBuffer** function) sleeps until the desired number of characters are finally read into the buffer.
2022-08-10 18:36:19 +02:00
To avoid waiting for data, set the length to ``0`` so that buffered data is returned immediately.
2019-12-02 05:58:26 +01:00
## ~
## Example
Read character data from the serial port one row at a time. Write the rows to an LED display connected to the I2C pins.
```typescript
2022-08-10 18:36:19 +02:00
serial.setRxBufferSize(10)
2019-12-02 05:58:26 +01:00
for (let i = 0; i < 24 ; i + + ) {
2022-08-10 18:36:19 +02:00
let rowData = serial.readBuffer(10);
2019-12-02 05:58:26 +01:00
pins.i2cWriteBuffer(65, rowData, false);
}
```
2022-08-10 18:36:19 +02:00
## Example Async
Read available data and process it as it comes.
```typescript
basic.forever(function() {
let rowData = serial.readBuffer(0);
if (rowData.length > 0) {
// do something!!!
}
})
```
2019-12-02 05:58:26 +01:00
## See Also
[write buffer ](/reference/serial/write-buffer )