We’re moving to a new home! Our website is currently in test mode while we update and transfer our content. Some pages and resources may be temporarily unavailable. We’ll be back with all resources shortly. Thank you for your patience.

VEX V5 PYTHON | 01.1 SETUP AND PROJECT STRUCTURE

Guide objective

Create and save a VEXcode V5 Python project, download it to the Brain and understand imports, device configuration, functions and competition callbacks.

01 | YOUR FIRST ROBOT PROGRAM

A robot program connects instructions to physical hardware. Before asking a robot to move, prove that you can create a project, save it, connect to the Brain, download it and run the intended version.

The first test in this lesson displays a message. You can practise Python structure without needing a finished drivetrain. Later lessons add motors, sensors and autonomous routines.

VEXcode V5 targets VEX V5 hardware. VEXcode VR is a separate environment for virtual robots, so check that you open the correct product.

02 | INSTALL VEXCODE V5, OR USE THE WEB VERSION

First choice for this course: install the desktop version of VEXcode V5. It gives your team a dedicated editor and supports working on projects without relying on the browser editor. Use the official download page to select the current Windows or Mac version, then follow your school’s installation process.

VEXcode V5 desktop downloads ↗

Second option: web-based VEXcode V5. If you cannot install the application, or you use a Chromebook, open the online editor in a supported Chrome-based browser. It provides an alternative route to creating and downloading V5 Python projects.

Open online VEXcode V5 ↗

Use VEXcode V5, rather than VEXcode Pro V5 or VEXcode VR, for the Python projects in this guide. Installing the editor and downloading a robot project are different actions: the second transfers your program to the Brain.

03 | WHAT YOU NEED

  • A supported computer with desktop VEXcode V5 installed, or access to its online version.
  • A powered V5 Brain and charged V5 battery.
  • A data-capable Micro-USB cable and any adapter your computer requires.
  • A folder where you can save your project.

For the first test, connect directly to the Brain. Motors and a Controller are not required for displaying a message. Some USB cables supply power only, so a cable that charges a device may still fail to carry programming data.

Stop any running program before changing the setup. This lesson’s supplied code contains no motor commands. When using an existing robot, inspect its project before running it and keep the work area clear.

04 | CREATE A PYTHON PROJECT

  1. Open the File menu and choose New Text Project.
  2. Select Python.
  3. Name the project clearly, for example team_setup_01.
  4. Save it in your team folder and confirm that the editor shows the intended project name.

A VEXcode Python project is saved as a .v5python file. Open saved projects from within VEXcode using File → Open. Do not assume that double-clicking a project file will open it correctly.

Keep dated or numbered checkpoints before major changes. For example, setup_01 and setup_02 tell you more than final and final_final.

05 | UNDERSTAND THE PROJECT PARTS

Read the file as a set of organised parts
PartPurposeExample
CommentsExplain intent without being executed# Display a setup message
ImportsMake VEX classes and constants availablefrom vex import *
Device configurationDefine the hardware objects used by the codebrain = Brain()
SettingsStore values that are easy to changemessage = "Hello, VEX!"
FunctionsGroup instructions under a namedef main():
Startup codeCall or register the functionsmain()

A new text project includes generated robot configuration. It creates the Brain and other configured objects and performs supporting setup. Keep this section intact. Your own code belongs after the generated region, below the # Begin project code marker.

The Devices panel can generate motors and sensors later. Choose either the generated configuration or a deliberately maintained manual configuration for each device. Avoid defining the same hardware twice or copying another robot’s port layout without checking it.

IMPORTANT | KEEP YOUR CODE OUT OF THE GENERATED REGION

Do not put your own functions, settings or robot instructions inside the VEXcode Generated Robot Configuration region. VEXcode manages this section. Changes you place there can be overwritten when it is regenerated or the project is reopened.

Find #endregion VEXcode Generated Robot Configuration, then continue down to # Begin project code. Add your code below that marker. Keep team settings, helper functions, autonomous routines and driver-control code there.

