Exploring I2C buses on ANAVI Info uHAT

I2C stands for Inter-Integrated Circuit, pronounced eye-squared-C, and alternatively known as IIC. It is a synchronous, multi-controller/multi-target (controller/target), packet switched, single-ended, serial communication bus. This protocol is suitable for devices wired at short distances, no more than 2-3m. We use I2C in pretty much all our open source products: Internet of Things, mechanical keyboards and Raspberry Pi HATs.

Anavi Info uHAT
I2C sensor modules attached to ANAVI Info uHAT

I2C was originally developed in 1982 by Philips. While that makes it 40 years old, it is still a very convenient and widely used bus. There are many I2C sensors and peripherals. It is in pretty much every smartphone, embedded electronics, microcontroller, personal computer and of course Raspberry Pi.

ANAVI Info uHAT with 4 slots for I2C sensors and mini OLED dsiplay

Actually, since the introduction of the famous 40-pin header in 2014, Raspberry Pi single board computers have not one but two I2C buses! We use them both on ANAVI Info uHAT and our other HATs. Th first I2C bus is on pins 3 and 5. On the ANAVI Info uHAT, it is used for the three I2C slots for sensors and the 4th dedicated slot for the mini OLED display.

The I2C bus on ANAVI Info uHAT in KiCad’s Schematic Layout Editor.

The second I2C bus is on pins 27 and 28 of the Raspberry Pi and is reserved exclusively for attaching an ID EEPROM. The ID EEPROM contains a software description of the hardware so the operating system on your Raspberry Pi can automatically identify the add-on board.

The EEPROM on ANAVI Info uHAT attached on the 2nd I2C bus

The I2C bus consists of two signals: SDA (Serial Data) is a data signal, SCL (Serial Clock) is a clock signal. I2C modules also need power, so the dedicated I2C connectors on the ANAVI Info uHAT and our other open source hardware provide two additional pins for VCC and GND. Typically, the VCC for the I2C connectors on our add-on boards for Raspberry Pi are 3.3V.

The I2C bus drivers are “open drain”, which means they can only pull the corresponding signal line at low level. They cannot drive it high. To restore the signal to high when no device is asserting it low, a pull-up resistor has to be added to each signal line. For example, on the ANAVI Info uHAT, we have 4.7K pull-up resistors R4 and R5 connected to SDA and SCL.

Resistor selection varies depending on the devices attached to the bus. In some specific use cases, further adjustment of the resistance value might be required. For systems with lots of devices or longer wires, smaller resistors are better.

How to Enable I2C on Raspberry Pi OS

Raspberry Pi OS, previously known as Raspbian, is the default and recommended Linux distribution for all models and versions of the Raspberry Pi single board computer. By default, I2C is not enabled. There are several ways to enable it, but probably the easiest is using the command-line tool raspi-config to perform few basic commands:

  • Open a terminal or login remotely via SSH to your Raspberry Pi and type in the following command: sudo raspi-config
  • Select Interfacing Options > I2C and enable it
  • Reboot the board

More details are available in the user’s manual for the ANAVI Info uHAT.

I2C Addresses

Each I2C device must have a unique address. The I2C reference design has a 7-bit address space, although rarely it might be used with a 10-bit extension. The 7-bit addresses range from 0 to 127 (0 to 0x7F hexadecimal). This is a limitation because it is not possible to have two I2C devices with the same address on the same I2C bus. For example, the I2C address on the mini OLED display included in all ANAVI Info uHAT kits is 0x3C. From the software side, this address is used in the example Python 3 script to access the display.

Python3 script controlling the mini OLED display over I2C on ANAVI Info uHAT

For Linux distributions, including Raspberry Pi OS, there is a package with a heterogeneous set of I2C tools called i2c-tools. To install it on Raspberry Pi OS, open a terminal and execute: sudo apt install -y i2c-tools. Once you have it installed, you can list attached I2C devices by their addresses with i2cdetect. For example, if the HTU21 temperature and humidity sensor module is attached to the Raspberry Pi, the output will be:

pi@raspberrypi:~ $ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: 40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

I2C Sensors and Peripherals

I2C Sensors and Peripherals

ANAVI Info uHAT officially supports the following I2C devices:

  • Mini OLED SSD1306 0.96″ display
  • HTU21D sensor for temperature and humidity
  • BH1750 sensor for light
  • BMP180 sensor for barometric pressure

