raspberry

Plug your Minitel on your Raspberry Pi

Hi,

So what is a Minitel? According to Wikipedia :

The Minitel was a Videotex online service accessible through telephone lines, and is considered one of the world's most successful pre-World Wide Web online services.¹

This service was accessible through particular devices. They had a screen, a keyboard and a modem.

A screen and a keyboard are just what we need for our Pi, so let's plug them together!

Minitel and serial communication

The Minitel have a serial port. It's goal is to communicate to peripherals such as a printer or whatever.

The socket is a classic 180° DIN with 5 pins :

Here is the description of the pins:

  • 1: Rx: data reception
  • 2: Ground
  • 3: Tx: data transmission
  • 4: Ready to work signal
  • 5: 8.5v - 1A power supply

So pins 1,2 and 3 are what we need to communicate through serial with the Pi.

Please note that not all Minitels have this kind of sockets. To find a compatible one, the Minitel must have this socket AND two special keys on the keyboard Fnct and Ctrl. They are usualy called Minitel 1B.

TTL levels and the Pi

The UART on the Pi works with 0v and 3.3v. But a lot of old stuff use 0v and 5v. This is the case of the Minitel, so we need to adapt the voltage levels :

  • Lower the Tx level of the Minitel from 5v to 3.3v
  • Raise the Tx level of the Pi from 3.3v to 5v

To achieve that, I used the following schema based on the recommendation of @lhuet35 (thanks!). You can check its Devoxx presentation (in french) here : 3615 Cloud

Be careful, the unused pin between the 5v and the GND of the Pi is not depicted on this schema!!

Here is the stuff mounted on a breadboard :

Configure a tty on the UART

You then need to configure a tty that will communicate through the UART.

The following configuration is based on a Raspbian, but it should be the same on other distros.

  • You may need to install getty :
    • sudo apt-get install getty
  • Backup the /boot/cmdline.txt file just in case :)
    • sudo cp /boot/cmdline.txt /boot/cmdline.bak.txt
  • Edit the file:
    • sudo vim /boot/cmdline.txt
    • and remove everything related to the serial port ttyAMA0, i.e. : console=ttyAMA0,115200 kgdboc=ttyAMA0,115200
  • Add a getty conf on /etc/inittab :
    • 7:2345:respawn:/sbin/getty ttyAMA0 4800v23
    • also check there is no other getty conf for this tty on the file
  • Then you need to create a gettydefs file (or edit it)
    • sudo vim /etc/gettydefs
    • and add the following 4800v23# B4800 CS7 PARENB -PARODD GLOBAL # B4800 ISTRIP CS7 PARENB -PARODD GLOBAL BRKINT IGNPAR ICRNL IXON IXANY OPOST ONLCR CREAD HUPCLISIG ICANON ECHO ECHOE ECHOK #@S login: #4800v23 on one line!
    • this will configure the tty on UART

You can now plug the Pi to the Minitel and reboot the Pi.

Configure the Minitel

You need to switch the Minitel mode to be able to communicate through the serial port.

  • Power on the Minitel
  • Press Fnct+T then A : the Minitel will switch to the serial mode
  • Press Fnct+P then 4 : the Minitel now communicate through serial at 4800bps (the max speed)
  • Press Fnct+T then E : to deactivate the local echo
  • Press and you should now see the login prompt (maybe with some white squares), put your login and you're done!

Be aware that you'll need to do this Minitel configuration everytime you power it up.

Here is a pic of my Minitel :

Happy coding!

Processing and GPIOs on Raspberry Pi

Hello,

Processing is a nice programming language for creative coding, and you can physically interact with the Raspberry Pi thanks to its GPIOs. So why not combining them?

Let's do it.

Prerequisites

  • A Raspberry Pi (sic!) running with a Raspbian image (it may work on other configurations, but not tested).
  • All command line below are executed from the home directory (i.e. /home/pi/ for the pi user).
  • You may need to install some tools sudo apt-get install unzip ca-certificates.

Install Oracle JDK8 on the Raspberry Pi

The idea of installing JDK8 is not to enjoy those long awaited Lambdas, but to provide the execution platform for Processing. Luckily, Oracle started to provide builds of the JDK for the arm platform.

Download the JDK.

wget --no-check-certificate http://www.java.net/download/JavaFXarm/jdk-8-ea-b36e-linux-arm-hflt-29_nov_2012.tar.gz

Untar the binaries at the right place.

sudo mkdir -p /opt/java
tar xvzf jdk-8-ea-b36e-linux-arm-hflt-29_nov_2012.tar.gz
sudo mv jdk1.8.0 /opt/java