View the generated template supplied for this guide
#region VEXcode Generated Robot Configuration
from vex import *
import urandom
import math

# Brain should be defined by default
brain=Brain()

# Robot configuration code


# wait for rotation sensor to fully initialize
wait(30, MSEC)


# Make random actually random
def initializeRandomSeed():
    wait(100, MSEC)
    random = brain.battery.voltage(MV) + brain.battery.current(CurrentUnits.AMP) * 100 + brain.timer.system_high_res()
    urandom.seed(int(random))

# Set random seed
initializeRandomSeed()


def play_vexcode_sound(sound_name):
    # Helper to make playing sounds from the V5 in VEXcode easier and
    # keeps the code cleaner by making it clear what is happening.
    print("VEXPlaySound:" + sound_name)
    wait(5, MSEC)

# add a small delay to make sure we don't print in the middle of the REPL header
wait(200, MSEC)
# clear the console to make sure we don't have the REPL in the console
print("\033[2J")

#endregion VEXcode Generated Robot Configuration

# ------------------------------------------
#
#   Project:      VEXcode Project
#   Author:       VEX
#   Created:
#   Description:  VEXcode V5 Python Project
#
# ------------------------------------------

# Library imports
from vex import *

# Begin project code
# Begin project code

# YOUR CODE STARTS HERE
TEAM_MESSAGE = "Ready to test"

def main():
    brain.screen.clear_screen()
    brain.screen.set_cursor(1, 1)
    brain.screen.print(TEAM_MESSAGE)

main()

This generated region is robot configuration. It is distinct from a competition project’s autonomous and driver-control callbacks. New Text Project creates the configuration; competition mode structure is added using the Competition Template or your own correctly registered callbacks.

06 | WRITE A MESSAGE TEST

# Add this below the generated configuration.
# A blank VEXcode V5 Python project already defines brain.

def main():
    brain.screen.clear_screen()
    brain.screen.set_cursor(1, 1)
    brain.screen.print("Hello, VEX!")

main()

def main(): defines a function. The indented lines belong to it. The final main() calls the function, so its instructions execute.

The code clears the Brain screen, moves the cursor to row 1, column 1 and prints a message. Put it below # Begin project code, outside the generated region. Do not add a second brain = Brain() if the project already defines it.

Use four spaces for each indentation level. Names are case-sensitive: main and Main are different names.

07 | CONNECT, SAVE, DOWNLOAD, RUN

  1. Power the Brain and connect it to the computer using the data cable.
  2. Check the Brain connection indicator in the desktop editor. If you use the online version, use its connection control, select the V5 device when prompted and allow the browser connection.
  3. Confirm that VEXcode indicates the Brain is connected.
  4. Save the source project and select the intended program slot. Check that it is not a slot containing work you need to keep.
  5. Choose Download and wait for successful completion.
  6. Choose Run, or start the downloaded program from the Brain.
  7. Check the Brain screen for Hello, VEX!, then stop the program.

Saving preserves your editable project on the computer. Downloading transfers a runnable version to a Brain slot. Editing the source afterwards does not automatically update the downloaded program: download again before testing the change.

08 | CHECK WHICH VERSION IS RUNNING

Change the message to Setup version 2, save and download again to the same intended slot. Run it and verify the new message.

This simple habit catches an important robotics mistake: testing an old downloaded version while looking at new code on your computer. Record the project name, slot, change and observed result in your engineering logbook.

Keep the development steps distinct
ActionWhat it changes
SaveThe editable source project on your computer
DownloadThe runnable program in the selected Brain slot
RunStarts the selected downloaded program
StopStops the running program

09 | COMPETITION PROJECT STRUCTURE

A competition robot needs code for different modes. Autonomous carries out programmed actions without live joystick commands. Driver control reads the Controller and updates the robot during the driver-controlled period.