Some of the other popular I2C sensor modules in maker community include:

  • APDS-9960 sensor for RGB color and gesture detection
  • BME680 for temperature, humidity, pressure and gas sensor
  • MCP9808 for temperature
  • MPL115A2 for barometric pressure
  • ADT7410 for temperature
  • MPU-6050 for triple axis acccelerometer and gyroscope

Which is your favorite I2C device? Join the discussion and let us know on Twitter!

You may also like

ANAVI Gardening uHAT: Shipping Soon

At the beginning of January all ANAVI Gardening uHAT kits were shipped to the Crowd Supply warehouse. We are happy we managed to do it ahead of schedule. Even Tux, the mascot of the Linux kernel, helped out with the transportation.

In the coming weeks, the crowdfundng orders will be prepared for shipment to backers. A tracking number when the order ships.

ANAVI Gardening uHAT
ANAVI Gardening uHAT

Thanks for your patience and support for this open source hardware project! We hope you will enjoy and have a lot of fun with ANAVI Gardening uHAT!

You may also like

ANAVI Gardening uHAT Manufacturing Progress

We have good news regarding ANAVI Gardening uHAT! All boards have been received almost fully assembled from the local factory and we have sourced all required peripherals.

Recently, we received the last batch of assembled printed circuit boards from the local factory. As you can see on the photo, only the EEPROM is missing. We will flash and solder it in-house.

The winter is coming… Grab a ANAVI Gardening uHAT for your Raspberry Pi

We have also received additional peripherals, which will be included in ANAVI Gardening uHAT Starter, Advanced, and Developer kits. On the photo you can see the big packages with analog capacitive soil moisture sensor. Each kit will contain a couple of capacitive soil moisture sensors.

Capacitive Soil Moisture Sensor v1.2

The recyclable cardboard boxes for our eco-friendly packaging have also already been delivered. Another local company here in Plovdiv, Bulgaria will print all stickers for us. We expect them next week.

Our crowdfunding campaign recently ended very successfully but you can still order our open source Gardening uHAT for your Raspberry Pi and be among the very first owners!

You may also like

ANAVI Gardening uHAT is now OSHWA certified

A few days ago we received an official confirmation that ANAVI Gardening uHAT has been certified as open source hardware by the Open Source Hardware Association with UID BG000079.

The Open Source Hardware Association (OSHWA) is a non-profit organization that supports the open source movement and maintains an open source hardware certification registry. OSHWA Certification provides an easy and straight-forward way to quickly check if a product complies with a uniform and well-defined standard for open source hardware.

Open source hardware certification guarantees the sharing of knowledge and keeps prices fairly based on the bill of materials of the hardware’s components. ANAVI Gardening uHAT hardware design files are available under CC BY-SA 4.0, which allows you to remix, transform, and build upon the material for any purpose, even commercially.

In a nutshell, OSHWA certifies a project as open source based on public access to four elements:

  • Hardware – functional elements of the product
  • Software – code, firmware, or other software involved in the product’s functionality
  • Documentation – including design files, schematics, and instructions
  • Branding – brand names, product names, logos, and product design

The exact certified version of each product receives a unique UID, for example, ANAVI Gardening uHAT is with UID BG000079. The prefix is the country code. We make our open source hardware in Plovdiv, Bulgaria, so the country code is BG. The suffix is a sequential ID number. At the moment, there are 79 certified open source hardware products from Bulgaria. For a comparison, the United States is leading with the amazing 2052 certified products, followed by Germany with 116. Bulgaria comes in at the third place, primarily thanks to our awesome open source neighbors from Olimex.

As a very small company we are all proud to have contributed to the Bulgarian success in this field. Hopefully, the popularity of the open source hardware movement will continue to increase worldwide.

You may also like

ANAVI Gardening uHAT

ANAVI Gardening uHAT is a low-cost, open source Raspberry Pi add-on board that helps you develop smart solutions for monitoring and growing plants.

ANAVI Gardening uHAT supports multiple sensors for soil moisture, temperature, humidity, barometric pressure, and light. Getting started is easy: just plug it into a Raspberry Pi with your bare hands and follow the instructions in the user manual. No soldering is necessary, and no tools are required.

We hope you’ll jump in and help us bring this entirely open source gardening project to life by supporting our new crowdfunding campaign at Crowd Supply.

You may also like