

Raspberry PI Multiple I2C Devices
source link: https://www.instructables.com/Raspberry-PI-Multiple-I2c-Devices/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Step 2: Case One: I2c Devices Have the Same Address
This was always the problematic case. An i2c bus can handle multiple devices, but they should have different i2c addresses. Some i2c devices have jumpers to set other i2c addresses, but many don't. In this case you may use a i2c multiplexer (hardware) to rotate the i2c SDA (Data) and SCL (Clock) or you can create an additional i2c bus or more.
I will create two aditional busses, nl bus 3 and 4
Open the cli and run
cd /boot
sudo nano config.txt
Add the following line of code, preferable in the section where spi and i2c is enabled.
dtoverlay=i2c-gpio,bus=4,i2c_gpio_delay_us=1,i2c_gpio_sda=23,i2c_gpio_scl=24
This line will create an aditional i2c bus (bus 4) on GPIO 23 as SDA and GPIO 24 as SCL (GPIO 23 and 24 is defaults)
Also add the following line to create i2c bus 3
dtoverlay=i2c-gpio,bus=3,i2c_gpio_delay_us=1,i2c_gpio_sda=17,i2c_gpio_scl=27
GPIO 17 will be the SDA and GPIO 27 will be the SCL for i2c bus 4.
Tipe control X to exit.
Note on the Bus Numbering and order:
Never use bus 0 and 2, it is use for other things in the board like eprom on hats etc
For the April 2019 raspbian release:
You should always start with the highest bus (Bus 4 in this case) in your config.txt and work through to the lowest bus (bus 3).
The lowest bus must always be bus 3
If you need 5 extra busses, the busses must bi in the order of 7,6, 5, 4, 3
This issue on bus order was not there when this Instructable was originally written. It seems like changes was made to the kernel.
Shut down your PI, switch it of. Connect your i2c devices to bus 4 (SDA to GPIO 23 and SCL to GPIO 24) and the other to i2c bus 3 (SDA to GPIO 17 and SCL to GPIO 27).
Switch on the pi.
sudo i2cdetect -l (Lower Case L)
You will now see that i2c bus 3 and 4 is also listed. Also run:
sudo i2cdetect -y 3
sudo i2cdetect -y 4
Now you can use your sensor in your programming language. Remember to specify the correct i2c busses.
Attach is an example for the popular BMP280 Temperature and Pressure sensor. No multiplexer can read 2 BMP280s this fast.
An example of 2 Sensirion SDP 810 sensors is also attach. Again working much faster than the multiplexer I used in the past
I created python code to read two new BMP388s from adafruit.
I may also add other sensors in future to https://github.com/JJSlabbert/Raspberry_PI_i2C_conficts
Recommend
-
25
作为I2C从机程序,关键变量aReceiveBuffer以及关键常量I2C0_SLAVE_ADDRESS7,第一个是I2C设备寄存器内容,第二个是I2C地址. 当上位机读写寄存器时候,实际上读写的是aReceiveBuffer的内容,除了0x00这个之外,其他全部可以读写.算是比...
-
16
I2C is perhaps the most commonly used bus to connect ICs together. As such, firmware engineers encounter it on most projects. In this post, we explain how I2C works, explore common bugs and investigate how to debug these...
-
14
rayjoh Posts:
-
19
Arduino : howto master to master I2C twi multi-master master...
-
9
Microchip MCP23008 : multiplexage 8-bits I2C atmega328 arduino i2c...
-
5
【.NET 与树莓派】i2c(IIC)通信 i2c(或IIC)协议使用两根线进行通信(不包括电源正负...
-
9
ESP32 連接 I2C 裝置-黑暗執行緒昨天介紹完可以用 C# 寫 ESP32 開發板程式的美妙開源平台 - nanoFramework,我迫不及待想把先前 Arduino C++ 寫的作品移植過來,但光是想接 I2C OLED 顯示...
-
10
OLED 顯示器 I2C vs SPI 效能評測-黑暗執行緒前陣子買了 Arduino/ESP 用的 TFT 彩色螢幕時,發現通訊介面清一色都是 SPI,不像之前買的 0.96" 128x64 單色 OLED 有 I2...
-
8
Connecting I2C Devices to the BBC micro:bit September 18, 2017 • APDS-9960 •...
-
3
i2c scan · GitHub Instantly share code, notes, and snippets.
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK