VGA library - now with TV output

Thanks for letting me know. I think I have found out what the actual problem is (basically in DMA mode SdFat gets SPI overruns if anything else is using DMA at the same time) but I'll bring it up in the SdFat thread where fat16lib is more likely to see it.

OK, after a lot of testing and debugging it turns out that using the #define USE_SAM3X_DMAC 0 workaround posted above is the fastest and best solution I can find to the problem of running DueVGA and SdFat together.

Does running SdFat at a slower SPI speed like this work?

  if (!sd.begin(chipSelect, SPI_HALF_SPEED)) sd.initErrorHalt();

No, even at SPI_SIXTEENTH_SPEED they still wouldn't work together in DMA mode.

I'm happy with the speed in non-DMA mode. It's fast enough for uncompressed full-screen animation at about 15fps. The code just loads each frame directly into the colour buffer:

#include <VGA.h>
#include <SdFat.h>

const int chipSelect = SS; // you may need to change this to the pin you connected SS to

SdFat sd;
SdFile file;

void setup() {
  VGA.begin(320,240,VGA_COLOUR);
  sd.begin(chipSelect, SPI_FULL_SPEED);
  file.open("anim.dat", O_READ);
}

void loop() {
  file.rewind();
  while(file.available()){
    file.read(VGA.cb,320*240);
  }
}

I've attached a video of the output (though being a highly compressed shaky video of a shaky video it doesn't look as good as it does in real life!)

shot0001.png

duevgaanim.mp4 (2.93 MB)

1 Like

I've made a new release of the library. Get it here: DueVGA-0.512.zip This release fixes a few bugs and clashes between DueVGA and the Serial and Audio libraries.

It also includes three longer demos - the GPS demo and the Animation demos have been posted above already, the other one is a demo of a waterfall plot. This takes an audio signal as inout, samples it and performs a FFT, and shows the result on a scrolling display. See the video and screenshot below for an example of what it does.

Very nice library ! I love it !

Just a little test : Display 256 colors palette.

Eddy

#include <VGA.h>
#define SQAURESIZE 8

void setup() {
  VGA.begin(320,240,VGA_COLOUR);
}

double a=0;

void loop() {

  int c=0;
  VGA.waitSync();
  
  double x = (320-SQAURESIZE*16)/2; 
  double y = (240-SQAURESIZE*16)/2;
  VGA.drawText("256 colors!",116,y-20,255,0);
  for (int j=0; j<16; j++){
    for (int i=0; i<16; i++){
      VGA.fillRect(i*SQAURESIZE+x,j*SQAURESIZE+y,i*SQAURESIZE+SQAURESIZE-1+x,j*SQAURESIZE+SQAURESIZE-1+y,c);
      c++;

    } 
  } 


}

Hi,

What about UNO board support? It makes sense to have light version of lib...

The

2leon76:
Hi,

What about UNO board support? It makes sense to have light version of lib...

DueVGA is too dependent on hardware features only available in the SAM3X chip in the Due (particularly DMA) so it would be impossible to port it to the Uno.

Not to mention going from 96k of ram to 2k..
Great work on this library. I've been looking for something cool to do with my Due, now I may have found it. :slight_smile:

I have been working on drawing bitmapped graphics with this library using a couple of techniques:

8-bit, 256 colour PNG images converted to unsigned char arrays of pixels

I have written a utility in Ruby that I'm finalising, which will convert 8-bit PNGs for display using Due VGA. It references a colour-palette PNG image that contains all the displayable colours on the Due, re-ordered so that they are correctly converted to their binary value.

8-bit, 16 colour PNG images converted to one-pixel-per-nibble unsigned char arrays

I have written a utility which, when given a 16-colour index palette, will produce an image at half the storage size. You will only have access to 15 actual colours, as index 0 is reserved for transparency.

Both of these things are in my GitHub and are highly experimental and very unfinished; https://github.com/Gadgetoid/Due-Megadrive-Controller/tree/Tinkering

See the Tools and MDC_VGA folders.

I have also produce an 8-bit palette which can be used with Adobe products (and possibly others) for compressing images for optimal display, see Tools/8bit-truecolor-palette.act

And, finally, a couple of photos to show what you can achieve with these tools:


UPDATE: I have now migrated the Arduino Due VGA specific stuff to a new repository, it was getting cluttered in with my MegaDrive controller library: GitHub - Gadgetoid/Arduino-DueVGA-Tools: Tools and code examples for converting/displaying bitmapped graphics on the Arduino Due using the DueVGA library.

And I've also thrown together a colour table which you can see here: http://pi.gadgetoid.com/arduino-due/DueVGA-colour-table

