This page (revision-10) was last changed on 2021-06-19 07:56 by Murray Altheim

This page was created on 2020-04-30 09:37 by Murray Altheim

Only authorized users are allowed to rename pages.

Only authorized users are allowed to delete pages.

Page revision history

Version Date Modified Size Author Changes ... Change note
10 2021-06-19 07:56 5 KB Murray Altheim to previous
9 2020-05-25 07:26 5 KB Murray Altheim to previous | to last
8 2020-05-24 09:48 5 KB Murray Altheim to previous | to last
7 2020-04-30 11:06 5 KB Murray Altheim to previous | to last
6 2020-04-30 10:34 4 KB Murray Altheim to previous | to last
5 2020-04-30 10:33 4 KB Murray Altheim to previous | to last
4 2020-04-30 10:24 4 KB Murray Altheim to previous | to last
3 2020-04-30 10:13 3 KB Murray Altheim to previous | to last
2 2020-04-30 10:06 3 KB Murray Altheim to previous | to last
1 2020-04-30 09:37 2 KB Murray Altheim to last

Page References

Incoming links Outgoing links

Version management

Difference between version and

At line 1 changed one line
This page describes experiments in communicating between a [Raspberry Pi] (as a master) and an [Arduino] (as a slave) over [I2C]. The Raspberry Pi is programmed in [Python], the Arduino using a sketch (the Arduino's own language).
This page describes experiments in communicating between a [Raspberry Pi] (as a master) and an [Arduino] (as a slave) over [I²C]. The Raspberry Pi is programmed in [Python], the Arduino using a sketch (the Arduino's own language).
At line 3 changed one line
I based this experiment on an article found on ''The Robotics Back-End'' (see References below), but have modified it to use Python rather than C on the Raspberry Pi, since that's the main language I've been using to write the operating system of the [KR01] robot.
I based this experiment on an article found on ''The Robotics Back-End'' (see References below), but have modified it to use Python rather than C on the Raspberry Pi, since that's the main language I've been using to write the operating system of the [KR01] robot. Some of the ideas I found online tended to lock up the I²C bus or cause other kinds of problems. When I stumbled onto an example using the WiringPi library things seemed to even out.
At line 6 changed one line
[WiringPi-Python|https://github.com/WiringPi/WiringPi-Python] library. This can be installed via:
[WiringPi-Python|https://github.com/WiringPi/WiringPi-Python] library. In particular, I tried using the {{wiringPiI2CRead()}} and {{wiringPiI2CWrite()}} methods. For documentation, see [The I²C Reference Library|http://wiringpi.com/reference/i2c-library/].
It should be noted that the I²C read and write methods send a single integer. In order to communicate
strings or other data, you'll need to serialise the data and then deserialise it on the other end.
For an example, see: [How do I serialize a Python dictionary into a string, and then back to a dictionary?|https://stackoverflow.com/questions/4342176/how-do-i-serialize-a-python-dictionary-into-a-string-and-then-back-to-a-diction]
In the end I developed a solution called __[pimaster2ardslave|https://github.com/ifurusato/pimaster2ardslave]__ that has been posted as a project on github, which includes a Raspberry Pi Python 3 script
and an Arduino sketch.
I found to my consternation that the ''Arduino Nano BLE Sense'' that I bought for the purpose of being used as
the slave processor __can't be used as a slave__: the Wire library it uses hasn't implemented the I²C slave protocol, though this is not documented anywhere (I found this out on the Arduino forum). One of the benefits of the Nano BLE Sense was that it's a 3.3V device, whereas the regular Nano is 5V. I'm still searching for the right
[Arduino] board now... (😠) maybe I'll use a Teensy or an Adafruit board.
!! Raspberry Pi Installation
WiringPi for Python can be installed via:
At line 28 added 3 lines
!! Arduino Installation
At line 103 added one line
* [WiringPi|http://wiringpi.com/] (C++ library)
At line 110 added 4 lines
* [Using I2C to connect two Arduino Nanos|https://sandervandevelde.wordpress.com/2015/10/13/using-i2c-to-connect-two-arduino-nanos/], blog post by Sander van de Velde
* [i2c SLAVE|https://github.com/adafruit/circuitpython/issues/437] on Adafruit's CircuitPython forum
* [Raspberry Pi - Arduino Serial Communication|https://www.instructables.com/id/Raspberry-Pi-Arduino-Serial-Communication/]
* [Raspberry Pi (master) Arduino (slave) I2C communication with WiringPi|https://roboticsbackend.com/raspberry-pi-master-arduino-slave-i2c-communication-with-wiringpi/], from ''[The Robotics Back-End|https://roboticsbackend.com/]'' ("Program Robots Like a Boss")
At line 115 added one line
! Arduino
At line 117 added 2 lines
* [Master Reader/Slave Sender|https://www.arduino.cc/en/Tutorial/MasterReader]
* [Master Writer/Slave Receiver|https://www.arduino.cc/en/Tutorial/MasterWriter]
At line 120 added one line