27 October, 2014

Get visual output from your Arduino with only 2 resistors (and a screen with Video-in)


We just need a TV-Out cable and a pair of resistors (1K and 470 Ohms) and use the library ofmdmetzle@gmail.com to show the output we want through video on any screen. 
Quite simply, no added circuitry.



Is not this just great? The simplicity to power ...
The timing and signal connections to Arduino
This video explains in detail:





This is the code for the cube in PAL:




#include
#include
#include "schematic.h"
#include "TVOlogo.h"

TVOUT TV;

Zoff int = 150;
XOFF int = 0;
Yoff int = 0;
cSize int = 50;
view_plane int = 64;
float angle = PI / 60;

Cube3D float [8] [3] = {
{XOFF - cSize, cSize + Yoff, Zoff - cSize}
{XOFF + cSize, cSize + Yoff, Zoff - cSize}
{XOFF - cSize, Yoff - cSize, Zoff - cSize}
{XOFF + cSize, Yoff - cSize, Zoff - cSize}
{XOFF - cSize, cSize + Yoff, Zoff cSize +},
{XOFF + cSize, cSize + Yoff, Zoff cSize +},
{XOFF - cSize, Yoff - cSize, Zoff cSize +},
{XOFF + cSize, Yoff - cSize, Zoff + cSize}
};
cube2d unsigned char [8] [2];


void setup () {
TV.begin (PAL, 120,96);
TV.select_font (font6x8);
intro ();
TV.println ("I am the TVOUT \ nlibrary running on a Freeduino \ n");
TV.delay (2500);
TV.println ("I generate a PAL \ NTSC composite video nor using \ ninterrupts \ n");
TV.delay (2500);
TV.println ("My schematic:");
TV.delay (1500);
TV.bitmap (0.0, schematic);
TV.delay (10000);
TV.clear_screen ();
TV.println ("Lets see what \ Nwhat I can do");
TV.delay (2000);
  
// Fonts
TV.clear_screen ();
TV.println (0.0, "Multiple fonts:");
TV.select_font (font4x6);
TV.println ("FONT 4x6 font");
TV.select_font (font6x8);
TV.println ("FONT 6x8 font");
TV.select_font (font8x8);
TV.println ("FONT 8x8 font");
TV.select_font (font6x8);
TV.delay (2000);
  
TV.clear_screen ();
TV.print (9.44 "Draw Basic Shapes");
TV.delay (2000);
  
// Circles
TV.clear_screen ();
TV.draw_circle (TV.hres () / 2, TV.vres () / 2, TV.vres () / 3, WHITE);
TV.delay (500);
TV.draw_circle (TV.hres () / 2, TV.vres () / 2, TV.vres () / 2, WHITE, INVERT);
TV.delay (2000);
  
// Rectangles and lines
TV.clear_screen ();
TV.draw_rect (20,20,80,56, WHITE);
TV.delay (500);
TV.draw_rect (10,10,100,76, WHITE, INVERT);
TV.delay (500);
TV.draw_line (60,20,60,76, INVERT);
TV.draw_line (20,48,100,48, INVERT);
TV.delay (500);
TV.draw_line (10,10,110,86, INVERT);
TV.draw_line (10,86,110,10, INVERT);
TV.delay (2000);
  
// Random cube forever.
TV.clear_screen ();
TV.print (16,40, "Random Cube");
TV.print (28.48 "Rotation");
TV.delay (2000);
  
randomSeed (analogRead (0));
}

void loop () {
rsteps int = random (10,60);
switch (random (6)) {
case 0:
for (int i = 0; i
zrotate (angle);
printcube ();
}
break;
case 1:
for (int i = 0; i
zrotate (2 * PI - angle);
printcube ();
}
break;
case 2:
for (int i = 0; i
xrotate (angle);
printcube ();
}
break;
case 3:
for (int i = 0; i
xrotate (2 * PI - angle);
printcube ();
}
break;
case 4:
for (int i = 0; i
yrotate (angle);
printcube ();
}
break;
case 5:
for (int i = 0; i
yrotate (2 * PI - angle);
printcube ();
}
break;
}
}


void intro () {
unsigned char w, l, wb;
int index;
w = pgm_read_byte (TVOlogo);
l = pgm_read_byte (TVOlogo + 1);
if (w & 7)
wb = w / 8 + 1;
else
wb = w / 8;
index = wb * (l-1) + 2;
for (unsigned char i = 1; i
TV.bitmap ((TV.hres () - w) / 2.0 TVOlogo, index, w, i);
= index-wb;
TV.delay (50);
}
for (unsigned char i = 0; i <(TV.vres () - l) / 2; i ++) {
TV.bitmap ((TV.hres () - w) / 2, i, TVOlogo);
TV.delay (50);
}
TV.delay (3000);
TV.clear_screen ();
}


printcube void () {
// Calculate 2d points
for (byte i = 0; i <8 i="" span="">
cube2d [i] [0] = (unsigned char) ((Cube3D [i] [0] * view_plane / Cube3D [i] [2]) + (TV.hres () / 2));
cube2d [i] [1] = (unsigned char) ((Cube3D [i] [1] * view_plane / Cube3D [i] [2]) + (TV.vres () / 2));
}
TV.delay_frame (1);
TV.clear_screen ();
draw_cube ();
}


zrotate void (float q) {
float tx, ty, temp;
for (byte i = 0; i <8 i="" span="">
tx = Cube3D [i] [0] - XOFF;
Cube3D = t [i] [1] - Yoff;
temp = tx * cos (q) - t * sin (q);
ty = tx * sin (q) + ty * cos (q);
tx = temp;
Cube3D [i] [0] = tx + XOFF;
Cube3D [i] [1] = t + Yoff;
}
}


yrotate void (float q) {
float tx, tz, temp;
for (byte i = 0; i <8 i="" span="">
tx = Cube3D [i] [0] - XOFF;
tz = Cube3D [i] [2] - Zoff;
temp = tz * cos (q) - tx * sin (q);
tx = tz * sin (q) + tx * cos (q);
tz = temp;
Cube3D [i] [0] = tx + XOFF;
Cube3D [i] [2] = tz + Zoff;
}
}


xrotate void (float q) {
float ty, tz, temp;
for (byte i = 0; i <8 i="" span="">
Cube3D = t [i] [1] - Yoff;
tz = Cube3D [i] [2] - Zoff;
temp = ty * cos (q) - tz * sin (q);
tz = t * sin (q) + tz * cos (q);
t = temp;
Cube3D [i] [1] = t + Yoff;
Cube3D [i] [2] = tz + Zoff;
}
}


draw_cube void () {
TV.draw_line (cube2d [0] [0], cube2d [0] [1], cube2d [1] [0], cube2d [1] [1], WHITE);
TV.draw_line (cube2d [0] [0], cube2d [0] [1], cube2d [2] [0], cube2d [2] [1], WHITE);
TV.draw_line (cube2d [0] [0], cube2d [0] [1], cube2d [4] [0], cube2d [4] [1], WHITE);
TV.draw_line (cube2d [1] [0], cube2d [1] [1], cube2d [5] [0], cube2d [5] [1], WHITE);
TV.draw_line (cube2d [1] [0], cube2d [1] [1], cube2d [3] [0], cube2d [3] [1], WHITE);
TV.draw_line (cube2d [2] [0], cube2d [2] [1], cube2d [6] [0], cube2d [6] [1], WHITE);
TV.draw_line (cube2d [2] [0], cube2d [2] [1], cube2d [3] [0], cube2d [3] [1], WHITE);
TV.draw_line (cube2d [4] [0], cube2d [4] [1], cube2d [6] [0], cube2d [6] [1], WHITE);
TV.draw_line (cube2d [4] [0], cube2d [4] [1], cube2d [5] [0], cube2d [5] [1], WHITE);
TV.draw_line (cube2d [7] [0], cube2d [7] [1], cube2d [6] [0], cube2d [6] [1], WHITE);
TV.draw_line (cube2d [7] [0], cube2d [7] [1], cube2d [3] [0], cube2d [3] [1], WHITE);
TV.draw_line (cube2d [7] [0], cube2d [7] [1], cube2d [5] [0], cube2d [5] [1], WHITE);
} 

Amazing what you can do ... an Arduino Atmega chip has the ability to display a tetris type game screen via a normal V-Out connection (which bring TVs and TFT frames), thanks to the libraryVideo Game Shield.




With the library prepared by Wayne and Layne I can make very useful things ... like a graphic of values ​​in real time on the screen:

  


In PAL format (for which also brings examples) has a sufficient resolution of 120x96 pixels; considering that it has to convert the signal by software in real time and also allow time for calculations for our program, is quite impressive.
The only problem can be that to use this method to display information on the screen is; limited remaining Atmel us to make other calculations in our project, and memory consumption; but you can always put another Arduino connected in series so that the work is distributed XDD.

Sources:

No comments :

Post a Comment