I recently got a MicroVGA output device for the Arduino:
From:
Cost: $US 29.95 + shipping
Using SPI you can send text to a normal VGA monitor (most of us will have one of them lying around).
Example output ...
To help use it I wrote a small library. First, to connect:
Wiring:
uVGA
Pin
1 GND Arduino GND
2 +5V Arduino +5V
3 +3V3 output NOT CONNECTED
4 /SS Arduino Digital 10
5 SCK Arduino Digital 13
6 /RDY Arduino Digital 9
7 MISO Arduino Digital 12
8 MOSI Arduino Digital 11
Switch to SPI mode
Plug in a PS2 keyboard (it only goes into one socket), power up the device, and short the "setup" pad (on the edge near the keyboard socket, see photo) with a screwdriver. It should enter "setup" mode.
- Select "Communication -> SPI Mode"
- Hit Enter
- (Note, if you go back in 1000000 baud is still selected, that is the default, not the current mode)
- Select "Save settings"
- Wait for confirmation
- Power device off (unplug Arduino from power)
Library
Download from:
http://gammon.com.au/Arduino/uVGA.zip (7 Kb)
Unzip contents into your "libraries" folder and then restart the IDE.
Sketch showing output
#include <SPI.h>
#include "uvga.h"
uVGA uvga;
void setup ()
{
uvga.begin ();
uvga.clrscr ();
uvga.println ("uVGA test.");
} // end of setup
void loop ()
{
for (int color = BLACK; color <= WHITE; color++)
{
uvga.textcolor (color);
uvga.print ("Color: ");
uvga.println (color);
uvga.println (micros ());
delay (1000);
}
} // end of loop
The class is based on the Stream class which lets you do the usual things you can with stuff like Serial. That is print, println, test if input is available, and so on.
You can also call these functions to do useful things with the screen like clearing it, changing colours and so on:
- clrscr
- clreol
- cursoron
- cursoroff
- textcolor
- textbackground
- textattr
- gotoxy
Sketch showing input
// Demonstrates text input
#include <SPI.h>
#include "uvga.h"
uVGA uvga;
void setup ()
{
uvga.begin ();
uvga.clrscr ();
uvga.println ("uVGA input test.");
} // end of setup
// callback handler for function keys
void fkey (const int key)
{
uvga.print ("Function key: ");
uvga.print (key, HEX);
uvga.println (" pressed.");
}
// get user input
void loop ()
{
char buf [20];
uvga.textcolor (WHITE);
uvga.print ("Enter something ... ");
uvga.getline (buf, sizeof buf, fkey);
uvga.textcolor (RED);
uvga.print ("You entered: ");
uvga.println (buf);
uvga.println ();
} // end of loop
The getline function lets you query for input. This is a blocking call. If you want to do it non-blocking just use uvga.available() and put things into a buffer (which is what getline does).
You can optionally supply a callback function to handle things like F3 being pressed, or the ESC key.
Streaming
Because the class is derived from the Print class (via Stream) you can also stream to it using the Streaming library, eg.
#include <Streaming.h>
...
uvga << x << "," << y << endl;
Cursor positioning
This sketch demonstrates cursor positioning, and turning the cursor off:
// gotoxy test
#include <SPI.h>
#include "uvga.h"
#include <Streaming.h>
uVGA uvga;
void setup ()
{
uvga.begin ();
} // end of setup
void loop ()
{
uvga.clrscr ();
uvga.cursoroff ();
for (int x = 1; x < 80; x += 10)
{
uvga.textcolor (x / 10 + 8);
if (x == 1)
uvga.textcolor (GREEN);
for (int y = 1; y <= 24; y++)
{
uvga.gotoxy (x, y);
uvga << x << "," << y;
}
}
delay (5000);
} // end of loop