Hello,
I successfully created this project and wanted to use this Pico - VGA hardware configuration (because the VGA cable is soldered to my Pico W) for another project (Pong game). I tried to code this in MicroPython but could't get a VGA output. So I started to create a test file at first which looks like this - but still no signal on the screen. This code compiles without problems in Thonny and was saved to the Pico W as main.py so that it should run on boot. Could you please tell me what I'm doing wrong?
`from machine import Pin
import rp2
import time
VGA timing constants for 640x480@60Hz
H_ACTIVE = 640
H_FRONT_PORCH = 16
H_SYNC = 96
H_BACK_PORCH = 48
V_ACTIVE = 480
V_FRONT_PORCH = 10
V_SYNC = 2
V_BACK_PORCH = 33
@rp2.asm_pio(
out_init=rp2.PIO.OUT_LOW,
sideset_init=(rp2.PIO.OUT_HIGH,) * 2,
autopull=True,
pull_thresh=32,
fifo_join=rp2.PIO.JOIN_TX
)
def vga_program():
# Active video area
pull(block) .side(0b11)
out(x, 32) .side(0b11)
pull(block) .side(0b11)
label("active")
out(pins, 1) .side(0b11)
jmp(x_dec, "active") .side(0b11)
# Horizontal sync (simplified timing)
nop() .side(0b11) # Front porch
nop() .side(0b01) # HSYNC pulse
nop() .side(0b11) # Back porch
Create a simple test pattern (white screen)
line_words = H_ACTIVE // 32
test_line = [0xFFFFFFFF] * line_words
Initialize pins
video_pin = Pin(18, Pin.OUT) # GPIO18 -> Physical Pin 24
vsync_pin = Pin(19, Pin.OUT) # GPIO19 -> Physical Pin 25
hsync_pin = Pin(21, Pin.OUT) # GPIO21 -> Physical Pin 27
Initialize state machine
sm = rp2.StateMachine(
0,
vga_program,
freq=125_000_000, # Run at maximum frequency
sideset_base=Pin(19),
out_base=Pin(18),
set_base=Pin(21)
)
print("Starting VGA output...")
sm.active(1)
Main loop with VSYNC handling
vsync_counter = 0
try:
while True:
# Output one complete frame
for line in range(V_ACTIVE):
# Send line data
for word in test_line:
sm.put(word)
# Handle VSYNC
vsync_counter += 1
if vsync_counter >= V_ACTIVE + V_FRONT_PORCH + V_SYNC + V_BACK_PORCH:
vsync_counter = 0
# Set VSYNC signal
if V_ACTIVE + V_FRONT_PORCH <= vsync_counter < V_ACTIVE + V_FRONT_PORCH + V_SYNC:
vsync_pin.value(0) # VSYNC active (low)
else:
vsync_pin.value(1) # VSYNC inactive (high)
time.sleep_us(31) # Line timing
except KeyboardInterrupt:
sm.active(0)
print("Stopped")`
Hello,
I successfully created this project and wanted to use this Pico - VGA hardware configuration (because the VGA cable is soldered to my Pico W) for another project (Pong game). I tried to code this in MicroPython but could't get a VGA output. So I started to create a test file at first which looks like this - but still no signal on the screen. This code compiles without problems in Thonny and was saved to the Pico W as main.py so that it should run on boot. Could you please tell me what I'm doing wrong?
`from machine import Pin
import rp2
import time
VGA timing constants for 640x480@60Hz
H_ACTIVE = 640
H_FRONT_PORCH = 16
H_SYNC = 96
H_BACK_PORCH = 48
V_ACTIVE = 480
V_FRONT_PORCH = 10
V_SYNC = 2
V_BACK_PORCH = 33
@rp2.asm_pio(
out_init=rp2.PIO.OUT_LOW,
sideset_init=(rp2.PIO.OUT_HIGH,) * 2,
autopull=True,
pull_thresh=32,
fifo_join=rp2.PIO.JOIN_TX
)
def vga_program():
# Active video area
pull(block) .side(0b11)
out(x, 32) .side(0b11)
pull(block) .side(0b11)
Create a simple test pattern (white screen)
line_words = H_ACTIVE // 32
test_line = [0xFFFFFFFF] * line_words
Initialize pins
video_pin = Pin(18, Pin.OUT) # GPIO18 -> Physical Pin 24
vsync_pin = Pin(19, Pin.OUT) # GPIO19 -> Physical Pin 25
hsync_pin = Pin(21, Pin.OUT) # GPIO21 -> Physical Pin 27
Initialize state machine
sm = rp2.StateMachine(
0,
vga_program,
freq=125_000_000, # Run at maximum frequency
sideset_base=Pin(19),
out_base=Pin(18),
set_base=Pin(21)
)
print("Starting VGA output...")
sm.active(1)
Main loop with VSYNC handling
vsync_counter = 0
try:
while True:
# Output one complete frame
for line in range(V_ACTIVE):
# Send line data
for word in test_line:
sm.put(word)
except KeyboardInterrupt:
sm.active(0)
print("Stopped")`