http://www.ninjagecko.co.uk/micropython-flashing-led-tutorial/
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!
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:
- It provides power to the MicroPython
- 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).
Double click on the drive and then open file main .py in notepad or another editor.
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!
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!
沒有留言:
張貼留言