Skip to main content


Sends data to the SPI port




Name Type Description
data String or blob The data to write to the bus


Integer — the number of bytes written to the SPI bus


This method writes the specified data to the target SPI bus and returns the number of bytes written.

Any data arriving on MISO while writing is taking place is ignored.

After writing, MOSI is held at the level of the last transmitted bit.

Example Code

The following code shows you how to write to an 8-bit shift register — a 74HC595 — via SPI. Note that this implementation also uses two GPIO pins: the first, pin 8, is used for Slave Select and the second, pin 1, to reset the SPI device.