sniffing i2c with the BusPirate

I received my BusPirate v4 a while ago, but didn’t really use it so far. That’s a cool analysis/debug tool for serial buses such as uart, spi, i2c and the like. For me i2c is the most interesting. From time to time, the communication doesn’t work as it should, and so far, I worked it out with trial and error. I hope the BusPirate can be of help in such situations in the future. So, here is my first test run.

The BusPirate is controlled through an uart textual interface:

minicom -D /dev/ttyACM1 -b 115200

When you connect to it, it performs a self test, and then you can choose the mode by entering m. In my case, that’s 4 for i2c. Next I get to choose between hardware and software. I don’t know the implications yet, but what I see is that hardware offers higher speeds, and locks up more often. Then I get to choose the bus speed. 100KHz is the standard. With ? you can always get a list of possible commands. (0) shows a list of available macros. (1) scans all possible addresses for connected devices, just like i2cdetect would do it on the computer. (2) finally is what I was after, that’s the i2c sniffer.

I was actually hoping it could find out why I’m having problems reading back a simple value from an AtMega8 to a RaspberyPi. The AtMega8 is at address 0x11 and the command to read the value is 0xA1. I verified with a serial connection to the AtMega8 that it has a proper value, but on the RaspberryPi I always get a 0. At least the command was received on the AVR as I could verify with the UART, but writing the value back is the problem. So here is what the sniffer outputs for the attempted read:

[[[][]][[[0x01+][0x04-[][[0x20+][[[[[][0x20-[][0x4C+][0x04-[][0x24+][0x20-][]]]

Let’s decipher those numbers. Plus means ACK and minus means NACK. Opening square bracked means start bit, and closing square bracket means stop bit. The expected sequence would be 0x22 (the address for sending to the AVR) 0xA1 (send back which value) 0x23 (the address for receiving from the AVR) 0x08 (or whatever value was stored on the AVR). But the above output doesn’t look like this at all. So, lets try to communicate from the BusPirate to the AVR directly. Here we go: Continue reading “sniffing i2c with the BusPirate”

AtTiny Advent Wreath

An advent wreath in late spring, you ask? Yes, the timing is a bit off, and that’s not just because the coldest spring in ages has not finished yet. While browsing for the topic of my last post, I discovered a nice little one-evening-project: Geeky advent from tinkerlog.
I had all the required parts here, so I just gave it a try. The adaptation from the AtTiny13 to an AtTiny45 was straight forward. But finding the right threshold value for the ambient light sensor was a bit trickier. Especially, as the ADC didn’t work at first. That was probably a difference between the two AtTiny’s. But once I configured the ADC properly for the AtTiny45, I flashed it a couple of times with different values, and turned the room light on an off, until I had a good threshold value.
It’s interesting how the flickering is done with the random values and the manual PWM. And especially, how one of the LED’s is used to sense the ambient light was intriguing. To save battery power during the day, it goes to sleep and waits for the watchdog timer to wake it up. It then senses the ambient light. If it is bright, it goes straight back to sleep. If it’s dark, it lights up the LED’s. Going through the four modes for the four weeks of advent is done by resetting, or just quickly disconnecting the power from the battery.

But now I look forward for the summer to come, before we can put the mini advent wreath to use…

As my modified code is so similar to the original, it’s not really worth to create a project on github. So, I just pasted the code below.

Continue reading “AtTiny Advent Wreath”

AtMega breadboard header

A while ago, I ordered some AtTiny breadboard headers from tinkerlog.com. Unfortunately, they didn’t have any boards for AtMega’s left. The ones for the AtTiny’s are very handy, and I used them whenever prototyping something with an AtTiny. In fact, I used it almost whenever flashing an AtTiny. Many times I wished I had one of these tiny boards for the AtMega’s and at some point I even forgot that they existed. Often times I just included in ICSP header on the stripboard.

Last week I thought I must have such a board for the AtMega’s as well, and created one with a bit of stripboard. The wiring is not pretty, but the device works well, and is a real help when prototyping.

Fritzing layout on github

switching the christmas tree online

The first time I got interested in home automation, was when browsing the arduino libraries. That was all about X10, which communicates over power lines. There are switches that can replace the regular light switches and are pretty cheap in the US. If you want such switches here in Switzerland, you’ll be surprised how expensive they are. And routers with X10 to make it accessible from your smart phone start at CHF 400. But what is easier to get here are the plugs with 433Mhz rf controllers. I got a set with one remote and three plugs for CHF 15 at hornbach. Then I ordered two different transmitters from China. One with the nRF905 chipset and an SPI interface. And one for sort of bit banging. I thought the one with SPI was going to be easier to use. I also found some code to interface it. But first I had to know what I need to send.

My first Idea was to use the DVB-T dongle with GnuRadio to sniff the rf protocol. Continue reading “switching the christmas tree online”

LED debugging the stereowrap hardware

I found out earlier that 5V is not enough to drive the shutter glasses. With my breadboard setup for stereowrap, I fed 12V to the op amps from an external source. Now that I moved the thing to a strip board, I added a step up converter that generates 12V from the 5V available on the USB port. I used an LT1301 which comes with an application note for exactly my use case. It was easy to implement and worked from the first try.

Then I temporarily switched from an arduino duemillanove to a leo stick. Although it’s a tiny clone which plugs directly into an USB port, it still seemed like a bit of an overkill. I thought of using one of the AtTiny’s for that project. As I was not too familiar with these yet, I first did a hello world blinking LED’s. Soon after, I learned that neither the Attiny45 nor the AtTiny85 have a hardware UART. Well, I thought, there is an arduino software serial library. Arduino libraries are generally very easy to use in the IDE. But as I programmed the chip directly this time I wanted to stay within CodeBlocks/CMake and use the arduino library from here. Continue reading “LED debugging the stereowrap hardware”

Make an RFID tag with an AtTiny and a coil

When I stumbled across this blog post, I was sure I have to try this at home. I had some interest in RFID for a while, but the Proxmark was too pricy for me just to play with. So this experiment came just right.

The attiny85’s were difficult to get in Switzerland, so I ordered them from Germany along with an ISP programmer. I think it would also work with other AtTiny’s for example the 45 is available from Conrad. The hex file is just 1.7 kB, so the AtTiny45 should suffice.

Continue reading “Make an RFID tag with an AtTiny and a coil”