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 Info uHAT Demo at the Technical University of Berlin

On 29th June, we had the opportunity to present and demonstrate the ANAVI Info uHAT add-on board for Raspberry Pi and some of our other open source hardware gadgets at the Technical University of Berlin for an event called “Open Source Hardware: Tools and Collaborations for A Better (Product) Future”.

OPENNEXT agenda on 29 June 2022

The event was organized by OPENNEXT. This is an organization that aims to bring together SMEs and makerspaces across the European Union (EU) to develop new hardware products based on open-source principles. The event brought together representatives of the Technical University Berlin, the Grenoble Institute of Technology, the University of Bath, the DDC – Danish Design Center, and many more organizations involved with open source software and hardware. Lukas Hartmann, the creator of the open source DIY laptop MNT Reform, was also a panel speaker at the event.

Panel discussion during OPENNEXT event in the Technical University of Berlin

This event was a great opportunity to show off the ANAVI Info uHAT with a mini OLED I2C display attached to the top of a Raspberry Pi and controlled using a Python3 script with the luma.oled library. The source code is available in GitHub. In the meantime, we are also improving the ANAVI Info uHAT user’s manual which is also available in GitHub.

Last but not least, don’t forget to check and support the crowdfunding campaign for ANAVI Info uHAT at Crowd Supply.

You may also like

ANAVI Info uHAT – an open hardware Raspberry Pi add-on board with a mini OLED display, buttons, and slots for sensors

Together with Crowd Supply we recently launched a new crowd funding campaign for ANAVI Info uHAT – an open hardware Raspberry Pi add-on board with a mini OLED display, buttons, and slots for sensors.

Thanks to early backers ANAVI Info uHAT was successfully funded and hit its first stretch goal in a just a couple of days. So we’ll be adding some awesome KiCad and ANAVI Technology stickers. KiCad is the free and open source software we used to design this and other Anavi printed circuit boards.

As a small open source project, ANAVI Info uHAT relies on the community of passionate open source makers. We are near our second stretch goal of $1,000. If we hit it, we will make more video tutorials for all supported sensors.

There is still more than a month until the end of the crowdfunding campaign and we hope more people will jump in and order ANAVI Info uHAT!

You may also like

AI-Thinker – a Trusted Supplier During the Global Chip Shortage

AI-Thinker is a leading supplier of IoT wireless products and solutions, including antennas, modules and RF lab service. Since 2017 we have been using AI-Thinker ESP-12E modules with ESP8266 in many of our open source hardware products, including ANAVI Fume Extractor, ANAVI Gas Detector, ANAVI Thermometer, ANAVI Light Controller and ANAVI Miracle Controller.

AI Thinker modules with ESP8266

Now, despite the hard times of global chip shortage, AI-Thinker keeps manufacturing and delivering high-quality modules on time. As a trusted supplier through the years, recently we have purchased from AI Thinker enough ESP-12E modules do fulfill the demand and keep making our open source hardware products.

AI Thinker modules with RISC-V microcontroller

Furthermore we stocked ESP-C3-12F modules with Espressif Systems ESP32-C3 Wi-Fi microcontroller based on the open standard instruction set architecture (ISA) RISC-V. ESP-C3-12F are pin to pin compatible with ESP-12E.

AI Thinker ESP32

AI-Thinker is based in Shenzhen, China. The company was founded 10 years ago, in 2012. They also provide LoRaWAN, NB-IoT, Bluetooth and other Wi-Fi modules.

You may also like

ANAVI Gardening uHAT: Safety First

Earlier in January all ANAVI Gardening uHAT kits were delivered to the Crowd Supply warehouse and soon after that Crowd Supply team sent them to their final destination: our valuable and trusting crowdfunding backers! Thank you again for the support.

ANAVI Gardening uHAT Developer Kit
ANAVI Gardening uHAT Developer Kit

ANAVI Gardening uHAT is a versatile development board, so please follow the instructions below for safe use:

  • ANAVI Gardening uHAT should only be connected to a compatible Raspberry Pi with 40-pin header.
  • Do not expose it to water or moisture, and do not place it on a conductive surface whilst in operation.
  • Do not expose it to heat from any source; it is designed for reliable operation at normal room temperatures.
  • Take care while handling the board to avoid mechanical or electrical damage to the printed circuit board and connectors.
  • Avoid handling ANAVI Gardening uHAT while it is powered on. Only handle by the edges to minimize the risk of electrostatic discharge damage.

In the meantime, there is a work in progress going on the user’s manual which is available at GitHub. We will soon update it. As usual, GitHub pull requests with improvements and fixes to the documentation or the source code examples are always welcome.

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

MicroPython on Raspberry Pi Pico with Thonny IDE