Then, you must tell raspbian to use these binaries to provide java.

sudo update-alternatives --install "/usr/bin/java" "java" "/opt/java/jdk1.8.0/bin/java" 1

If you already had another java version installed, you may need to choose the one we just installed, if not you can skip this.

sudo update-alternatives --config java

And choose the JDK8 by entering the corresponding number.

Now you need to define some environment variables for java to run properly.

echo export JAVA_HOME="/opt/java/jdk1.8.0" >> .bashrc
echo export PATH=$PATH:$JAVA_HOME/bin >> .bashrc
source .bashrc

It will add the environment variables at the end of your .bashrc. If you use zsh (and you should! with oh-my-zsh), just replace .bashrc with .zshrc in the three lines of code above.

Java is now installed, and you can check it with java -version. It should display something like this:

java version "1.8.0-ea"
Java(TM) SE Runtime Environment (build 1.8.0-ea-b36e)
Java HotSpot(TM) Client VM (build 25.0-b04, mixed mode)

Also check the environment variables, it should return something.

echo $JAVA_HOME | grep /opt/java/jdk1.8.0
echo $PATH | grep /opt/java/jdk1.8.0/bin

If those checks are not ok, something went wrong, feel free to drop a comment.

Install Processing

The long awaited 2.0 final version is still not here (at the time of writing), but you can download the last beta.

wget http://processing.googlecode.com/files/processing-2.0b8-linux32.tgz

Notice we'll use a x86 version, no worries we'll deal with it.

Untar it

tar xvzf processing-2.0b8-linux32.tgz

Java is bundled with Processing, so we need to tell it to use the java version we installed rather than the bundled one. To do that, we'll remove the java folder inside processing and replace this folder with a symbolic link to the java version we installed.

rm -rf processing-2.0b8/java
ln -s $JAVA_HOME processing-2.0b8/java

Processing is now installed! You can now log in the UI of the Raspberry (if not already) and run processing from the terminal with the following:

cd ~/processing-2.0b8;./processing

You'll have to wait a little bit to see the UI coming up.

You may notice some error messages in the terminal, but so far it had no incidence for me, so I ignore them.

Install a library to interact with GPIOs

So far, I haven't found any Processing ready library, so I'll use the Pi4J java library.

Processing has a particular way to handle library, you need to have a special structure in the folders. And Pi4J is not packaged according to the Processing convention. So you'll need to re-arrange stuff (see http://wiki.processing.org/w/How_to_Install_a_Contributed_Library).

First, go back to the /home/pi folder in the terminal.

Then download the Pi4J lib and unzip it:

wget https://pi4j.googlecode.com/files/pi4j-0.0.5.zip
unzip pi4j-0.0.5.zip

Since Processing is not happy when a lib have something else than letters and numbers in the lib name, you need to rename the unzipped folder.

mv pi4j-0.0.5 pi4j

Then you need to re-arrange files to stick with the Processing convention.

mv pi4j/lib pi4j/library
mv pi4j/library/pi4j-core.jar pi4j/library/pi4j.jar

Now you can put the lib in the Processing library folder (defaults to ~/sketchbook/libraries).

mv pi4j sketchbook/libraries

Done! You can now import Pi4J in your Processing sketch!

Getting started with Pi4J

Here is a simple skecth which will add an ellipse every time a button is pressed.

import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPinDigitalInput;
import com.pi4j.io.gpio.PinPullResistance;
import com.pi4j.io.gpio.RaspiPin;

int WIDTH = 1280;
int HEIGHT = 1024;
GpioController gpio;
GpioPinDigitalInput button;

void setup() {
	size(WIDTH, HEIGHT);
	gpio = GpioFactory.getInstance();
	button = gpio.provisionDigitalInputPin(RaspiPin.GPIO_02, PinPullResistance.PULL_DOWN);
}

void draw() {
	if (button.isHigh()) {
		println("pressed");
		fill(int(random(255)), int(random(255)), int(random(255)));
		float x = random(WIDTH);
		float y = random(HEIGHT);
		ellipse(x, y, 80, 80);
	};
}

I invite you to read the Pi4J documentation to dive into it. You should use events rather than testing the state of a button as shown above (see http://pi4j.com/example/listener.html).

Here is the wiring schema that comes along the sketch from above (borrowed from http://pi4j.com/).

If you try to run it, you'll face some permission issues since Pi4J require root privileges to access GPIOs. For now I export the application and run it with sudo to bypass it. It should exist a cleaner way to handle it. I'll update this post with a proper solution if there is.

You are ready to poop some creative code! Enjoy!