Oscilloscope
Connecting the Oscilloscope
Now let’s connect the oscilloscope to see the signal your program is generating. Connect two Dupont wires (with the black square ends) to the P0 signal (yellow) and P0 ground (black) pins on the breakout board. Then connect the alligator clips to the other end of the Dupont wires, and plug the alligator clips into the oscilloscope.
After you make these connections, trace the black alligator clip through the Dupont wire to the black P0 pin, and trace the red alligator clip through the Dupont wire to the yellow P0 pin.

Reading the Oscilloscope Trace
Follow these steps:
- Turn on the oscilloscope
- Download and run your analog write program
- Press the Auto button on the oscilloscope
When you run the program and look at the signal, this is what you will see:

The yellow line that goes up and down is the voltage on the P0 pin of the Micro:bit. The bottom of the line is at 0 volts, and the top is at about 3.3V. You can see these voltages in the white text in the background for Vmax and Vmin.
The “Dut” text in the background is the duty cycle, which is the percentage of time that the signal is at a high voltage. It should be 50%, because the value we set in the program (512) is 50% of the way between the minimum analog value of 0 and the maximum value of 1024.
We will be using this signal, called a square wave, for controlling the motors.
Changing the Duty Cycle
Unlike the steady signal on our oscilloscope, the duty cycle of a motor control signal will change to adjust the speed or position of the motor. Let’s update our program to change the signal.
Switch your program to Python mode using the toggle at the top of the screen, then edit the program to this:
def on_forever():
for index in range(5):
pins.analog_write_pin(AnalogPin.P0, index)
basic.pause(10)
basic.forever(on_forever)
After making this change, you will see the duty cycle change from 0% to 100%.
Watch the oscilloscope trace as the program runs. You should see the square wave getting wider (more time at high voltage) as the duty cycle increases.
Troubleshooting
- No trace on the oscilloscope: Press the “Auto” button. If that does not work, check that the alligator clips are firmly attached to the Dupont wires.
- Flat line on the oscilloscope: Your program may not be running. Re-download it to the Micro:bit.
- Duty cycle reads 0% or 100% and does not change: Make sure you entered the Python program exactly as shown. Check that
range(5)and thebasic.pause(10)are correct.
Challenge
Modify the Python program to sweep the duty cycle in both directions: from 0% up to 100%, and then back down from 100% to 0%. What would the oscilloscope trace look like?