ASEE 2013 Workshop
Embedded Linux Class by Mark A. Yoder
Here are the labs for the afternoon Linux part of the ASEE 2013 Workshop
Contents
Warm Up
Before we can interact with LEDs and switches we need to learn some simple Linux commands.
- On your host computer, running Windows, start up puTTY.
- If you get a Security Warning, click Run.
- Enter 192.167.7.2 in the Host Name field and click Open
- Login as root with no password.
- Enter ls to list what files you have. You shouldn't see much.
At this point you need to learn a few simple Linux commands for creating and displaying files. Once you know these commands it's easy to turn an LED on and off.
First, let's edit a file using the nano editor. Nano is a simple editor that easy to learn. This will edit (and create) the file play.
bone$ nano play
Add a couple of lines of text to the file, it doesn't really matter what and then Exit. You can list the files in the current directory with ls and show the contents of a file with cat.
bone$ ls Desktop play bone$ cat play A couple of lines of text.
Use echo to print a line of text.
bone$ echo This is a line of text This is a line of text
Here's a powerful operator. You can take the output of any command and redirect it to a file with >.
bone$ echo This is a line of text > here bone$ cat here This is a line of text
We are almost there. Use cd to change directories. / is the top level directory.
bone$ cd / bone$ ls bin dev home lost+found mnt run sys usr boot etc lib media proc sbin tmp var
If you ever get lost, cd alone takes you home.
bone$ cd gone$ ls Desktop here play
Now you are ready to flash an LED.
Blinking an LED
gpio via the Shell Command Line and sysfs
The easiest way to do general purpose I/O (gpio) on the Beagle is through a terminal window and a shell prompt. In Linux, almost everything is treated as a file, even things that aren't files. In our class we'll use a virtual file system called sysfs. sysfs exposes the drivers for the hardware so you get easily use them.
Try this:
bone$ cd /sys bone$ ls -F block/ bus/ class/ dev/ devices/ firmware/ fs/ kernel/ module/ power/
Here we see several directories that represent hardware we can control. Explore a bit and see what you find.
Now try:
beagle$ cd /sys/class beagle$ ls -F backlight/ firmware/ lcd/ mtd/ scsi_disk/ ubi/ bdi/ gpio/ leds/ net/ scsi_host/ udc/ block/ graphics/ mbox/ power_supply/ sound/ uio/ bluetooth/ hwmon/ mdio_bus/ regulator/ spi_master/ usbmon/ bsg/ i2c-adapter/ mem/ rfkill/ spidev/ vc/ dma/ i2c-dev/ misc/ rtc/ thermal/ vtconsole/ drm/ input/ mmc_host/ scsi_device/ tty/ watchdog/
Explore some.
The Beagle Black has four user LEDS, user0 - user3, that you can control. Try this:
bone$ cd /sys/class/leds bone$ ls -F beaglebone:green:usr0 beaglebone:green:usr2 beaglebone:green:usr1 beaglebone:green:usr3
Here you see the directories for controlling each of the usr LEDs. By default, usr0 flashes a heartbeat pattern and usr1 flashes when the micro SD card is accessed. Let's control usr0.
bone$ cd beagleboard\:\:usr0 bone$ ls -F brightness device@ max_brightness power/ subsystem@ trigger uevent
See what's in brightness, max_brightness and trigger by using the cat
command. For example:
bone$ cat trigger none nand-disk mmc0 timer oneshot [heartbeat] backlight gpio cpu0 default-on transient
This shows trigger can have many values. The present value is heartbeat. Check the LED, is it beating? You can stop the heartbeat via:
bone$ echo none > trigger bone$ cat trigger [none] nand-disk mmc0 timer oneshot heartbeat backlight gpio cpu0 default-on transient
Did it stop beating? You can now turn it on and off with:
bone$ echo 1 > brightness bone$ echo 0 > brightness
Is it responding correctly?
The Bone has more trigger options. Try:
bone$ cat trigger [none] mmc0 timer heartbeat backlight gpio default-on bone$ echo timer > trigger bone$ ls -F brightness delay_on max_brightness subsystem@ uevent delay_off device@ power/ trigger bone$ echo 100 > delay_on bone$ echo 900 > delay_off
What does this do?
Reading a Switch
Analog In
Pulse Width Modulation
Embedded Linux Class by Mark A. Yoder