Tag Archive : rpi

/ rpi

Raspberry Pi Project: Simple Blinking LED

December 11, 2015 | Article | No Comments

Blink LED, like what it should be, we make certain LED blinking. We can define “blinking” as continuous condition switching between ON and OFF condition. This is the simplest project we can do for Raspberry Pi.

Make sure you have wiringPi installed on Raspberry Pi already. If not, you can follow this article for guideline.

Objective

  • Make LED blinking.

Prerequisite

Requirement

Following is all materials I use for this tutorial.

  • Raspberry Pi model B
  • 5mm LED active high
  • 330 ohm resistor
  • USB A to micro USB (for powering Pi)
  • Raspbian Wheezy

This article will use Raspbian Wheezy. Although it is not a compulsion for you to update your Raspbian, it is recommended to do.

In this article, we will use pin numbering used in wiring Pi, not the one declared in Raspberry Pi reference.

Circuit

Here is the circuit image, created using Fritzing with Raspberry Pi Library update.

pi_blink_sketch

To build the circuit, attach the LED as shown in the figure. Remember that the long leg of LED is positive leg (also known as anode) and the short leg is negative leg (also known as cathode). The cable from GPIO 0 is directly connect to LED anode. The cathode is connected to resistor 330 ohm and then connected to ground on Raspberry Pi.

Code

Let’s see what code we use for this project and discuss it later.

#include <wiringPi.h>

const unsigned int LED_PIN = 0;
const unsigned int PAUSE = 500;

int main() {
   wiringPiSetup();

   //-- setup
   pinMode(LED_PIN, OUTPUT);

   //-- loop
   for(;;) {
      digitalWrite(LED_PIN, HIGH);
      delay(PAUSE);
      digitalWrite(LED_PIN, LOW);
      delay(PAUSE);   
   }
   return 0;
}

Notice that we define two constant here, LED_PIN which is pin we use, and PAUSE for the delay interval which is 500 ms.

The heart of this project is pin 0. We use this pin as output pin. Therefore we initialize pin 0 as an output pin with the statement:

pinMode(LED_PIN,OUTPUT);

Next in the main loop, we turn the LED on by:

digitalWrite(LED_PIN, HIGH);

and turn it off by:

digitalWrite(LED_PIN, LOW);

And we now know that digitalWrite() function is used to output signal on a pin.

The delay() command is used to tell Arduino to do nothing for given time. In our case, we make Arduino wait for 500 miliseconds.

To compile, use following command:

gcc -Wall -o blink blink.c -lwiringPi

To run it, use following command:

sudo ./blink

Result

LED is blinking.

Why it Works

There are two condition of logic in circuit, HIGH and LOW. If you know boolean value, yes this is boolean value with HIGH is true and LOW is false.

The LED we use is active-high LED, which means it can turn on when it is given HIGH voltage.

WiringPi and Raspberry Pi

December 11, 2015 | Article | 1 Comment

In this article, I use:

  • Raspberry Pi model B
  • Raspbian Wheezy

What is WiringPi?

WiringPi is a GPIO access library written in C for BCM2835 used in Raspberry Pi. It is designed to be familiar to people who have used the Arduinowiring” system.

Raspberry Pi has a 26-pin General Purpose Input/Output (GPIO) connector and this carries a set of signals and buses. There are 8 general purpose digital I/O pins – these can be programmed as either digital outputs or inputs. Besides input/output capability, one of these pins can be designated for PWM output too. Additionally there is a 2-wire I2C interface and a 4-wire SPI interface (with a 2nd select line, making it 5 pins in total) and the serial UART with a further 2 pins.

The Revision2 Raspberry Pi has an additional 4 GPIO lines on a separate connector which you have to solder on the board.

The I2C, SPI and UART interfaces can also be used as general purpose I/O pins when not being used in their bus modes, giving a grand total of 8 + 2 + 5 + 2 = 17 I/O pins on the P1 connector (plus 4 more on the P5 connector on a Revision 2 Pi).

WiringPi includes a command-line utility gpio which can be used to program and setup the GPIO pins. You can use this to read and write the pins and even use it to control them from shell scripts.

WiringPi is extendable and modules are provided to extend wiringPi to use analog interface devices on the Gertboard, and to use the popular MCP23x17/MCP23x08 (I2C 7 SPI) GPIO expansion chips, as well as module that will allow blocks of up to 4 74×595 shift registers to be daisy-chained together for an additional 32-bits worth of output as a single unit. (You can have several blocks of 4 74x595s if needed) One of the extension modules allows you to use an ATmega (e.g. Arduino, or the Gertboard) as more GPIO expansion too – via the Pi’s serial port.

