PyRaspBeta

Your first circuit

This page takes you from an empty workspace to a blinking LED. You will buy two parts, wire them in circuit.py, blink them in main.py, and watch it happen on the board.

1. Open the workspace

Sign up (or sign in) from the front page first, with GitHub or a username and password: apart from these docs, PyRasp needs an account. Then click Sandbox in the top bar. In the middle you get two editors, circuit.py and main.py; the board view is on the right; the shop and the guide are on the left. If you want the grand tour first, read Workspace tour — otherwise, keep going.

2. Wire the LED in circuit.py

Type this into circuit.py:

circuit.py
from wiring import *

pi = Pi()
pi.GPIO17 >> Resistor(330) >> LED("red") >> pi.GND

Line by line:

  • from wiring import * brings in the board and every part in the shop.
  • pi = Pi() adds the Raspberry Pi. A board is free and there is exactly one of it.
  • The last line is the whole circuit: from GPIO17, through a 330 Ω resistor, into the LED, and back to ground. >> wires two things together and returns the far side, so a chain reads left to right.

The resistor is not optional: an LED without one pulls too much current and can burn out. That is basic electricity, and the LED's own page has the numbers.

Type this into main.py:

main.py
from gpiozero import LED
from time import sleep

led = LED(17)

while True:
    led.on()
    sleep(0.5)
    led.off()
    sleep(0.5)

main.py is the program that runs on the Pi once the board is powered. It uses gpiozero, the same library you would use on a real Raspberry Pi. LED(17) takes the BCM number — GPIO17, not physical pin 11.

4. Press Run

Run in the toolbar powers the board on and starts main.py. The LED on the board starts blinking, half a second on and half a second off, and the console stays quiet because nothing is printed. Press ■ Stop to end the run; press Run again to restart it.

If the board does not come to life, look under circuit.py: a wiring mistake shows as an error with its traceback, and the status chip next to the file tabs says circuit.py has an error. A part drawing too much current shows as a warning on the board.

5. Press Run tests

Run tests is the button next to Run when a task is open — the daily contest, or a problem from Practice. It runs the judge's checks here in your browser, using the task's sensors and stimuli, and fills the Results tab with a verdict and one line per check. This exact pair of files is what a "blink once a second" task such as Heartbeat passes. In the sandbox there is no task, so there are no tests to run.

The bill

Once circuit.py builds, the cost in the top right and the Shop tab show what you have bought: $1 for the LED plus $0.25 for the resistor is $1.25. In a contest or practice task the header also shows the task's budget, and a build over budget cannot be submitted.

Going deeper

  • Why 330 Ω? A red LED drops about 2 V while lit. From the Pi's 3.3 V pin the resistor sees the rest, so the current is (3.3 − 2.0) V ÷ 330 Ω ≈ 4 mA — still well within the LED's nominal 20 mA, and enough for the tests to count it as lit. 220–330 Ω is the usual range from 3.3 V; blue and white LEDs drop about 3 V and glow only faintly from a GPIO.
  • The resistor can go on either side of the LED — it only has to be somewhere in the same loop. The LED itself is directional: anode (longer leg) toward the GPIO, cathode (flat side) toward ground.
  • Ground is shared. Each call to pi.GND returns a fresh ground pin, so many parts can be grounded without stacking wires on one pin.
  • GPIO17 is physical pin 11. pinout.xyz maps every BCM number to its physical pin, and the official Raspberry Pi 4 datasheet describes the 40-pin header. The gpiozero docs have the full LED class reference.
  • In the simulator, an overcurrent is a warning you can fix in the workspace; the judge counts it as damage, so a task's noDamage check fails. Turning off the LED while it is overdriven is not enough — fix the wiring.