Quick dynamic DNS update

Every time I switch to a new distro or do a reinstall to reset any OS issues I spend a lot of time researching and redeveloping a way to automatically update my subdomain with a dynamic IP Address.  Here’s a quick and painless way to do it; more for my reference than yours.

I’m using Fedora 18 for my distro and NameCheap as my registrar.

yum install gnome-schedule

Open “Scheduled Tasks” and create a new hourly task with the following command:

echo -e "\n" >> dns.log; date -Iseconds >> dns.log; wget -q -O - "https://dynamicdns.park-your-domain.com/update?host=[SUBDOMAIN]&domain=[DOMAIN_NAME]&password=[PASSWORD]" >> dns.log

Sample output:

 <?xml version="1.0"?><interface-response><Command>SETDNSHOST</Command><Language>eng</Language><IP></IP><ErrCount>0</ErrCount><ResponseCount>0</ResponseCount><Done>true</Done><debug><![CDATA[]]></debug></interface-response>


Raspberry Pi — First Steps

My Raspberry Pi (model B) just arrived last week after being on hold for over 5 months.  Despite the nail biting waiting for it to arrive, I was very excited seeing the package on my doorstep.  The board set me back a measly 35$ and I also the procured the HDMI and stereo cables and the SD card with OS already on it for , maybe, 20$ more.

Hooking up a USB keyboard, mouse, monitor, ethernet, and power (mini-USB connector) was easy enough and I was soon at the Linux login.  I didn’t know the credentials as it was never included any documentation (nor did documentation exist) but a quick search on Google and i got what I was looking for: user: pi, pass: raspberry.

I then prodded around the filesystem a little and found no surprises since I’m familiar with the Debian-based Linux distributions.  Running ‘ifconfig’ showed that the network device had already been initialized and consumed an IP address from my router without any configuration!  An initial nmap scan from my workstation didn’t bring up anything interesting.

I then fired up the GUI by executing ‘startx’, just as we had to do a decade ago.  Nothing spectacular there — just a barebones LXDE environment.  It comes with a text editor, web browser, etc.  Trying to bring up youtube.com presented me with a notice that I need to install Adobe’s Flash player or use an HTML5 browser.  Bummer.

A couple of days go by and I find out there’s an update to the OS.  The new version enables hardware floating point math which is reported to speeding up the device around 10-20%.  I downloaded the new OS (~40MB) and unzipped it.  Before writing the new firmware from my workstation, I wanted to backup the existing SD card.  After plugging in the SD card, and umounting the card (Ubuntu auto-mounts everything you stick in it), this did the trick:

# sudo dd if=/dev/sdh of=/home/bryan/raspi.img

To copy the new firmware to the board:

# sudo dd bs=1M if=/home/bryan/2012-07-15-wheezy-raspian.img of=/dev/sdh

Plugging that sucker into the RPi and booting it up worked just as before.  Starting the GUI brought up an ncurses-style GUI with some options that you can safely skip if you’re eager to see the new desktop.  LXDE showed up and I was convinced the flash was successful.

Dropping back to the shell, I wanted to setup a web server, database server, PHP, and VNC.  Here’s how i did it:

# sudo apt-get update
# sudo apt-get install tightvncserver apache2 mysql-server mysql-client
       php5-mysql php5 php5-common php5-cli libapache2-mod-php5 php5-curl php5-gd

… and followed the prompts.  This was taking a little while so I switched to another console by hitting Ctrl + Alt + F2, logged in, and ran ‘top’.  At one point it had only 8MiB of free memory; WOW!  I’m sure there will be a hack to get more RAM on this thing ASAP.  Anyway, everything got setup and I created a file called info.php in /var/www and typed the following in it:


Opening a browser on my workstation and requesting the page at was a success!

My thoughts about this device are mixed.  The desktop environment is slow, I don’t like LXDE, and it didn’t come with Firefox, BUT this is a full-fledged linux computer with USB, HDMI, and ethernet for 35$!  I wont be using this for the desktop environment, but more in a headless system.  In fact, I think most users will do the same.  The only great thing about the GUI is that you can fallback to it if you need to open a webpage that’s not lynx-friendly.  There’s still a lot I want to do with this board: install XBMC, control the GPIO’s, give it Bluetooth or WiFi, etc.  Finally, If you’re into Arduino’s, GET THIS!  You will not be disappointed.

Setting up your environment for PIC32 development on Linux

Here we are in part 2 of this series and I’d like to walk you through setting up your development environment to create firmware for the UBW32 on Linux since there are no others I found on the net.

Briefly, here are the things you will accomplish in this tutorial:

  1. Download and install Microchip’s cross-platform IDE, MPLAB X
  2. Download and install Microchip’s free 32-bit compiler for PIC32’s
  3. Download and extract the Microchip Application Library
  4. Download the latest version of the UBW32 firmware source code
  5. Configure your environment
  6. Compile the new firmware
  7. Program your UBW32 with the new firmware

Let’s get started, shall we?  First, go to the MPLAB X site, select your platform — Linux (32/64 bit), here — and select the newest MPLAB IDE X and MPLAB C32 Lite Compiler as shown in the following screenshot.

After it downloads, you’ll need to add execute permissions on the file and install it with root privileges by issuing these shell commands in your download directory:

bryan@Plato:~/Downloads$ chmod +x mplabc32-v2.02-a-linux-installer.run
bryan@Plato:~/Downloads$ sudo ./mplabc32-v2.02-a-linux-installer.run

