Hello fellow creators,
as this is my first time posting please point out any missing information, I'd be glad to give information wherever I can.
I have been working on a Data-Transfer project lately with the following setup:
PC <- Raspberry Pi <- Master Arduino (nano, 1 piece) <- Slave Arduinos (nano, 4 pieces) <- Capacitive Sensors (7 Pieces per Slave, 28 total)
The reason why I use an Arduino as a master is because I want to later Expand this setup and occupy all usb slots on the rpi without significant loss of transfer speeds.
The slaves should gather relevant Data (with the help of the capsense library) and send that Data directly to the master. The master on the other hand will route the data-packets over serial to a rpi, which will process that data further. The master will also append a letter to discern from what slave that data came from.
This process has to be fast and the code for the master should itterate at least 10 times a second.
The data package sent from the slaves to the master are packaged as follows:
aa and bb is used in order to check if the package is sent correctly, the values inbetween correspond to the sensor values in percent. The dash is used to later on discern from which sensor that data came from.
The Slaves are connected on digital pin 10, 11, 12 and 13 with the master. Pin 13 is used as SS.
I have attached a schematic of the Slave and Master below.
The problem I currently have with SPI is that it is in my oppinion is too unstable to call an interrupt and send an array like the one mentioned above, which is why I am trying to work out a better alternative.
I have decided that a good solution would be for the slave to convert the String "aa100-100-100-100-100-100-100bb" to Bytes and send one Bit at a time with digitalWrite() and then disconnect to tell the master that the byte has been transferred. The Master should listen to the incoming traffic while also pulsing the slave to act as a clock.
I have included all codes of both the master and the slave below.
When telling the master to listen to a slave however I get something lie this:
Converted to Ascii this gives aa0-1Ï1¦ à0Ä00íó00Ó0-0â@
indicating that probably only the first two bytes were correctly transferred.
I suspect that this may be because of clock differences between the arduinos, but I am not sure how to solve this. I have tried out different microsecond delays and some seem to work better than others, but when changing the overall length of the sent string the previously used delays are now useless.
I'd really appreciate any input as I am eager to better myself in this topic.
Also I feel like I've just reinvented the wheel
Master.ino (898 Bytes)
Slave.ino (1.23 KB)