Bus Pirate Commandeers I2C

The Bus Pirate is one of our favorite tool for quick-and-dirty debugging in the microcontroller world. Essentially it makes it easy to communicate with a wide variety of different chips via a serial terminal regardless of the type of bus that the microcontroller uses. Although it was intended as a time-saving prototyping device, there are a lot of real-world applications where a Bus Pirate can be employed full-time, as [Scott] shows us with his Bus Pirate data logger.

[Scott] needed to constantly measure temperature, and the parts he had on hand included an LM75A breakout board that has a temperature sensor on board. These boards communicate with I2C, so it was relatively straightforward to gather data from the serial terminal. From there, [Scott] uses a Python script to automate the process of gathering the data. The process he uses to set everything up using a Raspberry Pi is available on the project site, including the code that he used in the project.

[Scott] has already used this device for a variety of different projects around his house and it has already proven incredibly useful. If you don’t already have a Bus Pirate lying around there are a few other ways to gather temperature data, but if you have an extra one around or you were thinking about purchasing one, then [Scott]’s project is a great illustration of the versatility of this device.

19 thoughts on “Bus Pirate Commandeers I2C

    1. I think he’s used the Bus Pirate to get it working on Windows as well as Raspberry Pi (note code comment about device manager).

      Either that or HaD gets royalties from the sale of bus pirates ;)

  1. When I saw “bus pirate commandeers I2C” I had imagined someone had written an I2C library for it (or something) and intentionally implemented a broken version of I2C’s multi-master bus arbitration. One could do this in order to force complete control over any device with an I2C bus one could tap into (say, through a front panel display) since your master device would always win a buss arbitration against a master running a stock library (chosen by the developer for ease of use) that implemented a version that played by the rules.

  2. I don’t quite get the advantages of the Bus Pirate yet. So far, it’s a lot easier to use i2c through a Raspberry Pi for essentially the same functionality. Even using an Arduino Nano through the IDE seems to be easier than using the Bus pirate command line. The raspberry Pi isn’t that much more expensive, even if you don’t have one already. And, in contrast to the BusPirate, higher level libraries for many parts already exist.

    I’d be delighted if someone could prove me wrong about this. I own a BusPirate, and so far it is quite useless to me.

    1. You have to remember that the BusPirate was around before the Pi was launched.
      You may be correct in saying that at this point in time, it is easier (for yourself) to use a Pi, but there was a point when this wasn’t an option!
      Personally, I find the BP quite useful when starting out with a new IC or debugging dodgy microcontroller comms. It is also one of the better options for me, as I don’t own a Pi (gasp!).

      1. That makes a ton of sense. The raspberry pi is very “challenged” when it comes to precise timings, but otherwise it is probably one of the easiest ways to access gpio pins, i2c or spi remotely.

    2. I haven’t tried with the RasPi… but I find the cycle times with the Arduino are annoying. The buspriate allows VERY fast changes to the codes being sent. Especially when used with a small user interface like the one I made for the cell phone above. That also allows me to make use of it on the road, when I don’t have my PC for the Arduino updates. I can just pull out my cell phone, hook up the Pirate, and away we go.

    3. I’m already graphing things in real time using visual IDE on a Windows system, and at the last minute I wanted to add temperature data to this setup. If my goal were only to pull two bytes from an I2C sensor, Raspberry Pi would certainly be easier. Since my goal is integration into an already-running Windows system, Bus Pirate was really handy to have. Notice that I used Python to control its menus, automating the process:

      https://github.com/swharden/AVR-projects/blob/master/BusPirate%202017-02-04%20i2c%20temperature/busPirate_LM75A.py#L49

      Bus Pirate does a binary mode, but in my experience it can be buggy, and this was incredibly rapid to implement. Since speed is 0% my concern, this was a good solution. I was so pleased by the absolute simplicity of this solution that I wrote it up on my website.

  3. Bus Pirate looked like a good idea, until I got my hands on the first MicroPython board. Now I get the Python REPL over the serial, with control over all the peripherals. And somehow I find it easier to write short Python commands to poke at the buses, than to use the menus. And as a bonus, at the end of the session I can copy the commands that worked into my program.

      1. I just use the cheapest ESP8266-based dev boards out there, with a built-in cp2021 usb2ttl. Granted, that doesn’t let me use the UART for other stuff — for this I have a pyboard tucked away.

  4. I was on a Windows computer and wanted to analyze temperature data in Python in real time, and the Bus Pirate was an excellent and rapid way to pull temperature from the I2C sensor given my situation.

    I have previously interacted I2C devices using the Raspberry Pi, which is great to know how to do (and really convenient considering you can do it directly from bash):
    http://www.swharden.com/wp/2016-10-10-raspberry-pi-rf-frequency-counter/

    On the other end of the spectrum, there’s code on my GitHub to pull I2C data from a LM75A temperature sensor directly into a microcontroller (ATMega328 in my case, notably not Arduino):
    https://github.com/swharden/AVR-projects/tree/master/ATMega328%202017-02-08%20i2c%20LM75A%20thermometer

    Hope it helps someone out there who might wish to do something similar one day!

Leave a Reply to Andreas KCancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.