Now, go download the Microchip Application Library (MAL) which includes many libraries — some of which are needed to build the UBW firmware — and several examples showing how to work with the PIC32’s on-chip devices.  If, by chance, the above link no longer works, search for “Microchip MAL” on Microchip’s website or your favorite search engine.  For my environment, I downloaded the “Microchip Application Libraries v2012-04-03 Linux” file.  Add execution attributes and run it the same way you did for the IDE and compiler.

Now, download the latest UBW32 source code from the UBW32’s project page and extract it into the MAL folder that was extracted in the last step.  Now, rename the newly extracted directory to “D32.X”, Open up MPLAB X, go >> File >> Open Project, browse to the “D32.X” directory, and click “Open Project”.  If you try to build the project right off the bat, you’ll get some errors.  I found that a couple of #include directives were inserted incorrectly — USB\usb_device.h and USB\usb.h.  Simply remove the “USB\” on lines 50:51 of main.c and save that file. Also, I found I needed to include a file called “procdefs.ld” from the “D32.X” directory into your project.  A warning from various sources on the net state that if you do not include this file, you will certainly soft-brick your UBW32 and will need a PICKIT3 programmer to re-flash the bootloader, so don’t forget this step!  Now you should be able to build the project sucessfully!  In order to load the new file to your UBW32, use the ubw32 command outlined in the previous post.

Congratulations!  You now have a complete development environment for creating firmware for your UBW32.  In follow up articles, I hope to add features to the firmware such as I2C, SPI, oscilloscope, etc. so stay tuned for more!

PIC32 & Linux

There’s a neat little Arduino-like microcontroller board with a very powerful PIC32 called the USB 32-Bit Whacker (UBW32) that can be had for $40 from Sparkfun.  Side-by-side, the UBW32 blows the Arduino Mega out of the water!  The UBW32 is a 32-bit microcontroller, runs at 80 MHz, packs 128 KB RAM, 512 KB Flash, and has 78 IO pins!  Compare that with the top of the line Arduino — the Arduino Mega 2560 — which is an 8-bit microcontroller, runs at 16 MHz, and only has 8 KB and 256 KB of RAM and Flash, respectively.  Almost 50% more expensive, the Mega can only process roughly 5% of what the beastly UBW32 can do.

Now, programming the UBW32 isn’t quite as easy as programming the Arduino’s, so I hope to spread some light on how to program it.  First, unlike older microcontrollers you do not need a dedicated hardware programmer.  It comes shipped with a USB Bootloader that allows you to easily upload new firmware to it.  Because this article’s title implies doing this with Linux, and because I like Linux more than the other operating systems out there, I’ll only be concentrating on delivering the steps on how to do this with Linux.  Additionally, there is a wealth of information on the web dealing with the PIC32 on Windows, whereas that is not so true with Linux.

Probably one of the first things you’ll want to do when you receive your UBW32 is to add some 0.1″ male headers along the length of the underside of the board so you can easily plug it into a breadboard.  Also, I’d suggest adding an 8-pin male or female (doesn’t matter which) on the top of the board, opposite the side of the USB connector.

Here’s a picture of the unpopulated UBW32 as it comes from Sparkfun:



So, whether or not you’ve soldered the headers to the board, let’s connect to it and issue some commands to the firmware.  I’m using Ubuntu 11.10 (Oneiric) with minicom (sudo apt-get install minicom) so the command I use to connect to the board is:

minicom -D /dev/ttyACM0

Your serial device could be in another location.  “lsusb” and “ls /dev/tty*” will help your out in the shell.

Once I’ve connected I get the following text:

Welcome to minicom 2.5

 Compiled on May  2 2011, 10:05:24.
 Port /dev/ttyACM0

Press CTRL-A Z for help on special keys

AT S7=45 S0=0 L1 V1 X4 &c1 E1 Q0
 !8 Err: Unknown command 'AT:4154'

You can safely ignore this as minicom, by default, is treating your device as a modem and trying to send it “AT” commands.  Type in “V” and hit enter.  This will give you the version number.  If Sparkfun decides to ship these with the newest firmware (1.6.3 as of this writing) and you see this in the output, then great!  You don’t need to hastle with upgrading the firmware and you can wait till I publish the next article in this series.

Otherwise, if you get “UBW32 Version 1.4” like I did, this is how you go about upgrading the firmware.  You’ll need libhid-dev which is no longer in the Ubuntu repositories.  The yaVDR PPA has these packages, so if you’re on 11.10, add these to your repositories:

deb http://ppa.launchpad.net/yavdr/main/ubuntu oneiric main
deb-src http://ppa.launchpad.net/yavdr/main/ubuntu oneiric main

Then, just “sudo apt-get install libhid-dev” and you’re one step closer…

Now download the programmer from http://members.dslextreme.com/users/paintyourdragon/uc/ubw32/ubw32.tar.bz2, extract it, and “cd” to that directory.  “make”, “sudo make install”, and “sudo chmod +s /usr/local/bin/ubw32”.  Now download the latest version of the firmware from http://www.schmalzhaus.com/UBW32/ and extract it.  Now do “ubw32 -w D32.hex -n -r” which will erase the current firmware on your board, upload the new one (D32.hex), NOT verify the write, and reset the device.

You’re now all set!  In later articles, I’ll possibly go into installing MPLAB X — the cross-platform Microchip IDE, — installing the C32 compiler, installing gcc for the pic32’s, etc.  My ultimate goal with this device is to create a “Universal bus interrogator” which reads and writes several protocols like SPI, I2C, MIDI, etc. like the Bus Pirate with an oscilloscope, spectrum analyzer, and logic analyzer and have it all controllable via Python.  For now, here are some references which you may find useful: