This is only a preview of the October 2009 issue of Silicon Chip. You can view 32 of the 104 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Items relevant to "High-Quality Stereo Digital-To-Analog Converter, Pt.2":
Items relevant to "Digital Megohm & Leakage Current Meter":
Items relevant to "Using A Wideband O₂ Sensor In Your Car, Pt.2":
Articles in this series:
Purchase a printed copy of this issue for $10.00. |
Open-USB-IO:
a universal
I/O solution
This hardware I/O board will let you drive a host of digital
and analog I/O (input/outputs) via the USB interface on
your laptop or desktop computer. Based on an Atmel
Atmega32 microprocessor and not much else, it works on
Windows, Linux and Macs.
I
n the days of Windows 98 and
DOS, you could directly write to
the hardware ports on your computer, typically to the parallel printer
port and serial port. This was great
for hobbyists and many good projects
were built around programs which
directly accessed hardware.
I built a very useful logic analyser
that worked at 1MHz just by reading
the digital inputs of the parallel port.
I also controlled a bank of relays with
C code, writing to the parallel port.
Then came Windows XP, a great
improvement over Windows 98, except that it blocked direct access to
hardware ports. There was a quick and
dirty fix called giveio.sys but it wasn’t
always reliable.
Next, parallel and serial ports
started to disappear from laptops and
even desktop PCs. Finally, along came
Window Vista which has completely
blocked I/O access. Thus hobbyists
have been deprived of a powerful, simple, and cheap way to access hardware
from program code.
This inability to easily control hard26 Silicon Chip
ware is not just a problem for hobbyists.
At RMIT University where I lecture, we
had the same problem with our labs
and major projects.
In the Computer and Networks degree, students need to become familiar
with hardware, software, networks
and the interaction between hardware
and software (optional in Electrical
and Electronic and Communications
degrees).
In our quest to find ways for software
to control hardware we found several
USB boards that allowed digital input
and output (I/O) but they were either
expensive, didn’t do all we wanted,
didn’t work on Windows and Linux
and Macs or needed special drivers
to be installed.
We drew up the specifications for
our ideal hardware I/O board:
• Cheap, under $50 in bulk.
By
Dr Pj Radcliffe
Senior Lecturer, School of Electrical &
Computer Engineering, RMIT University.
• Lots of digital I/O, analog inputs
and PWM outputs.
• Basic I/O: LEDs, a Light Dependent Resistor (LDR) and a trimpot
for simple analog work.
• An RS-232 serial data port not
used for any system function such
as programming.
• The ability to drive DC motors or
stepper motors (at least 500mA
and 50V each).
• USB-driven, with no special drivers for Windows, Linux and Mac.
• Hardware I/O can be controlled
from the PC via a GUI, command
line or program code.
• Some prototyping area.
• Interface with simple hardware
using easy-hooks, or complex
hardware with a cable.
• All ICs in sockets to allow easy
repair if they are damaged.
• Users must be able to download
their own code into a powerful
microprocessor. Hardware can
thus be controlled direct from the
microprocessor with the USB just
providing power.
siliconchip.com.au
JTAG ICE
INTERFACE
STK200
PROGRAMMING
PORT
USB TO PC
RS232
MOTOR
POWER
RESET
TRIMPOT
ATMEGA32
NEW PIC TO COME
ALL I/O ON IDC PINS
LDR
8 SWITCHES
PROTOTYPE AREA
8 LEDS
Reproduced here significantly larger-than-life for clarity (it’s actually 125mm wide), this is the Open-USB-I/O Board
showing key interfaces.
• The whole thing should be Open
Source and GPL for both software
and hardware. This makes it easy
for anyone to modify and extend
the hardware or software but
they must release these changes
back into the public domain. It
also keeps the price down as no
one manufacturer can have a monopoly on the board.
The result is the Open-USB-I/O
board. Let’s look at its key features and
then see how to drive it.
What’s on the Open-USB-I/O
The compact PC board packs a lot
of features. Its heart is an Atmel ATMEGA32 microprocessor with 32KB
of code memory, 1KB of EEPROM and
2KB of RAM. You can do a lot with
32KB of code memory!
It also has three timers, four PWM
(Pulse Width Modulation) lines, eight
A-D converter ports with 10-bit accuracy, serial data ports, digital I/O ports
and much more.
Open-USB-I/O makes many of these
available to the user but a few must be
siliconchip.com.au
kept to drive the interfaces such as the
USB and the programming port.
The board has eight LEDs and eight
switches which can also be used as
eight digital inputs and eight digital
outputs. In fact these 16 lines can be
used as any combination of inputs and
outputs by reprogramming the data direction registers in the microprocessor.
Above the LED array there is a LDR
(light dependent resistor) which is
read via one of the analog inputs on
the microprocessor. The LDR can sense
the output of nearby LEDs which gives
interesting possibilities, including an
optical oscillator.
The trimpot in the middle of the
board is connected to another analog
port and provides a convenient variable analog input. Near the trimpot is
a space where the user can add an additional 2-pin device, such as a buzzer.
Circuit description
The full circuit of the Open-USB-I/O
board is shown in Fig.1. Only three IC
packages are used: IC1 is the MAX232ACPE RS232 interface chip; IC2 is
the Atmel Atmega32 microprocessor
and IC3 is the ULN2003A Darlington
array.
The top left shows the USB interface where the zener diodes ZD1
and ZD2 act as voltage limiters while
the 68resistors present the correct
load to the PC USB port. The USB
lines carry both DC power and high
frequency data signals. Inductor L1
and the associated capacitors filter
out noise to provide the DC rail, VCC.
On a desktop computer the USB port
can supply up to 500mA but laptops
can provide rather less. VCC is clean
enough for digital circuits but has too
much noise for analog circuitry so the
combination of inductor L2 and the
100nF capacitor gives extra filtering to
provide the AVCC rail which is used
for all the analog circuits in IC1.
The USB data interface is handled
by firmware on the ATMEGA32 which
uses interrupt PD2 and pin PD7 to receive or drive signals to the USB line.
The bottom right of the circuit has
S2-S9, a bank of eight switches which
can be read by the microprocessor. The
October 2009 27
Vcc
A
1.5k
Vbus
K
68
D–
21
GND
68
D+
K
16
K
ZD2
3.6V
A
Vcc
K
Vcc
RST
4
6
8
C5
100nF
Vcc
RST
PC2
PC4
PC3
PC5
8
2
10
X1 12MHz
C3
27pF
C7
1 F
C8
1 F
RS232C
CON11
(J11)
7
8
9
1
2
3
PD5
PB7
PB6
IC1
ATMEGA32
DSR
RxD
RTS
TxD
CTS
4
5
12
32
2
PIEZO
LDR1
1
17
20
18
19
8
7
6
PB5
PB4 5
4
PB3
3
PB2
2
PB1
PB0 1
PC0
PC1
PC2
PC3
PC4
PC5
PC6
PC7
X1
40
39
38
37
36
35
34
33
22
23
24
25
26
27
28
29
X2
C4
27pF
16
2
6
1
6
PD4
13
Vcc
PD6
RST
EDITORIAL NOTE: This circuit does
not have any protection for the inputs
to the IC1 processor; voltages of more
than 5V can damage the input.
A series resistor for each input would
provide protection, as the input
clamping diode within IC1 will be
current limited. Also, the power input
for open collector drives at CON1 does
not have reverse polarity connection
protection and a reverse supply can
destroy the IC3 clamping diodes.
10
5
9
7
PD3
9
RESET
S1
PB5
PB7
PB6
1
3
47k
A
7
9
4
6
PA0
PA1
PA2
PA3
PA4
PA5
PA6
PA7
D1
PA6
VR1
10k
CON9
(J9)
1k
47k
PD2
A
3
ICE/JTAG
CON8
(J8)
ARef
PD7
ZD1
3.6V
ICSP & TIA
COMMS
CON7
(J7)
2
5
1
30
AVcc
10
Vcc
LED1
1
2
3
4
AVcc
C2
100nF
PA7
CON6
(J6)
C1
100nF
1k
Vcc
L1
10 H
L2 10 H
USB
SOCKET
Vcc
C6
10 F
3
4
IC2
MAX232
5
14 T1o
T1in 11
7 T2o
T2in 10
13 R1in
R1o 12
8 R2in
15
R2o 9
C9
1 F
A
C10
1 F
15
K
14
A
K
A
K
A
K
A
K
A
K
A
K
K
PD1
PD4
10k
A
LED9
LED2
PD0
9x220
PD6
11
31
CON10
(J10)
1
RN2
2
Fig.1: the circuit diagram for the Open USB I/O module shows it is primarily based on a programmed ATMEGA32
along with several input/output devices and LED indicators. The various input/output and power connectors are
labelled here as CON1, CON2, etc, as is our normal practice. However, on the PC board overlay and in the text of this
article they are labelled J1, J2 etc, so we have shown both to avoid any confusion.
28 Silicon Chip
siliconchip.com.au
AVcc
CON3
(J3)
PA0
PA1
PA2
PA3
PA4
PA5
1
2
3
4
5
6
PA7
PD3
PD6
8
9
10
11
12
13
14
15
16
17
IC3 ULN2003A
18
19
20
1 1B
1C 16
2 2B
2C 15
3 3B
3C 14 PB4*
4 4B
4C 13 PB3*
5 5B
5C 12 PB2*
6 6B
6C 11 PB1*
7 7B
7C 10 PB0*
E
8
1
3
5
7
9
11
13
15
17
19
21
23
25
27
29
31
33
35
37
39
7
PD4*
PD5*
COM
POWER FOR
OPEN COLLECTOR
DRIVES
Vcc
CON1
(J1)
9
PORT C 8 DIGITAL
INPUTS (OR OUTPUTS)
PORT B 8 DIGITAL
OUTPUTS
CON2
(J2)
1
3
5
7
9
11
13
15
17
19
21
23
25
27
29
31
33
35
37
39
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
PB0
PB1
PB2
PB3
PB4
PB5
PB6
PB7
19
20
S2-9
9x 4.7k
RN1
ZD1, ZD2
A
SC
2009
LEDS
K
D1: 1N4148
A
K
K
A
K
A
OPEN USB I/O MODULE
siliconchip.com.au
2
4
6
8
10
12
14
16
18
20
22
24
26
28
30
32
34
36
38
40
CON5
(J5)
PC0
PC1
PC2
PC3
PC4
PC5
PC6
PC7
VSUPPLY
PORT A ANALOG
INPUTS,
PORT D DIGITAL I/O
(OPEN COLLECTOR
OUTPUTS:
50V/500mA)
Vcc
CON4
(J4)
2
4
6
8
10
12
14
16
18
20
22
24
26
28
30
32
34
36
38
40
LOAD
2.7k
7.2k
3k
Fig.2: the internal
circuit of one ULN2003
driver. The diode
connected to VSUPPLY
stops inductive spikes
from destroying the
chip when a load is
turned off.
microprocessor provides internal 100k pull-up resistors
on each port C pin. These set each port C pin to logic high
when the associated switch is open and logic low then the
switch is closed, bringing the external 4.7kpull-down
resistor (resistor array RN1) into play.
These inputs are available on the J4 connector (and the
J2 holes below the connector). Any external output capable
of driving the 4.7k resistor could be connected here and
be read by the microprocessor. If all the switches were
set to off the external input would only have to drive the
100k pull-up resistor.
Port B of the microprocessor drives eight LEDs (LED2-9,
labelled on the PC board DS2-DS9) through a 220resistor
array and then via link J10 to 0V. If the link is removed
the LEDs will not light. This can be useful if port B pins
on connector J5 are intended to drive external devices.
Alternatively, the LEDs may be left connected when
driving external circuitry, as the ATMEGA32 outputs are
capable of driving 20mA and the LEDs only take around
12mA, thus leaving spare drive for external devices.
The ATMEGA32 should not drive more than 200mA for
the entire chip as an absolute maximum but given the chip
only requires some 12mA for its internal uses this leaves a
Controlling Open-USB-I/O from the command line
[user]$ ousb io PORTB 85
PORTB = 85
[user]$ ousb io PORTB 0xff
PORTB = 255
[user]$ ousb io PINC
PINC = 1
[user]$ ousb -h io PINC
PINC = 0x1
[user]$ ousb -b io PINC
PINC = 0b00000001
[user]$ ousb adc 6
ADC6 = 119
[user]$ ousb adc 5
ADC5 = 481
[user]$ ousb io PORTB 0
PORTB = 0
[user]$ ousb pwm-freq 1 7000
PWM #1 on pin 4 operating at 5859.375000 Hz
[user]$ ousb pwm 1 30
PWM #1 on pin 4 operating at a duty cycle of 0.301961
October 2009 29
J7
J11
J6
MOTOR
POWER
L1
4148
47k
1k
47k
L2
lot of drive for external devices.
The RS232 interface at the
bottom left of the circuit uses
C7
1
a standard MAX232 chip to
C1
RESET
+
C5
C9 +
4148
1.5k
4148
interface to the RS232 lines and
MAX232ACPE
C2
C6
68
X1
+
+
+
to provide the ±3V power sup10k
C3
C4
68
C8
C10
plies needed to drive the RS232
LSI
outputs. The device not only
J9
VR8
ULN2003A
handles transmit and receive
ATMEGA32
1k
but also one status line in and
one status line out. If the RS232
J5
port is not needed for serial
1
data, then the two output lines
J4
can be used as general purpose
1
outputs that drive around +3V
RN1 RN2
and --3V.
J10
BREADBOARD
PROTOTYPE AREA
AREA
The right side of the circuit
ON
DIP
LDR
LED1
shows the open-collector drive POWER
A
1 2 3 4 5 6 7 8
chip, ULN2003A, which has
LEDS 2-9
DIP SWITCHES 1-8
seven open-collector drivers.
A A A A A A A A
Fig.2 shows the circuit of one
Fig.3: PC boardONLY
layout,
looking from
top
(component
side).
The PC board is
TOP (COMPONENT)
SIDEthe
OF PC
BOARD
SHOWN FOR
CLARITY
of the Darlington drivers. An
double-sided but the bottom tracks are not shown for clarity.
input of 3V or more applied to
the 2.7k resistor will turn on
the Darlington transistor and current such an arrangement a signal on one
the microprocessor and hence every
can flow from VSUPPLY through the wire will usually create glitches on the
hardware interface.
load to ground. If the input goes to 0V wire next to it in the cable.
The ISP socket conforms to the
the Darlington turns off and the load
The pins on the 20-pin IDC arrays
older STK-200 programming interface
current drops to zero.
can be connected via easy-hooks or
standard which is supported by many
If the load is inductive, the built-in a proper cable, as can be found in
programmers. Using this you can downdiode connected to the positive supply
older computers (often on the side
load your own code into the microwill short-circuit the inductive current
of the road) that use IDE drives. The
processor or reload our USB interface
and ensure there are no large voltage right connector also has seven opencode.
spikes that could destroy the chip.
collector drivers powered from the
The JTAG interface allows an In
VSUPPLY is not tied in any way to motor power plug (top right of board).
Circuit Emulator (ICE) to be conthe board +5V and can range from 0V
The RS232 port provides a serial
nected and provide powerful debugto 50V. The Darlingtons can handle data link that is entirely at the user’s
ging facilities. Such ICE devices cost
500mA and so each of the seven driv- control; it’s not used for any programanywhere from about $50 to many
ers can control a small DC motor or a ming or control function.
hundreds of dollars.
coil in a stepper motor.
The USB socket takes a standard
If you are doing serious developOur students at RMIT have used USB A-B printer cable which provides
ment work that needs debugging, then
such a configuration to drive one
+5V power from the PC. Code on the
an ICE can save you a lot of time by
6-wire stepper motor (using four out- microprocessor enables the board
making it much quicker to find errors.
puts) and three DC motors or servo to act as a standard USB device and
You won’t need either of these sockets
units. The power for these motors is allows the ousb program on the PC
if you just want to control the I/O
usually connected to the 2.5mm DC to directly control every register in
ports from your PC. (Editor’s Note: for
socket (centre pin positive) which
corresponds to VSUPPLY above.
If you use the USB +5V as described
BASH script file example
above and your commands to Open#!/bin/bash
USB-I/O start to generate errors, then
#
it is likely that the output devices are
#----- BASH script to read the LDR light sensor and
drawing too much current from the
write the value to the LEDs.
USB port.
set –u
# stop autodeclaration of variables.
The two 20-pin IDC connectors, J4
LDR=
& J5, provide access to most of the
until [ 0 != 0 ]
# A forever loop, control-C from the keyboard to stop.
microprocessor pins and all the opendo
collector drivers. The back row of these
sleep 0.3
# pause for 300 ms.
pins are all connected to 0V. When a
LDR=$(ousb adc 6)
# get the LDR reading from Open-USB-I/O
cable is connected this means each
let “LDR = LDR/4”
# scale the 10 bit ADC back to 8 bits.
signal wire has a 0V wire on each side.
ousb io PORTB $LDR # write the value to the LEDs
This helps to stop interference both
done
to and from the signal wire. Without
J8
30 Silicon Chip
siliconchip.com.au
more on JTAG see the review article on
pages 44-48 of the August 2009 issue
of SILICON CHIP).
Lastly, the prototype area is big
enough to add your own hardware, for
example a motor, a relay or a number
of opto-isolators.
Obtaining the software
and hardware
There are several key resources that
will help you understand much more
about Open-USB-I/O and provide all
the required hardware, programs and
circuit diagrams.
The web site http://pjradcliffe.word
press.com/ has:
• A reference manual which covers
the USB commands in more detail,
how to program the board from
script files (.bat under Windows
or BASH under Linux), how to
write and download your own C
programs onto the ATMEGA32
and a description of various development tool chains.
• The Windows and Linux programs
that give the ousb command line
functionality described later in
this article. Normally the firmware
is pre-programmed into the OpenUSB-I/O board but the web site has
the firmware and instructions on
how to program it into the board.
• Hardware circuit diagrams for the
Open-USB-I/O board and a simple
programming cable which enables
you to download your own programs into the board.
The web site http://interestingbytes.
wordpress.com/ supplies the OpenUSB-I/O boards and also has a liveDVD with a huge range of development
tools. This bootable DVD provides
an excellent and surprisingly easy to
use Linux system running straight off
the DVD.
Live-DVDs do not touch the hard
disk, they run from just your DVD
drive and the RAM. However, if you
like the live-DVD then it takes only 15
minutes to install it as a dual boot to
the hard drive.
To boot the live-DVD ensure your
BIOS is set to boot first from DVD,
then put in the DVD and restart the
computer. When the desktop appears
double click on the readme.html file
and read through the help and howto information. Key features on the
live-DVD related to the Open-USB-I/O
board include:
• Code editors and avr-gcc C comsiliconchip.com.au
How to connect your circuitry to
Open-USB-I/O
piler and assembler for Atmel
microprocessors.
• The VMLAB emulator that enables
you to simulate your code, including hardware, before downloading
the code to real hardware.
• An excellent set of examples
which can serve as the basis of
your own projects.
• A variety of useful documentation,
including all data sheets for the
ATMEGA32 and Open-USB-I/O
board.
The live-DVD has an extensive array
of other development tools for Linux
including the Eclipse IDE for C, C++,
java, python, Perl, and C for the ATMEGA32. Other tools include Apache
web server, MySQL database server,
PHP, web editors such as Kompozer,
Qt Designer for GUI development and
much more. There is also a whole
range of network tools, drawing tools,
Open Office, audio-visual programs,
and a few games.
Construction
The Open-USB-I/O is available in
kit form or built and tested. The preassembled version is only slightly
more expensive than the kit version
and available from http://interestingbytes.wordpress.com/. However, any
hobbyist with reasonable soldering
skills should be able to build the board
themselves.
The following is for those constructing from a kit. Using the component
layout of the PC board (Fig.3), start
with the IC sockets, ensuring that pin
1 of each is properly orientated. The
notch at one end of the socket should
match the notch in the socket outline
on the board.
Next, solder in the sockets on
the back edge of the board, the two
shrouded IDC connectors, the USB
connector, the RS-232 connector and
the DC power connector. Note that
the notch in the two shrouded IDC
connectors should face the outside of
the board.
As you solder in the two 20-way IDC
connectors, be careful that they are
sitting flush to the board and solder
one pin on each end first.
Do not apply heat for too long to
any pin as the plastic can melt and the
pin will shift, making it impossible to
place a plug into the socket.
Now it is simply a matter of placing
and soldering in the rest of the components, starting on one side of the board
and moving to the other side.
Be especially careful with all polarised devices such as electrolytic
capacitors and LEDs.
Finally, insert the ICs into their
respective sockets (again watch the
polarity) and do a careful visual inspection, checking the board against
the photos and the overlay diagram of
Fig.3. Don’t forget to put in link J10
directly above the LEDs or the LEDs
will not light!
Power up by connecting the board,
via a USB cable, to a powered-up computer. The yellow power LED should
October 2009 31
immediately light. If not, check for
shorts between +5V and ground on
the board.
Start playing
The simplest way to control the
Open-USB-I/O board is via the command line.
On a Windows computer copy the
ousb.exe file from http://pjradcliffe.
wordpress.com/ to My Documents.
Start a terminal by clicking the start
icon, select Run, then type cmd in
the command box and hit enter. Use
the command cd “My Documents”
(change directory) to move to where
you have saved the ousb.exe file.
For Linux, copy the ousb file to some
where convenient. The location /usr/
local/bin is a good place for programs
as this is in the path. Another good
place is your home directory.
Check the program works by typing
just ousb in the command window,
help information should be displayed
(if you are using your home directory
on Linux use ./ousb).
To begin, let’s control the LEDs.
First, ensure link J1 directly above the
LEDs is plugged in. Type the command
ousb io PORT B 85 and every alternate
LED should be lit. This command is
writing to PORTB of the microprocessor which is connected to the LEDs.
Now try ousb io PORTB 0xFF
which will light all LEDs and uses
a hexadecimal number with all bits
set high. To turn off the LEDs, use
the number 0. Next try reading the
switches, first set all switches to ON
and try the command ousb io PINC.
The result should be zero. Now try
setting any switch and issue the command again. The result should show
a one bit for each switch turned off.
To view it in hexadecimal try ousb
–h io PINC, to see the result in binary
try ousb –b io PINC.
The LDR is a slow responding light
detector. Try the command ousb ADC
6 to see the light level. Try different
light levels and turning the LEDs on
and off, to see changes in the reading.
The trimpot provides a convenient
analog input, use the command ousb
adc 5 to read the setting. Try moving
the pot and note the reading changes.
If you have some easy-hooks and a
small DC motor then you can use the
PWM and the motor drivers. PWM generates a fixed frequency square wave
but varies the ‘on’ period (duty cycle).
A motor responds to the effective
32 Silicon Chip
Connections to drive a small motor with the pulse width modulator. Inset top
right is the J5 37-39 jumper required to drive the motor from USB port +5V.
average voltage so if the duty cycle
is 10% then the effective voltage to
the motor is 0.5V and the motor will
probably not even move. However, for
a duty cycle of 90% (which translates
to an average voltage of 4.5V), your
motor will spin freely.
There are two ways to get power for
the motor. The first is to use an external power source that plugs into the
2.5mm DC socket (centre pin positive)
on the board – in this case the motor
can be connected between pins 27
and 37 of J5.
The second approach is to use
the +5V supplied by the USB which
should be OK for a small DC motor.
If you are using this method you will
need to link pins 39 and 37 of J5.
The photograph above shows both
options. Note that the red and black
connections are required for both,
while the jumper between pins 39 and
37 of J5 (inset in red) is only required
for option 2, in order to use the USB
+5V to drive the motor.
The first PWM output can only operate at four set frequencies and the
output is connected to LED3 as well
as an open collector driver.
First set the LEDs to off using the
command ousb io PORTB 0 and then
set the frequency of the PWM to say
7kHz using the command ousb pwmfreq 1 7000. Note the frequency will
be rounded to one of the several fixed
values available.
Now set the duty cycle to 50% with
the following command: ousb pwm
1 50. LED2 should now be at half
intensity. Try other duty cycles to see
the intensity change, or if you have a
motor connected then the motor speed
will vary as the duty cycle changes.
Advanced play
The ousb io command allows the
user to access any register in the microprocessor and so gain full access
to all the on-chip peripherals which
include extra timers, I2C interfaces,
more PWMs, interrupts, input time
capture, the RS232 interface and more.
As an example let’s take port B
which is an output by default and then
make it an input.
First use the command ousb io
PORTB 255 to turn on all the LEDs.
siliconchip.com.au
Next, the data direction register for
port B must be altered – use ousb io
DDRB to read the current value, then
ousb io DDRB 0 to turn all the pins
to inputs which should turn off all
the LEDs. Add the command ousb io
PORTB 0 to turn off the microprocessor’s 100k pull-up resistors which
may cause the LEDs to glow dimly.
Now try the command ousb io PINB
to read the inputs. Use an easy-hook or
similar to connect the J4 pin for port
B bit 0 (pin 21) to +5V (pin 37) or 0V
(any even pin). Read the value of the
pin using ousb io PINB. To restore the
microprocessor to its default state first
remove all connections and then hit
the reset button.
Any ousb command can be placed in
a script file; a .bat file for Windows or a
BASH script file under Linux or Macs.
The Windows .bat files are not very
powerful compared to Linux BASH
script files. Under Windows you can
download a package called cygwin
(www.cygwin.com). This gives you a
Linux command line and BASH script
capability on Windows.
With a BASH script you can now
write complex programs to control
your Open-USB-I/O board. For example, the bash script file earlier reads the
Light Dependent Resistor and writes
the reading to the LEDs.
Starter projects to
power projects
The ATMEGA32 is a cheap yet very
powerful microprocessor and quite
amazing things can be done with it.
The web is filled with the hardware
and software that you can download
for free.
For example, Neil Franklin on his
website http://neil.franklin.ch/Projects/SoftVGA/ shows how to drive a
VGA display from the ATMEGA 32
with just six resistors. Austin Lu and
Albert Ren show to build an iPod interface (http://dev.emcelettronica.com/
how-to-control-ipod-atmel-mega32).
Perhaps you are just beginning, how
about just flashing a LED (at www.
dharmanitech.com/2008/10/adcproject-with-atmega32.html).
Some of the best projects and
information can be found at www.
avrfreaks.net; here you can find tools,
data sheets, getting started information
and projects ranging from the simple
to the extreme.
Low speed activities (below 1kHz)
can be driven from the PC via comsiliconchip.com.au
mand line, script, or C/C++ code.
Higher speed activities need to be programmed directly on the ATMEGA32
microprocessor.
Conclusion
The Open-USB-I/O board is an easy
and inexpensive way to achieve digital
and analog I/O from your laptop or
desktop using just the USB port. It
will work on Windows XP, Vista, Mac
OSX, Linux and other POSIX operating
systems without the need for special
drivers.
The board contains a whole range
of I/O pins, Pulse Width Modulators,
analog inputs, motor drive pins, and
more. The board also contains the
powerful ATMEGA32 microprocessor
and using the live-DVD you can write
your own assembler or C code then
download it into the ATMEGA32. The
live-DVD has several project examples
which can serve as the basis of your
own projects.
We have found the Open-USB-I/O
board very useful at the School of
Electrical and Computer Engineering
at RMIT University (Melbourne, Australia). It can be used in simple first
year programming activities right up
to final year microprocessor subjects
that require students to use the full
complexity of the ATMEGA32.
The board is used in our major
project activities which are both fun
and very important to our students
(employers want evidence that students can achieve things not just be
good at passing exams!). Hopefully
you will find Open-USB-I/O as useful
as we have.
We are developing more useful tools
based around Open-USB-I/O including a GUI controller and the ability to
program the ATMEGA32 just through
the USB connection.
Check the websites below in the
near future to get these tools.
SC
JOIN THE TECHNOLOGY
AGE NOW
with
PICAXE
Developed as a teaching tool,
the PICAXE is a low-cost “brain”
for almost any project
Easy to use and understand,
professionals & hobbyists can
be productive within minutes.
Free software development
system and low-cost in-circuit
programming.
Variety of hardware, project
boards and kits to suit your
application.
Digital, analog, RS232,
1-Wire™, SPI and I2C.
PC connectivity.
Applications include:
Datalogging
Robotics
Measurement & instruments
Motor & lighting control
Farming & agriculture
Internet server
Wireless links
Colour sensing
Fun games
Where do you get it?
See www.interestingbytes.word
press.com to purchase an OpenUSB-IO board and the live-DVD
which contains development tools
and example projects.
See www.pjradcliffe.wordpress.
com for a detailed reference manual,
and all the programs that you will
need.
Distributed in Australia by
Microzed Computers
Pty Limited
Phone 1300 735 420
Fax 1300 735 421
www.microzed.com.au
October 2009 33
|