Need to change i2c port


#1

Hello—using Scroll PHAT hooked up works great on compute module (like an rpi3) with Stretch. Used your software examples to scroll around some messages.

However my circuit board MUST wire it to SDA0 & SCL0 (i2c0) rather than i2c1. Note, unlike the rpi3, both i2c ports are usable (as I have done so with several chips)
Using the sudo i2cdetect -y 0 Phat shows up correctly with the module address on I2C0. However my sample programs now give an OSError: [Errno 121] Remote I/O error, since obviously the other port needs used (it is still trying to use I2C1).

What parameter do I need to change or supply (or edit a file) so the script will work on the other port SDA0 & SCL0? Again the way my board is made, it must connect to these pins.

import time
import scrollphathd as ledbar
ledbar.write_string(“hello there–it works!!”)

while True:
ledbar.show()
ledbar.scroll(1)
time.sleep(0.1)


#2

At the moment it’s hard-coded to use bus 1 here- https://github.com/pimoroni/scroll-phat/blob/6a6dfcd946b28f76378239d6ebe860f23b2ab0de/library/scrollphat/IS31FL3730.py#L17

You should clone the GitHub repo, change that line to whatever you need and then reinstall the library from source with sudo python setup.py install.


#3

Can you be more specific? I’ve never worked with a library…do I just save this file somewhere & type the above?
Also is this correct for the PIM276, which is 7x17?


#4

Thanks, I got it working…should have mentioned I have HD scrolller (didn’t know there was a non-HD).
I modified the .show to accept an i2c port parameter (0 or 1) & send that to setup, where the smbus is selected,
changed these lines:
def setup(self,i2cport): …added i2cport
self.i2c = smbus.SMBus(i2cport) …changed from 1 to i2cport
def show(self, i2cport=1, before_display=None): …added i2cport with default of 1
self.setup(i2cport) …added i2cparameter

Then did this:
If you want to contribute, or like living on the edge of your seat by having the latest code, you should clone this repository, cd to the library directory, and run:

sudo python3 setup.py install


#5

Nice sleuthing! Glad you’re up and running.

i2cport should most likely be added into the setup() function as standard, although I’d probably use:

def setup(self, i2c_bus=1):

So that it has a default value. And then add that into __init__.py as setup = display.setup so that it can be called when loading the library like:

import scrollphathd
scrollphathd.setup()

Or to change bus:

import scrollphathd
scrollphathd.setup(i2c_bus=0)

That way if you don’t call setup it’ll get called with the default value for you.