VGA library - now with TV output

Well done!

Rossler chaotic attractor

#undef printf
#include <VGA.h>

  float a = 0.2;
  float b = 0.2; 
  float c = 8;

  float x,y,z;

  float xnn = 0;
  float ynn = 0;
  float znn = 0;

  float dt = 0.02;
  
  int cnt = 0;
  
  boolean vis;

void setup() {
  
  VGA.begin(800,600);
  VGA.clear();
  VGA.drawText(" Rossler chaotic attractor ",25,25,0,1);
  VGA.drawText("dx/dt = -y - z",25,50,1);
  VGA.drawText("dy/dt = x + ax",25,60,1);
  VGA.drawText("dz/dt = b + z(x-c)",25,70,1);
  VGA.drawText("a = 0.2",25,90,1);
  VGA.drawText("b = 0.2",25,100,1);
  VGA.drawText("c = 8",25,110,1);
}

void loop() {
  
       xnn = -(y+z);
       ynn = x+a*y;
       znn = b+x*z-c*z;

       x = x+xnn*dt;
       y = y+ynn*dt;
       z = z+znn*dt;
  
       VGA.drawPixel(350+(16*((z/2)-x)), 200+(12*((z/2)-y)), vis);
       
       if (cnt == 1500) { 
         vis = !vis;
         cnt =0; 
       }
       
       cnt ++;
}

Rossler_VGA.zip (633 Bytes)

Update: The Due VGA Library now has a github page :slight_smile:

http://stimmer.github.com/DueVGA/

I have written some instructions on how to wire up the circuit on a breadboard:
http://stimmer.github.com/DueVGA/breadboard.html

No code updates yet but the next release will have a big improvement in the speed of the colour modes, as I have now worked out how to do them using DMA :grin:

JLS1: May I include your Rossler code as an example in the next release of the library?

Hi stimmer

Yes all my codes is absolutelly free for anything use :slight_smile:

Many thanks your great works !

Kamil

Thanks JLS1, I added the Rossler demo :slight_smile:

I've made a new release of the library. The big news is the colour mode now uses DMA resulting in a speed increase of a factor of 4 :grin: I also added keywords.txt. Download is in the attachments on the first post.

No new release but I just had to share this: Whilst working on some experimental PAL code with a modified branch of the library I accidentally created the fractal below :fearful: :fearful: :fearful:

nice one :slight_smile:

please post code - THANKS

I've realised where I went wrong, I made a mistake in the calculus. It was supposed to be a fractal based on Newton's method - here is the correct code:

// Newton-Raphson fractal of Z^3+Z^2+Z+1=0

#include <VGA.h>
#include <complex>
using namespace std;

const byte cmap[]={0b00000000,0b11100000,0b11100100,0b11101000,0b11101100,0b11110000,0b11110100,0b11111000,0b11111100,
                   0b11011100,0b10111100,0b10011100,0b01111100,0b01011100,0b00111100,0b00011100,0b00011101,0b00011110,
                   0b00011111,0b00011011,0b00010111,0b00010011,0b00001111,0b00001011,0b00000111,0b00000011,0b00100011,
                   0b01000011,0b01100011,0b10000011,0b10100011,0b11000011,0b11100011,0b11100010,0b11100001,0b11100000,0b00000000};

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

void loop(){
  for(int i=0;i<320;i++){
    for(int j=0;j<240;j++){     
      complex<float> c(0,0),z((i-160.0)/80.0,(j-120.0)/60.0),zz,zzz;
      complex<float> one(1.0,0.0),two(2.0,0.0),three(3.0,0.0);
      int n;
      for(n=1;n<sizeof(cmap);n++){        
        zz=z*z; zzz=zz*z;
        c=(zzz+zz+z+one)/(zz*three+z*two+one);
        z-=c;        
        if(norm(c)<0.01)break;
      }
      VGA.drawPixel(i,j,cmap[sizeof(cmap)-n]);
    }
  }
  for(;;);
}

The correct output is attached. To get the bizarre picture above, change the line to:

c=(zzz+zz+z+one)/(zztwo+ztwo+one);

Thanks :slight_smile:

I've merged in the PAL and NTSC branches so the VGA library now does TV output. The circuit uses just 6 resistors and a capacitor. Quality is... err... well if you remember what home computers used to be like in the 80s you will have a fair idea of how low to set your expectations :wink:

Resolution is fixed at 320x240 in PAL and 320x200 in NTSC. I've tested it on 5 different TVs and monitors, but my timings are quite a way off spec so I would expect some trouble particularly on old TVs. I'll try and do a proper release tomorrow but the code is already on Github.