UPDATE 2: From an idea I had this morning. HSV to RRRGGGBB conversion: Arduino-DueVGA-Tools/DueVGA_HSV.ino at master · Gadgetoid/Arduino-DueVGA-Tools · GitHub

@Stimmer this code could be dropped straight into a SetPixelHSV function.

Hi,
I'd like to know what is the real reason to use the MOSI pin (A26).
Isn't it possible to use another pin, allowing to obtain a simpler connector ?
Thanks in advance for the reply,

gadgetoid: Wow, impressive work! Thanks for the HSV code, I may well add it to the library because it would simplify my fractal demos (which use an ugly look up table at the moment)

fog44: Monochrome mode uses the SPI hardware to generate pixels. Therefore the output has to be on the MOSI pin. I am experimenting if it is possible to use the SSC hardware (in which case output would be on port A.16 / Arduino pin A0) but I don't know if it will work yet.

Stimmer,
Is there a similar library for VGA input? I want to convert a VGA signal from my computer to a composite RCA output to a TV.

I figure the problem with this is the processor speed and not being able to both read the incoming signal and generate the outgoing signal quickly enough. Is that the limiting factor here?

I suppose I could write a PC application that would capture the screen and send it over serial to the Arduino and fill the frame buffer, and then simply have the Arduino generate the composite video signal. That may be doable, as long as I can cram that much video data over serial quickly enough to get it to appear to be video instead of stop-motion.

At 320x240 at 8-bit color, that'd be 76800 bytes of data for the frame buffer, at a baud rate of 115200 (bits per second) or 14400 Bytes/sec. By my calculation, it'd take 5.3 seconds to transfer one frame, which is far too slow.

I do have a wifi shield. I wonder if I can get better throughput using that. It looks like the wifi benchmarks are pretty good for throughput (can range from 0.7 Mbps to 3.4 Mbps reasonably). Although, that won't overcome the memory constraint.

From what I understand, the 480i (interlaced) TV format is equivalent to 640x480 resolution. Does the fact that the TV format is interlaced mean that that the frame is actually half the size (half-line or every-other line)? Or will I have to downsample my video to fit the memory of the microcontroller?

You're right about the limiting factor of processing and I/O speed. Also, grabbing a VGA signal would need 3 A/D converters running at 12.5Msps each just for 320x240 :slight_smile:

In composite mode there still isn't much processing capacity left for input. The closest thing to what you are doing that I have tried is the SD card animation demo, which loads uncompressed animations from an SD card straight into the framebuffer ram. In VGA mode the frame rate is acceptable but in composite mode it slows to a few frames per second (I can't remember exactly how slow it was, but it was unwatchable)


I created a shield to utilize this awesome library you made. I need to order a few more components before I can be sure I got it right, but I suspect it will work fine. I used jumpers to isolate the composite video resistors from the VGA resistors, and I went ahead and tossed in an LM386 amplifier hooked to the DAC0 and DAC1 pins with an audio out jack (may have accidentally selected the very small size audio jack, oops). Oh, and VGA has i2c data, I went ahead and broke out those pins. I left out support for monochrome mode, it just made things more manageable in the PCB layout.
I made a whole bunch of the boards, so once I confirm they actually work, I'll have them up on my Tindie store as DIY kits.. :slight_smile:

Wow, fantastic work 8)

One suggestion, if you are connecting to DAC0 and DAC1 put 4.7k resistors in series to make sure the output impedance is high enough, some of us have broken our DACs because RLOAD was too low.

I2C could come in useful, it can be used to tell the make and model of the monitor (quite easy, it's in ASCII) and the refresh rates and modes it supports (much harder, it is in a strange binary format)

I've got the DAC's capacitively decoupled from each other, and from the amp chip, definitely don't want to blow my or anyone else's DAC's. I'll keep everyone posted on when the parts come in, and I've had a chance to test out the board.

Ok, the shield I made "works".. I got the polarity backwards on the composite jack, the silkscreen is backwards on the jumpers, so you have to select VGA for composite, and composite for VGA.. DOH.. And the audio output jack is 2.5mm rather than 3.5mm.. It all works, so I'm going to respin the board and have another batch made. Anyone want one of these mostly working boards?
Great job on the library guys. I went ahead and added a jack for a Wii nunchuck adapter to the next rev, maybe someone can use this shield and this library to write video games. :slight_smile:

Ok, the board works well enough that I know the minor fixes will solve the minor mistakes of the first batch. I went ahead and listed them as a fundraiser on Tindie. Hope you don't mind me linking to your video stimmer, that was a pretty epic demonstration. :slight_smile:

Thanks For Awe Some Library :smiley:

I ask If you can Make tutorials for how you can make the Timing Signals Using The Arduino Board

And How you Write Library Like That If you can

I will be very Glad To learn from you

I know that my Request is strange some way :slight_smile:

Thanks In Advance