Inexpensive USB Keyboard
September 9, 2010
I had done some work recently to show that a quick and easy USB keyboard could be created created with the teensy and found it to be a 1 day project that was easy to implement. There was one problem with this solution, the cost. It was very pricey for something as simple as a USB keyboard. I wanted to keep some of the nice processor functionality so a dumb terminal that translated into USB would not quite cut it.
I stuck with AVR in this case and took a look at v-usb which lets you create simple HID Keyboards and a large number of other projects quickly and easily. The good news is you can do it on small cheap hardware that is still extremely powerful. I choose the attiny85-20pu as my processor going over the 4-key keyboard schematic and found it to be perfect for what I was looking to do. Here is the part list and pricing:
- ATTiny85-20pu – $1.80 from Mouser
- 2x 68 ohm resistors – $0.30
- 1x 1.5k resistor – $0.15
- 2x 1N4148 Diode – $0.04
- 1 ended USB type-A cable – $2.10
- 1x 0.1uF ceramic capacitor – $0.30
Total: $4.69
The same using the teensy was about $32. While the teensy is of course a more powerful device, it all depends on what you intend to do with it.
I will post more later with the rest of the details on the project as it gets finished. I have some boards to etch and some molds to resin..
There was some issues out of the box, the first thing you should do when you get one is to connect the Arduino Gnd pin to pin 1 on the MicroVGA and 5V pin to pin 2. This will cause the unit to power up and output a display on both the VGA and SVideo outputs. Connect a convenient TV or monitor to one of the outputs and dig out an old PS/2 keyboard. The keyboard provides direct input to the MicroVGA for setup. Once you have this setup there are two contacts on the top of the board by pin 20 labeled “Setup”, put a wire across them and the output on the screen will switch to a menu that can be browsed with the keyboard. Select communications and change the value to SPI. There seems to be a display issue, after selecting SPI if you go back into the communications menu it still lists the wrong value but it is indeed selected. Restart by powering off / on and then you will be ready to setup your Arduino.
Once the SPI is enabled there were a few issues with the default library (the __builtin_avr_delay_cycles method was not defined). I found a nice answer on the Arudino Forums. Just in case there is an issue getting to the site here’s the code that should replace the existing arduino_uvga.c code in the microvga library for the Arduino.
// debugged 25/1/10 by Shaun Ruscoe
// changed 14/03/10 by Copabel for Arduino Mega.
// fixed 16/05/10 by Sh00rGEn
/*
This file implements low-level routines for Arduino MicroVGA-TEXT.
The MicroVGA has to be configured for SPI mode and connected as follows:
*/
#include "WProgram.h"
#include "conio.h"
#ifndef __builtin_avr_delay_cycles
void __builtin_avr_delay_cycles(unsigned long __n) {
while(__n)
__n--;
}
#endif
#if defined(__AVR_ATmega1280__)
// Arduino Mega Pin definitions
#define DD_SS 0 // PB0 | Arduino Mega Digital 53
#define DD_MOSI 2 // PB2 | Arduino Mega Digital 51
#define DD_MISO 3 // PB3 | Arduino Mega Digital 50
#define DD_SCK 1 // PB1 | Arduino Mega Digital 52
#define DD_RDY 4 // PB4 | Arduino Mega Digital 10
#else
// Arduino Duemilanove pin definitions
#define DD_SS 2 // PB2 | Arduino Digital 10
#define DD_MOSI 3 // PB3 | Arduino Digital 11
#define DD_MISO 4 // PB4 | Arduino Digital 12
#define DD_SCK 5 // PB5 | Arduino Digital 13
#define DD_RDY 0 // PB0 | Arduino Digital 8
#endif
#define DDR_SPI DDRB
void SPI_MasterTransmit(char cData)
{
/* Start transmission */
//SPDR = cData;
SPDR = cData;
/* Wait for transmission complete */
while ( ! (SPSR & (1<<SPIF)));
}
#define KEYBUF_SIZE 10
unsigned char keybuf[KEYBUF_SIZE];
unsigned char khead, ktail;
char kbhit;
int _getch()
{
int key;
while (!_kbhit()) ;
key = keybuf[khead];
khead++;
khead %= KEYBUF_SIZE;
if (key == 0) {
key = 0x100 | keybuf[khead];
khead++;
khead %= KEYBUF_SIZE;
}
return key;
}
int _kbhit()
{
if (khead == ktail)
_putch(0);
if (khead == ktail)
return 0;
if (keybuf[khead] == 0 && ((khead+1)%KEYBUF_SIZE) == ktail) {
_putch(0);
if (keybuf[khead] == 0 && ((khead+1)%KEYBUF_SIZE) == ktail)
return 0;
}
return 1;
}
void _putch(char ch)
{
unsigned char response;
__builtin_avr_delay_cycles(100);
PORTB &= ~(1<<DD_SS); // SS#=0
__builtin_avr_delay_cycles(100);
// wait for RDY signal to go low!
while (PINB & (1<<DD_RDY) );
__builtin_avr_delay_cycles(100);
/* Start transmission */
//SPDR = cData;
SPDR = ch;
__builtin_avr_delay_cycles(100);
/* Wait for transmission complete */
while ( ! (SPSR & (1<<SPIF)));
__builtin_avr_delay_cycles(100);
response = SPDR;
if (response != 0xFF) {
keybuf[ktail] = response;
ktail++;
ktail %= KEYBUF_SIZE;
kbhit = 1;
}
__builtin_avr_delay_cycles(100);
PORTB |= (1<<DD_SS); // SS#=0
}
void microvga_init()
{
kbhit = 0;
khead = 0;
ktail = 0;
/* Set MOSI and SCK output all others input
This agrees to AVR151 Table 1 also */
DDRB = (1<<DD_MOSI) | (1<<DD_SCK) | (1<<DD_SS);
DDRB &= ~(1<<DD_RDY);
DDRB &= ~(1<<DD_MISO); // MISO is always input
/* Enable SPI, Master, set clock rate fck/16 */
SPCR = (1<<SPE) | (1<<MSTR) | (1<<SPR0) | (1<<CPHA);
}
This should fix the compilation issues. The pin setup for this library is:
Here’s a couple pics of the board and the first image I got on the screen.
(yes… Exterminate is blinking…)
Scrounging Reveals a Heat Sink
May 15, 2010
A friend gave me some old PC’s he was going to toss out and I set to work taking them apart. Just recently I ordered 5 L293N H-bridges. These are going to be parts for my next motor driver. One thing I was missing was a good heat sink. I was lucky as I found a really nice heat sink that was used in the PC for heat dissipation for 6 Mosfets. The heat sink not only will work great for 4 of my L293N’s but also dissipates the correct amount of heat.
Below are some pics of the 4 L293N attached to the heat sink ready for mounting. I am going to redesign the PCB to match this change in arrangement. I’m currently using Fritzing to do my Schematics and PCB layout so I will post some nice looking results soon. I just submitted my L293N part to the Fritzing part contribution.
No Disassemble!
May 5, 2010
Here’s a pic of me tearing apart a server I got for free. It was quite fun and I got some nice things including a 256K sram chip. No idea if I can make it work yet but there were lots of caps resistors and other components that are just as useful.
Custom PCB Etching
April 25, 2010
Today I picked up the chemicals and parts needed for custom PCB printing. I will be doing a run tomorrow on a single sided PCB (no need to waste a nice double sided on the first try). I found out about an interesting way to reuse the chemicals over many many runs which should reduce the overall waste produced.
Here is the instructable with the method I will be using:
I won’t be building a UV light since I will be using our saltwater aquarium lights which should do the job about 1000x faster. Here is more information on the chemicals used and why they are a bit more earth friendly:!–A-better-etc/step4/Chemistry-Break/
Teensy Keyboard
April 15, 2010
A friend wanted to build a cool foot pedal game device. He purchased a teensy 2.0 from for a very reasonable $18. After about 2 hours I had the breadboard setup and the program put together to act as a USB keyboard. I am still trying to decide how to switch the keys that are assigned to each button later without having to reprogram the device.
To Build a Robot Part 5
April 11, 2010
I found a 15+ year old pre-printed circuit board from Radio shack and found it to fit just right for what needed. It would be nice to have a properly designed circuit board printed out but this will do nicely for now. Later after I decide if this is the best way to arrange the different parts of the robot I will put something together in Eagle and have someone create a cheap board for this.
Here is the finished solder job ( a bit butchered but it works )
The battery and motor connections are done through some nice terminals I picked up for $2 for the 6 pack. The PWM wire connector from the Arduino is a chopped up extension cord selected because it has enough wires to run the 4 PWM lines and the power and ground wire. It is also nicely shielded to keep noise down.
I will be adding a second L293B H-Bridge to this but I haven’t finished the soldering yet. I also need to setup the output for the second motor from the first L293. I left the solder points for the TLC 5940 NT un soldered so later i can setup a series of them to run even more motors. I will likely add a simple connector for the additional boards once i get a bit closer. When complete this board will drive 4 motors with a total of 2 amps at 3V. Due to the gearing it is more than enough. The gear I am using in the video below is a Tamiya 70103 Universal Gearbox. At some point I may change out the H-Bridge for a heavy duty mosfet for something that can withstand 30A of current.
Here’s a video of the motor spinning backward and forward.
Motor Controller
Next up, completion of the soldering on this board and beginning to fabricate the legs.
To); }
Arduino Lexan Case
April 3, 2010
I had some extra lexan laying around from an old project so I figured I would build a box. It’s not exactly square but it accomplishes the task of keeping it safe from.. Lexan stops bullets right? (jk)
I still need to attach a hinge and clean up the top to match the completely uneven box. I drilled holes for the USB VDIP1 Module im using to access a flash drive and I put in holes for the Arduino power supply and USB UART connections.
TLC 5920 48 Pin SSOP solder
April 3, 2010
I managed to get my 5920 on my breakout board. It took about 17 minutes which I am quite proud of. This is the LED driver I picked up from SD Electronics last week. It lets you control a number of LED’s at once. I am using it to control a number of motors rather than LED’s using H-Bridge chips to power the motors. It should work but I haven’t completed the schematic yet just going to try for a prototype to see what happens. Fingers crossed I don’t wreck an H-Bridge those things are expensive.
The other chip I ordered from Texas Instruments is the 5940 which was shipped two days ago so I expect that to arrive soon. I am quite excited to see the differences between the two considering how close they are to one another.
Here’s a before and after of the soldering.
I hope there is never a shortage of rosin flux or I’m gonna be in trouble.