How to set a script to run on a specific I2C bus?

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
rallydarkstrike
 
Posts: 5
Joined: Thu Nov 18, 2021 8:33 am

How to set a script to run on a specific I2C bus?

Post by rallydarkstrike »

Hi all - I have a Raspberry Pi 4 that I am trying to get an I2C info screen working according to this video:
https://www.youtube.com/watch?v=lRTQ0Ns ... ex=1&t=32s

The script is this one: https://github.com/mklements/OLED_Stats ... n/stats.py

He had a previous setup using an older Adafruit library to run the info screen and in that script there was s specific line I could state which bus to use. In his guide he uses the default I2C bus on the Pi, but on my Pi, I have a power button hooked up to the default bus and have a second bus created that is called Bus 4.

How would I go about directing the script to use that bus instead to find the screen...?

Thanks! :)


User avatar
rallydarkstrike
 
Posts: 5
Joined: Thu Nov 18, 2021 8:33 am

Re: How to set a script to run on a specific I2C bus?

Post by rallydarkstrike »

adafruit_support_carter wrote:Checkout this library:
https://github.com/adafruit/Adafruit_Py ... tended_Bus
Thanks for the reply - I'm fairly new to the Pi / Adafruit / Python, but I don't see anything at the like you provided that would tell me how to set my screen script for a different 12C bus?

User avatar
adafruit_support_carter
 
Posts: 29457
Joined: Tue Nov 29, 2016 2:45 pm

Re: How to set a script to run on a specific I2C bus?

Post by adafruit_support_carter »

Once the alternate bus is setup, you access it like this:
https://github.com/adafruit/Adafruit_Py ... est.py#L11

User avatar
rallydarkstrike
 
Posts: 5
Joined: Thu Nov 18, 2021 8:33 am

Re: How to set a script to run on a specific I2C bus?

Post by rallydarkstrike »

adafruit_support_carter wrote:Once the alternate bus is setup, you access it like this:
https://github.com/adafruit/Adafruit_Py ... est.py#L11
In the script I referenced:
https://github.com/mklements/OLED_Stats ... n/stats.py

There is the line:
i2c = board.I2C()

Are the brackets in that script where I would put bus 4 if I wanted to use bus 4?

User avatar
adafruit_support_carter
 
Posts: 29457
Joined: Tue Nov 29, 2016 2:45 pm

Re: How to set a script to run on a specific I2C bus?

Post by adafruit_support_carter »

Yes. Just like the example linked shows putting a 1 in the brackets to use bus 1. But you need to set up the bus separately, to actually have a bus 4.

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”