I2C Part 2 - Build a I2C Sensor
In the second look at I2C, we will design our own I2C sensor. We’ll also look at the protocol used to exchange data on the I2C bus.
Full article with code at https://dbot.ws/i2cpart2
We are back working with the I2C bus, this time to examine the protocol used to exchange data on the bus. We will also look at the addressing scheme.
Then we will take four HC-SR04 ultrasonic distance sensors and create our own I2C sensor using them.
A lot of inspiration for this came from an excellent video by Andreas Spiess, the ”guy with the Swiss accent”. In his video, he created a 3-sensor device using an ATtiny85.
In my implementation, I used an Arduino Uno, but this is only to make development a bit easier. If I were to create a permanent version of this sensor I would probably use either an Arduino Pro Mini (which would also allow a 3.3-volt version to be created) or an ATmega328 chip.
Here is the outline of today's video:
00:00 - Introduction
01:26 - I2C Protocol and Addressing
07:14 - Ultrasonic Sensor Wiring and Testing
14:09 - Remote I2C Sensor Intro
19:21 - Remote I2C Sensor Code
While this sensor certainly could be improved upon it should serve to illustrate how easy it is to create your own I2C device.
You can get all of the code that I used in this video at https://dbot.ws/i2cpart2.
"Never trust a computer you can’t throw out a window." — Steve Wozniak
Thanks for posting an excellent tutorial. Although the topic of your video is "building an i2c sensor", but i am struggling to find some information about building a true i2c sensor. If I have a bunch of analog sensors like pressure, distance or temperature with analog current or voltage signal, how can I connect them as slave directly to a microcontroller over i2c line? There are many dedicated i2c sensors available but I would like to build an i2c sensor board with specific sensor of my choice.
@khurram Check out a company called WaveShare, they have a few interesting I2C products.
It is considered poor judgement to traverse a chasm in 2 leaps.