Open the built-in Competition Template from File → Open Examples and choose the Python version. It provides the structure for competition operation. Adapt the template to your own hardware.

The VEX Python registration order is Competition(driver_control, autonomous). Pass function names without parentheses: these are callbacks to be called when the appropriate competition mode starts.

A setup function such as pre_autonomous() is a name we choose for preparation. Defining it does not make it run automatically; startup code must call it. Setup may later include sensor calibration before the match.

10 | READ A SCREEN-ONLY COMPETITION SKELETON

# Keep the VEX import and generated device configuration above.
# Replace the earlier demonstration functions/startup with this section.

def pre_autonomous():
    brain.screen.clear_screen()
    brain.screen.set_cursor(1, 1)
    brain.screen.print("Ready")

def autonomous():
    brain.screen.clear_screen()
    brain.screen.set_cursor(1, 1)
    brain.screen.print("Autonomous")
    # Later: add a finite sequence of autonomous actions here.

def driver_control():
    brain.screen.clear_screen()
    brain.screen.set_cursor(1, 1)
    brain.screen.print("Driver control")
    while True:
        # Later: read controls and update motors here.
        wait(20, MSEC)

# Run our setup explicitly, then register the two callbacks.
pre_autonomous()
competition = Competition(driver_control, autonomous)

# Keep this project's main task alive.
while True:
    wait(100, MSEC)

This is an instructional skeleton to read and test with suitable competition controls. It displays messages and contains no drive commands. Preserve the VEX import and generated Brain configuration, and replace the earlier simple main test instead of keeping two startup sections.

The competition object registers the two callbacks. It does not immediately execute autonomous and then driver control. Their execution follows competition mode signals. Ordinary Run starts the project; it is not a substitute for testing match mode transitions.

The waits let a repeating task pause between updates. Later, the driver loop will read joysticks and buttons. Do not put an endless loop before callback registration, because execution would never reach that registration.

11 | TROUBLESHOOT ONE LAYER AT A TIME

Start with the simplest explanation
SymptomUseful first check
Brain not detectedPower, data cable, browser connection prompt and another connected application
Download does not completeConnection status and any firmware message shown by VEXcode
Old message appearsProject name, successful new download and correct Brain slot
NameErrorSpelling, capitalisation and whether the object or function was defined
Indentation errorSpaces beneath def, while and other blocks
A function never runsWas it called or registered? Is earlier code blocking startup?

Follow VEXcode’s firmware prompts when required. If school policies block browser device access, ask the teacher or IT team rather than changing settings at random.

Change one thing, repeat the same test and record the result. This makes troubleshooting evidence-based instead of guesswork.

12 | OFFICIAL TOOLS AND REFERENCES

Interface details can change. Use the current official guides if your menus differ. This lesson is an independent learning resource; VEX and VEXcode are trademarks of their respective owners.

CHALLENGES | PROVE YOUR SETUP WORKS

Complete these in order. Keep the project file and a brief record of each result in your engineering logbook.

  1. Create and save: make a new Python text project with your team name and a version number. Save it, close it and reopen it from VEXcode.
  2. Find the boundary: identify the generated region and the Begin project code marker. Show a partner where your code must go.
  3. First download: add the screen-message example below the marker. Download it to a chosen Brain slot and verify the message.
  4. Version check: change the message, save and download again. Confirm that the Brain shows the new version.
  5. Reusable function: create a function that displays your team name, then call it. Explain the difference between defining it and calling it.
  6. Reopen check: save, close and reopen the project. Confirm your user code remains below the generated region and run your test again.
  7. Explain competition structure: identify setup, autonomous, driver control and callback registration in the screen-only skeleton. Explain why the registered names have no parentheses.
Challenge success criteria
  • The project is saved and can be reopened.
  • All student code is outside the generated region.
  • The correct Brain slot runs the intended message.
  • A second download produces the changed message.
  • You can explain save, download, run and callback registration.