My i2c-0 isn´t appear in dev list

I am tried execute one python program with pcf8563 rtc, when I execute the program come this message:

root@sensorial_new:/etc/pcf8563# python uprtc.py
Traceback (most recent call last):
File "/etc/pcf8563/uprtc.py", line 80, in
i2c = mraa.I2c(0)
File "/usr/lib/python3.10/site-packages/mraa.py", line 528, in init
this = _mraa.new_I2c(bus, raw)
ValueError: Invalid i2c bus
root@sensorial_new:/etc/pcf8563#

If I list the dev dir:

root@sensorial_new:/dev# ls
autofs mmcblk0p2 mtd4 mtdblock3 random ttyS11 ttyS6
bus mtd0 mtd4ro mtdblock4 shm ttyS12 ttyS7
console mtd0ro mtd5 mtdblock5 stderr ttyS13 ttyS8
full mtd1 mtd5ro mtdblock6 stdin ttyS14 ttyS9
hwrng mtd1ro mtd6 null stdout ttyS15 urandom
kmsg mtd2 mtd6ro port tty ttyS2 watchdog
log mtd2ro mtdblock0 ppp ttyS0 ttyS3 watchdog0
mmcblk0 mtd3 mtdblock1 ptmx ttyS1 ttyS4 zero
mmcblk0p1 mtd3ro mtdblock2 pts ttyS10 ttyS5

Can help me please!!

What is the model of your router, how your RTC device is connected? No need to mention python for now.
Show the output of logread | grep -i i2c after reboot. Please use forum formatting (</> icon).

Good morning!

I Use a linkit smart 7688, myrtc it´s DS3231, but pcf8563 it´s ok, my hardware it´s ok because in a old version openwrt it works.

The result the command its:
root@sensorial_new:/# logread | grep -i i2c
Wed Jul 19 15:06:28 2023 kern.info kernel: [ 17.348848] i2c /dev entries driver

Install kmod-rtc-ds1307 and run echo ds3231 0x68 > /sys/bus/i2c/devices/i2c-0/new_device and check the log again.
If the RTC module is recognized then you can access it with hwclock.
If not - install i2c-tools and execute i2cdetect 0.

Hi!

root@sensorial_new:~# opkg install kmod-rtc-ds1307
Unknown package 'kmod-rtc-ds1307'.
Collected errors:

  • opkg_install_cmd: Cannot install package kmod-rtc-ds1307.

root@sensorial_new:~# opkg install i2c-tools
Package i2c-tools (4.3-1) installed in root is up to date.

root@sensorial_new:~# i2cdetect 0
Error: Could not open file /dev/i2c-0' or /dev/i2c/0': No such file or directory

Check from the OpenWrt GUI what is the right package for ds1307 and load it. Make sure the package list is updated.
Please run i2cdetect -l and show the result.

I install kmod-i2c-gpio and install kmod-i2c-mt7628 now appear.

It´s appear in dev list.
autofs mmcblk0p1 mtd3ro mtdblock2 pts ttyS10 ttyS5
bus mmcblk0p2 mtd4 mtdblock3 random ttyS11 ttyS6
console mtd0 mtd4ro mtdblock4 shm ttyS12 ttyS7
full mtd0ro mtd5 mtdblock5 stderr ttyS13 ttyS8
hwrng mtd1 mtd5ro mtdblock6 stdin ttyS14 ttyS9
i2c-0 mtd1ro mtd6 null stdout ttyS15 urandom
kmsg mtd2 mtd6ro port tty ttyS2 watchdog
log mtd2ro mtdblock0 ppp ttyS0 ttyS3 watchdog0
mmcblk0 mtd3 mtdblock1 ptmx ttyS1 ttyS4 zero

root@sensorial_new:/# i2cdetect -l
i2c-0 i2c 10000900.i2c I2C adapter

