# Enable non-standard I2C RTC module (DS3231) on RPi 4

**URL:** <https://forums.balena.io/t/enable-non-standard-i2c-rtc-module-ds3231-on-rpi-4/119406>\
**Category:** balenaOS\
**Tags:** systemd\
**Created:** [May 25, 2020, 11:47pm UTC](https://forums.balena.io/t/enable-non-standard-i2c-rtc-module-ds3231-on-rpi-4/119406 "2020-05-25T23:47:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![HakanL](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/hakanl/32/3674_2.png) [@HakanL](https://forums.balena.io/u/HakanL)\
**Post date:** [May 25, 2020, 11:47pm UTC](https://forums.balena.io/t/enable-non-standard-i2c-rtc-module-ds3231-on-rpi-4/119406/1 "2020-05-25T23:47:27Z")

</div>

I have balenaOS 2.48.0+rev1 running on my Raspberry Pi 4 fine. But I need to have a RTC module on it (DS3231), which would be fine in standard configuration (just enable the dtoverlay command). The issue is that I have to use a different i2c driver (i2c-gpio) because the built-in hardware i2c in the RPi doesn’t handle clock stretching that my slave devices require. I can enable i2c-gpio perfectly fine, my devices run through docker and life it great. But that means the i2c bus moves to another device id, so the i2c-rtc dtoverlay doesn’t work (can’t find the RTC clock). I can manually “fix” this by writing to the new\_device via the i2c-adapter, the rtc clock is found and communicated to perfectly fine. But how can I persist this with balenaCloud? On a standard RPi OS I’ve created a new unit file for systemd, it works great, it gets loaded and the rtc clock is found. But how do I do that in balenaOS?

---

<div class="post-metadata">

**Author:** ![georgiats](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/georgiats/32/2571_2.png) [@georgiats](https://forums.balena.io/u/georgiats)\
**Post date:** [May 26, 2020, 7:44am UTC](https://forums.balena.io/t/enable-non-standard-i2c-rtc-module-ds3231-on-rpi-4/119406/3 "2020-05-26T07:44:25Z")

</div>

Hello @HakanL!  
Welcome to our community!  
In most linux environments, using this kind of low level communication requires enabling a kernel module. In balena containers this can be done in a similar way because the containers are run in --priviledged mode. To enable I2C communication in your projects you will need to add the command modprobe i2c-dev to your package.json or Dockerfile. In our [documentation](https://www.balena.io/docs/learn/develop/hardware/i2c-and-spi/#raspberry-pi-family) you can read more about how to do that.  
Please let me know if that helps and I’ll be glad to assist you with any further questions.

Georgia

---

<div class="post-metadata">

**Author:** ![HakanL](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/hakanl/32/3674_2.png) [@HakanL](https://forums.balena.io/u/HakanL)\
**Post date:** [May 26, 2020, 2:52pm UTC](https://forums.balena.io/t/enable-non-standard-i2c-rtc-module-ds3231-on-rpi-4/119406/5 "2020-05-26T14:52:50Z")

</div>

Yea, but I2C is already enabled, the issue is with the RTC module, which is for the host (so the host will have the correct time).

---

<div class="post-metadata">

**Author:** ![ljewalsh](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/ljewalsh/32/3783_2.png) [@ljewalsh](https://forums.balena.io/u/ljewalsh)\
**Post date:** [May 26, 2020, 10:18pm UTC](https://forums.balena.io/t/enable-non-standard-i2c-rtc-module-ds3231-on-rpi-4/119406/6 "2020-05-26T22:18:49Z")

</div>

Hey there,

Are you able to give us a little bit information about the unit file you have created for systemd? Could you elaborate on what you mean when you talk about writing to the new device via the i2c-adapter?

Could the unit file be expressed as a service in the docker-compose file instead?

Lucy-Jane

---

<div class="post-metadata">

**Author:** ![HakanL](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/hakanl/32/3674_2.png) [@HakanL](https://forums.balena.io/u/HakanL)\
**Post date:** [May 26, 2020, 10:45pm UTC](https://forums.balena.io/t/enable-non-standard-i2c-rtc-module-ds3231-on-rpi-4/119406/8 "2020-05-26T22:45:06Z")

</div>

Sure, I was using this guide: [https://www.willhughes.name/post/ds3231\_raspi3/](https://www.willhughes.name/post/ds3231_raspi3/)  
You assign a module to the i2c address by writing to new\_device (see link above).  
I need to set this prior to the start of the docker containers so the host has the correct time, normally it would’ve been done with dtoverlay, but the i2c-rtc driver for dtoverlay doesn’t seem to support an alternative bus-id/address, so that’s why I enable it using the systemd unit file.

---

<div class="post-metadata">

**Author:** ![jimsynz](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/jimsynz/32/4663_2.png) [@jimsynz](https://forums.balena.io/u/jimsynz)\
**Post date:** [May 27, 2020, 7:37pm UTC](https://forums.balena.io/t/enable-non-standard-i2c-rtc-module-ds3231-on-rpi-4/119406/13 "2020-05-27T19:37:11Z")

</div>

Hi there

Thanks for the information. Probably the most simple way would be to have it as another service in your `docker-compose.yml` and a very simple container with the CMD `/bin/bash -c "echo ds1307 0x68 | tee /sys/class/i2c-adapter/i2c-1/new_device && sleep infinity"` This has the added advantage that you can add `depends_on ` values for your other services so you can make sure that the RTC is set up before your other services start.  
Happy to walk you through this solution if you need more information.

Cheers,  
James.
