HowTo: GPIO access, I2C, Kernel Building
- Alex

- Jan 8, 2020
- 2 min read
by p3dt
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:
cd /sys/class/gpio/gpio32/
Which contains the following files
active_low device direction edge power subsystem uevent value
To use this pin as an output pint you can configure it
echo out > /sys/class/gpio/gpio32/direction
And enable it
echo 1 > /sys/class/gpio/gpio32/value
Or disable it
echo 0 > /sys/class/gpio/gpio32/value
Short version for I2C (Setup)
If you mount /dev/mmcblk0p1 /mnt/boot/ you will find a file sun8i-r16-clockworkpi-cpi3.dtbwhich is missing the entry (in it’s original source form)
&i2c1 {
status = "okay";
};
Which I rebuilt using the kernel sources version 5.2-rc4. I replaced the file (and the Kernel with my rebuilt kernel). And then got the device /dev/i2c-0 after a reboot.
Details for I2C
I wrote the long version down while figuring things out on my blog (it’s a bit much for a forum post):
Let me know if this helps or if you have any questions
Resulting Kernel/DeviceTree files for I2C
If you don’t want to build everything yourself you can download my kernel and the accompanying files here:
https://p3dt.net/assets/downloads/cpi-0.4-kernel-5.2-rc4-i2c.tar.gz Using these files is at your own risk, if you run into issues, I will do my best to answer your questions in this thread.
You need to replace these (make backups first!) on the boot partition. Note: It might be the case that replacing the .dtb file is sufficient if you have a different kernel, but I haven’t tested this. If you are up for some tests, try this first and let us know, thank you.
Have fun, Paul



papa's games offers engaging gameplay that combines time management and creativity, letting players customize food orders and upgrade their shops for better performance
GPIO and I2C setup! Saved me time and worked flawlessly. Thanks for sharing! https://EscapeCity.games
EA88 bữa mình cũng ghé thử cho biết vì thấy mọi người nhắc hoài. Vừa vào là đập ngay cái H1 “Lorem ipsum dolor sit amet…” nhìn khá rõ, kiểu đặt tiêu đề to nên khỏi phải tìm. Kéo xuống chút thì thấy họ chia nội dung theo dạng câu hỏi, có mục “Lorem Ipsum là gì?” nên đọc lướt cũng bắt nhịp nhanh. Phần thân bài đúng kiểu đoạn văn mẫu dài, có đoạn nhắc tới Cicero với “De Finibus Bonorum et Malorum” nên trông giống trang tổng hợp thông tin tham khảo hơn là gì rối rắm. Mình thích cái cách họ tách đoạn khá thoáng, cuộn không bị ngợp chữ. Nói chung giao diện đơn giản, dễ…
https://tylekeobongda88.com/ mình lướt trúng lúc đang tìm chỗ xem kèo nên bấm vào thử cho biết. Trang nhìn sáng sủa, bố cục kiểu chia khối nên kéo xuống khá nhẹ mắt, không bị rối. Mình thích nhất là phần kèo nhà cái với tỷ lệ kèo bóng đá hôm nay để ngay chỗ dễ thấy, nhìn qua là nhận ra trận nào với mấy con số nằm đâu, khỏi phải soi. Lướt thêm chút thấy có mục bài mới đăng nên cũng tiện xem họ cập nhật đều không. Nói chung không cần rành vẫn dùng được, mấy bảng tỷ lệ trình bày theo cột gọn gàng, nhìn khá “sạch” trên màn hình. Mình để ý tiêu đề “Kèo Nhà…
guide on GPIO and I2C setup! Helped me get started quickly with minimal fuss. Thanks for sharing! https://super-star-car.com