Go Down

Topic: Library for MicroVGA adapter (Read 3662 times) previous topic - next topic

Nick Gammon

Apr 17, 2012, 05:36 am Last Edit: Apr 17, 2012, 07:15 am by Nick Gammon Reason: 1
I recently got a MicroVGA output device for the Arduino:



From:

http://www.microvga.com/

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:

Code: [Select]
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

Code: [Select]

#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

Code: [Select]
// 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.


Code: [Select]
#include <Streaming.h>
...

     uvga << x << "," << y << endl;





Cursor positioning

This sketch demonstrates cursor positioning, and turning the cursor off:

Code: [Select]
// 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
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

robtillaart


Thanks for sharing!

Now I have no excuse anymore not to build a VT100 terminal that can be used instead of the serial Monitor ;)

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

brunialti

This is the case to find some practical use to unexpected device.
Great!

Royal

I gave this a try and I get the fault code of ('uVGA dose not name a type').  What am I doing wrong?

Nick Gammon

Can you copy and paste all the error messages please? Not just retype one of them.

I suspect you didn't install the library correctly, or restart the IDE after you installed it.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Royal

#5
Apr 22, 2012, 03:57 pm Last Edit: Apr 22, 2012, 04:16 pm by Royal Reason: 1
Please bare with me as I am not good at programming.  This is the error code I get---

demo.cpp:2:18: error: uvga.h: No such file or directory
demo.pde:-1: error: 'uVGA' does not name a type
demo.cpp: In function 'void setup()':
demo.pde:-1: error: 'uvga' was not declared in this scope
demo.cpp: In function 'void loop()':
demo.pde:-1: error: 'BLACK' was not declared in this scope
demo.pde:-1: error: 'WHITE' was not declared in this scope
demo.pde:-1: error: 'uvga' was not declared in this scope

Could you recommend a good tutorial for Arduino programming?

Nick Gammon

You have to download the .zip file mentioned above:

http://gammon.com.au/Arduino/uVGA.zip

Unzip it. Inside is a folder:

Code: [Select]
uVGA

Put that folder inside the "libraries" directory where all your Arduino sketches are.

Then close and re-open the Arduino IDE. If you put it in the right place that error will go away. If not, search for "how to install Arduino libraries".
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Royal

I am not doing very well with this project.  I think I am not doing something properly with my library files. I get this code---
demo.cpp.o: In function `uVGA':
C:\Users\Royal\Documents\Arduino\libraries\uvga/uvga.h:80: undefined reference to `vtable for uVGA'
C:\Users\Royal\Documents\Arduino\libraries\uvga/uvga.h:80: undefined reference to `vtable for uVGA'
demo.cpp.o: In function `loop':
C:\Users\Royal\AppData\Local\Temp\build1427714621194795111.tmp/demo.cpp:20: undefined reference to `uVGA::textcolor(int)'
demo.cpp.o: In function `setup':
C:\Users\Royal\AppData\Local\Temp\build1427714621194795111.tmp/demo.cpp:11: undefined reference to `uVGA::begin()'
C:\Users\Royal\AppData\Local\Temp\build1427714621194795111.tmp/demo.cpp:12: undefined reference to `uVGA::clrscr()'

Any thoughts?

Nick Gammon

My thoughts are that if you want help on your code you have to post it.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Royal

Due to the fact that I am new at Arduino I have a hard time getting things to work properly.  Thanks to you I did get the uvga board to work.
Thanks a lot for your help.  Now I hope I can learn to make programs that use the uvga.

isloman

Hi Nick,
  Thanks for your libraries and examples. Since I am running on an Arduino Mega 2560, I need to know where the SPI pins are defined, so I can modify for this Arduino?  Thanks.

robtillaart

check these page - http://arduino.cc/en/Main/ArduinoBoardMega2560 -
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

isloman

Thanks for your deeply.  I know which pin on the 2560 that I have to use, but I don't where in the software I need to go to change from the current default values.  For example I know that miso is 50 and mosi is 51, but where do I make these changes known to the software.  I must be somewhere in a library but which library and how do I override it?

isloman

Am I missing something?  I understand that the MicroVGA to Arduino (for the UNO) is:
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
And I can see from your code how I think I can the chip select (SS) and the ready (/RDY).  Where can I indicate to the software that I am using MEGA 2560 with, SCK: 52, miso: 50 and mosi: 51.  Are there some constructs that I need to add to uvga.cpp or some #defines?

Nick Gammon

I think in that sketch I used the alternative SPI on the USART:

http://www.gammon.com.au/forum/?id=10892&reply=3#reply3

Off-hand I don't know the pins on the Mega, but it would be in the datasheet.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Go Up