Skip to main content

spi.write(data)

Sends data to the SPI port

Availability

Device

Parameters

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

Returns

Integer — the number of bytes written to the SPI bus

Description

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.