After the SPI settings are completed, communication is possible. In Master mode, you are master and can send data at any time you like. You will not receive data without doing anything. With SPI, it receives as much data as it transmits. In other words, SPI is a communication method that "exchange data".
Use spi.writeWait() to send data. Set an array of data. In the example below, three bytes of [0x01, 0x02, 0x03] are transmitted. Then, the three bytes received from the other party will be the return value. The length of transmitted data and the one of received data are always same.
Like UART, SPI can communicate even if there is no actual partner. It will send data successfully and receive data that has the same length as the transmitted data, but the data received will be meaningless.
The amount of data sent at a time depends on the version of obnizOS or obniz.js. Normally, it is 1KByte.
Sending not need receiving data
spi.writeWait() sends data and waits until receiving data. In case received data is not needed, such as when the connection destination is a display, use spi.write().
The write() function sends data from MOSI like the writeWait() function, but ignores any data coming from MISO. A large amount of data or continuous data can be sent with the SPI of the device via the Internet, because it does not