[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/session.php on line 574: sizeof(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/session.php on line 630: sizeof(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 113: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 5348: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3937)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 5348: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3937)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 5348: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3937)
Plum Geek Forum • Pi data to Arduino via SPI
Page 1 of 1

Pi data to Arduino via SPI

Posted: Sat Feb 10, 2018 2:57 am
by Kevin
Hey all. This has been mentioned a few times so I wanted to post a new thread for it.

The Pi does indeed connect directly to the Arduino via a SPI bus, and as far as I can tell, it works as expected.

We already have a SPI protocol implemented between the two devices that you can latch on to with your own code.

Here's the quick overview...

The Arduino has a SPI buffer length of 11 bytes (this is set in the Comms.h tab of Arduino). This allows for 1 "register address", 8 bytes usable for your data, 1 byte for a checksum (if you want to add it), and 1 trailing byte, which needs to be sent if you're reading the full response string as SPI clocks the outgoing bytes one behind the incoming bytes.

Look at the SPI_Handler function in the Comms tab, and see how we use it to control motors. The first byte sent in the string is intended to "key" the string to a certain behavior or handler on the other end.

We reserve the value 130 to control motors, and you shouldn't use 255 as it's a catch all needed to ignore occasional data errors from teh Pi.

On the Arduino look at SPI_BufferIn and SPI_BufferOut in the Comms tab, and look at all the SPI functions near the bottom of that tab. You should be able to add your own hooks in there for other stuff.

It's hard to process data and pack up the outgoing buffer fast enough to do on the fly, so you may want to send and query back any data in separate packets, so you have time to load up the outgoing buffer on the Arduino side before it's needed by the Pi.

To pack up a packet from the Pi to the Arduino, have a look at the motors function in the spirit_core.py.

Be careful to not flood the SPI bus with too much traffic - I think it'll work fine, but remember the Arduino needs a short time to deal with the incoming data. Maybe add some real short pauses (like maybe 100 to 500 microseconds?) between sequential SPI sends from the Pi. It may work faster, but if you're having dropped data, this may be the problem.

That's not super detailed but hopefully useful to someone.

-Kevin

Re: Pi data to Arduino via SPI

Posted: Sat Feb 10, 2018 4:24 am
by gpvillamil
How feasible is it to do what is described in this article:

https://learn.adafruit.com/program-an-a ... s/overview

Re: Pi data to Arduino via SPI

Posted: Sun Feb 11, 2018 1:32 am
by esba1ley
Again, seconded. Being able to program the Arduino from the on-board PI via SPI would be awesome. That way we could treat the Pi as a development workstation when needed -- no external computer necessary, if you plug in an HDMI cable and have a bluetooth keyboard/mouse configured to use with the Pi.

This also opens up the possibility of re-configuring the Arduino code based on a higher level decision making being done on the Pi. Say you're robot has a bunch of autonomous modes that are off-loaded to the Arduino, but you want to change the behavior based on something that the RasPi processes via the camera... you could in theory have the .hex files all pre-compiled waiting, and script avrdude to flash the arduino with the code from the main Pi as needed to "change the mode" on the arduino. This could allow for more complex mode switching, pushing the automation down into the Arduino to free the Pi to do more heavy lifting (like vision processing).

Just a thought.

-E

Re: Pi data to Arduino via SPI

Posted: Sun Feb 11, 2018 10:21 pm
by gpvillamil

Re: Pi data to Arduino via SPI

Posted: Sun Feb 11, 2018 10:51 pm
by esba1ley
FWIW, FPGAs do something similar -- they can literally reconfigure their *hardware* while running, if designed properly. Pretty cool stuff. This would open students' worlds into this concept.

-E