Quantcast
Channel: Blogs at All About Circuits
Viewing all articles
Browse latest Browse all 742

Part 2: Omega2 - Blink LED

$
0
0
If you have managed to successfully setup your Omega2 as described in Part 1 of this series, here is where the fun begins.

The goal when getting started on a new microcontroller system is to:
  1. get the controller to flash an LED,
  2. become familiar with the IDE, the Integrated Development Environment and the new MCU platform.

Step 1

The first thing we will do is connect an LED (Light Emitting Diode) to a GPIO (General Purpose Input/Output) pin on the microcontroller (MCU).

For this, we will need:
  1. solderless breadboard
  2. LED
  3. 1kΩ ¼W resistor
  4. male-male jumper cables or wire

[​IMG]

This schematic (from Onion website) shows a 200Ω resistor instead of 1kΩ. Anything from 200 to 1kΩ is adequate for this experiment.

Photo (from Onion website) showing 200Ω ½W resistor (which will also work for this setup):
[​IMG]


Step 2

Test that your LED circuit works. To do this, instead of connecting to GPIO0, drive the LED circuit from the 3.3V or 5V connection on the Expansion Dock. The LED should be lit. If the LED does not turn on, try turning the LED around in the circuit, i.e. reverse the connections to the LED.


Step 3

Test that the MCU is functional and can control the selected GPIO pin. To do this, connect to the Omega2 using your PC browser.

Onion Console.jpg

Using the Onion Console, click on the GPIO Tool icon.

Onion GPIO Tool.jpg



Select the GPIO0 pin and set Direction to Output. Set Value to 1 and verify that the LED turns on.


Step 4 - Write a Python Script

Select the Editor icon from the Onion Console screen.

Enter the following code:

Code (Text):
  1. import onionGpio
  2. gpio0 = onionGpio.OnionGpio(0)
  3. gpio0.setOutputDirection(0)
  4. value = 1
  5. while 1:
  6.    gpio0.setValue(value)
  7.    value = 1 - value
  8.    count = 100000
  9.    while count > 0:
  10.       count -= 1
It is important that you enter the program exactly as shown. Indented lines are part of the control structure and must be indented as shown.

Save your file with an appropriate name such as blink.py in your directory named /root
Click on the Terminal icon to go back to the terminal screen. Log in to the Omega2 Linux.
If you are new to Linux you may want to spend some time exploring the Linux CLI (Command Line Interface).

Try the following commands. The text from = onwards is what the command does and is not to be entered.

pwd = print working directory
cd / = change directory to the system root directory (not the same as /root directory)
cd /root = change to directory named /root
ls
= list the files in the current directory (You should see your program file blink.py).
cat blink.py = view the contents of blink.py

Step 5 - Run the blink.py program

Enter:
python blink.py

Tip: When switching back and forth between the editor and the command line, pressing the up arrow Δ on your PC keyboard will recall the last command entered.

At this stage, if everything was done correctly, you should see the LED flash about twice every second.

To stop the program, type Ctrl-C.


Congratulations! You have successfully run your first program on the Omega2.

In Part 3, I will show how to use the serial UART (Universal Asynchronous Receiver/Transmitter) interface.

Viewing all articles
Browse latest Browse all 742

Trending Articles