Stuff you  need

For this project you will need the following:

  • MicroPython Microcontroller with headers soldered on ( or a soldering iron)
  • 2 Jumper Leads
  • Breadboard
  • 1 LED
  • 1 560 ohm resistor

Step 1 – Wire up your LED and resistor.

The first thing you need to do is wire up your LED and resistor circuit as shown below!

flashing LED breadboard view

Connecting up the Resistor

Resistors can be connected either way around.

Need help calculating the color code for the resistor? Click here!

Connecting up the LED

LED stands for light emitting diode, and diodes only allow electricity to pass through in one direction. If you wire up an LED the wrong way round then your LED will never turn on!

When you are wiring up an LED the flat side is negative, as you can see below:

led-wiring-jpg

Step 2 – Connect your MicroPython Controller to the Computer.

Once your have completed the wiring you now need to plug your MicroPython in to your computer using a micro USB cable. This serves 2 purposes:

  1. It provides power to the MicroPython
  2. It gives you access to the Python main.py file that we need to edit.

Step 3 – Open the main.py file and add your code

Your PC should have automatically recognised the MicroPython as a USB device and you should have access to a new drive that should look something like below ( if you are using Windows).

pyb flash icon

Double click on the drive and then open file main .py in notepad or another editor.

mainpyicon

Python Code

import time
from pyb import Pin
led1 = Pin("Y1",Pin.OUT_PP)
while True:
    led1.high()
    time.sleep(1)
    led1.low()
    time.sleep(1)
Python Code with Comments
import time #Go get the time module
from pyb import Pin #Go get the Pin class from the pyb module
led1 = Pin("Y1",Pin.OUT_PP) #Create a new instance of the Pin class and set is to output
while True: # Create an infinite loop
    led1.high() #Turn the LED on
    time.sleep(1) #Wait 1 second
    led1.low() #Turn the LED off
    time.sleep(1) #Wait 1 second

Step 4 – Save your code

Save your changes to the code and then wait until the red light on your MicroPython Turns off – this means it has finished saving!

Step 5 – Reset your MicroPython

Press the reset button and your LED should flash!

reset

Troubleshooting

  • Make sure you have typed ‘Y1’ not ‘y1’ – The capitalisation is important!
  • Take care that you wait for the red light to turn off before pressing the reset button!