• Alex

HowTo: GPIO access, I2C, Kernel Building

by p3dt

from: https://forum.clockworkpi.com/t/howto-gpio-access-i2c-kernel-building/5036


Hi, it’s Paul again


Intro

I found some time over the last days to play with the GPIOs and I2C. And got all of them to work, as well as I2C support:


   WARNING! This program can confuse your I2C bus, cause data loss and worse!
    I will probe file /dev/i2c-0.
    I will probe address range 0x03-0x77.
    Continue? [Y/n] 
        0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
    00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
    10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    30: -- -- -- -- -- -- -- -- -- -- -- -- 3c -- -- -- 
    40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    70: -- -- -- -- -- -- 76 --    

The GPIOs worked out of the box. I2C was a bit tricky (especially if you know nothing about linux kernel development, kind of like me)


GPIOs

This section describes how to use the pins via the sysfs interface.

Create the pin’s interface:

echo 32 > /sys/class/gpio/export # PB0, green cable

which creates the interface’s pin directory:

<