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. Some of the ideas I found online tended to lock up the I2C bus or cause other kinds of problems. When I stumbled onto an example using the WiringPi library things seemed to even out.
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.
[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/].
At line 8 changed 26 lines
WiringPi (both C++ and Python versions) has an I2C class to provide communication over I2C. The basic API is as follows:
{{{
class I2C(object):
def setupInterface(self,*args):
return wiringPiI2CSetupInterface(*args)
def setup(self,*args):
return wiringPiI2CSetup(*args)
def read(self,*args):
return wiringPiI2CRead(*args)
def readReg8(self,*args):
return wiringPiI2CReadReg8(*args)
def readReg16(self,*args):
return wiringPiI2CReadReg16(*args)
def write(self,*args):
return wiringPiI2CWrite(*args)
def writeReg8(self,*args):
return wiringPiI2CWriteReg8(*args)
def writeReg16(self,*args):
return wiringPiI2CWriteReg16(*args)
}}}
In particular, we can expect to be using the {{wiringPiI2CRead()}} and {{wiringPiI2CWrite()}} methods.
For documentation, see [The I2C Reference Library|http://wiringpi.com/reference/i2c-library/].
It should be noted that the I2C read and write methods send a single integer. In order to communicate
It should be noted that the I²C read and write methods send a single integer. In order to communicate
At line 13 added 2 lines
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.
At line 16 added 5 lines
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.
At line 110 added one line
* [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
At line 113 added one line
* [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 6 lines
! Arduino
* [Master Reader/Slave Sender|https://www.arduino.cc/en/Tutorial/MasterReader]
* [Master Writer/Slave Receiver|https://www.arduino.cc/en/Tutorial/MasterWriter]