Additionally, you can easily write your own expansion modules to integrate your own peripheral devices with wiringPi as required.

WiringPi supports analog reading and writing, and while there is no native analog hardware on a Pi by default, modules are provided to support the Gertboards analog chips and other A/D and D/A devices can be implemented relatively easily.

WiringPi Installation

Before you can use WiringPi, of course you have to install it inside your Raspberry Pi. The installation is fairly simple. There are two way to get WiringPi installed to Pi: clone from git, download the source tar ball.

Before we go, it is recommended to check whether our distribution is up to date or not.

sudo apt-get update
sudo apt-get upgrade

Remember, this is optional.

Plan A

Installing using git, involving clone the source code tree from git repository. Make sure you have GIT installed. If you do not have one, you can install it by:

sudo apt-get install git-core

Then, clone the WiringPi source code tree by:

git clone git://git.drogon.net/wiringPi

To build WiringPi, do this command:

cd wiringPi
git pull origin
./build

The second command will fetch an updated version of WiringPi source code (if any) and the third script will start building the library. The script will compile and install the library automatically. Remember to use root privilege to do this.

Plan B

If you can’t or don’t want to use git, use following step for manual download and installation:

Click on following URL: https://git.drogon.net/?p=wiringPi;a=summary

Look for the link marked as “snapshot”. Click on the top one which is the latest source code. You will download a tar.gz file with a name like “wiringPi-f18c8f7.tar.gz”. Note that the numbers and letter after “wiringPi” (f18c8f7 in this case) might be different. They are unique identifier for each release.

Extract and then build the package:

tar xfz wiringPi-f18c8f7.tar.gz
cd wiringPi-f18c8f7
./build

Testing WiringPi

After success installation, we should check our WiringPi. WiringPi has a utility called “gpio” which is used for GPIO access. Here how we check:

gpio -v
gpio readall

Pin Numbering

Pin numbering of the BCM2835 GPIO port(s) on the Raspberry Pi has been a source of great confusion since the designs for the Pi were first published. In the early days (even beofre hardware was avalable) the default usable GPIO pins were simply referred to by number as GPIO0 through GPIO7. Additionally there were pins for other purposes, SPI, I2C and serial. This was highlighted on the original image on the Raspberry Pi Wiki site too.

Reference: Raspberry Pi GPIO Reference

wiringPi supports its own pin numbering scheme as well as the BCM_GPIO pin numbering scheme, and as of Version 2, it also supports the physical hardware pin numbers (for the P1 connector only). However, simplified wiringPi numbering is really recommended. In this way, our programs will be portable over different hardware revisions without needing any changes.

The following tables give the mapping of the Raspberry Pi GPIO Pins to the (P1) GPIO connector in relation to the pin numbers and the physical location on the connector. This is a representation of the GPIO connector as viewed looking at the board from above. The GPIO connector is to the top-right of the board with the Ethernet and USB sockets to the bottom.

P1 Header

gpio1

RPi_P1_header

P5 Header (Rev. 2 Pi only)

gpio21

RPi_P5_header

Further Read

Raspberry Pi, a small computer powered by ARM architecture is a very interesting board for learning embedded system. In this article we will discuss about how to install how to install Occidentalis v0.2 Rubus occidentalis.

For this article I use following:

  1. Slackware64 14.0
  2. Windows 8.1
  3. Raspberry Pi model B
  4. Official Occidentalis v0.2

You can use either Linux (in this article, Slackware) or Windows (in this article Windows 8.1). Just pick one and follow the rest of article for your choice.

About Occidentalis

Occidentalis is a embedded Linux distribution derived from Raspbian Wheezy. This distro is created and maintained by Adafruit Industries. The latest version is Occidentalis v0.2 which is derived from Raspbian Wheezy August 16 2012.

What differs occidentalis and other distro?

Occidentalis is tweaked in purpose to make DIY electronics more fun using Raspberry Pi. Yes, we have kernel modules for DS1307, AD525x, I2C digipots, HMC6352, BMP085, ADS1015, easy PWM/Servo control, and many more. It’s not very surprising as this distro is officially created for learning purpose in some Adafruit materials.

However, Adafruit is not full time linux distro maintainers, which means you can’t expect too much. Adafruit state that this distro is not for beginners or people who are new to linux.

Obtain the Materials

The Operating System images I used is Occidentalis v0.2 which can be downloaded from here. The size is about 900MB, per August 31, 2012.

Prepare the Disk (SD Card)

To boot the Raspberry Pi, an installation media and storage media is needed. All we need is a single SD card. On this article I use my 4GB SD card. The image we download on previous section will be stored on this card and later installed. Make sure you have a way to write on SD card.