Raspberry Pi Pico is a tiny and fast development board by the Raspberry Pi Foundation built using the brand new RP2040 32-bit dual ARM Cortex-M0+ microcontroller. The major advantage of Raspberry Pi Pico is the affordable price as it is available for about $4 (without taxes and shipping).

In this video tutorial you will learn how to get started with MicroPython using the open source Thonny IDE on Raspberry Pi Pico. Thonny runs on Mac, Windows and Linux distributions, in the video it is used on Ubuntu. The video includes Pico unboxing, MicroPython installation guide, blinking LED example, MicroPython REPL demo and conclusions.

Useful links:

The video tutorial was sponsored by PCBway which provide high-quality prototyping services. On the photo you can see prototypes of green printed circuit boards with white silkscreen following Raspberry Pi specifications for micro Hardware Attached on Top (uHAT).

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

Add Capacitive Soil Moisture Sensors to Raspberry Pi

Raspberry Pi is a famous series of small single-board computers (SBCs) developed in the United Kingdom by the Raspberry Pi Foundation in cooperation with Broadcom. This is a step by step tutorial for using Raspberry Pi and capacitive soil moisture sensor with Microchip MCP3002 analog-to-digital converter (ADC) and a Python script for detecting the soil moisture in percentage.

Capacitive Soil Moisture Sensor

Capacitive Soil Moisture Sensor v1.2 and v2.0 measures the volumetric content of water inside the soil and retrieves the moisture level by capacitive sensing rather than resistive sensing like other sensors. The benefit of using a capacitive soil moisture sensor is the lack of corrosion and longer lifespan.

Wiring

Unlike Raspberry Pi Pico, the recently released microcontroller, all versions and models of the Raspberry Pi single-board computers do not include an analog-to-digital converter (ADC). This tutorial explains how to use Microchip MCP3002 with Raspberry Pi.

Microchip MCP3002 is a 10-bit resolution, dual channel ADC with SPI hardware bus. It can be connected to any Raspberry Pi single board computer version and model, including Raspberry Pi 4 and Raspberry Pi 0. However, this tutorial is not for Raspberry Pi Pico microcontroller. For more details about the wiring of Microchip MCP3002 a Raspberry Pi single-board computer have a look at my previous tutorial.

Prototypes for Raspberry Pi add-on boards

Alternatively, the easier option without a breadboard an a bunch of cables, is to use a dedicated Raspberry Pi add-on board with built-in ADC. Using the free and open source tool KiCad we designed ANAVI Gardening uHAT exactly for this purpose. It has dedicated pins for connecting a couple of capacitive soil moisture sensors. The prototype has been created thanks to PCBWay. This is a lead-free prototype printed circuit board with 2 layers, green solder mask and white silkscreen. PCBway offers a huge variety of colors and even flexible PCB.

Software

Flash Raspberry Pi OS, the official Debian based GNU Linux distribution by the Raspberry Pi, on microSD card and boot it. On the Raspberry Pi, open a terminal and using the raspi-config tool enable SPI as shown in the video. Reboot the Raspberry Pi.

Python3 script for reading data from a couple of capacitive soil moisture sensors through Microchip MCP3002 ADC is available at the anavi-examples repository in GitHub. The script relies on popular Python libraries spidev and RPi.GPIO. Open a terminal and run the following commands to clone anavi-examples and run the script:

git clone https://github.com/AnaviTechnology/anavi-examples.git
cd anavi-examples/anavi-gardening-uhat/soil-moistore-sensors/python/
python3 soil-moistore-sensors.py

You may also like

ANAVI Macro Pad 2 – a Tiny 2% Mechanical Keyboard

ANAVI Macro Pad 2

Meet ANAVI Macro Pad 2! It is an open source, programmable two-key mechanical keypad with backlighting. Each of the keys on ANAVI Macro Pad 2 can be reprogrammed for use as a macro or even as a dedicated shortcut key, making it perfect for a number of applications across various industries.

ANAVI Macro Pad 2

ANAVI Macro Pad 2 runs on a Microchip ATtiny85, which is a reliable, low-cost, 8-bit AVR RISC-based microcontroller. It has a gold-plated printed circuit board, Gateron red mechanical switches, 3mm red LEDs and translucent keycaps.

Gateron red mechanical switches with 3mm LEDs on ANAVI Macro Pad 2

Only free and open source software tools like KiCad, OpenSCAD, and Inkscape were used to design ANAVI Macro Pad 2. Quantum Mechanical Keyboard (QMK) with V-USB is the default open source firmware. Source code and schematics are available on GitHub.

ANAVI Macro Pad 2 with stickers on the translucent keycaps of the mechanical switches

We kicked off a crowdfunding campaign for ANAVI Macro Pad 2 at Crowd Supply. We have a stable product and we are ready to proceed with low-volume manufacturing. We hope you help us bring this entirely open source project to life by ordering a developer or a maker kit!

You may also like