Home » 2012 » September

Monthly Archives: September 2012

Advertisements

Setting up Git for Arduino and Raspberry Pi Development

For my future projects, I plan to do a combination of Arduino and RPi development.  The development of the Arduino code will be on my MS Windows PC and the RPi solution will be developed naively within the RPi Linux environment   Given this distributed environment (and my ability to bungle things), I can foresee  potential problems maintain good source code control.  To deal with this, the combination of git and gethub seems the right way to proceed …. after all it has worked for the distributed Linux development community.

Git on MS Windows

The first thing I did was to set up git within my MS Windows PC.  Given that I installed Cygwin when setting up the RPi, that is where I returned to install git.  Therefore, I plan to use git within the Cygwin environment on my PC and not within MS Windows per say.  This could be done, but my approach allows me to learn git commands once since, Cygwin is a Linux-like environment, everything should look and operate the same.

To accomplish this I follow the instructions outline in Installing Git on Cygwin.  These instructions are very straight forward.  The challenge was in initializing git for my first project, at least it was a challenge for me since git is new tool for me and Cygwin didn’t always cooperate.  I had to address this the old fashion way …. read the documentation and trouble logs (vs. doing a web search for someones web post with instructions).  All the important secrets of git can be found widely dispersed and buried deep withing these web sites: Git Documentation and Git Reference.  Source information from trouble logs will be listed below.

So how did I do it?  It’s easy once you successively done it once.  First let me state the context; for the exercise I’m doing, I’m attempting to place my .bashrc, .profile, .vimrc, and a few other configuration files under gits control.  The basic sequence of operation is to initialize the git environment, configure some parameters, and then add the files.  It goes like this (I’ll let you research the git documentation, just like I did, to understand the command.  Trust me, this is good for you!):

git init
git config --global user.name "jeffskinnerbox"
git config --global user.email jeff.irland@verizon.net
git config --global core.editor vim
git config --global merge.tool vimdiff
git add .bashrc .profile .vimrc .bash_profile .minttyrc .inputrc .gitconfig .gitignore

To see what you got, use the git status command.  This will tell you the files got staged but not committed. The commit will come later.  First we need to set up our communal repository within github.

Setting Up Github

You may be asking, What Exactly Is GitHub Anyway?  Well, in a few words, github is a web-based hosting service for software development projects that use git. The next step is to go to github, set up your free login, and then set up a repository.  In my case, I set up a github repository called Cygwin-Configuration-Files to store my configuration files established earlier under git control.  It will be empty at this point, and that’s all for now, loading it with files comes later.

I didn’t say much about how to set up github, but trust me, it is as simple as outlined above.  It’s via git that all the real work takes place.  Github is all about giving you an off-site, web-access-able, complete version controlled historical record of your code that can be shared with others.

Back to Git within Cygwin

Now that we have established github and initialized, configured, and added files to the Cygwin environment  we can associated the PC and github environments.  It wasn’t clear to me, from the git documentation, how to best do this association.  Using  git clone isn’t intuitive to me, but it seems to work.  This is how I did it:

git clone https://github.com/jeffskinnerbox/Cygwin-Configuration-Files.git

Warning You may, as I did, get the following error:

Cloning into 'Cygwin-Configuration-Files'...
error: error setting certificate verify locations:
CAfile: /usr/ssl/certs/ca-bundle.crt
CApath: none while accessing https://github.com/jeffskinnerbox/Cygwin-Configuration-Files.git/info/refs
fatal: HTTP request failed

If you get the above error, the problem is that Cygwin hasn’t installed the ca-certificates package.  Run the Cygwin installer again, and add that package; after that git clone should start working.

The next step is to commit your files to the git local repository within the PC under Cygwin.  To do this, execute the following command:

git commit

You will be put into vim to provide a comment that will be posted with the git version.  Why vim?  Because you executed the command git config --global core.editor vim  earlier.  If you don’t want to use vim for adding comments under git, supply another editor when you do the configuration step.

The next step, which strictly isn’t required but a nice to have, is to associate a descriptive identifier with the github repository.  The descriptor I used is “Cygwin-Configuration-Files”.  The command I used is:

git remote add Cygwin-Configuration-Files https://github.com/jeffskinnerbox/Cygwin-Configuration-Files.git

The final step is to push your local files to the github repository,

git push Cygwin-Configuration-Files

Warning … It was during the git push that I ran into another problem, but it could happen nearly any time.  I discovered that sometimes, after multiple Cygwin updating or installing packages, you’ll start to get strange errors related to “fork()” or .dll loading. After some research, I discoved these errors are usually solved by rebasing your packages.  While rebasing, which is executed using the Cygwin rebaseall command, is is a bit of a mystery, it does appear to work

Rebasing Cygwin

Before you can run the rebaseall command, you’ll need to make sure no Cygwin-based services are running.   To do this, you need to run two cygwin command, cygrunsrc and rebaseall,  under the ash command in MS Windows command prompt, not in a Cygwin Terminal window.   The sequence of activity is as follows:

    1. Exit the Cygwin Terminal
    2. Run as administrator the MS Windows Command Prompt window
    3. Execute ash via \cygwin\bin\ash.exe
    4. Now under ash, see if any Cygwin processes are running via /usr/bin/cygrunsrc -L
    5. Stop any of the  running processes via /usr/bin/cygrunsrc --stop <process's>
    6. Now do the rebase via /usr/bin/rebaseall