Windows-based Instruction

For Windows user, you can follow this section to “burn” the image. For this purpose you need additional software for writing to SD card, such as Win32DiskImager utility.

  1. Extract the image (in this case Occidentalisv02.zip) so you will get an .img file.
  2. Insert SD card into SD card reader and check what drive letter it assigned to. For example G:\
  3. If it is not new, format it. Or at least make sure there is only one partition (FAT32 is recommended).
  4. Run the Win32DiskImager with administrator privileges.
  5. Select the image we have extracted (Occidentalis_v02.img).
  6. Select the drive letter of the SD card on our machine. Make sure you have the correct drive, or you will destroy data on that drive.
  7. Click Write and wait. The process should be not long.
  8. Exit the imager and eject the SD card

Beside Win32DiskImager, you can also use other tool such as Flashnul.

  1. Follow step 1 to step 3 for Win32DiskImager’s solution
  2. Extract Flashnul from the archive
  3. Open command prompt with elevated privilege (administrator privilege).
  4. Go to your extracted directory and run flashnul with argument “-p”. For example: flashnul -p
  5. You will get list of physical drive attached on your machine, and list of drive. Make sure the drive is correct. At time of writing this article, the SD card is detected as device number 1 with and mounted to drive G:
  6. Load the image to flashnul: flashnul 1 -L Occidentalis_v02.img
  7. If you get an access denied error, try re-plugging the SD card and make sure to close all explorer windows or folders open for the device. If still get denial, try substitute the device number with its drive letter: flashnul G: -L Occidentalis_v02.img

At this point, you have successfully written image to your SD card. And I assume you are. You can proceed to next stage.

Linux-based Instruction

Writing image on Linux is easier, in my opinion. The utility we use is “dd” which is already bundled on most distro. Make sure you know the correct device file for your SD card. In my machine I use a built in card reader and detect my SD card as /dev/sdb. It might be different on your system so better check it. For this article I use /dev/sdb to refer to SD card.

  1. Extract the image (in this case Occidentalisv02.zip) so you will get an .img file.
  2. Insert SD card into SD card reader .
  3. If it is not new, format it. Or at least make sure there is only one partition (FAT32 is recommended).
  4. Unmount the SD card if it is mounted. We need the whole SD card so if you see partition such as /dev/sdb1, etc its better you unmount them all.
  5. Write the image to SD card. Make sure you replace the input file after if= argument with correct path to .img file and “/dev/sdb” in the output file of= argument with your device. Also make sure to use whole SD drive and not their partition (i.e. not use /dev/sdb1, /dev/sdb1, etc). The command: dd bs=4M if=Occidentalis_v02.img of=/dev/sdb
  6. Run sync as root. This will ensure the write cache is flushed and safe to unmount SD card.
  7. Remove SD card from card reader.

If you hesitate to use terminal and prefer to use GUI method, here is the tutorial. Note that we

  1. Do step 1 to step 3 for previous tutorial. Make sure your directory or image file doesn’t contain any spaces.
  2. Install the ImageWriter tool from https://launchpad.net/usb-imagewriter
  3. Launch the ImageWriter tool (needs administrative privileges)
  4. Select the image file (in this case Occidentalis_v02.img) to be written to the SD card (note: because you started ImageWriter as administrator the starting point when selecting the image file is the administrator’s home folder so you need to change to your own home folder to select the image file)
  5. Select the target device to write the image to. In my case, it’s /dev/sdb
  6. Click the “Write to device” button
  7. Wait for the process to finish and then insert the SD card in the Raspberry Pi

At this point, you have successfully written image to your SD card. And I assume you are. You can proceed to next stage.

Running the Pi

You have write image and at this point your raspberry pi is ready. Now set up raspberry pi to boot: insert your SD card back to raspberry pi, put on power, plug video output (either HDMI or RCA).

To resize the SD card after installation, you can follow this article. Another way, you can use “raspi-config” utility to do it.

To log in on your Raspberry pi you can use the default login, which is:

Username: pi
Password: raspberry

Side Notes

I2C Support

I2C support is on SDA and SCL pins. To test, connect any I2C device to power, ground, SDA, and SCL. Run this command as root to detect which addresses are on the bus:

i2cdetect -y 0

SPI Support

SPI support is on the CLK/MOSI/MISO/CS0/CS1 pins. To test, connect your logic analyzer / scope to the pins and run following command to send some dummy data to the SPI port.

echo "xathrya test" > /dev/spidev0.0

You can simply read/write the /dev/spidev files to read/write from SPI.

One Wire Support

