DIY Arduino – the Ghettoino

intr0duction

I`m sorry for the long period of silence, but i had a lot of work in the last weeks…

Three months ago, i`ve started to extend my world of bits and bytes to a world of bits, bytes and a few blinking leds… and i still feel like iam still only scratching on the surface of this topic.

To speed up my learning process, i decided to get an Arduino. It is a realy great Project and uses a very intuitive and easy programming interface. But there was a little logical problem.. learning elecronics by buying a ready-to-use device that you can program doesn`t sound very educative… One of the great advantages about the Arduino Project is that everything is open source! Hardware, Bootloader, IDE.. it`s all open!! So i grabbed everything i have found and started to design my own basic Arduino-like Circuit.

This Arduino was named “the FAILduino” first, but was renamed to “Ghettoino” after it realy works ;)

To be able to communicate with my Arduino i used an Attiny85 with the avr-cdc USB to Serial Firmware. This is one of the cheapest solutions for USB i have found…

Due to my actual state i can not guarranty that everything works like expected, this is also the reason i have to declare this Project as “in heavy developement”. If you find errors or have some improvements than write a comment ;)

#1 get the parts!

  • 1x Atmega328 (or any other Arduino compatible MCU)
  • 1x Attiny45/85 (i`ve used an 85)
  • 1x USB connector (USB B shape)
  • 1x LED
  • 2x Ceramic Capacitor 100nf
  • 2x Ceramic Capacitor 22pf
  • 1x 16mhz Crystal
  • 1x Pushbutton
  • Resistors (2x 68Ω, 2x 1k5Ω and one that fits for your LED)

you also need a small perfboard and soldering equipment (wire, soldering tin etc…).

#2 preparing the MCUs

On this point we need an Atmel compatible Programmer, i used steve bolts Programmer because its very easy to built on a Breadboard.

SP12 schematic:

steve bolts programmer

Programming the Attiny with avr-cdc:

first, wire up the ATTiny85 to your Programmer and test it using the following command:

avrdude -csp12 -pt85 -v

you should get a few informations about your chip. When avrdude returns with -1, check your wires and setup and try again.

If everything succeded, you need to download the cdc-232 Firmware from http://www.recursion.jp, upload cdctiny45/85.hex to the chip and set the Fuse settings.

Uploading the Firmware using the following command:

avrdude -csp12 -pt85 -U flash:w:cdctiny85.hex -U lfuse:w:0xf1:m
-U hfuse:w:0xce:m -U efuse:w:0xff:m

If everything is done so far, grab your ATmega328 and connect it to your Programmer and download ladyada`s optimized Arduino Bootloader here. Because of our tiny ATTiny85 (hehe..), we need to change the Baudrate define and recompile the Bootloader.

Open ATmegaBOOT_xx8.c and change line 90 to:

#define BAUD_RATE   4800

4800 baud is also the maximal value you should use in your Arduino sketches.

now upload your fresh compiled Bootloader to your ATmega328 chip.

avrdude -c sp12 -p m328p -e -u -U lock:w:0x3f:m -U efuse:w:0x05:m
-U hfuse:w:0xDA:m -U lfuse:w:0xFF:m

avrdude -c sp12 -p m328p -U flash:w:ATmegaBOOT_xx8_adaboot328.hex
-U lock:w:0x0f:m

 

Short note about Fuses: be carefull when you set the fuse settings, you can lock yourself out of the chip. I had messed up the Fuses several times. Here are two tips to get your chip back when something bad happened:

  1. use a Crystal (<20mhz, i used 12mhz).
  2. use a high voltage Programmer.

#3 Building the Circuit

Ghettoino Schematic (very first version)

* UPDATE: fixed AVCC and AGND connections on pins 20 and 22

yeah… i have to get warm with Fritzing.. i will correct the glitches in the next Version ;) Please note that i used a low current LED, depending on the LED youre using, you have to change R5! The ATMEGA168 in this schematic is actually a 328. This version does not provide any protection for your USB Port! I will fix that (serious) issue in the next version. If you want to build this one, you better double-double check the connections for shorts. Or use a different Powersource for building.

Some notes for debugging:

  • the status LED (pin19) should blink 3 times on power up. if your LED is always on, then there is a chance you messed up the fuse part.
  • if you bridge the RXD and TXD pin (pin2 and 3 on your ATmega328), you can test your USB to Serial circuit with screen.
    screen /dev/ttyACM0 4800

    Every key you type should be echoed to your terminal.

#4 A little hack for the Arduino IDE

open the File Boards.txt:

  • Windows: Go to [Arduino-1.0 path]\hardware\arduino
  • Linux: Go to /usr/share/arduino/hardware/arduino

paste the following snippet to the end of the File (maybe you have to be root under Linux):

##############################################################

atmega328.name=Arduino Ghettoino w/ ATmega328

atmega328.upload.protocol=arduino
atmega328.upload.maximum_size=30720
atmega328.upload.speed=4800

atmega328.bootloader.low_fuses=0xFF
atmega328.bootloader.high_fuses=0xDA
atmega328.bootloader.extended_fuses=0x05
atmega328.bootloader.path=atmega
atmega328.bootloader.file=ATmegaBOOT_168_atmega328.hex
atmega328.bootloader.unlock_bits=0x3F
atmega328.bootloader.lock_bits=0x0F

atmega328.build.mcu=atmega328p
atmega328.build.f_cpu=16000000L
atmega328.build.core=arduino
atmega328.build.variant=standard

##############################################################

Save Boards.txt and launch the Arduino IDE. now go to tools -> Boards and select Arduino Ghettoino.

#5 Testing and Done :D

whew.. we are nearly done ;) you should try to upload a tiny sketch to your new little friend :D

Blink Example:

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  This example code is in the public domain.
 */

void setup() {                
  // initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards:
  pinMode(13, OUTPUT);     
}

void loop() {
  digitalWrite(13, HIGH);   // set the LED on
  delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // set the LED off
  delay(1000);              // wait for a second
}

just click Upload and press the Reset Button on your Ghettoino Board when you read something like “Binary sketch size: “. Try it several times if it doesn`t work, maybe you pressed the Button too late ;)

 

 

 

driving 8 LEDs over LPT

Hey there,

today i will show you how to control 8 LEDs over the LPT Port… And yes.. i will use the ugly LPT to breadboard cable :)

1. wiring the breadboard:

  • connect the anodes with the 8 data pins (2 – 9) from the LPT Port.
  • connect the cathodes with a suitable Resistor to one of the LPT ground pins (18-25)

PIN-2 — (+) >> Diode >> (-) — Resistor — GND
PIN-3 — (+) >> Diode >> (-) — Resistor — GND
PIN-4 — (+) >> Diode >> (-) — Resistor — GND
PIN-5 — (+) >> Diode >> (-) — Resistor — GND
PIN-6 — (+) >> Diode >> (-) — Resistor — GND
PIN-7 — (+) >> Diode >> (-) — Resistor — GND
PIN-8 — (+) >> Diode >> (-) — Resistor — GND
PIN-9 — (+) >> Diode >> (-) — Resistor — GND

I used LEDs with an integrated Resistor.

Programming the LPT port:

here is my tiny C program ive used for the video. It uses the ppdev kerneldriver. i will release the windows port in a few days ;)

pptest.c

/********************************
pptest

small and simple demoprogram to test
the LPT port.

this code was hacked in 5 minutes
and HANDLES NO ERRORS! 

2012/12/31 by Tino Goehlert (cmdrk33n)

http://cmdrkeen.net

********************************/

#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <linux/ppdev.h>
#include <unistd.h>
#include <stdlib.h>

int parportfd = 0;
unsigned char r_data = 0x00;

unsigned char togglepin(unsigned char pin)
{
	r_data ^= 1 << pin;
	ioctl( parportfd, PPWDATA,&r_data);
	return r_data;
}

unsigned char clearpin(unsigned char pin)
{
	r_data &= ~(1 << pin);
	ioctl( parportfd, PPWDATA,&r_data);
	return r_data;
}

int main()
{
	parportfd = open("/dev/parport0", O_RDWR);
	ioctl( parportfd, PPCLAIM, NULL );
	//
	int repeats=0;
	for(;repeats<=10;repeats++){
		int pin = 0;
		for(pin=0;pin<8;pin++){
			togglepin(pin);
			usleep(50000);
		}

		for(pin=0;pin<8;pin++){
			clearpin(pin);
			usleep(50000);
		}
	}

	ioctl(parportfd,PPRELEASE);
	return 0;
}

pptest running on arch linux X64:

LPT to breadboard cable (the ugly way)

Working with PC ports on a breadboard was an frustrating task for me and i couldn’t find cables with only one pin row.

I will try to build my own breadboard 2 PC cables. I use different methods for each cable to develop a clean and easy solution.

and here is the first one:

LPT to breadboard cable

parts used:

  • pin bar
  • small shrink-on tube
  • old LPT cable
  • soldering equipment

yeah.. maybe this is one of the ugliest solutions. First i have measured every pin and noted the color of the cord, because i used an old LPT cable that can’t be opened. Oh.. and i want to thank my wife for holding the Multimeter on the cord end :D

We need 2 small shrink-on tubes to cut them into small pieces (1,5 cm – 2,0 cm should be enouth). And again.. thank you honey! ;)

Now we have the pin numbers and their colors, 25 pieces of shrink-on tube and our solder iron heating up. Lets start soldering the 25 cords to our pin bar… hmpf!!

I have started with cord 1 on the right end. Do not overheat the pin, the plasic in the middle can melt and loose the pin! You should also trim the cords in the middle because the outer cords need to be longer.

And now say hello to your new (and ugly) LPT cable that you can use on your breadboard!

image

I will provide a better method for an RS232 to breadboard cable this evening.. so stay tuned and thanks for reading! ;)