I2C with Arduino an...
Clear all

I2C with Arduino and Raspberry Pi - Two Methods

DroneBot Workshop
Workshop Guru Admin
Joined: 3 years ago
Posts: 1114
Topic starter  

In the third installment of the I2C series, I will show you two ways to interface a 3.3-volt Raspberry Pi with a 5-volt Arduino Uno.

Article with code samples - https://dbot.ws/i2c3

Today we are back working with the I2C bus, and this time we’ll be interfacing an Arduino with a Raspberry Pi.

By hooking an Arduino to a Raspberry Pi we can get the best of both worlds. The Raspberry Pi is a powerful single-board computer, capable of running a Linux operating system and connecting natively to the internet. The Arduino is a very capable microcontroller with several I/O pins, an Analog to Digital converter, and precise timing and interrupt capabilities. Together, they make an incredible team.

But one issue is that the two devices use different logic levels. The Raspberry Pi GPIO (General Purpose Input/.Output) bus operates using 3.3-volt logic, while most Arduino’s use 5-volt logic. Incorrectly interfacing them can lead to a non-functional Raspberry Pi, a situation best avoided!

You CAN hook the two devices together directly, providing that certain specific conditions are met. Alternatively, you can use a very inexpensive logic level converter to isolate the 3.3-volt and 5-volt logic safely. In this video, I will show you both methods.

Here is what you will see in today's video:

00:00 - Introduction
03:42 - I2C Logic Levels
06:47 - Raspberry Pi I2C Busses
08:30 - Setting up the Raspberry Pi
14:15 - Direct Hookup
15:35- Arduino Sketch
17:31- Raspberry Pi Python Code
20:30- Running the Demo
24:02- Using a Logic Converter

While the demonstration is extremely simple it does effectively illustrate how easy it is to interface these two popular boards.

"Never trust a computer you can’t throw out a window." — Steve Wozniak

New Member
Joined: 2 years ago
Posts: 2

Hello.  I've recently watched this two-year-old video that has RPi as I2C master and Arduino Uno as I2C Slave. I have a situation very close to this but not quite the same. I'm attempting, unsuccessfully so far, to use an ESP8266 ESP01 as the master (also 3.3V) with an Arduino Nano as the slave. Can this situation use the same direct wiring as the RPi/Uno case or do I need a level converter which would be the case if the Nano uses 5V pullups on the I2C connection?

Trusted Member
Joined: 3 years ago
Posts: 66

New Device-

I2C and SPI are mature but they do have problems. I2C can be relatively slow and SPI usually requires extra pins for each device. Besides that, there is poor support for adding and removing devices dynamically or discovering devices automatically.

I3C, created by the MIPI Alliance, aims to fix these problems. It does use the usual two wires, SCL for the clock and SDA for data. One device acts as a controller. Other devices can be targets or secondary controllers. It is also backward compatible with I2C target devices. Depending on how you implement it, speeds can be quite fast with a raw speed of 12.5 Mbps and using line coding techniques can go to around 33 Mbps.