Home » Posts tagged 'Raspberry Pi' (Page 2)
Tag Archives: Raspberry Pi
As stated in an earlier post, I plan to run my Raspberry Pi (RPi) as an attached device to my homes LAN and use my MS Windows PC to access the RPi. The RPi will use my PC for display output and key board / mouse as input. With the X Window System on the RPi, I can transmit an entire RPi desktop if I wish (using LXDE and it would look and feel much like VNC). I find this cumbersome since now your dealing with two desktop environments: MS Windows desktop and X Window System based desktop all one display.
There is an alternative way. One of the cool things about the X architecture is that it can use MS Windows as your window manager (at least with the tools like Cygwin/X, Xming, and MI/X) but the application within the window frame can be the RPi based X Window System application. Now you have a single desktop (MS Windows) but your running RPi application within a MS Windows window. And with this configuration, you can run both Linux programs within a standard terminal window and graphic X Window System applications in another window.
For me this is clearly the way to go. It will allow me to hop on my PC, and with a double-click on a desktop icon, get me to a password prompt on the RPi. Enter the password, and I can immediately run both command line and X graphics application on the RPi, along side MS Windows applications, all concurrently on a single desktop.
How I did this, along with some background information, is provide below.
X Window System
The X Window System (commonly referred to as X Windows or just X or X11) is a software system and network protocol that provides a basis for graphical user interfaces (GUIs) and rich input device capability for networked computers.
X uses a client/server model, but appears backwards when you first learn of X. In X, it’s the server that runs on the local machine (the PC), providing its services to the display based on requests from client programs that may be running remotely (the RPi). Within a X Window System, a client can also run locally. The server also manages the input devices (your keyboard and mouse), and it manages the display of colors and fonts on the screen, all based on requests from a client.
One of the most significant features of X is that it was specifically designed to work across a network. The client and the server communicate via the X Protocol, a network protocol that can run locally or across a network. Regardless of whether a client program is local or remote, it communicates with the server through the X Protocol.
X Window System Components
A X Window System consist of several components which work together. They are:
- X Server – manages the display, based on requests from the window manager.
- Window Manager – is an application that is itself an X client, with responsibility for managing the appearance and placement of the windows on the screen. The window manager takes care of the appearance and placement of the windows; it doesn’t determine what goes on inside.
- Windows – are the X clients, typically providing user functionality. Windows are fully in control of the application but their placement, geometry etc. are controlled by the window manager.
- Display Manager – runs as a program that allows the starting of a session on an X server from the same local or remote computer A display manager presents the user with a login screen which prompts for a username and password. A session starts when the user successfully enters a valid combination of username and password.
- When the display manager runs on the user’s computer, it starts the X server before presenting the user the login screen, optionally repeating when the user logs out.
- When the display manager runs on a remote computer, it acts like a telnet server, requesting username and password and starting a remote session.
- Desktop Environment – go further than a window manager in providing an integrated graphical environment where all applications and windows have a common look and feel. The desktop environments also include session management, for saving and restoring your work sessions.
In the spirit of user-friendliness and security, the desktop and display manager hides much of the X Window System and its’ subtleties. If you want to really explore X (and light its load on the RPi), it’s helpful to run with just a window manager for a while (even if you plan to go back to the desktop). That is what I plan to do.
Cygwin’s X Server and Window Manager
Before you can run a X client, you need to start the X server. You can run the X server in two ways: it will automatically start if your Linux is configured with a X Display Manager (XDM), and if not, at the Linux command line you can start X manually. It is the latter that I want to do on my PC / RPi combination (and the way my RPi distribution Occidentalis is pre-configured). Also, in my configuration, I’ll be using the Cygwin X server on the PC, and no server will be running on the RPi, only X clients.
Now there are some important capabilities within the Cygwin X server. Cygwin/X can work with its window managers in several different ways.
- Internal window manager – The internal window manager creates a MS Windows window for each top-level X window. This window manage is “internal” to the Cygwin X server.
- External local window managers – These local window managers must be installed on Cygwin and runs on the PC (e.g. twm, mwm, fvwm2, openbox, aewm++, WindowMaker).
- Remote window managers – This would be a situation where the window manager is on the RPi and would connect via a remote sessions using XDMCP (X Display Manager Control Protocol).
I plan to keep things simple and use the Cygwin internal window manage.
XWin is the X Server for the X Window System on the Cygwin environment running on Microsoft Windows. It can operate in three different modes:
- Single Window – This is the default mode. Each X screen appears as a single MS Windows window and all X windows are contained within this window. (In X terminology, the MS Windows window contains the root window for the screen.)
- Multi-Window – In this mode XWin uses its own integrated window manager in order to handle the top-level X windows, in such a way that they appear as normal MS Windows windows.
- Rootless – In this mode the X server works in a window containing the whole screen but this root window (traditionally covered with an X hatch pattern) is hidden from view, so only top-level X windows are seen.
To get a better idea on what the different modes can provide you from a user experience perspective, check out some Cygwin/X screen shots. Again, my objectives are to keep things simple and clean, so I will be using the multi-window mode.
To operate Cygwin/X in multi-window mode you use the command
startxwin (You use
startx for window mode.
startxwin is a specialized version of
startx with a few differences appropriate to running in multi-window mode, rather than windowed mode). The
startxwin program has a resource file called
.startxwinrc. You can create a
~/.startxwinrc script to start client programs, such as mintty or xterm. An example
.startxwinrc file is:
mintty --position 100,100 --size 80,50
mintty --position 150,150 --size 80,50
mintty --position 600,500 --size 80,25 --exec ssh -X firstname.lastname@example.org
This will open up two xterm windows for your in the left hand corner of the screen and a thrid xterm window in the center of the screen. This third screen is automatically logging in to the RPi as user pi and will wait four you to enter the password.
Also make sure that you export your
DISPLAY for the X server on your PC. You can do this by placing the following in your
# environment variables required by X Window System
Not much needs to be done to the RPi to prepare for the X applications. You may wish to launch some X Window System application upon logging in. You can do this by adding the X applications to your .bash_profile. For example, add the following line to launch the LXDE file manager:
# execute X Window System programs
Starting and Stopping the Cygwin X Server
The environments are now set. Time to start the X Server. The easiest way for starting Cygwin/X is using the “XWin Server” shortcut under “Cygwin-X” on the Start Menu or on the MS Windows desktop. You could also type
startxwin on the Cygwin command line.
As to stopping the X Server, for the window mode I’m working in (multi-window), stopping Cygwin/X can be done by Selecting the “Exit…” option from the notification area icon menu.
How Does It Look
So given the configuration discussed above, your get a nice clean display with MS Windows, Cygwin, RPi command line, and RPi X Window application running in a single windows management environment. Picture provided below:
You thought the Raspberry Pi was a simple little hardware hackers computer …. but its running like a big dog now!
Much of what is provided here was lifted from the following sources:
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 config --global user.name "jeffskinnerbox"
git config --global user.email email@example.com
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:
CApath: none while accessing https://github.com/jeffskinnerbox/Cygwin-Configuration-Files.git/info/refs
fatal: HTTP request failed
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:
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
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:
- Exit the Cygwin Terminal
- Run as administrator the MS Windows Command Prompt window
- Execute ash via
- Now under ash, see if any Cygwin processes are running via
- Stop any of the running processes via
/usr/bin/cygrunsrc --stop <process's>
- Now do the rebase via
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.
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.
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 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 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 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
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
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
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:
On 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 firstname.lastname@example.org 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.
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
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:
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.
Within the mintty window, log into the Raspberry PI:
ssh -Y email@example.com
An once in the Raspberry Pi, startup the LXDE Desktop Client using the command:
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.
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: