Pages: [1]   Go Down
Author Topic: vga synth box - help wanted  (Read 5629 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello, I would really appreciate some help on sending image data over serial to my arduino set-up.

I'm fairly new to Arduino, I've been working through some of the tutorials recently such as play melody and the virtual colour mixer, trying to get my head around the programming side of things.

I jumped into a project, perhaps a little hastily - following instructions for making a vga synthesiser (from here: http://arcanebolt.net/page/4) by Mark Beasley

As I understand it, the arduino is outputting an image to the red, green and blue colour channels of a vga monitor. I have followed the schematic and hooked up potentiometers to analog inputs 0,1,2 to control and distort h-sync, v-sync and image scroll.



Here is the code provided:

Code:
// copy-it-right

#define VSYNC 1 << 0
#define HSYNC 1 << 1

// high voltage (bright) RGB
#define HR     1 << 2
#define HG     1 << 3
#define HB     1 << 4

// low voltage (dim) RGB
#define LR     1 << 5
#define LG     1 << 6
#define LB     1 << 7


#define NOM1 asm("nop");
#define NOM10 asm("nop\t\nnop\t\nnop\t\nnop\t\nnop\t\nnop\t\nnop\t\nnop\t\nnop\t\nnop");


int lnc = 0;
int lna = 0;
int lnt = 479;

int imgb, imgc = 0, imgf = 0;

unsigned short int lni = 0;
unsigned char img[1792];


void hsync()
{
  NOM10;
  PORTB &= ~HSYNC;
  NOM10; NOM10; NOM10; NOM10; NOM10; NOM10;
  PORTB |= HSYNC;
  NOM10; NOM10; NOM10;
}


inline void pxl(int x)
{
  PORTD = img[lni + x];
  NOM1; NOM1; NOM1; NOM1; NOM1; NOM1;
}


ISR(TIMER1_COMPA_vect)
{
  // vsync
  if (lnc == -35) PORTB &= ~VSYNC;
  if (lnc == -37) PORTB |= VSYNC;

  hsync();

  if (lnc > -1) {
    // drawing a 30x30 image for now

    lni = (lnc + lna) >> 4 << 5;

    // 382 cycles
    pxl( 0); pxl( 1); pxl( 2); pxl( 3); pxl( 4); pxl( 5); pxl( 6); pxl( 7);
    pxl( 8); pxl( 9); pxl(10); pxl(11); pxl(12); pxl(13); pxl(14); pxl(15);
    pxl(16); pxl(17); pxl(18); pxl(19); pxl(20); pxl(21); pxl(22); pxl(23);
    pxl(24); pxl(25); pxl(26); pxl(27); pxl(28); pxl(29); pxl(30); pxl(31);

    // 2 cycles
    PORTD = 0;
  }

  lnc++;
  if (lnc > lnt) {
    lnc = -45;
  }
}


void setup()
{
  // pins
  DDRD = HR | HG | HB | LR | LG | LB;
  DDRB = VSYNC | HSYNC;
  PORTB = VSYNC | HSYNC;

  // timer
  TIMSK0 &= !(1 << TOIE0);
  cli();
  TCCR1A = 0;
  TCCR1B = 1 << WGM22 | 1 << CS10;
  OCR1A = 508;
  TIMSK1 = 1 << OCIE1A;
  sei();
 
  Serial.begin(9600);
}


void read_img_data()
{
  if (Serial.available() > 0) {
    if (Serial.read() == B11111100) {
      noInterrupts();
      lnt = 479;
      while (imgc < 1792) {
        imgb = Serial.read();
        if (imgb > -1) {
          img[imgc] = (unsigned char) imgb;
          imgf = 0;
          imgc++;
        } else {
          imgf++;
          if (imgf > 4096) {
            interrupts();
            return;
          }
        }
      }
      interrupts();
    }
  }
}


void loop()
{
  read_img_data();
  OCR1A = analogRead(0);  // 5K potentiometer
  lnt = analogRead(1) * 2;  // 5K potentiometer
  lna = analogRead(2);  // 1K or 5K potentiometer
}

I am trying to get my head around the code - I have some idea of what's going on, but not much. I THINK what's going on is this:
The code divides image data into red, green and blue signals, sets timings for hsync and vsync, displays an image, and waits for new image data to be transmitted over serial connection.

Is this correct? If so -

I am wondering how I can transmit new images to the arduino over serial - am I right in thinking this would require a script or Processing sketch? There is a Python script here which I think converts an image into the correct data format, but how is this then "pushed" through the serial connection for the arduino to access?

I hope this is making sense, I would really appreciate any help in clearing things up. I thing I was a over-ambitious here, but I really don't want to give up with this, since I've learned so much already!

Thanks in advance,

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hm - I have wired everything up and uploaded the code, and the monitor says that the signal the Arduino is outputting is out of range.

I'll have to figure that one out first!

Still looking for help if anyone is interested,

Cheers
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 220
Posts: 13836
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can't help you but maybe this thread has some interesting links - http://arduino.cc/forum/index.php?topic=102181.0 -
Logged

Rob Tillaart

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

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Did you move on with this project? I have same problems you had. I will really appreciate your help.

Thanks in advance!
Logged

Pages: [1]   Go Up
Jump to: