Bitbanging I2C by hand

I2C

Play around with electronics long enough, and eventually you’ll run into I2C devices. These chips – everything from sensors and memory to DACs and ADCs – use a standardized interface that consists of only two wires. Interacting with these devices is usually done with a microcontroller and an I2C library, but [Kevin] wanted to take that one step further. He’s bitbanging I2C devices by hand and getting a great education in the I2C protocol in the process.

Every I2C device is controlled by two connections to a microcontroller, a data line and a clock line. [Kevin] connected these lines to tact switches through a pair of transistors, allowing him to manually key in I2C commands one bit at a time.

[Kevin] is using a 24LC256 EEPROM for this demonstration, and by entering a control byte and two address bytes, he can enter a single byte of data by hand that will be saved for many, many years in this tiny chip.

Of course getting data into a chip is only half of the problem. By altering the control byte at the beginning of an I2C message by one bit, [Kevin] can also read data out of the chip.

This isn’t [Kevin]’s first experimentation in controlling chips solely with buttons. Earlier, we saw him play around with a 595 shift register using five push buttons. It’s a great way to intuit how these chips actually work, and would be an exceptional learning exercise for tinkerers young and old,

15 thoughts on “Bitbanging I2C by hand

  1. Writing your own software-I2C routine on any microcontroller is also a great source for information on the I2C-protocol. And is is actually useful when you for instance need a small microcontroller (without hardware I2C) to talk to a RTC or a EEPROM.

    1. Even if the microcontroller has hardware I2C, I often still use my software version, just because it’s easier to drop in code that works instead of figuring out how to use the (often overly complicated) I2C hardware/libraries.

  2. I was developing a wired dash board remote for a car amplifier at my previous company. The main board and correspondingly the firmware was not finished and I needed to test out my board for functionality. Built around a TL595 and rotary encoder I bit banged it by hand to test the functionality.

  3. For anyone who might attempt this, but doesn’t want to wait through a 30 minute video – always debounce your switches. Otherwise this won’t work!

    I learned I2C by manually bitbanging lines on a parallel port, so bounce wasn’t an issue.

    The ICs with maximum I2C clock times that [cde] mentions are rare, and not true to the spirit (if not the spec) of I2C. I have yet to encounter one. But more common are those that need some time to process a byte once the last bit has been sent, and hold the clock line low until this occurs; even though the master has released it. This is called “clock stretching”, and is something you should check for should you ever write generic I2C bitbang code.

  4. I have once done this with SPI devices using a short little row of toggle switches I debounced. This graduated on to a PI-SO shift register and several bits of toggles! It was a simple device for prototyping, and it worked surprisingly well.

    1. Wouldn’t you really just need to debounce the clock button? By the time your meatbrain gets round to pressing the clock, the data switches should’ve long since settled down.

    1. We know. It’s debatable how that would show up in the title bar of a browser though. Sometimes they’re not as versatile there as they are in rendering body text. Possibly something to do with being handled by the OS and not the application.

      So compatibility rules! You’re lucky you’re not stuck with 7-bit ASCII! You’re lucky you have lower-case letters!

  5. Hey, I follow the exact things in the video, but doesn’t work for me. I’m using PCF8575C with write mode supposed to be S 0100 A2 A1 A0 R/W 0. Nothing works! Please help me!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s