XRP
  • Experiential Robotics Platform (XRP)
    • Building the XRP Robo
    • Programming Raspberry Pi Pico W
    • Programming with XRPCode IDE
    • Programming with wpilib
      • Hardware
      • Imaging and Setup
      • Creating an XRP Program
    • Programming with ROS
  • Hardware Components
    • Different Types of Motors
      • Brushed DC Motors
      • Brushless Motor
      • Stepper Motor
      • Servo Motors
    • Key Characteristics of DC Motors
    • Encoders
  • Motor Control Theory
    • What use in FRC
    • PID control (Proportional-Integral-Derivative control)
    • Field Oriented Control (FOV)
  • Use XRP to practice
    • Plotting Fix
    • Reading from the Encoder
    • Measure position
    • Control the motor
    • Tuning PID
  • Use XRP with Micropython
    • Setup Envirrment
    • Use the Shell
    • XRP library
  • Connect with Wifi
Powered by GitBook
On this page
  1. Use XRP with Micropython

Use the Shell

PreviousSetup EnvirrmentNextXRP library

Last updated 7 months ago

In this step, you will use the Thonny Shell to run some simple Python code on your Raspberry Pi Pico.

Make sure that your Raspberry Pi Pico is connected to your computer and you have selected the MicroPython (Raspberry Pi Pico) interpreter.

Look at the Shell panel at the bottom of the Thonny editor.

You should see something like this:

REPL initial connection messages

Thonny is now able to communicate with your Raspberry Pi Pico using the REPL (read–eval–print loop), which allows you to type Python code into the Shell and see the output.

Now you can type commands directly into the Shell and they will run on your Raspberry Pi Pico.

Type the following command.

print("Hello")

Tap the Enter key and you will see the output:

MicroPython adds hardware-specific modules, such as machine, that you can use to program your Raspberry Pi Pico.

Let’s create a machine.Pin object to correspond with the onboard LED

If you set the value of the LED to 1, it turns on.

Enter the following code, make sure you tap Enter after each line.

from machine import Pin
led = machine.Pin("LED", machine.Pin.OUT)
led.on()

You should see the onboard LED light up.

Type the code to set the value to 0 to turn the LED off.

led.off()

Turn the LED on and off as many times as you like.

Tip: You can use the up arrow on the keyboard to quickly access previous lines.

If you want to write a longer program, then it’s best to save it in a file. You’ll do this in the next step.

Print Hello output
Onboard LED on