Sunday, June 30, 2013

Hanging Lake Hike


It's been long overdue, but we finally made it to Hanging Lake Trail in Glenwood Springs, CO. Once we got there, the parking was full as it usually is on weekends! When we finally got to the trailhead, we noticed this sign. It's a bit misleading since there were many kids and many families carrying young ones so "difficult" does not really apply.

The hike is about a 1000 ft ascend and is about 1.1 miles one way. The views are very nice and the pictures below do not do it justice!

The forecast was for 92 degrees, but we lucked out as going up a passing storm went by and dropped some rain which made it much cooler.




Here are some pictures from the beginning of the trail.
For the most part, the trail consists of rock, but there are some areas where it's either gravel or dirt.

Some nice views of Glenwood Canyon are visible from the trail as well.













At the top, there is a nice view of a waterfall. Going a bit past it to Spouting Rock yields a nice waterfall and can cool you off!



Sunday, June 23, 2013

Bitmap on Adafruit 128x64 using a Raspberry Pi


It's been a while, but I *finally* got my Adafruit 128x64 OLED working to display a bitmap image. From the Adafruit forums, unfortunately (or fortunately!) they currently do not have support for C++ libraries for this display on the Raspberry Pi, which is why I had to write my own. It was also a great learning experience! The code is written in C++ so I plan to use it for my BeagleBone Black as well. I believe nothing needs to be changed, but just recompiled for that platform, but I'll test that a bit later.

The OLED memory map isn't linear; probably because it's primarily use for rendering output in text which is typically in the form of a 5x7 font. Thus, the biggest challenge is to read and rotate the data. I used an 8 byte array as the memory map is aligned that way. So reading the 8 bytes from the bitmap and rotating those bytes from being horizontal to being vertical is the biggest challenge. Essentially, that  is what I did to take advantage of how I write out the bytes. I have one method that writes out the bytes for both text and bitmap images.

Next up... Hooking up a GPS receiver and getting the output to display on the OLED. Hopefully, this should be a bit easier since I now have a library to interface with when using the OLED.

Saturday, June 15, 2013

Beaglebone Black

I kept reading good things about the Beaglebone Black and wanted to try things out for myself so I ordered one. I recently got it in the mail and it has a pretty cool look to it (though I do like the original beaglebone look better). However, this one is much more powerful and comes at a lower price. Here is a closer look.
Figure 1 - Powered on with stock image
I then wanted to upgrade to the latest image. This platform uses a different flavor of linux called Angstrom. Different commands to do similar things as I'm more familiar with RedHat (rpm based) and Ubuntu (debian based). Nothing too far fetched, so I'm sure the learning curve won't be too steep. Anyway, on to the upgrade.

As there are many blogs about how to do it, I'll just detail out what I did to get mine updated.

1. Download the latest image from here: http://beagleboard.org/latest-images

2. Uncompress the image file. I used 7zip

3. I then got my micro SD card (8GB) and plugged it into my adapter then to the computer.

4. I still had used Win32 Disk Imager since I had it installed from using different images with my Raspberry Pi. You can download it here: here

5. I then powered down the BBB and inserted the micro SD card that has the latest image that Win32 Disk Imager just wrote to it.

