dracode
Posts: 6
Joined: Wed Jun 14, 2017 11:00 am

Adding an I2C device via sysfs -- how to specify parameters?

Mon May 13, 2019 1:30 am

Greetings,

Using Device Tree, one can specify extra parameters for interfacing with a specific peripheral.
For example, adding this line to /boot/config.txt:

Code: Select all

dtoverlay=ssd1306,height=32
The extra parameter changes the height of the display from the default of 64.

One can also add an I2C device after boot through the sysfs interface, like so:

Code: Select all

echo ssd1306 0x3c > /sys/bus/i2c/devices/i2c-1/new_device
My question is: when adding a device like this (through sysfs, not device tree) after boot, how does one pass additional parameters? I can't figure out a way to use a non-default "height".

I know that using device tree would be the preferred way, but that isn't my question. I'm specifically looking to set up the device after boot on an already-running system.

davef
Posts: 52
Joined: Wed Feb 20, 2013 8:39 pm

Re: Adding an I2C device via sysfs -- how to specify parameters?

Thu May 16, 2019 12:31 am

If I recall correctly, doing this years ago, that in

Code: Select all

/sys/bus/i2c/devices/i2c-1/new_device
or

Code: Select all

/sys/bus/i2c/devices/i2c-1/
there should be a list of parameters that you are allowed to change. Again, I think something like

Code: Select all

echo some number to that location 


How you might add new ones I never tried.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6640
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Adding an I2C device via sysfs -- how to specify parameters?

Thu May 16, 2019 9:30 am

You can use "sudo dtoverlay ssd1306 height=32" on a running system to dynamically load the DT overlay with parameter.
Add -R to remove the overlay (only works if loaded dynamically and not via config.txt).
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

dracode
Posts: 6
Joined: Wed Jun 14, 2017 11:00 am

Re: Adding an I2C device via sysfs -- how to specify parameters?

Thu May 16, 2019 11:58 pm

6by9 wrote:
Thu May 16, 2019 9:30 am
You can use "sudo dtoverlay ssd1306 height=32" on a running system to dynamically load the DT overlay with parameter.
Add -R to remove the overlay (only works if loaded dynamically and not via config.txt).
This worked, thanks!

Return to “Interfacing (DSI, CSI, I2C, etc.)”