Image Image Image 01 Image Image Image Image Image Image Image Image Image Image

arduino

Attiny85 + arduino serial monitor

Tags | , , , ,

arduino2

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.

OLYMPUS DIGITAL CAMERA

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

Download latest version (choose the with arduino-tiny in title):
http://code.google.com/p/arduino-tiny/downloads/list

For example, my directory looked like:
/Users/[username here]/Documents/Arduino/hardware

ISP Sketch

In order to program with arduino you have to upload a sketch so it knows what to do with itself. Else it gets all frantic paranoid :)

https://github.com/Coding-Badly/TinyISP add this library to your arduino folder or download my modified version here: TinyISP

if you download source library you have to make some changes though (skip this if you download mine, I’ve already made these changes):

Navigate to the TinyISP_BuildOptions.h file

Locate this line…

#define RELAY_KNOCK_BANG_ENABLED 1

…and change it to this (change the one to a zero)…

#define RELAY_KNOCK_BANG_ENABLED 0

Locate this line…

#define RELAY_SERIAL_ENABLED 1

…and change it to this (change the one to a zero)…

#define RELAY_SERIAL_ENABLED 0

add the library

You also need to add the TinyDebugKnockBang library, download it here: TinyDebugKnockBang add it to your “Arduino > Libraries” folder

Next Step

choose your chip (ATtiny 84 (44/24), ATtiny 85 (45/25), ATtiny 2313 processor) in our case we have an attiny85. Remember we have to set at 8MHz because that is only speed the processor can use serial!

lets start simple, some test code:

#define KNOCK_BANG 1
#include <TinyDebugKnockBang.h>

#ifdef KNOCK_BANG
#define Serial Debug
#endif
void setup() {
    Serial.begin( 9600 );
}

void loop() {
    delay(1000);
    Serial.println("Can it be true?! An attiny serial monitor indeed!"); // debug output
}

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.

Screen Shot 2013-05-05 at 3.35.13 PM

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

Comments

  1. Francine Y. Mcmillan

    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.

  2. I cannot seem to get your code to pass the compile check. I get the following error:

    ketch_apr17b.cpp.o: In function `TinyDebugSerial::begin(long)’:
    /Users/aaronciuffo/Documents/Hobby/Arduino/hardware/
    tiny/cores/tiny/TinyDebugSerial.h:682: undefined reference to `Debug’
    /Users/aaronciuffo/Documents/Hobby/Arduino/hardware/
    tiny/cores/tiny/TinyDebugSerial.h:682: undefined reference to `Debug’
    sketch_apr17b.cpp.o: In function `loop’:
    /Applications/sketch_apr17b.ino:13: undefined reference to `Debug’
    /Applications/sketch_apr17b.ino:13: undefined reference to `Debug’

    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.

    Thanks for the write up and any help you can offer.

  3. 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!

    • lukasz

      @aaron. what parts did you find difficult?

  4. 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.

  5. Amazing tutorial. Fully detailed!

    I would also like to know what theme on your mac you are using if its possible, much appreciated :)

Submit a Comment