Most commonly used for DS18B20 temperature sensors. The Pi does not have ‘hardware’ 1-wire support but it can bit bang it with some success. Connect a DS18B20 with VCC to 2V, ground to ground, and Data to GPIO #4. Then connect a 4.7K resistor from Data to VCC.

Run following commands as root. Both command will be used to attach the temperature sub module.

modprobe w1-gpio
modprobe w1-therm

You can then run following command to read the temperature data from the bus:

cat /sys/bus/w1/devices/28-*/w1_slave

WiFi Support

The kernel has been patched with RTL8192cu-based patches.

Adafruit Kernel Source Code

You can get the kernel source code here.

Have fun 😀

Smart Card is a pocket-sized card with embedded integrated circuits. It provides identification, authentication, data storage and application processing on simple medium. There are two big categories of smart card: contact and contactless. To identify and authenticate a smart card properly we need a smart card reader. There are many smart card reader and the way we operate is depend on what smart card it can detect.

To detect and use smart card, there is a specification for smart card integration into computing environments. It is called PC/SC (Personal Computer / Smart Card). The standard has been implemented to various operating system: Windows (since NT/9x), Linux, Unix.

We can however create a small device which can make use of smart card reader, instead of using our PC. That’s what we will discuss on this article.

As title suggest, after we have smart card connected we will use PHP as a programming environment.

For this article, we use:

  1. Working Raspberry Pi model B (+SD card)
  2. Raspbian Wheezy release date 2013-09-25
  3. Smart Card Reader, ACR122
  4. USB power hub

Grab the Materials

Make sure the Raspberry Pi is working properly with Raspbian Wheezy installed. Also make sure all the hardware are available.

We need USB power hub as the ACR122 Smart Card Reader gives too high load for Raspberry Pi so we will feed electricity from somewhere else.

Installation

Install the drivers and related package

apt-get install build-essential libusb-dev libusb++-dev libpcsclite-dev libccid
  • build-essential is package for building a application
  • libusb-dev and libusb++-dev are package for user-space USB programming
  • libpcsclite-dev is a middleware to access a smart card using PC/SC (development files) using PC\SC-lite definition
  • libccid is a smart card driver

Install PHP and all needed development tool

apt-get install php5-dev php5-cli php-pear

Once PHP installed, we need a PHP extension for smart card:

pecl install pcsc-alpha

You can see the documentation here.

Configuration

On some case, we need to add an entry to php.ini manually for registering pcsc extension. To do this, open up php.ini and add following entry:

extension = pcsc.so

Folks at Google Creative Lab has release a project to develop a web application using Raspberry Pi platform. This project is pure open source project which turn a Raspberry Pi to a simple web server platform. This way, educators and parents can use to teach the basics of building for the web. New coders can craft small projects in HTML, CSS, and Javascript, right from the web browser. Enthusiasts can also experiments on web programming. All come from a single distribution image.

The project itself is revealed as Coder. How do we setup the Coder to run properly and operated from our machine is what we will discussed in this article.

In this article I use

  1. Raspberry Pi model B, 512MB RAM
  2. SD Card 4 GB
  3. Slackware64 14.0 as client station
  4. Windows 8 64-bit as client station
  5. Mac OS X as client station

Note that I mention three machine for experiment. You can choose any (or all) operating system and to work with.

Prologue