rdac.png

First of all, really great work!

I tried the DrawingTestPal example of your library with the Arduino Ide 1.5.2 on my Arduino Due, but it show me this error :

In file included from DrawingTestPAL.ino:1:
C:\Users\andrea\Desktop\Andrea\Arduino\arduino-1.5.2\libraries\VGA/VGA.h: In function 'void _v_digitalWriteDirect(int, boolean)':
C:\Users\andrea\Desktop\Andrea\Arduino\arduino-1.5.2\libraries\VGA/VGA.h:49: error: 'g_APinDescription' was not declared in this scope
C:\Users\andrea\Desktop\Andrea\Arduino\arduino-1.5.2\libraries\VGA/VGA.h:50: error: 'g_APinDescription' was not declared in this scope

Ithos92:
First of all, really great work!

I tried the DrawingTestPal example of your library with the Arduino Ide 1.5.2 on my Arduino Due, but it show me this error :

In file included from DrawingTestPAL.ino:1:

C:\Users\andrea\Desktop\Andrea\Arduino\arduino-1.5.2\libraries\VGA/VGA.h: In function 'void _v_digitalWriteDirect(int, boolean)':
C:\Users\andrea\Desktop\Andrea\Arduino\arduino-1.5.2\libraries\VGA/VGA.h:49: error: 'g_APinDescription' was not declared in this scope
C:\Users\andrea\Desktop\Andrea\Arduino\arduino-1.5.2\libraries\VGA/VGA.h:50: error: 'g_APinDescription' was not declared in this scope

Make sure you have selected Arduino Due in the Tools/Board menu - that's the main cause of that particular error message.

stimmer:
Make sure you have selected Arduino Due in the Tools/Board menu - that's the main cause of that particular error message.

It works!

Thank you!

Quick preview of the next release: Only minor bugfixes in the library, although one of those bugs was causing a hang when receiving Serial data, so if you use Serial and VGA you should upgrade (the fix is already in github master if you need it now)

The major addition is a new demo, which decodes GPS GPGGA/GPGSV strings and shows a rotated globe and satellite positions. Data can be taken from a real GPS or entered in the serial monitor. You have probably seen smartphone apps which do this, well now you can do it on an Arduino too 8) Watch satellites move across the sky in real time (although only if you are very patient as it takes the satellites 6 hours to get from one side of their orbit to the other!)

Sparkfun has a VGA breakout introduced lately, can this make connections for Due users easier? Papilio VGA Wing - WIG-11569 - SparkFun Electronics

Yes you could use that although it is actually 6 bit, not 8, so in colour mode you would only get 64 colours (you might be able to get all 256 by adding a few extra resistors). Mono mode should be just fine. It would need a bit of work to wire it to the right pins - it wouldn't just be able to plug straight into the Due like it can with a Papilio.

Stimmer,
I downloaded the library, but running into issues when also using the SDFat library to read my graphics off the SD Card. Any thoughts why these libraries conflict? Is there any potential for making them able to work together? It was possible previously with the PWM version.

I'd really like to use the VGA library because it's so convienient, but reading the graphics data off the SD card is absolutely needed (ie: I can't load the bitmap into the VGA library framebuffer without the SDFat library being initialized at the same time). I was hoping to take advantage of the speed increases you mentioned before, as well as the image stabilization using the additional timer.

Thanks for any info you can provide.

If it worked before I'd say there's a good chance that it will work again. I'll take a look at it later today.

Could you tell me a few things: which VGA screen mode are you using (mono, colour, PAL or NTSC), and which exact version of the SDFat library are you using and how is it wired up?

Stimmer,

VGA Library:
stimmer-DueVGA-0.404-3-g86f6dc0

Color at 320x240

Adruino Pin
34, 35 --> Blue
36, 37, 38 --> Red
39, 40, 41 --> Green
42, 43 --> Hsync / Vsync

I'm using the Arduino Wifi Shield (R2) with onboard SD Card reader. I'm not actually using the Wifi functions at the moment.

SDFat Library:
SdFatBeta20130207

Thanks - could you please try the following as a temporary workaround.

In the SdFat library, in file Sd2Card.cpp on line 85:
change "#define USE_SAM3X_DMAC 1" to "#define USE_SAM3X_DMAC 0"

Tell me if it works, and if it does work is the SdFat library now too slow or at an acceptable speed?

It looks like there is a DMA clash between the VGA and SdFat libraries. It should be possible to sort it out properly somehow - there should be a way to use DMA for both at the same time.