Category Archives: AVR Basics

As part of my cunning plan to develop ‘smart’ sensors, I’ve been playing around with infrared rangefinders (and may do a post on those soon). But the first kind of rangefinder I ever tried was the ultrasonic type, so it was time to reacqauint myself. And, in particular, I wanted to see if I could do this on the cheap…. Read more »

It’s an increasingly digital world, but not all information comes packaged neatly in 1s and 0s. Sometimes you have to deal with analogue voltage levels using the microcontroller’s analogue to digital (ADC) converter. Measuring analogue voltages is made easy in Arduino projects because the IDE comes with a handy analogRead() function. Providing your input voltage does not exceed what the… Read more »

In building my AVR ATMEGA328P-based ‘virtual parallel printer‘, there were two signals that required special treatment. So it was time to revisit interrupts. On a Centronics-style parallel port, the host machine sends an ‘init’ or reset signal to the printer to tell it to flush its buffers and set itself to the default state. It also sends a ‘strobe’ signal… Read more »

Part 1 – bit rate Part 2 – transmitting Part 3 – sending data Part 4 – receiving data Part 5 – final thoughts The I2C bus isn’t that hard to use and for most applications it’s pretty simple. However, there is a lot more depth to it than we’ve covered here. The purpose of this final post in the… Read more »

Part 1 – bit rate Part 2 – transmitting Part 3 – sending data Part 4 – receiving data Part 5 – final thoughts This builds on the previous two posts that dealt with the fundamentals of sending data over the I2C bus on AVR microcontrollers and then how you actually do it. Receiving is a similar process, except for… Read more »

Part 1 – bit rate Part 2 – transmitting Part 3 – sending data Part 4 – receiving data Part 5 – final thoughts In part 2 we looked at the fundamentals of how data is transmitted over the I2C bus. Now let’s actually do it. And, as usual with AVR microcontroller stuff, it’s all about registers. As before, our… Read more »

Part 1 – bit rate Part 2 – transmitting Part 3 – sending data Part 4 – receiving data Part 5 – final thoughts So in the first post in this series, we looked at how to configure the bus speed for I2C. Now we’ve got that out of the way, let’s start sending stuff over the bus. The I2C… Read more »

Part 1 – bit rate Part 2 – transmitting Part 3 – sending data Part 4 – receiving data Part 5 – final thoughts When I first started playing around with Arduinos I quickly grew to like the I2C bus, and for a couple of good reasons. First, it was easy to use. And second, there are lots of fascinating… Read more »

One of the issues with the Serial Peripheral Interface (SPI) bus, as many people have noted, is that it requires one Slave Select (SS) line – which means one GPIO pin on your microcontroller – for each device on the bus. That’s in addition to the three main bus lines – MOSI, MISO and SCK. This might be difficult on… Read more »

In Part 1 we got the SPI bus set up on an AVR ATMEGA328P microcontroller. Now let’s start using it. Settings pins Before we get going, we need to set up the pins for the SPI bus on the AVR (which we’re using in master mode). I’m using the ATMEGA328P here, so I’m going to define some macros to make… Read more »

When it comes to getting devices to talk to each other you’re spoiled for choice. There’s good, old-fashioned serial via UARTs, I2C (which I like a lot) and what is rapidly becoming my new favourite, the Serial Peripheral Interface (SPI). So let’s take a look at that. [Quick side note: please remember I don’t claim to be an expert. I’m… Read more »

It seems like an obvious point, but it’s sometimes handy to know what your code is up to. If you normally write code for desktop systems – and especially if you’re hacking out something that works on the command line – then it’s easy. Just pepper your program with print statements to show the state of play. (Then try to… Read more »

Do you ever get the feeling that a compiler is acting weird just to mess with your head? That’s how it felt yesterday. I was tinkering with the code for my HexMonitor. This uses an ATMEGA328P microcontroller to read values in from an eight-bit data bus or a 16-bit address bus (selectable via a switch) and display them on a… Read more »

One of the more challenging aspects of writing code for microcontrollers is not being able to liberally sprinkle your code with PRINT statements to show the state of variables and whatnot at particular moments. If you’re working with Arduino-type devices you can always fire up the Serial library and print stuff that way – back down the wire to a… Read more »

Once you’ve set up a pin, or a whole port’s worth of pins, as inputs or outputs, it’s time to start writing and reading values. This series is part of my learning process and I hope it will help others who, like me, are embarking on projects such as programming AVR chips. The way I learn things is to write… Read more »

Posts navigation

This is my journey through the worlds of electronics, robotics and retro computing. I’m not an expert – I’m learning as I go, and this is my way of sharing what I’ve learned. Think of it as a geek's diary and lab notebook.