Monday, May 27, 2013

Blink an LED on the BeagleBone Black using Python

Using Command Terminal


Probably the most basic example you could do but its a great start for using digital output on your device. Before I attempted this in Python, I turned and LED on simply through the command terminal. This begins with defining the pin you are going to use. This creates a directory by executing the following command

cd /sys/class/gpio
echo ## export

The ## being which pin you will be using as the digital pin on the BBB

This will create the directory for the pin you have specified. Next is to define it as an INPUT or an OUTPUT pin.

This pin will be an "out" as we are turning off and on and LED controlled by the device.

echo out > direction


Using Python

The same concepts are utilized when executing the commands in python. Rather than using "echo" to write values to the pin files, you use python to write the commands to the files on the BeagleBone.

The link to the code is located at Blink.py

I will explain it in segments,

1. The first setup is to define which pin will be used, just as we did before.
2. The second setup is to define whether it is an INPUT or an OUTPUT, as we did before
3. We then open the value file so we can write to it. Because this is a digital output we will write a "1" for on and a "0" for off.

We then just create a loop that turns the LED off and on in 1 second intervals.

The except is for when we want to end the program. You have to unexport the pin that was being used so you execute the command

/sys/class/gpio/unexport

This will occur when the user uses Ctrl+C in the terminal window to end the python program.


This is a great start to understanding how to use digital input and output on the BeagleBone Black. From here you can use this to turn on much more than just and LED.



Wednesday, May 22, 2013

Setting up Nano the Lightweight Editor for Any Syntax

Previously you may have seen my post on how I connect to my Beaglebone. I generally don't program everyday in my line of work so I have not put in the effort to lean Vim or emacs. I'd most likely learn all the shortcuts and forget them a week later. As I mentioned, I generally like using an IDE and transfering my files over. Then there are times I want to make quick changes right within the terminal. This is what I like using nano for...


It is lightweight and can be navigated easily, similar to opening a text file in Notepad for instance. One thing it was originally lacking was syntax highlighting which I enjoy a lot. I had to set this up on my laptop so I wanted to talk everyone else through it. The general setup file for nano is a hidden file that should be located in your home directory. If not you can create it and call it .nanorc. The link below is an example of a file you can use and modify to your preference. Rename this to the .nanorc and copy it to your home directory. 


From here, you can add the syntax setup to the main file or create separate files for specific coding and scripting languages. I prefer this route so if I want to change what my syntax looks like I only have to go to a file with 8 lines in it.

This example will setup highlighting for python. Line 245 in the link above is where you uncomment the code

include "/usr/share/nano/python.nanorc"

Save this file and cd to /usr/share/nano. If the directory does not exist, create it. Then create a file python.nanorc. This goes for any language you want to create custom syntax highlighting for. Edit this file similar to the code below

## Here is an example for Python.
##
syntax "python" "\.py$"
icolor brightblue "def [0-9A-Z_]+"
color brightcyan "\<(and|assert|break|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|map|not|or|pass|print|raise|return|try|while)\>"
color brightgreen "['][^']*[^\\][']" "[']{3}.*[^\\][']{3}"
color brightgreen "["][^"]*[^\\]["]" "["]{3}.*[^\\]["]{3}"
color brightgreen start=""""[^"]" end=""""" start="'''[^']" end="'''"
color red "#.*$"

When nano starts, the .nanorc file will look for this python setup file and syntax highlight according to how you want it. These colors will appear for the variables you define in the "". That is what each line has in common. This makes it easier to make those quick changes to code as you are tinkering in the terminal.


Sunday, May 19, 2013

Transfering Files to the BeagleBone

iTerm2

I recently got using iTerm2 because as I was trying to set up the regular terminal on my mac, there were a few more features I was wanting. A great feature is the ability to save window arrangements.  This allows the user to configure profiles and save them as a "Window". In each window you can start the shell with a command giving you a head start. When I use the Beaglebone I have one shell start with

ssh root@192.168.7.2

which starts the ssh to access my Beaglebone. In the other window I have the command

cd /Documents/Beaglebone

which is where I contain files that I use a favorite IDE on my Mac or Linux to copy over to my Beaglebone. I saved these two shells in my "Beaglebone" window arrangement.  I am not to familiar with Vim or eMacs because I do not program everyday so I have not invested the time to learn. This make it easy to start up the iTerm2 and get right into working on my Beaglebone.

SCP (Secure Copy)

Once I have my terminal all set, I use SCP to copy files from my Mac to the Beaglebone. The command is as follows

scp test.py root@192.168.7.2:~/Python

The first argument is the file you want transferred. Next is the the Beaglebone user and IP address followed by a colon and the path to where you want to transfer the file.

The iTerm allows me to work entirely from the terminal. I have also reconfigured the light weight editor nano to syntax highlight for python files so I can do quick corrections without going to my favorite IDE everytime. I'll place another post how I configured nano for the syntax highlighting.

Sunday, May 12, 2013

Laser Wood Burning

I usually complete my projects about 85-90% before moving on to the next one. As I mentioned before, I wanted to do a laser wood burner. The idea is you would take a gray scale image with has the data stored in a particular way. Regardless of how your program would interpret the data, there is a scale from light to dark.

Gray Scale Range

I want to use this stored data in an image file to control a laser. It would ride on a X-Y carriage as the laser is controlled maybe by pulse width modulation. This would effect how long the laser burns and at what intensity to get contrast on the image.

Pulse Width Modulation

I think this would be a cool project to do where you can have 
  1. An image processed
  2. Converted to data for the laser to interpret X,Y and power
  3. Have a microcontroller or computer control the burning process
The end result would hopefully be something along the lines of

Hopefully final result for the laser wood burning project
If this can be done by hand why not have a computer do it :-) I think it would be a pretty cool challenge . Any suggestions are appreciated.



Saturday, May 11, 2013

I want a real work shop!!!!

I really want  a designated area for a workshop which apartments are no good for. I have a few cordless tools and it gets me by but I want the works. Large bench, shelving, table saws room for a 3d printer, etc. I am talking about a shop that is similar to the one below.


As I have mentioned previously in my blog, I am working on a "barn door" tracker for my astrophotography. I struggled to cut out the "doors" for my tracker on my small second floor patio. One day, I'll have the workshop I want. 

Wednesday, May 8, 2013

Beagle Bone Black Up and Functional

I have had limited time as of late but I wanted to confirm that after updating to the latest Angstrom distro that my Beagle Bone Black is functioning. I can properly SSH into the device so this weekend I plan on getting more involved with it...time permitting. Hope others are enjoying the Beagle Bone!

Sunday, May 5, 2013

Beagle Bone Black SSH Issue

I bought some new toys for my beagle bone black and wanted to get started this weekend. Unfortunately there is a SSH problem with the release distribution of angstrom. I could not connect to the board through the SSH but apparently it is fixed with the latest. I found the a forum on the discussion posted below.

Link to solution

Now I need to get a bigger micro SD card to get going...guess I have to wait :-(