Knowledge Base

The AB Electronics UK Knowledge Base provides support solutions, tutorials and troubleshooting guides.

Knowledge Base

Using I2C Devices on the Raspberry Pi with Home Assistant

Install Home Assistant on your Raspberry Pi and enable I2C

Created 11/11/2023 | Last Updated: 01/08/2024

This tutorial will guide you on how to install the Home Assistant Operation System on your Raspberry Pi and enable I2C. This will allow you to use our ADC Pi and IO Pi Plus development boards, as well as many other I2C devices with Home Assistant.

First, we must set up a microSD card with the Home Assistant Operation System.

You will need the following items:

  • Raspberry Pi. Model 3 or later.
  • Power Supply for the Raspberry Pi
  • Micro SD Card. Ideally, a 32 GB card or larger.
  • SD Card Reader
  • Ethernet Cable

Optional: An IO Pi Plus to add additional GPIO channels or an ADC Pi to add analogue inputs to Home Assistant.

Installing the Home Assistant Operating System

To install the Home Assistant Operating system onto your Raspberry Pi you can use the Raspberry Pi Imager on Windows, MacOS or Ubuntu

Writing the OS image to your SD card

  1. Download and install the Raspberry Pi Imager on your computer as described under https://www.raspberrypi.com/software/.
  2. Insert the SD card into your Micro SD Card reader and connect it to your computer.
  3. Open the Raspberry Pi Imager software and select your Raspberry Pi.
  4. Select the operating system:
    • Select Choose OS
    • Select Other specific-purpose OS > Home Assistants and Home Automation > Home Assistant.
    • Choose the Home Assistant OS that matches your Raspberry Pi, i.e., RPi 3 or RPi 4.
  5. Click Choose Storage and select your SD card.
  6. Write the image to your SD card by clicking the “Next” button and wait for the file to be transferred to your card.
  7. When the transfer has been completed, close the Raspberry Pi Imager software.

How to Enable I2C

Before you can use any I2C devices, you need to enable I2C for the Home Assistant Operating System and then set up your I2C devices, such as sensors or GPIO expanders.

You need to access the boot partition on your SD card with the Home Assistant Operating System installed on it. If Home Assistant is running, shut down your Home Assistant system, unplug the SD card, insert the card into your card reader and connect it to your computer.

The card will mount as a drive or file system called hassos-boot.

You must create two new folders and add and edit config files to enable I2C.

In the root of the hassos-boot partition, add a new folder called CONFIG.

In the CONFIG folder, add another new folder called modules.

Inside the modules folder, add a text file called rpi-i2c.conf with the following content:

i2c-dev

In the root of the hassos-boot partition, edit the file called config.txt and add two lines to it at the end of the file:

dtparam=i2c_vc=on

dtparam=i2c_arm=on

Unmount or disconnect the card reader, insert the SD card into your Raspberry Pi and reconnect the power to turn it on.

If this is the first boot of your new Home Assistant Operation System, you will be taken through the onboarding process where you set up user accounts, location and other preferences.

Using a web browser on your desktop system you will be able to reach your new Home Assistant at homeassistant.local:8123 or the IP address of your Raspberry Pi and port 8123

During the first boot it can take over 20 minutes for the operating system to load and configure so don't be concerned if nothing happens for a long time.

When the operating system starts, the hassos-config.service will automatically process the new rpi-i2c.conf configuration.

Another reboot might be necessary to ensure the imported rpi-i2c.conf is present at boot time.

I2C will now be enabled and available for you to connect sensors or development boards to your Raspberry Pi.

Home

Shop

Learn

Forum

FAQ

Contact

0 item

Your cart is empty

Please browse our shop to order from the wide range of Raspberry Pi boards and accessories.

Subtotal:£0.00
View Basket Continue to Checkout