[last updated: 2025-11-11]
i2c on DigiSpark
i2c on rPi for GMC
SPI vs. i2c
i2c: minimum code
Programming Wire.h library commands:
-----
- i2C (Inter-Integrated Circuit) is a protocol for serial communication.
It is usually used between components in an embedded system (which already share power and ground lines).
In such a system, it only requires 2 signal lines
(if it is not being used in an "embedded" system, then at least the ground lines must be connected between master and slave):
- SCL = serial Clock (usu pin A5)
- SDA = serial Data (usu pin A4)
- SDA & SCL lines need pullup resistors,
however the Wire.h library enables the Arduino's internal pullups
when initializing with Wire.begin().
- Two or more nodes communicate according to:
- one master
(however there are ways to use more than one master - see details later)
- one or more slaves
- Range is probably 1 - 3 meters.
- researching this subject on the net reveals lots of different opinions:
- The answer apparently depends mostly on capacitance between the wires.
- There are reports of achieving 25m or even more.
- At some point I'll just get some longer wires and test it myself...
- Most common library is built-in Wire.h
- Programming Wire:
--------------------------------------
Projects:
------------------------------
i2c on rPi:
had to do several things to get this to work:
- $ sudo nano /etc/modprobe.d/raspi-blacklist.conf
make sure that this file does not contain a line like this:
blacklist i2c-bcm2708
if it does, "comment it out" by putting a hash ("#") in front of it:
#blacklist i2c-bcm2708
- $ sudo nano /etc/modules
make sure this file contains the line:
i2c-dev
- $ sudo apt-get install i2c-tools
$ sudo apt-get install python3-smbus
$ sudo adduser [userName] i2c
- $ sudo nano /boot/config.txt
however in my newest version, the config.txt files is moved to /boot/firmware
add this line, or uncomment it (remove leading "#") if it is already there
dtparam=i2c_vc=on
- reboot
- $ i2cdetect -y 1
original instructions were to use ... - y 0
however this failed for /dev/i2c-0 no such file
ls /dev showed that there was however a /dev/i2c-1, so that's the command parameter I used
this worked. A table was printed that showed the address (48 in my case) of the i2c device that was connected
------------------------------
Links:
.
.
.
eof