For an example the steps above performed within the Command Prompt under ash, see below:

Git on the Raspberry Pi

Admittedly, getting git setup under MS Windows / Cygwin isn’t a walk in the park.  It appears to work fine once set up, but the setup process can be painful.

Git under the Raspberry Pi’s Linux installs flawlessly, as you would expect, given git origins.  First you  install git via sudo apt-get install git.  Then, just as was done above, do the initialization of the git environment, configure some parameters,  add the files, setup the github, clone, and push.

In my case, I setup a separate  a github repository called RPI-Configuration-Files to store my RPi configuration files.  I could have used the same repository as was setup for the PC environment but that didn’t make sense for my present needs.

Conclusion

So that’s it!  Its a long post for what is really a simple to use tool, but setting it up the first time could be a challenge.

Advertisements

Installing Packages into the Raspberry Pi’s Linux

Once I got the RPi up and running headless on my local network, its time to build the software foundation that I’ll need to make it an effective development environment.  These are the packages that I loaded to get myself up and running.

Do Your House Cleaning First

I’m loading software via the Linux apt-get utility and you need to make sure its database is up to date. First thing to do is to update apt-get’s local database with server’s pkglist’s files.  Then checks for outdated packages in the system and automatically upgrades them.  Execute the following commands:

sudo apt-get update
sudo apt-get upgrade

Search for Package or Package Description

Some times you don’t know package name but aware of some keywords to search the package.  To search for packages, use the following:

apt-cache search "text-to-search"
apt-cache search "text-to-search" | grep "more-search-text"

Synaptic

Synaptic is a graphical package management program for Linux software. It provides the same features as the apt-get command line utility with a X Windows GUI front-end.  While I will not be using X Windows at this moment, in the future I will and synaptic is a very nice alternative to apt-get when in in X Windows.

sudo apt-get install synaptic

Vim

Vim is a highly configurable text editor and widely available for many different platforms.  Emacs also has a large following, but I think everyone needs to be prepared to use vim if your serious about Linux.  The RPi Linux distribution appears to have vi loaded but vim is a superior tool.

sudo apt-get install vim
sudo apt-get install vim-gtk

PyRoom

PyRoom is a a fullscreen editor without buttons, widgets, formatting options, menus and with only the minimum of required dialog windows, it doesn’t have any distractions and lets you focus on writing and only writing.  It is the polar opposite of Vim, and as such, is a good editor for the novice or casual user, but requires X Windows and Python.

sudo apt-get install pyroom

Git

Given that I plan to hack some to-be-determined applications using the RPi, I should consider establish some tools for  source code management. The last time I did serious software development in Linux (really Unix), I was using Source Code Control System (SCCS). The tools are much improved now and git is hands down the way to go.

sudo apt-get install git

Chromium

We all have a favorite browser and I choose chromium for my RPi.  Chromium serves as a base for Google Chrome, which is Chromium re-branded (name and logo) with very few additions.

sudo apt-get install chromium

Raspberry Pi Hardware

The Raspberry Pi is a small, barebones computer developed by The Raspberry Pi Foundation, a UK nonprofit, with the intention of providing low-cost computers and free software to students. Their ultimate goal is to foster computer science education and they hope that this small, affordable computer will be a tool that enables that.

What has sparked my interest in the RPi is the fact that it a full functioning linux board, requires minimal peripheral to operate, engineered to support hardware hacking, and cost only $35 (only $25 if your willing to drop the Ethernet port and reduce the memory).

I’m posting here some links to specs for the RPi hardware for latter reference:

Arduino Memory

As I have been exploring the Arduino hardware platforms for my TBD project, I find myself forgetting the memory options available.  I’m recording here my findings so I can reference it later.

Arduino

Chip

Flash

SRAM

EEPROM

Nano 2.3

ATmega168

16K bytes

1024 bytes

512 bytes

Nano 3.0

ATmega328

32K bytes

2048 bytes

1024 bytes

Uno

ATmega328

32K bytes

2048 bytes

1024 bytes

Mega 2560

ATmega2560

256K bytes

8192 bytes

4096 bytes

    • SRAM (Static Random Access Memory) is where the sketch creates and manipulates variables when it runs.
    • EEPROM (Electrically Erasable Programmable Read-Only Memory) is memory space that programmers can use to store long-term information.
    • Flash memory is where the Arduino sketch is stored (program space).  The bootloader takes about 2 KB of flash memory and remaining space is for the sketch.

The Arduino IDE will tell you exactly how much Flash is being used after each compile/upload.  EEPROM is an older, more reliable technology. It is somewhat slower than Flash.  In Flash, a large block is erased all at once, much faster than the EEPROM method of going cell-by-cell.

If you don’t need to modify the strings or data while your sketch is running, you can store them in Flash (program) memory instead of SRAM; to do this, use the PROGMEM keyword.