[embedplusvideo height=”495″ width=”880″ editlink=”http://bit.ly/18HOj1C” standard=”http://www.youtube.com/v/wH24YwdayFg?fs=1″ vars=”ytid=wH24YwdayFg&width=880&height=495&start=&stop=&rs=w&hd=0&autoplay=0&react=1&chapters=&notes=” id=”ep8669″ /]
Coder is not only designed for people who start web developing. Google also has big idea to make this platform as fun as possible to experiment and to play around.

Obtain the Material

Coder is like other Linux distribution on Raspberry Pi. It comes with SD card image which will be burned to SD card.

The latest version of Coder is 0.4 which can be downloaded here. The compressed image has size 1.04 GB.

Coder is derived from Raspbian, therefore the basic is not much different from Raspbian. The only thing differ is Coder has special codebase and platform. Though you can install the code on existing distro, we won’t cover it in this article.

The distro has several files and directory inside in hierarchical structure. There is an image with filename raspi.img which we will use later.

Preparation

You should prepare the machine well. We will use this machine (a client) to interact with our Coder. Once you choose either Windows, Mac, or Linux you should read what you need to do to prepare your machine.

Windows

A Windows user should install Apple’s Bonjour Print Service. This application will install Bonjour, a Zero-Configuration Networking system on Windows

Mac OS

You can go, Apple has installed Bonjour on their own machine.

Linux

Follow this link to install Zero-Configuration Networking on Linux.

Prepare the Disk (SD Card)

To boot the Raspberry Pi, an installation media and storage media is needed. All we need is a single SD card. The bigger space, the better. You need space for OS and additional space to hold your ROMS. On this article I use my 4GB SD card. You can use any SD card you want, but I recommend to use at least 4GB SD card (recommended by Google too). The image we download on previous section will be stored on this card and later installed. Make sure you have a way to write on SD card.

Windows

For Windows user, you can follow this section to “burn” the image. For this purpose you need additional software for writing to SD card, such as Win32DiskImager utility.

  1. Insert SD card into SD card reader and check what drive letter it assigned to. For example G:\
  2. If it is not new, format it. Or at least make sure there is only one partition (FAT32 is recommended).
  3. Run the Win32DiskImager with administrator privileges.
  4. Select the image we have extracted (raspi.img).
  5. Select the drive letter of the SD card on our machine. Make sure you have the correct drive, or you will destroy data on that drive.
  6. Click Write and wait. The process should be not long.
  7. Exit the imager and eject the SD card

Beside Win32DiskImager, you can also use other tool such as Flashnul.

  1. Follow step 1 to step 2 for Win32DiskImager’s solution
  2. Extract Flashnul from the archive
  3. Open command prompt with elevated privilege (administrator privilege).
  4. Go to your extracted directory and run flashnul with argument “-p”. For example: flashnul -p
  5. You will get list of physical drive attached on your machine, and list of drive. Make sure the drive is correct. At time of writing this article, the SD card is detected as device number 1 with and mounted to drive G:
  6. Load the image to flashnul: flashnul 1 -L raspi.img
  7. If you get an access denied error, try re-plugging the SD card and make sure to close all explorer windows or folders open for the device. If still get denial, try substitute the device number with its drive letter: flashnul G: -L raspi.img

At this point, you have successfully written image to your SD card. And I assume you are. You can proceed to next stage.

Mac OS

Run the provided installer. This should be sufficient.

You should be able to go to next stage.

Linux

Writing image on Linux is easier, in my opinion. The utility we use is “dd” which is already bundled on most distro. Make sure you know the correct device file for your SD card. In my machine I use a built in card reader and detect my SD card as /dev/sdb. It might be different on your system so better check it. For this article I use /dev/sdb to refer to SD card.

  1. Insert SD card into SD card reader .
  2. If it is not new, format it. Or at least make sure there is only one partition (FAT32 is recommended).
  3. Unmount the SD card if it is mounted. We need the whole SD card so if you see partition such as /dev/sdb1, etc its better you unmount them all.
  4. Write the image to SD card. Make sure you replace the input file after if= argument with correct path to .img file and “/dev/sdb” in the output file of= argument with your device. Also make sure to use whole SD drive and not their partition (i.e. not use /dev/sdb1, /dev/sdb1, etc). The command: dd bs=4M if=raspi.img of=/dev/sdb
  5. Run sync as root. This will ensure the write cache is flushed and safe to unmount SD card.
  6. Remove SD card from card reader.

If you hesitate to use terminal and prefer to use GUI method, here is the tutorial. Note that we

  1. Do step 1 to step 3 for previous tutorial. Make sure your directory or image file doesn’t contain any spaces.
  2. Install the ImageWriter tool from https://launchpad.net/usb-imagewriter
  3. Launch the ImageWriter tool (needs administrative privileges)
  4. Select the image file (in this case raspi.img) to be written to the SD card (note: because you started ImageWriter as administrator the starting point when selecting the image file is the administrator’s home folder so you need to change to your own home folder to select the image file)
  5. Select the target device to write the image to. In my case, it’s /dev/sdb
  6. Click the “Write to device” button
  7. Wait for the process to finish and then insert the SD card in the Raspberry Pi

At this point, you have successfully written image to your SD card. And I assume you are. You can proceed to next stage.

Accessing the Coder

Plug the SD card to Raspberry Pi.

Make sure Zero-Configuration Networking service is up (it should be).

Open up your browser and visit following url:

coder.local

Like Raspbian, when you run coder for first time you will be asked to do some configuration for example resize the SD card. Or you can resize the SD card later which you can find the guide on this article.

There are some ways for accessing Raspberry Pi: access Pi directly or indirectly. You might at least try one of thus method for connecting your Pi to your PC.

The direct access involving access without any medium. You connect screen (LCD screen, for example), keyboards, mice, etc to your Pi. This way, your Raspberry Pi act as normal computer. You operate it like you operate your PC. This method has a drawback, whenever you want to use Pi you must provide appropriate input and output device (keyboard, mouse, screen).

Another way to access Pi is using indirect access. This method involving other medium to access Pi, technically a network. In this term, your Pi is connect to a network and you can access the Pi over the network. SSH and VNC are the good example of this. This method demand us to provide good network connection if you want a good connection.

Accessing Pi over network is good, you don’t need other peripheral / device such as keyboard, mouse, or LCD screen. If you want to do thing graphically you can use VNC (Virtual Network Computing). However, using VNC is somehow slow because the application and desktop environment are rendered both on your Pi and your desktop. VNC also require better network as it sends picture / screen image over time.

There is a better solution for this problem. Instead of rendering the graphic on Pi, why don’t we render it on our local computer? This way, Pi only send us minimal packet. Using this method, we can also use keyboard and mouse on our local computer, just like indirect access do.

In this article we will discuss about other way to remote accessing your desktop without VNC. If in other article we use X.org server on Linux & Unix, on this article we still use X but in cygwin environment. For this article I use:

  1. Windows 8 on PC
  2. cygwin64
  3. Raspbian Wheezy on Raspberry Pi

Alternatively, you can use cygwin for 32-bit. However as my Windows 8 is 64-bit I will stick to it.

X Window System – Server & Client Architecture

X Window is originated at the Massachussetts Institute of Technology (MIT) In 1984. X11 is the system-level software infrastructure for the windowing GUI on Linux, *BSD, and other UNIX-like Operating System. It is designed to handle both local display, as well as across the network displays. X Window is a computer software system and network protocol that provides a basis for graphical user interfaces (GUIs) and rich input device capability for networked computers. It creates a hardware abstraction layer where software is written to use a generalized set of commands, allowing for device independence and reuse of programs on any computer that implements X.

X was designed from the beginning to be network-centric. It adopts a “client-server” model.

In the X model, the “X server” runs on the computer that has the keyboard, monitor, and mouse attached. The server’s responsibility includes tasks such as managing the display, handling input from the keyboard and mouse, and other input or output devices (i.e., a “tablet” can be used as an input device, and a video projector may be an alternative output device). Each X application (such as XTerm or Firefox) is a “client”. A client sends messages to the server such as “Please draw a window at these coordinates”, and the server sends back messages such as “The user just clicked on the OK button”.

In a home or small office environment, the X server and the X clients commonly run on the same computer. However, it is perfectly possible to run the X server on a less powerful desktop computer, and run X applications (the clients) on, say, the powerful and expensive machine that serves the office. In this scenario the communication between the X client and server takes place over the network.

This confuses some people, because the X terminology is exactly backward to what they expect. They expect the “X server” to be the big powerful machine down the hall, and the “X client” to be the machine on their desk.

It is important to remember that the X server is the machine with the monitor and keyboard, and the X clients are the programs that display the windows.

Preparations

As stated before, the X window is using client/server model. Our communication would be on top of secure connection. Specifically, SSH (Secure SHell) connection are chosen to transport data (as a tunneling). Therefore, we should configure SSH server properly.

Now on your Raspberry Pi, configure SSH server. Obviously, you MUST install your SSH server program. Edit following file /etc/ssh/ssh_config, make sure these lines are not commented.

ForwardAgent yes
ForwardX11 yes
ForwardX11Trusted yes

Now open /etc/ssh/sshd_config and edit the file so it has following line:

X11Forwarding yes

Restart the SSH Server.

On our host, make sure X11 is installed on cygwin. We won’t cover how we installed cygwin or X11.

Remote Display

Open up cygwin terminal. We need an X server. At default, cygwin will not running X at startup.

We want to create a server on our local machine. This X server will manage our local screen output as well as other X client (Raspberry Pi in this case). To initiate a server, do following (assuming we use default display :0):

export DISPLAY=:0
xinit -- $DISPLAY

A new window should appear with a black blank screen. You would see a new terminal there.

Now connect to Raspberry Pi using SSH.

ssh -X [email protected]_ip_address

user is the username we will use and the raspberry_ip_address is the Pi’s IP address. Make sure you can access and you can login to Pi.

Once you are logged in, execute this to start the X.

lxsession &
lxpanel &

Now, your window should be drawn to your Raspbian’s LXDE.

Because X on cygwin implementation is a window, you can view both your desktop and remote desktop at same time.

Arch Linux ARM is a Linux operating system distribution for ARM architecture. This distribution is one of recommended OS for Raspberry Pi board.

By default, Arch Linux ARM has a global repositories. On some point, the repository can redirect your pacman to appropriate (other) repository based on your location. But sometimes, it’s not enough.

In this article, we will discuss about how to change ArchLinux ARM repository manually.

Preparation

Make sure your Pi has Arch Linux ARM inside. You should also make sure your Pi can connect to internet.

You need to acquire root privileges. We need root privileges to edit pacman configuration file.

Configuration

First see the /etc/pacman.d/mirrorlist and search location closest to you. If you see a preferrable repository, you can start edit this file.

Comment out line under “Geo-IP based mirror selection and load balancing”:

# Server = http://mirror.archlinuxarm.org/armv6h/$repo

and uncomment the mirror server you choose, for example I choose Finland:

Server = http://fi.mirror.archlinuxarm.org/armv6h/$repo

If you have another mirror which are not listed there (you have to really sure about it), you can comment out every line and add new line at the bottom. For example, the mirror server is http://archarm.xathrya.web.id, then you write following line:

Server = http://archarm.xathrya.id/armv6h/$repo

Haskell is one of powerful functional programming language. More specific, it is a polymorphically statically typed, lazy, purely functional language. It is the good language for expressing math equation and logic naturally. Haskell is based on the lambda calculus, thus it use lambda as the logo.

Despite of functional paradigm nature, Haskell is very good for network and distributed system application. It can also applied as application on cloud computing.

After installing haskell on Raspberry Pi, it is worth to test what Haskell can do. This article will discuss about creating a simple Echo Server on Raspberry Pi using Haskell programming language.

In this article I use:

  1. Raspberry Pi model B 512MB RAM
  2. Raspbian Wheezy 2013-07-26 hardfloat

Overview

What we really want to build in this article is a modified Echo server. This program will run forever (infinite loop) and listen on port specified by user when invoking program. Like any socket-based application, when a connection come, it will accept and process it according to our app’s logic. Our logic is so simple. Whenever user connect to server using telnet, this server will echo every line they write (echo). However when they write “ping” without quote, the server will reply with “pong”.

Preparation

Make sure you have install Haskell on your Pi.

Writing code to Pi can be done using any method. You can access your Pi remotely or access directly. At least, make sure you can create a file and write it.

Writing the Code

Write this snippet and save it as “echoserver.hs”:

import System.Environment (getArgs, getProgName)
import Control.Concurrent (forkIO)
import Network (Socket, PortID(PortNumber), withSocketsDo,
        listenOn, accept)
import System.IO (hPutStrLn, hGetLine, hFlush)
import Control.Monad (forever)

main = withSocketsDo $ do
    args <- getArgs
    prog <- getProgName
    case args of
        [port] -> do
            socket <- listenOn $ PortNumber (fromIntegral (read port :: Int))
            putStrLn $ "Listening for pings on " ++ port
            handleRequest socket
        _ ->
            putStrLn $ "usage: " ++ prog ++ " <port>"

handleRequest s = do
    (handle, _, _) <- accept s
    forkIO $
        forever $ do
            input <- hGetLine handle
            processPing (hPutStrLn handle) (init input)
            hFlush handle
    handleRequest s

processPing f msg = do
    if msg == "ping" then 
        f "pong!"
        else
            f msg

Also, make sure you pay attention to the indentation.

This code is simple and should run on any architecture supported by GHC, including our Pi.

Build and Testing

To build the above code, run this command (assume the code is saved as echoserver.hs):

ghc -O2 --make echoserver.hs

The -O2 flags are used to apply every non-dangerous optimization, but might make the compilation time longer.

After compilation successful, you will have a new file name echoserver. To run the server do this on your Pi:

./echoserver 5000

This will run a server and make it listen to port 5000.

Now on your local computer, open up command prompt / terminal and invoking telnet to connect to your Pi. Suppose our Pi is on address 192.168.1.11, do following:

telnet 192.168.1.11 5000

which will connect us to Pi on port 5000.

You can test by write any line there. Good luck 🙂

Running Haskell on Raspberry Pi

December 9, 2015 | Article | 1 Comment

Haskell is one of powerful functional programming language. More specific, it is a polymorphically statically typed, lazy, purely functional language. It is the good language for expressing math equation and logic naturally. Haskell is based on the lambda calculus, thus it use lambda as the logo.

Haskell can be installed on various operating system, from Linux, Windows, Mac OS. Most of them are Operating System for Personal Computer (PC). Now, can we install Haskell to different platform? ARM maybe? Yes it can.

In this article we will discuss about how to install Haskell on top of Raspberry Pi device. Specifically, the Raspberry Pi device which running Linux OS. The device I use as test is Raspberry Pi model B with 512MB RAM.

Preparation

Make sure you have a good preparation. You have downloaded Raspberry Pi’s OS images and write to your SD card. Therefore, I assume you have install Linux operating system on your Raspberry Pi.

There is no special treatment for installation. I assume you have a ready to play Pi with network support.

You can either use SSH or connect some peripheral (keyboard, mouse, display) to access Pi. We won’t cover much detail here.

Theory Behind

There are two package we will discuss on this article: ghc and haskell-platform.

GHC or Glasgow Haskell Compiler, is a package with compiler, and interactive interpreter for Haskell.

Haskell-platform is a platform, has a collection of haskell code and tools for developing Haskell application.

Installation

on Raspbian Wheezy

The raspbian I use here is 2013-07-26. To install Haskell on Raspbian, use:

# make sure you have root privilege to install
sudo apt-get install ghc haskell-platform

If you take it correctly, you has already install Haskell. It should be no problem at this point.

The real problem might occur here. The ghc used on Raspbian (per September 5th, 2013) are version 7.4.1 and according to Haskell official site ghci or the interpreter cannot be used for version lower than 7.4.2 on ARM based device.

A cross compiler is a compiler that runs on one platform/architecture but generates binaries for another platform/architecture. With devices like the Raspberry Pi, where you really don’t have much CPU or memory to work with, if you’re doing any heavy compiling (like when working on the kernel) a cross compiler is the only way to go.

While there are a lot of different methods for building cross-compilers, by far the quickest and easiest is to use crosstool-ng. This is a set of scripts that bring up a menuconfig-like interface to choose your compiler settings, then goes off and downloads what it needs, patches it, configures it, builds it and installs it all for you.

For this article I use:

  1. Slackware64 14.0 (Linux)
  2. crosstool-ng

Crosstool-NG Overview

Crosstool-ng is a set of scripts that bring up a menuconfig-like interface to choose compiler settings. The project aims to build a toolchain. Crosstool-ng also support alternative components such as uClibc, glibc, or eglibc.

Insight

Our example will build a cross compiler toolchain for Raspberry Pi, which use ARMv6 and running Linux as operating system. This will assume our OS on Pi only Linux and we cannot use this toolchain to build for other OS (RISC OS, etc).

Obtain Material

Download crosstool-ng from their official site. The latest version available per August 30th 2013 is crosstool-ng 1.18. Once the download complete, extract the content.

We also need to install crosstool-ng to our system. Let’s say we want to install it to /opt/crosstool-ng

To complete above, do following:

wget http://crosstool-ng.org/download/crosstool-ng/crosstool-ng-1.18.0.tar.bz2
tar xjf crosstool-ng-1.18.0.tar.bz2
cd crosstool-ng-1.18.0
./configure --prefix=/opt/crosstool-ng
make
make install
export PATH="${PATH}:/opt/crosstool-ng/bin"

For installation of crosstool-ng, make sure you do `make install` using root privileges.

Preparing Environment

We need a working directory for compiling our cross-compiler. This will contain toolchain configuration, downloaded files, and intermediary build results. This is not where the final location the toolchain will end up. You should reserve some space, at least 3.5GB.

Create a directory, you choose it. For example, I will use ~/working as the working directory. Go to that directory.

mkdir ~/working
cd ~/working

Compilation & Installation

Go to working directory.

Run ct-ng script to display you a configuration menu. Make sure /opt/crosstool-ng/bin is in your search path.

ct-ng menuconfig

You should see some configuration options there.

Here is the important stuff:

Path and misc options

  • Enable “Try features marked as EXPERIMENTAL”.
  • Change the prefix directory, from ${HOME}/x-tools/${CT_TARGET} to /opt/cross/x-tools/${CT_TARGET}

Target options

  • Change the “Target Architecture” to arm
  • Change the “Endiannes” to Little endian
  • Change the “Bitness” to 32-bit

Operating System

  • Change “Target OS” to Linux

Binary utilities

  • Change “binutils version” to the latest one you can find which isn’t marked as experimental (at this time 2.22)

C Compiler

  • Enable “Show Linaro versions”
  • In the gcc version field, choose the Linaro version of gcc

Once the configuration done, save it.

To build the toolchain, do following:

ct-ng build

This should take some times, minutes in my case.

Once it done, you should have cross toolchain reside on /opt/cross/x-tools/arm-unknown-linux-gnueabi/bin. You might want to add this to your search path.

Testing

First, test the version

arm-unknown-linux-gnueabi-gcc --version

Now test for the compilation. Write this source code as test.c.

#include <stdio.h>

int main() {
    printf("Hello, world!\n");
    return 0;
}

and compile it.

arm-unknown-linux-gnueabi-gcc -o test test.c

Social media & sharing icons powered by UltimatelySocial