root@sensorial_new:/# echo ds3231 0x68 > /sys/bus/i2c/devices/i2c-0/new_device
[ 142.833093] i2c i2c-0: new_device: Instantiated device ds3231 at 0x68

root@sensorial_new:/# i2cdetect 0
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 0x08-0x77.
Continue? [Y/n] y
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

When I execute my program return

root@sensorial_new:/etc/pcf8563# python uprtc.py
Traceback (most recent call last):
File "/etc/pcf8563/uprtc.py", line 80, in
i2c = mraa.I2c(0)
File "/usr/lib/python3.10/site-packages/mraa.py", line 528, in init
this = _mraa.new_I2c(bus, raw)
ValueError: Invalid i2c bus

You don't need kmod-i2c-gpio when you use native I2C interface.
I cannot comment on your program behaviour but now you should be able to access your RTC module by using hwclock.

root@sensorial_new:/usr/bin# hwclock -w
hwclock: can't open '/dev/misc/rtc': No such file or directory

Weird... Try logread | grep -i 'i2c\|rtc'

root@sensorial_new:/# logread | grep -i 'i2c|rtc'
Wed Jul 19 15:06:28 2023 kern.info kernel: [ 23.432363] i2c /dev entries driver
Wed Jul 19 15:06:28 2023 kern.info kernel: [ 23.505089] i2c-mt7621 10000900.i2c: clock 100 kHz
Fri Jul 21 14:06:19 2023 daemon.notice procd: /etc/rc.d/S99pcf8563: File "/etc/pcf8563/hwrtc.py", line 132
Fri Jul 21 14:07:48 2023 local1.notice libmraa[2837]: i2c_init: Selected bus 0
Fri Jul 21 14:07:48 2023 local1.err libmraa[2837]: i2c_init: No i2c buses defined in platform

reference time (in seconds since 1900-01-01 00:00:00)

TIME1970 = 2208988800L # 1970-01-01 00:00:00

It´s the line 132

echo ds3231 0x68 > /sys/bus/i2c/devices/i2c-0/new_device
needs to be re-applied after reboot.

Please repeat logread | grep -i 'i2c\|rtc' afterwards. Please temporary remove your python script(s) from startup.

With kmod-rtc-ds1307 driver loaded you should see a line saying
rtc core: registered ... as rtc0
next to the following line:
i2c i2c-0: new_device: Instantiated device ds3231 at 0x68

I don´t know the local of the python script startup, sorry because I am new in openwrt system

There is in a etc/rc.d two files K5pcf8563 and S99pcf8563 in this files has in start hwrtc.py, i coment the line hwrtc.py and now the result its

root@sensorial_new:/# echo ds3231 0x68 > /sys/bus/i2c/devices/i2c-0/new_device
[ 119.765597] i2c i2c-0: new_device: Instantiated device ds3231 at 0x68
root@sensorial_new:/# logread | grep -i 'i2c|rtc'
Fri Jul 21 15:07:31 2023 kern.info kernel: [ 17.548941] i2c /dev entries driver
Fri Jul 21 15:07:31 2023 kern.info kernel: [ 17.620980] i2c-mt7621 10000900.i2c: clock 100 kHz
Fri Jul 21 15:10:05 2023 kern.info kernel: [ 119.765597] i2c i2c-0: new_device: Instantiated device ds3231 at 0x68

It looks like you do not have kmod-rtc-ds1307 installed.
For whatever reason no "kmod-rtc" files available for mt76x8 in 22.03.5
https://downloads.openwrt.org/releases/22.03.5/targets/ramips/mt76x8/kmods/5.10.176-1-a90af1d1eca8a5093db982a2a36fb9bc/

@psherman do you know why is that?

I wish I could offer some help here, but this isn't my area of experties at all.

Now I see why someone may need an app to work with RTC module. As far as I understand, the Python application you are trying to use communicates directly with the module, no driver is required and the app only needs to know I²C bus information and module address.
I posted a question in Developers section, so will see...

Here's the reason and the solution: