I want to communicate between RPi (Master) and Arduino (Slave) using SPI and WiringPi library. I have read the following post, which talks about sending and receiving data between RPi and Arduino.
With this method, I can send and receive 1 byte of data. My question is how to send/receive "int", "float" or "string" data types? I understand that I should send the data 1 byte at a time, but I can't figure out how to decode the data.
I read the following post by Nick Gammon, to send/receive any data type. But the problem is that the wiringPi library sends the data as 1 byte, however if I want to send a pointer, like the following link, the size of pointer is 4 bytes and I get errors.
So, it looks like the 'wiringPiSPIDataRW()' function takes a unsigned integer value for spi channel, a pointer to the buffer (char *), and number of bytes to send.
You can send any type of object that way. You might need to cast the address of the array, struct, variable that you're sending as a char *. Use sizeof() to get the number of bytes to send.
You just need to receive the bytes on the Arduino side and perhaps memcpy() them into to final array, struct, variable. Make sure the size and endianness of the data are the same for both processors.