6. Hold down the S2 button (located on the opposite side of the RJ-45 jack. Here is an image
Figure 2 - S2 button location

7. Plug in the 5V adapter into the wall. After a few seconds the LED's begin to blink and you can let the S2 button go.

8. To flash the image, it took about 30 minutes. When it is complete, all 4 LEDs will be lit and look something like this:
Figure 3 - Flash complete

9. Disconnect power and remove the micro SD card.

10. Boot up to the new image.

Thursday, June 13, 2013

Raspberry Pi and 128x64 OLED




I recently purchased a LCD display for some projects I have going. Initially, I hooked it up to my arduino since Adafruit has libraries already written that can let you run things easily (just has to solder the header pins to the PCB and you are in business). Their library support is great and it makes things easy to use and they have some working examples too. Unfortunately (or fortunately!), if you plan to use this for a Raspberry Pi or Beaglebone Black, you are not so lucky as there are no libraries that you can download and use for those (yet!). Since I wanted to learn more about interfacing with hardware/firmware, this was a great place to start. The driver chip on the OLED board is a SSD1306 one and the datasheet is available here. I have mine connected to the PI via I2C. Note, by default, the OLED comes with SPI enabled, so closing 2 gates on the back with a little solder needs to be done to enable I2C. Just using a 2 jumper wires for clock and data, we are in business!

I was able to get some simple text up on the LCD and played around with placement (ie. centered and left justified). For me, it was easier to develop on ubuntu and copy my files over to the PI. It allowed me to do remote debugging and my core i7 was much faster than the processor on the PI. I still have a bit more functionality to add but so far it has been an enjoyable project to work on.

Friday, June 7, 2013

Reformat SD card after using it in Raspberry Pi

If you try to use your SD card after having used in your Raspberry Pi, you will notice your OS will not recognize it. OS X and Windows, it's pretty straight forward to reformat, but Linux is a bit more tricky, but here are the steps.
  1. Mount the SD card
  2. Find where the SD card is mounted. You can do this with the
    mount
    command. If you are not root, try
    sudo mount
    The SD card will be mounted to something like
    /dev/sdbx
    where x is a number.
  3. Delete the partitions from the SD card. The command to do this is
    sudo fdisk /dev/sdbx
    • p is the command to list the existing partitions
    • d is the command to delete the partition
    • delete all partitions on SD card
  4. Create a new partition
    • n is the command to create a new partition
    • p is the command to to create a primary partition
    • Enter the sector size 8192
    • press Enter to select the default last sector
    • t is the command to change the partition type
    • We want FAT32, so type b
    • w is the command to write the changes to disk
  5. Now we have our partition created, we need to format it. We can do that using this command
    mkdosfs -vF 32 /dev/sdb1
  6. That is it. You should now see this drive as a thumb drive again.

Wednesday, June 5, 2013

Linux IPC

I needed a way for my raspi program to communicate with with some events from the GPIO. Some options that quickly come to mind are sockets, shared memory, files, and signals. I wanted to briefly share an example in c++ using signals. For this example, we will use the SIGUSR1 signal, which by default, will terminate your application if not caught.

Lets create the signal handler. Pretty straight forward... If we get the SIGUSR1 signal, print out a message to stdout
// signal handler function
void sig_handler (int signo)
{
   if (signo == SIGUSR1)
      cout << "got SIGUSR1" << endl;
}

Next, we need to tell our application to listen for the signal. We do that by calling signal(). If we try to register our listener and something fails or a that signal can't be listened to, we will see an error message printed out to stdout. Note, not all message can be trapped and acted upon. For example, SIGKILL can't be caught. If you were to try and register a listener for it (I encourage you to do so), you will see it will fail.
if (signal(SIGUSR1, sig_handler) == SIG_ERR)
      cout << "Unable to catch SIGUSR1" << endl;

Now, if we put this all together and run our program, we can try to send the SIGUSR1 signal and see if we trap it in our application. Here is a complete example (signal-receiver.cpp).
#include <iostream>
#include <signal.h>
#include <stdio.h>

using namespace std;

// signal handler function
void sig_handler (int signo)
{
   if (signo == SIGUSR1)
      cout << "got SIGUSR1" << endl;
}

int main()
{
   if (signal(SIGUSR1, sig_handler) == SIG_ERR)
      cout << "Unable to catch SIGUSR1" << endl;

   // simulate a long process - calling sleep() so CPU doesn't go to 100%
   while (1)
      sleep(1);

   return 0;
}

To compile, nothing special.
g++ -Wall signal-receiver.cpp -o signal-receiver 

Run and send the SIGUSR1 signal. Notice the program does not terminate upon receiving the signal. You can send it over and over and it will not terminate. Try commenting out the adding of the listener in the program above, re-compile, and run. When you send the SIGUSR1 signal, it will terminate your application.
$ ./signal-receiver 
got SIGUSR1
got SIGUSR1
got SIGUSR1

To send the signal from the command line
$ kill -USR1 <PID>

Lastly, if you are curious if you can send a signal from another c++ program, the answer is yes! Here is a simple example.
#include <iostream>
#include <signal.h>

using namespace std;

int main (int argc, char* argv[])
{
   if (argc != 2)
   {
      cout << "Usage: " << argv[0] << " <PID>" << endl;
      return 1;
   }
   int ret;
   ret = kill(atof(argv[1]), SIGUSR1);
   if (!ret)
      cout << "Successfully sent signal";
   else
      cout << "Error sending signal";
   cout << endl;
   return 0;
}

Tuesday, June 4, 2013

Compiling for Raspberry Pi



Installed wheezy 7.0 on an 8GB micro SD card and booted my raspi. ssh'ed in and was able to test out my cross compiled program (compiled on linux). Wasn't as painful as I thought... So I took the next step and setup remote debugging as well with gdbserver. I can now compile the code on my linux machine, run it on my raspi, and also debug it from my linux machine. Pretty cool!