# Enter '''192.167.7.2''' in the '''Host Name''' field and click '''Open'''

+

# Enter '''192.168.7.2''' in the '''Host Name''' field and click '''Open'''

# Login as '''root''' with no password.

# Login as '''root''' with no password.

# Enter '''ls''' to list what files you have. You shouldn't see much.

# Enter '''ls''' to list what files you have. You shouldn't see much.

Line 15:

Line 15:

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.

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'''.

+

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.txt'''.

−

bone$ '''nano play'''

+

bone$ '''nano play.txt'''

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'''.

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'''

bone$ '''ls'''

−

Desktop play

+

Desktop play.txt

−

bone$ '''cat play'''

+

bone$ '''cat play.txt'''

A couple of lines

A couple of lines

of text.

of text.

Line 32:

Line 32:

Here's a powerful operator. You can take the output of any command and redirect it to a file with '''>'''.

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$ '''echo This is a line of text > here.txt'''

−

bone$ '''cat here'''

+

bone$ '''cat here.txt'''

This is a line of text

This is a line of text

Line 45:

Line 45:

bone$ '''cd'''

bone$ '''cd'''

gone$ '''ls'''

gone$ '''ls'''

−

Desktop here play

+

Desktop here.txt play.txt

Now you are ready to flash an LED.

Now you are ready to flash an LED.

Line 52:

Line 52:

=== gpio via the Shell Command Line and sysfs ===

=== 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.

+

Another easy 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. Here we'll use a virtual file system called '''sysfs'''. sysfs exposes the drivers for the hardware so you can easily use them.

Try this:

Try this:

Line 59:

Line 59:

block/ bus/ class/ dev/ devices/ firmware/ fs/ kernel/ module/ power/

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.

+

The "'''/'''" after the name means it's a directory. Here we see several directories that represent hardware we can control. Explore a bit and see what you find.

Now try:

Now try:

Line 89:

Line 89:

brightness device@ max_brightness power/ subsystem@ trigger uevent

brightness device@ max_brightness power/ subsystem@ trigger uevent

−

See what's in '''brightness''', '''max_brightness''' and '''trigger''' by using the <code>cat</code> command. For example:

+

(The "'''@'''" after the name means it's a link.) See what's in '''brightness''', '''max_brightness''' and '''trigger''' by using the <code>cat</code> command. For example:

bone$ '''cat trigger'''

bone$ '''cat trigger'''

Line 141:

Line 141:

bone$ '''cd gpio60'''

bone$ '''cd gpio60'''

+

bone$ '''ls'''

+

active_low direction edge power subsystem uevent value

bone$ '''echo out > direction'''

bone$ '''echo out > direction'''

bone$ '''echo 1 > value'''

bone$ '''echo 1 > value'''

−

+

Your LED should be on!

−

Your LED should be on! When you are done you can unexport the pin and it will disappear.

+

bone$ '''echo 0 > value'''

−

bone$ '''cd ..'''

+

Now it's off.

−

bone$ '''echo 60 > unexport'''

+

== Reading a switch ==

== Reading a switch ==

Line 164:

Line 165:

1

1

Once you have the switch and LED working use '''nano''' and put the following in a file.

Once you have the switch and LED working use '''nano''' and put the following in a file.

−

bone$ '''nano flash.sh'''

+

bone$ '''cd''' (Go back home)

+

bone$ '''nano button.sh'''

#!/bin/bash

#!/bin/bash

cd /sys/class/gpio

cd /sys/class/gpio

while [ 1 ]

while [ 1 ]

do

do

−

cat gpio7/value > gpio60/value

+

cat gpio7/value

sleep 0.25

sleep 0.25

done

done

Quit nano and run

Quit nano and run

−

bone$ '''chmod +x flash.sh''' (This makes flash.sh executable)

+

bone$ '''chmod +x button.sh''' (This makes button.sh executable)

−

bone$ '''./flash.sh'''

+

bone$ '''./button.sh'''

−

What happens when you push the button?

+

What happens when you push the button? Hit '''Ctrl-C''' to quit button.sh.

−

Now experiment around. How fast can you flash the LED?

+

Now experiment around. Can you flash the LED? How fast? Make the LED read the switch.

== Analog In ==

== Analog In ==

−

The bone has eight Analog Inputs. Several are exposed on P9. They are labeled '''AIN''' in table 11 below. How many do you find?

+

The bone has eight Analog Inputs. Several are exposed on P9. They are labeled '''AIN''' in the table below. How many do you find?

[[File:P9PWMs.jpg|800px]]

[[File:P9PWMs.jpg|800px]]

Line 186:

Line 188:

The AIN pins are sampled at 12 bits and 100k samples per second. The input voltage is between 0 and 1.8V. Fortunately, both voltages are available on P9.

The AIN pins are sampled at 12 bits and 100k samples per second. The input voltage is between 0 and 1.8V. Fortunately, both voltages are available on P9.

−

You've already wired these up for the AM lab. You interact with the analog in much like the gpio, but it appears in a different. We have to run a command before the AIN interface appears. Just run them now, later I'll explain what you did if you are interested.

+

You've already wired up P9_39 for AIN0 in the AM lab. You interact with the analog in much like the gpio, but it appears in a different place. We have to run a command before the AIN interface appears. Just run them now, later I'll explain what you did if you are interested.

bone$ '''SLOTS=/sys/devices/bone_capemgr.*/slots'''

bone$ '''SLOTS=/sys/devices/bone_capemgr.*/slots'''

Line 197:

Line 199:

AIN0 AIN2 AIN4 AIN6 driver@ power/ uevent

AIN0 AIN2 AIN4 AIN6 driver@ power/ uevent

AIN1 AIN3 AIN5 AIN7 modalias subsystem@

AIN1 AIN3 AIN5 AIN7 modalias subsystem@

−

+

bone$ '''cat AIN0'''

−

There are the various analog inputs, but watch out. This interface starts numbering at '''1''' and Table 11 starts at '''0''', so to read AIN5 you need to look at '''AIN6'''!

+

−

+

−

bone$ '''cat AIN6'''

+

1185

1185

Change the pot and rerun '''cat'''. What's the min and max value you get? Is it 12 bits?

Change the pot and rerun '''cat'''. What's the min and max value you get? Is it 12 bits?

−

You can use the following script to continuously read the input.

+

You can use the following script to continuously read the input and print it on the same line.

−

while [ 1 ]; do

+

bone$ '''cd'''

−

tr '\n' '\r' < AIN5

+

bone$ '''nano ainOut.sh'''

+

+

cd /sys/devices/ocp.2/helper.14

+

while [ 1 ]

+

do

+

tr '\n' '\r' < AIN0

done

done

+

+

bone$ '''chmod +x ainOut.sh'''

+

bone$ '''./ainOut.sh'''

+

Use '''Ctrl-C''' to quit ainOut.sh

== Pulse Width Modulation ==

== Pulse Width Modulation ==

Line 214:

Line 222:

(Note: The pwm interface seems to changing. Some of this may not apply in the future.)

(Note: The pwm interface seems to changing. Some of this may not apply in the future.)

−

The Bone has a PWM interface at <code>/sys/class/pwm/</code>. You can see what's there by:

+

We have to run a couple of commands to make the PWM interface appear. Try

−

+

−

bone$ '''cd /sys/class/pwm'''

+

−

bone$ '''ls -F'''

+

−

export unexport

+

−

Hmmm, there isn't much there. We have to run a command to make something appear. Try

+

bone$ '''SLOTS=/sys/devices/bone_capemgr.*/slots'''

bone$ '''SLOTS=/sys/devices/bone_capemgr.*/slots'''

−

bone$ '''echo am33xx_pwm > $SLOTS'''

+

bone$ '''echo am33xx_pwm > $SLOTS'''

−

bone$ '''ls -F'''

+

bone$ '''echo bone_pwm_P9_21 > $SLOTS'''

−

export pwmchip0@ pwmchip2@ pwmchip3@ pwmchip5@ pwmchip7@ unexport

+

bone$ '''cd /sys/devices/ocp.2/pwm_test_P9_21.14'''

−

Now we need to run another command to say which pwm pin we want to use. I'm using P9_21.

+

bone$ '''ls'''

−

bone$ '''echo bone_pwm_P9_21 > $SLOTS

