[Dprglist] Raspberry Pi Master to Arduino Slave (pimaster2ardslave)

Chris N netterchris at gmail.com
Sun May 10 08:47:24 PDT 2020


Thanks for sharing your Pi to Arduino code.    This is of interest to me
because I'm doing something quite similar.

Ever since I started playing around with Lidar, and thus have outgrown my
Atmega1280P (Pololu Orangutan 1280p board), I have been looking at ways to
pair up a Raspberry Pi with "something else" that takes care of all the
bit-banging and low-level stuff.

Over the years I have explored a number of options, including of course the
obvious options such as UART, I2C and SPI.    They all have some gotchas,
and most of those gotchas stem from the fact that the Pi is so much faster
than the AVR.

*UART & SPI:  *
As long as the bitrate is kept low enough, this will  work fine.  The AVR
does not have any FIFO, so operating the UART or SPI at around 1Mbit/second
would probably be tough to get working reliably because that results in an
interrupt every 10microseconds or so.   100Kbits/sec on the other hand is
not be an issue.   Its been a while since I have checked, but I don't think
the SPI port on the Pi can even go below a certain speed - i.e. I don't
think its possible to run the SPI port on the Pi at 100 or 200 Khz.    If
you run the SPI port very fast, you run the risk of loosing data on the
other end due to lack of FIFO.

*I2C:*
Need to watch out for that infamous Pi I2C hardware bug.   *Murray - Since
you implemented your own I2C based mechanism you may want to look into
this.*   See links below.
I'm not 100% sure if this bug still applies to the Pi 4, but from what I
have read, it does seem to.
I2C  is what I'm current using actually.   Pololu has a few boards that are
designed to be mated up with a Pi.  One of them is the Romi controller
<https://www.pololu.com/product/3544> that goes with their Romi chassis.
Pololu has created a Python  library for the Pi and they have provided the
code that runs on the Atmega.  See link below.  Their implementation
specifically takes the Pi I2c bug and the slowness of the Atmega into
account.  As a result, the performance that can be achieved is limited to
much less than the raw I2C bitrate of 100Khz.


*Pi clock-stretching bug:*
https://www.advamation.com/knowhow/raspberrypi/rpi-i2c-bug.html

*Another good article about Pi and I2C:*
https://www.recantha.co.uk/blog/?p=19880

*Pololu's library for Pi to Arduino comms via I2c:*
https://github.com/pololu/pololu-rpi-slave-arduino-library


Chris N.

On Sat, May 9, 2020 at 5:13 AM Murray Altheim via DPRGlist <
dprglist at lists.dprg.org> wrote:

> Bit busy, been raining here.
>
> Just a note to say that with my most recent code revision the project at
>
>      Raspberry Pi Master to Arduino Slave (pimaster2ardslave)
>      https://github.com/ifurusato/pimaster2ardslave
>
> is functional and now has three working tests:
>
>    * test_echo.py:  this tests that the Raspberry Pi and Arduino can
>      talk to each other, and doesn't require any sensors or additional
>      hardware other than the I²C between the two boards.
>    * test_blink.py:  this test blinks an LED connected to pin 5 of the
>      Arduino. This requires a Raspberry Pi connected to an Arduino
>      over I²C on address 0x08.
>    * test_config.py:  this tests a hardware configuration of one button,
>      one LED, two digital and one analog infrared sensors, first
>      configuring the Arduino and then performing a communications loop.
>
> I've also posted a "technology preview" (not yet complete) of the Robot
> Operating System (ROS) in Python 3 to:
>
>      A Python-based Robot Operating System (ROS)
>      https://github.com/ifurusato/ros
>
> and a new blog entry on Mecanum wheels to:
>
>      We’re Goin’ Mecanum!
>      https://robots.org.nz/2020/05/09/goin-mecanum/
>
> If anyone is an expert on Mecanum wheels, the post includes a schematic
> diagram ("Plan 1") for a new robot and I'd dearly like a review, i.e.,
> does it makes sense in terms of placement of the wheels? I.e., should the
> wheel centers be on the circumference of a circle or does that really
> matter? Any comments or suggestions very welcome.
>
> Cheers,
>
> Murray
>
> On 7/05/20 4:30 pm, Murray Altheim via DPRGlist wrote:
> > Hello all,
> >
> > As discussed in the last Robot Builders Night Virtual, I've been working
> on
> > a project to communicate between a Raspberry Pi as master (in Python)
> and an
> > Arduino slave. This uses a two byte call and response pattern over I2C so
> > its performance seems pretty good (and it's relatively simple).
>
> ...........................................................................
> Murray Altheim <murray18 at altheim dot com>                       = =  ===
> http://www.altheim.com/murray/                                     ===
> ===
>                                                                     = =
> ===
>      In the evening
>      The rice leaves in the garden
>      Rustle in the autumn wind
>      That blows through my reed hut.
>             -- Minamoto no Tsunenobu
>
> _______________________________________________
> DPRGlist mailing list
> DPRGlist at lists.dprg.org
> http://lists.dprg.org/listinfo.cgi/dprglist-dprg.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.dprg.org/pipermail/dprglist-dprg.org/attachments/20200510/7f0da403/attachment-0001.html>


More information about the DPRGlist mailing list