Attiny85 + arduino serial monitor

Attiny85 + arduino serial monitor

so I’m working on this cloud project with a co-worker and trying to get a capacitive switch to work with it. If you have ever worked with capacitive switches you know how tedious this can be. Now imagine you have no way to monitor output, well that is what I was running into. Problem is you can never know what the output is with stock settings of an attiny. So my solution comes from the good boys/gals of MIT.

Lets set up a little basic “hello world” type example.

Make sure you connect a 220k resistor between pin 3 and Tx(transmit) input of arduino and put a jumper from ground to reset. if you do not do this, you could damage your board and/or attiny. (refer to picture above or pseudo-schematic below).

burn baby, burn…the bootloader

I really had never done this before I had to tinker with an Attiny85, but what this does, according to arduino guide, is sets fuse bits and bytes on the chip that allows us to compile code on it. here is an except (skip if you don’t care about details, just know you need it):

The items in this menu allow you to burn a bootloader onto the microcontroller on an Arduino board. This is not required for normal use of an Arduino board but is useful if you purchase a new ATmega microcontroller (which normally come without a bootloader). Ensure that you’ve selected the correct board from the Boards menu before burning the bootloader…When you upload a sketch, you’re using the Arduino bootloader, a small program that has been loaded on to the microcontroller on your board. It allows you to upload code without using any additional hardware. The bootloader is active for a few seconds when the board resets; then it starts whichever sketch was most recently uploaded to the microcontroller. The bootloader will blink the on-board (pin 13) LED when it starts (i.e. when the board resets).

But what if I haven’t installed attiny for arduino?! I’m freaking out maaaan.

Lo, and behold! If you do not have attiny85 (or other attiny) installed for arduino, it’s you’re lucky day! If you do, just skip to next step. Here is how to install:

Support for third-party hardware can be added to the hardware directory of your sketchbook directory. Platforms installed there may include board definitions (which appear in the board menu), core libraries, bootloaders, and programmer definitions. To install, create the hardware directory, then unzip the third-party platform into its own sub-directory. (Don’t use “arduino” as the sub-directory name or you’ll override the built-in Arduino platform.) To uninstall, simply delete its directory. —arduino website

Once code is uploaded you have one more setting to go, set the serial monitor to 19200 on reading. I can’t confirm why it doesn’t match the read speed, but it might have to do with the clock speed being at 8mhz, but that is a total guess. If you know, leave a comment I am interested in knowing.

Open up your serial monitor and type an exclamation mark “!” and this will initiate the serial monitor (I’ve noticed sometimes you have to open and close the monitor to get it to work right, and send it more than once. To turn serial monitor off, just send another “!”

other available commands are:

@ Toggle between holding the target in reset after programming and allowing the target to run immediately
# Reset the target now or allow the target to run if it is held in reset
$ Hold the target in reset

special thanks to Coding Badly and Erni for all their help, most info comes from here: Arduino Forum

Join the discussion
7 Comments

When you get a new blank microcontroller, you need to do a couple things before it will start running your sketches. You need to set the fuses on it, and possibly upload the Arduino bootloader to it, and you need to be able to actually upload the sketches to the chip. Fortunately, the Arduino folks have a great tutorial on how to use your existing Arduino to burn the bootloader onto a new chip and upload sketches to it. Unfortunately, this method isn’t really that permanent. I mean yes, you can keep a breadboard set up like that and just plug it in when you need it, but to me it seems messy. I wanted to make the process easier.

I’m pretty new to arduino and just bought my first attiny85. I successfully wired up my ’85 to a Duemilanove using these instructions (http://hlt.media.mit.edu/?p=1695) and sent the blink sketch so I’m pretty confident that I’m programing it correctly.

I copied the TinyKnockBang and TinyISP folders to ~/foo/Arduino/libraries, but I still simply cannot figure out how to get your code to work on my ’85 and send back data.

I *really* want to figure out how to do a serial read from the attiny so I can use it to debug an intervalometer program that I’m writing that uses a POT. I just can’t figure out how to get a serial read to work.

I figured out my problems; I’ve learned quite a bit from your entry and wrote my own and noting the steps that I found hard. I borrowed quite a bit from your blog including the awesome sketch you have.
Thanks very much for your help!

Many of the products SparkFun sells use an AVR, like an ATmega168 or an ATmega328, as a microprocessor. There are many reasons we like this microprocessor, not the least of which is that it is the processor used in Arduino. Just because a board uses an ATmega, though, doesn’t mean it’s an Arduino. However it does mean that code written for an Arduino can be used on a board that uses the same microprocessor! The only thing standing in the way of running custom code on a board with an AVR is actually loading the code onto the chip (since it likely isn’t loaded with the serial bootloader used on an Arduino). This tutorial is a guide on how to use an Arduino as a programmer to load code onto a standalone ATmega microcontroller.