+

driver duty modalias period polarity power run subsystem uevent

−

Now you can export a pwm much list you export a gpio port

+

−

bone$ '''echo 1 > export'''

+

The units are in ns.

−

bone$ '''cd pwm1'''

+

−

bone$ '''ls -F'''

+

−

device@ duty_ns period_ns polarity power/ run subsystem@ uevent

+

Try a 1Hz frequency with a 25% duty cycle

Try a 1Hz frequency with a 25% duty cycle

−

bone$ '''echo 1000000000 > period_ns'''

+

bone$ '''echo 1000000000 > period'''

−

bone$ '''echo 250000000 > duty_ns'''

+

bone$ '''echo 250000000 > duty'''

bone$ '''echo 1 > run'''

bone$ '''echo 1 > run'''

Line 241:

Line 241:

Combine the analog in and the PWM by having the pot control the frequency or the duty cycle of the LED.

Combine the analog in and the PWM by having the pot control the frequency or the duty cycle of the LED.

Blinking an LED

gpio via the Shell Command Line and sysfs

Another easy 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. Here we'll use a virtual file system called sysfs. sysfs exposes the drivers for the hardware so you can easily use them.

Blinking an External LED via gpio

In the AM lab we wired an LED to the P9_12 General Purpose IO (gpio) port and controlled it via BoneScript. Here we'll control it via a shell command. First we need to figure out which gpio pin P9_12 is attached to. The following figure shows it attached to gpio_60.

Now experiment around. Can you flash the LED? How fast? Make the LED read the switch.

Analog In

The bone has eight Analog Inputs. Several are exposed on P9. They are labeled AIN in the table below. How many do you find?

The AIN pins are sampled at 12 bits and 100k samples per second. The input voltage is between 0 and 1.8V. Fortunately, both voltages are available on P9.

You've already wired up P9_39 for AIN0 in the AM lab. You interact with the analog in much like the gpio, but it appears in a different place. We have to run a command before the AIN interface appears. Just run them now, later I'll explain what you did if you are interested.