Part of my interest in the Arduino’s memory is my concern about how much memory a sketch uses.  Here are some sites that provide insight and algorithms for calculating the memory:

Arduino Electronic Design Automation

Electronic design automation (EDA or ECAD) is a category of software tools for designing electronic systems such as printed circuit boards.  In my professional life, I have been work apart from this domain, and only now because of renewed interest in electronics, I have come back to do some research.  I was pleasantly amazed by what I found.

Schematic and PCB Layout Editors

EAGLE (Easily Applicable Graphical Layout Editor) is a very popular (and free) solution for PCB design, including Schematic Capture, Board Layout and Autorouter.

Other tools are specifically focused on the Arduino that allows users to document their prototypes, share them with others, teach electronics in a classroom, and to create a PCB layout for professional manufacturing.

Arduino Platform Simulation

PCB Board Creation

You can crate printed circuit board (PCB) with the aid of some web sites.  You submit your PCB design; they add your design to the batch of orders. When the batch is big enough, the batch is set off to be manufactured.

SPICE

SPICE (Simulation Program with Integrated Circuit Emphasis) is a general-purpose, open source analog electronic circuit simulator

Raspberry Pi has arrived

Raspberry PiOn Friday, September 7th, my Raspberry Pi arrived!  A $35 hackable Linux box … not a bad deal!  I got it from Newark/element14, one of the few place where you can order a Raspberry Pi and not wait for many weeks.

I immediately proceeded to set it up, and after over coming the typical barriers (e.g. my PC’s SD Card reader wouldn’t cooperate), things came together very nicely.  Here is how I did it.

What Raspberry Pi software distribution should I use?

Given that my objectives are to do some hardware hacking using the Pi, I quickly concluded that the distribution being offered by Adafruit was for me. Adafruit offers a distribution called Occidentalis.  Unlike the typical Raspberry Pi software distributions, it comes equipped with  access to SPI, I2C, one wire, and WiFi preconfigured. It also has some things to make overall use easier, such as sshd on start-up  and Bonjour (so you can simply do ssh pi@raspberrypi.local from my PC when I place the Pi on my local network).  And it appears that Adafruit will continue to support and enhance the software as things evolve with the Pi.

I followed the instructions given by Adafruit and had no problems.  I suggest when you do the first boot up, hook up the Pi with a monitor and keyboard to do the initial configuration.  Once that is accomplished, you can leverage the installed Avahi (zeroconf or zero configuration networking) daemon (i.e. Bonjour-like service), as I do below.

How can I access the Raspberry Pi via my PC through my local network?

I have seen this called “running headless”.  For me, this is the way to go.  The last thing I need is another monitor and keyboard to peck at.  Key to this will be getting a terminal emulator and a X terminal running on my PC. I choose Cygwin/X to get this job done. Cygwin/X comes with all the Cygwin utilities, but for me, that is a good thing.

On to your PC, download Cygwin/X and use the set-up procedures listed at the Setting Up Cygwin/X page.  During the “Select Packages” step (step 15), also make sure to include the openssh package.

How do you get shh working on the PC?

This proves to be very easy despite the potential complexities. Follow the procedures in “How To Get SSH Command-Line Access to Windows 7 Using Cygwin“.

How do you connect from the PC to the Raspberry Pi?

Fire up Cygwin Terminal on your PC, and at the prompt, enter

ssh pi@raspberrypi.local

You’ll then be asked for the password for the pi login, enter it, and your should be in the Raspberry Pi via terminal emulation. Note that this is all being done without the assistance of a X Server on the PC.  Your not running in X Windows … that comes next (Make sure to exit the Pi and return back to the Cygwin Terminal for the next step).

How do you run X Windows on the Raspberry Pi and use the PC as your X Terminal?

If you want to run X Windows on the Raspberry Pi with your PC being the X Server display, you need to provide a Display Name and the start the X Server.  This is done within  following command in the Cygwin Terminal:

export DISPLAY=:0.0
startxwin &

Now you should start an X Terminal (Cygwin/X has a light weight version called mintty).  So type in the following into the Cygwin Terminal.

mintty &

Within the mintty window, log into the Raspberry PI:

ssh -Y pi@raspberrypi.local

An once in the Raspberry Pi, startup the LXDE Desktop Client using the command:

startlxde

You should now be in the Pi running X Windows!  No need for an extra keyboard, mouse, or monitor!

Some fine tuning will be necessary so you don’t have to do the export DISPLAY=:0.0 every time you login and other things, but that is all that what is needed to get going.

Getting started with the Raspberry Pi

As I have been doing for the Arduino, I have been doing some research on the Raspberry Pi.  This post will help get you going.

What is a Raspberry Pi?

First things first – Just what is an Raspberry Pi?  Check out the following links for a brief introduction:

Now let’s go a bit deeper to understand the Raspberry Pi hardware and capabilities:

One of the key things the Raspberry Pi team has pushed is that this is a tool for education.

Raspberry Pi Setup

To help with the setup of the Raspberry Pi Linux environment, consider the following:

Some tutorials and other things

%d bloggers like this: