Hey again all, I've been looking around and found an old project that generates an RGB signal, and that would be handy to have something to test monitors that would be quite small, instead of having to hook them up to a pc, and a place where I volunteer often gets many, many monitors and this would save time, plus it's another fun thing I could use an attiny85 for, I would just need to tweak the code to change the pattern every now and then.
So, I was wondering, how do I update this code to work with arduino 1.0.3?
The problem is that I guess arduino no longer uses "# define" anymore, so would I just need to make those variables? I'm going to mess around and try stuff but you guys can probably tell me in 10 minutes.
Anyways, here's the code, sorry it's long but I don't think there are spoilers on these forums.
/*
VGA
Author: Chris @ PyroElectro.com
Description:
This project is meant to be an example source for anyone
interested in outputting VGA signal's from a standard
Arduino UNO development board. The goal is to output VGA
800x600 @ 60 Hz.
Full project details:
http://www.pyroelectro.com/tutorials/arduino_basic_vga/
*/
#include <avr/io.h>
//Quickly Turn VSYNC On/Off
//Or You Can Change The VSYNC Pin..
#define VSYNC_LOW PORTD &= ~_BV(6)
#define VSYNC_HIGH PORTD |= _BV(6)
//Quickly Turn HSYNC On/Off
//Or You Can Change The HSYNC Pin..
#define HSYNC_LOW PORTD &= ~_BV(7)
#define HSYNC_HIGH PORTD |= _BV(7)
//RED
#define RED_ON PORTB |= _BV(4)
#define RED_OFF PORTB &= ~_BV(4)
//Green
#define GREEN_ON PORTB |= _BV(3)
#define GREEN_OFF PORTB &= ~_BV(3)
//BLUE
#define BLUE_ON PORTB |= _BV(2)
#define BLUE_OFF PORTB &= ~_BV(2)
void setup() {
}
void loop() {
//Initializations
int i = 0;
cli();
DDRB = 0xFF;
DDRD = 0xFF;
//Loop Over-And-Over Again
while(1){
//Clear The i counter
i=0;
//VSYNC Low
VSYNC_LOW;
//200 Lines Of Red
while(i < 200){
//Red Color High
RED_ON;
//2.2uS Back Porch
delayMicroseconds(2);
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
//20uS Color Data
delayMicroseconds(20); // 1uS
//Red Color Low
RED_OFF; //Low
//1uS Front Porch
delayMicroseconds(1); // 1uS
i++;
//3.2uS Horizontal Sync
HSYNC_HIGH; //HSYNC High
delayMicroseconds(3);
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
HSYNC_LOW; //HSYNC Low
//26.4uS Total
}
//Clear The i counter
i=0;
//VSYNC Low
VSYNC_LOW;
//200 Lines Of Green
while(i < 200){
//Green Color High
GREEN_ON;
//2.2uS Back Porch
delayMicroseconds(2);
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
//20uS Color Data
delayMicroseconds(20); // 1uS
//Green Color Low
GREEN_OFF; //Low
//1uS Front Porch
delayMicroseconds(1); // 1uS
i++;
//3.2uS Horizontal Sync
HSYNC_HIGH; //HSYNC High
delayMicroseconds(3);
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
HSYNC_LOW; //HSYNC Low
//26.4uS Total
}
//Clear The i counter
i=0;
//VSYNC Low
VSYNC_LOW; //Low
//200 Lines Of Blue
while(i<200){
//Blue Color High
BLUE_ON; //Low
//2.2uS Back Porch
delayMicroseconds(2);
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
//20uS Color Data
delayMicroseconds(20); // 1uS
//Blue Color Low
BLUE_OFF; //Low
//1uS Front Porch
delayMicroseconds(1); // 1uS
i++;
//3.2uS Horizontal Sync
HSYNC_HIGH; //HSYNC High
delayMicroseconds(3);
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
HSYNC_LOW; //HSYNC Low
//26.4uS Total
}
//Clear The i counter
i=0;
//VSYNC High
VSYNC_HIGH;
//4 Lines Of VSYNC
while(i<4){
//2.2uS Back Porch
delayMicroseconds(2);
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
//20 uS Of Color Data
delayMicroseconds(20);// 20uS
//1uS Front Porch
delayMicroseconds(1); // 1uS
i++;
//HSYNC for 3.2uS
HSYNC_HIGH; //High
delayMicroseconds(3);
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
HSYNC_LOW; //Low
//26.4uS Total
}
//Clear The i counter
i=0;
//VSYNC Low
VSYNC_LOW;
//23 Lines Of Vertical Back Porch + 1 Line Of Front Porch
//This is very, very flexible...I'm setting it to 22 Lines!
while(i < 22){
//2.2uS Back Porch
delayMicroseconds(2);
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
//20uS Color Data
delayMicroseconds(20);// 20uS
//1uS Front Porch
delayMicroseconds(1); // 1uS
i++;
//HSYNC for 3.2uS
HSYNC_HIGH; //High
delayMicroseconds(3);
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
HSYNC_LOW; //Low
//26.4uS Total
}
}
}
The problem is that I guess arduino no longer uses "# define" anymore,
That is not correct.
What error messages do you get?
I get these.
sketch_apr05a.ino: In function 'void loop()':
sketch_apr05a:47: error: 'DDRD' was not declared in this scope
sketch_apr05a:54: error: 'PORTD' was not declared in this scope
if I take out some of the first stuff I get some others later on but maybe they are due to these.
hmm you know I think I figured it out, the numbers after the part of the code for things like "PORTB" and "PORTD" match up with the pins they are using, maybe I just need to define those pins as those things.
/*
VGA
Author: Chris @ PyroElectro.com
Description:
This project is meant to be an example source for anyone
interested in outputting VGA signal's from a standard
Arduino UNO development board. The goal is to output VGA
800x600 @ 60 Hz.
Full project details:
http://www.pyroelectro.com/tutorials/arduino_basic_vga/
*/
#include <avr/io.h>
#define PORTD 6
#define PORTB 4
//Quickly Turn VSYNC On/Off
//Or You Can Change The VSYNC Pin..
#define VSYNC_LOW PORTD &= ~_BV(6)
#define VSYNC_HIGH PORTD |= _BV(6)
//Quickly Turn HSYNC On/Off
//Or You Can Change The HSYNC Pin..
#define HSYNC_LOW PORTD &= ~_BV(7)
#define HSYNC_HIGH PORTD |= _BV(7)
//RED
#define RED_ON PORTB |= _BV(4)
#define RED_OFF PORTB &= ~_BV(4)
//Green
#define GREEN_ON PORTB |= _BV(3)
#define GREEN_OFF PORTB &= ~_BV(3)
//BLUE
#define BLUE_ON PORTB |= _BV(2)
#define BLUE_OFF PORTB &= ~_BV(2)
void setup() {
}
void loop() {
//Initializations
int i = 0;
cli();
DDRB = 0xFF;
DDRD = 0xFF;
//Loop Over-And-Over Again
while(1){
//Clear The i counter
i=0;
//VSYNC Low
VSYNC_LOW;
//200 Lines Of Red
while(i < 200){
//Red Color High
RED_ON;
//2.2uS Back Porch
delayMicroseconds(2);
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
//20uS Color Data
delayMicroseconds(20); // 1uS
//Red Color Low
RED_OFF; //Low
//1uS Front Porch
delayMicroseconds(1); // 1uS
i++;
//3.2uS Horizontal Sync
HSYNC_HIGH; //HSYNC High
delayMicroseconds(3);
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
HSYNC_LOW; //HSYNC Low
//26.4uS Total
}
//Clear The i counter
i=0;
//VSYNC Low
VSYNC_LOW;
//200 Lines Of Green
while(i < 200){
//Green Color High
GREEN_ON;
//2.2uS Back Porch
delayMicroseconds(2);
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
//20uS Color Data
delayMicroseconds(20); // 1uS
//Green Color Low
GREEN_OFF; //Low
//1uS Front Porch
delayMicroseconds(1); // 1uS
i++;
//3.2uS Horizontal Sync
HSYNC_HIGH; //HSYNC High
delayMicroseconds(3);
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
HSYNC_LOW; //HSYNC Low
//26.4uS Total
}
//Clear The i counter
i=0;
//VSYNC Low
VSYNC_LOW; //Low
//200 Lines Of Blue
while(i<200){
//Blue Color High
BLUE_ON; //Low
//2.2uS Back Porch
delayMicroseconds(2);
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
//20uS Color Data
delayMicroseconds(20); // 1uS
//Blue Color Low
BLUE_OFF; //Low
//1uS Front Porch
delayMicroseconds(1); // 1uS
i++;
//3.2uS Horizontal Sync
HSYNC_HIGH; //HSYNC High
delayMicroseconds(3);
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
HSYNC_LOW; //HSYNC Low
//26.4uS Total
}
//Clear The i counter
i=0;
//VSYNC High
VSYNC_HIGH;
//4 Lines Of VSYNC
while(i<4){
//2.2uS Back Porch
delayMicroseconds(2);
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
//20 uS Of Color Data
delayMicroseconds(20);// 20uS
//1uS Front Porch
delayMicroseconds(1); // 1uS
i++;
//HSYNC for 3.2uS
HSYNC_HIGH; //High
delayMicroseconds(3);
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
HSYNC_LOW; //Low
//26.4uS Total
}
//Clear The i counter
i=0;
//VSYNC Low
VSYNC_LOW;
//23 Lines Of Vertical Back Porch + 1 Line Of Front Porch
//This is very, very flexible...I'm setting it to 22 Lines!
while(i < 22){
//2.2uS Back Porch
delayMicroseconds(2);
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
//20uS Color Data
delayMicroseconds(20);// 20uS
//1uS Front Porch
delayMicroseconds(1); // 1uS
i++;
//HSYNC for 3.2uS
HSYNC_HIGH; //High
delayMicroseconds(3);
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
HSYNC_LOW; //Low
//26.4uS Total
}
}
}
Now I try compiling and it highlights VSYNC_LOW and gives these errors.
sketch_apr05a.ino: In function 'void loop()':
sketch_apr05a:57: error: lvalue required as left operand of assignment
sketch_apr05a:61: error: lvalue required as left operand of assignment
sketch_apr05a:71: error: lvalue required as left operand of assignment
sketch_apr05a:78: error: lvalue required as left operand of assignment
sketch_apr05a:81: error: lvalue required as left operand of assignment
sketch_apr05a:88: error: lvalue required as left operand of assignment
sketch_apr05a:92: error: lvalue required as left operand of assignment
sketch_apr05a:102: error: lvalue required as left operand of assignment
sketch_apr05a:109: error: lvalue required as left operand of assignment
sketch_apr05a:112: error: lvalue required as left operand of assignment
sketch_apr05a:120: error: lvalue required as left operand of assignment
sketch_apr05a:124: error: lvalue required as left operand of assignment
sketch_apr05a:133: error: lvalue required as left operand of assignment
sketch_apr05a:140: error: lvalue required as left operand of assignment
sketch_apr05a:143: error: lvalue required as left operand of assignment
sketch_apr05a:150: error: lvalue required as left operand of assignment
sketch_apr05a:165: error: lvalue required as left operand of assignment
sketch_apr05a:168: error: lvalue required as left operand of assignment
sketch_apr05a:176: error: lvalue required as left operand of assignment
sketch_apr05a:192: error: lvalue required as left operand of assignment
sketch_apr05a:195: error: lvalue required as left operand of assignment
I'll see if defining vsync or something like that fixes it.
umm, ok I guess I fixed it? I'm not really sure how, but I just deleted stuff I put in and compiled and no errors, I'm gonna run it through notepad++ to compare but here it is.
/*
VGA
Author: Chris @ PyroElectro.com
Description:
This project is meant to be an example source for anyone
interested in outputting VGA signal's from a standard
Arduino UNO development board. The goal is to output VGA
800x600 @ 60 Hz.
Full project details:
http://www.pyroelectro.com/tutorials/arduino_basic_vga/
*/
#include <avr/io.h>
//Quickly Turn VSYNC On/Off
//Or You Can Change The VSYNC Pin..
#define VSYNC_LOW PORTD &= ~_BV(6)
#define VSYNC_HIGH PORTD |= _BV(6)
//Quickly Turn HSYNC On/Off
//Or You Can Change The HSYNC Pin..
#define HSYNC_LOW PORTD &= ~_BV(7)
#define HSYNC_HIGH PORTD |= _BV(7)
//RED
#define RED_ON PORTB |= _BV(4)
#define RED_OFF PORTB &= ~_BV(4)
//Green
#define GREEN_ON PORTB |= _BV(3)
#define GREEN_OFF PORTB &= ~_BV(3)
//BLUE
#define BLUE_ON PORTB |= _BV(2)
#define BLUE_OFF PORTB &= ~_BV(2)
void setup() {
}
void loop() {
//Initializations
int i = 0;
cli();
DDRB = 0xFF;
DDRD = 0xFF;
//Loop Over-And-Over Again
while(1){
//Clear The i counter
i=0;
//VSYNC Low
VSYNC_LOW;
//200 Lines Of Red
while(i < 200){
//Red Color High
RED_ON;
//2.2uS Back Porch
delayMicroseconds(2);
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
//20uS Color Data
delayMicroseconds(20); // 1uS
//Red Color Low
RED_OFF; //Low
//1uS Front Porch
delayMicroseconds(1); // 1uS
i++;
//3.2uS Horizontal Sync
HSYNC_HIGH; //HSYNC High
delayMicroseconds(3);
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
HSYNC_LOW; //HSYNC Low
//26.4uS Total
}
//Clear The i counter
i=0;
//VSYNC Low
VSYNC_LOW;
//200 Lines Of Green
while(i < 200){
//Green Color High
GREEN_ON;
//2.2uS Back Porch
delayMicroseconds(2);
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
//20uS Color Data
delayMicroseconds(20); // 1uS
//Green Color Low
GREEN_OFF; //Low
//1uS Front Porch
delayMicroseconds(1); // 1uS
i++;
//3.2uS Horizontal Sync
HSYNC_HIGH; //HSYNC High
delayMicroseconds(3);
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
HSYNC_LOW; //HSYNC Low
//26.4uS Total
}
//Clear The i counter
i=0;
//VSYNC Low
VSYNC_LOW; //Low
//200 Lines Of Blue
while(i<200){
//Blue Color High
BLUE_ON; //Low
//2.2uS Back Porch
delayMicroseconds(2);
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
//20uS Color Data
delayMicroseconds(20); // 1uS
//Blue Color Low
BLUE_OFF; //Low
//1uS Front Porch
delayMicroseconds(1); // 1uS
i++;
//3.2uS Horizontal Sync
HSYNC_HIGH; //HSYNC High
delayMicroseconds(3);
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
HSYNC_LOW; //HSYNC Low
//26.4uS Total
}
//Clear The i counter
i=0;
//VSYNC High
VSYNC_HIGH;
//4 Lines Of VSYNC
while(i<4){
//2.2uS Back Porch
delayMicroseconds(2);
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
//20 uS Of Color Data
delayMicroseconds(20);// 20uS
//1uS Front Porch
delayMicroseconds(1); // 1uS
i++;
//HSYNC for 3.2uS
HSYNC_HIGH; //High
delayMicroseconds(3);
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
HSYNC_LOW; //Low
//26.4uS Total
}
//Clear The i counter
i=0;
//VSYNC Low
VSYNC_LOW;
//23 Lines Of Vertical Back Porch + 1 Line Of Front Porch
//This is very, very flexible...I'm setting it to 22 Lines!
while(i < 22){
//2.2uS Back Porch
delayMicroseconds(2);
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
//20uS Color Data
delayMicroseconds(20);// 20uS
//1uS Front Porch
delayMicroseconds(1); // 1uS
i++;
//HSYNC for 3.2uS
HSYNC_HIGH; //High
delayMicroseconds(3);
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
HSYNC_LOW; //Low
//26.4uS Total
}
}
}
I'm gonna test it out, but I was wondering, do pwm pins have to be pwm, and digital digital?
According to that schematic it uses 3 pwm pins 2 digital but I can't be sure. Can anyone confirm if this is true or false and if they need to be the same?
Aslo, since the attiny only has 2 pwn pins is there a workaround to use, say, an analog pin as pwm?
If you read the article he has a workaround, sending 200 lines at a time, you don't get full pixel control but you get 3 lines, one of each red, green, and blue and that's all I need to test monitors (although I'll have them switch places).