Updates from admin RSS

  • Servo festival with node.js on Raspberry Pi

    Ellen 17:51 on October 25, 2014 | 0 Permalink | Reply
    Tags: , , servo

    pi-blaster.js was used in the ballon project with 2 servos controlling the flow of helium and cutting the cord to the ballon.

    Running several servo motors on Raspberry Pi with pi-blaster.js works like a charm. Install node.js on your Raspberry to run the pi-blaster.js package.

    Install pi-blaster

    git clone https://github.com/mwilliams03/pi-blaster.git
    cd pi-blaster
    make pi-blaster

    Start pi-blaster deamon

    sudo ./pi-blaster

    Defines outputs to use. In this case I use 2 but you can use up to 8 pins.

    sudo ./pi-blaster 22 24

    Try it out from the command line setting channel 0(GPIO 22) to 0.2.

    echo "0=0.2" > /dev/pi-blaster

    Install pi-plaster.js

    npm install pi-blaster.js

    In your node.js script you can now control your servos like this:

    var piblaster = require(‘pi-blaster.js’); // Import package

    piblaster.setPwm(0, 0.2); // Sets servo on pin 22 to 20 %
    piblaster.setPwm(1, 0.4); // Sets servo on pin 24 to 40%

    To set the pi-blaster setting on reboot, create this shell script and call on reboot crontab:

    sudo /path_to/pi-blaster/pi-blaster 22 24

    To connect a servo motor to Raspberry Pi:

  • Raspberry Pi with Node.js and Alamode

    Ellen 15:52 on July 1, 2014 | 0 Permalink | Reply
    Tags: alamode, , , , serial port


    For this tutorial I use the latest Raspbian version from http://www.raspberrypi.org/downloads.

    Setup Alamode
    Install the arduino IDE on the Raspberry

    sudo apt-get update
    sudo apt-get install arduino

    Get the Alamode setup files and install them by following these steps:

    git clone git://github.com/wyolum/alamode.git
    cd /alamode/alamode-setup
    sudo ./setup

    In order for these setting to take effect, please reboot your Raspberry PI:

    sudo reboot

    Load an Alamode sketch
    If you don’t have your Raspberry Pi connected to screen, keyboard and mouse you can access the GUI from your computer. I have a Mac and use XQuartz.

    As you start XQuartx open the Terminal in this application with Command + N and log into your Raspberry Pi like this:

    ssh -X user@ipaddress

    When you are logged in, just type:


    and the Arduino IDE will start up on your computer.

    The Alamode setup added the Alamode board to your Arduino IDE. Select it by
    Tools > Board > Alamode
    Tools > Serial Port > /dev/ttyAMA0

    Copy the following code and paste it (Ctrl+V) into a new sketch. Put an LED into ground and pin 13 on your Alamode.

    void setup()
      pinMode(13, OUTPUT);

    void loop()
      char inSerial[5];  
      int i=0;
      if (Serial.available() > 0)
           while (Serial.available() > 0) {
             inSerial[i]=Serial.read(); //read data  
           if(!strcmp(inSerial,"high")) {
            digitalWrite(13, HIGH);
          if(!strcmp(inSerial,"low")) {
            digitalWrite(13, LOW);

    To send data from Alamode to Arduino, just write to the serial port with:


    Install node.js

    wget http://nodejs.org/dist/v0.10.12/node-v0.10.12-linux-arm-pi.tar.gz
    tar xvfz node-v0.10.12-linux-arm-pi.tar.gz
    sudo mv node-v0.10.12-linux-arm-pi /opt/node/

    Set the path to node.js:

    echo‘export PATH="$PATH:/opt/node/bin"’ >> ~/.bashrc
    source ~/.bashrc

    Install serialport
    To communicate between the Alamode and node.js we need the serialport package for node.js:

    npm install serialport

    More information on: https://github.com/voodootikigod/node-serialport
    Node.js coding

    var SerialPort = require("serialport").SerialPort
    var serialPort = new SerialPort("/dev/ttyAMA0", {
    baudrate: 9600
    }, false); // this is the openImmediately flag [default is true]

    serialPort.open(function () {

    Trigger this command and “high” will be sent to the Alamode

    // Sends "high" to the Alamode
    serialPort.write("high", function(err, results) {
          if(err != undefined) {
                console.log(‘err ‘ + err);

    To receive serial data from the Alamode, listen for data with this code:

    serialPort.open(function () {
          serialPort.on(‘data’, function(data) {
                console.log(‘data received: ‘ + data);
                if(data == "alamode_data") {
                     // Do something

    External power
    If you are dealing with many power consuming sensors on your Alamode, it’s a good idea to power your Alamode externally with its own 5V power adapter.

  • Control stepper motors with Raspberry Pi and node.js

    Ellen 11:55 on February 25, 2014 | 11 Permalink | Reply
    Tags: , , , , steppers

    Continuing the journey on how to control things with node.js on the Raspberry Pi I set up 2 stepper motors and controlled them in real time with Hydna. You can can read futher on how to install Hydna on Raspberry Pi here.


    Wire up your motors with a stepper motor driver shield. I used Easy Driver and connected it with Pololu stepper motors:
    The to pins that controls the motors in this diagram are pin number 16(GPIO 23) and pin number 18(GPIO 24). Pin number 18 controls the direction of the motor and pin number 16 the speed. With 1K ohm resistors connected to the ground for each of these pins we connect them to the Easy driver.

    Depending on the stepper motor you have, you will need to check the bipolar stepper motor wiring diagram for your motor. The motors I used had the following diagram where A(black) and C(green) connects to the A pins and B(red) and D(blue) connects to B pins.


    Install pi-gpio and go ahead with this script to control the stepper motors:

    var gpio=require("pi-gpio");

    stopMotors = false;

    function sleep(milliseconds) {
      var start = new Date().getTime();
      for (var i = 0; i < 1e7; i++) {
        if ((new Date().getTime() - start) > milliseconds){

      console.log("Pin 16 open"); // Opens pin 16 as output  

      console.log("Pin 18 open"); // Opens pin 18 as output  

    // Runs motor in the set direction
    function move() {
       gpio.write(16, 1, function() {
             gpio.write(16, 0, function() {

    function stopMotor() {
      stopMotors = true;

    // Changing direction of motor
    function left() {
      stopMotors = false;
      gpio.write(18, 1, function() {

    // Changing direction of motor
    function right() {
      stopMotors = false;
      gpio.write(18, 0, function() {

  • Realtime control of GPIO:s with Hydna

    Ellen 12:33 on February 13, 2014 | 0 Permalink | Reply
    Tags: , gpio, , , , realtime


    Want to control the pins on you Raspberry Pi in real time? With the scaleable realtime platform from Hydna you can set how many that can access the GPIOs and when. Install the node modules gpio and hydna to controll your GPIO:s over the net.

    Install node.js

    sudo apt-get upgrade;
    sudo apt-get update
    sudo apt-get install nodejs npm node-semver
    npm config set registry http://registry.npmjs.org/

    Open the profile file with:

    sudo nano /etc/profile

    And enter the following:


    NOTE! Log out and then in again in order to make the changes go through.

    To run nodejs with with the command node, link them to with:

    sudo ln -s /usr/bin/nodejs /usr/bin/node

    Make sure to check where your node was installed and add it to NODE_JS_HOME

    Install GPIO

    npm install pi-gpio

    Install GPIO-ADMIN

    cd /home/pi
    sudo git clone git://github.com/quick2wire/quick2wire-gpio-admin.git
    cd quick2wire-gpio-admin
    sudo make
    sudo make install
    sudo adduser pi gpio

    Try out gpio-admin with the following line:

    gpio-admin export 22

    If you get this error

    Error /bin/sh: 1: gpio-admin: Permission denied

    follow these steps:

    sudo groupadd gpio
    sudo usermod -aG gpio
    sudo chgrp gpio /sys/class/gpio/export
    sudo chgrp gpio /sys/class/gpio/unexport
    sudo chmod 775 /sys/class/gpio/export
    sudo chmod 775 /sys/class/gpio/unexport

    Install Hydna

    npm install hydna

    With Hydna you can send real time messages to your pi and allow a certain number of clients to connect to your Raspberry Pi. With Hydna’s Behaviours you set the behaviours of your different channels.

    The following example code shows how to control your gpios with messages from Hydna:

    var gpio=require("pi-gpio"); // Include the pi-gpio library to control the gpios
    console.log("Pin open"); // Opens pin 12 as output
    var hydna = require(‘hydna’);
    // Open channel in "read/write" mode. All data sent to channel will
    // loop back from the remote connection.
    var channel = hydna.createChannel(‘domainname.hydna.net/rpi’, ‘readwrite’);
    // Connect handler, is triggered once that the channel is connected
    channel.on(‘connect’, function () {
    this.write(‘Status: ok’);
    // Data handler, is triggered each time DATA is received on the channel
    channel.on(‘data’, function (data) {
    // Log data received on channel.
    if(data == "on") {
    gpio.write(12, 1, function() {
    } else if(data == "off") {
    gpio.write(12, 0, function() {
    } else if(data == "end") {
    gpio.close(12); // Close pin
    this.end(); //Close the channel, which terminates the underlying receive-loop.

  • Looping videos seamlessly OMXPlayer

    Ellen 16:30 on October 15, 2013 | 37 Permalink | Reply
    Tags: omxplayer, python,

    As I looked for different solutions for looping videos on the Raspberry Pi seamlessly I eventually came out with a solution that worked quited good for videos looping with sounds. Looking at the possiblities of using the existing example of hello_video/video.c to loop a video wasn’t an option as sound was not supported and syncing sound was not something I wanted to spend time on.

    Instead I looked to jbaiter’s OMXPlayer library pyomxplayer build in python. It calls the OMXPlayer through the command line and with some testing I could run several instances of OMXPlayer at the same time. This meant that I could start one movie and pause a copy of the same movie in the background. When the first movie came to an end I could start the second movie which was an exact copy of the first one in order to get the seamless loop. No terminal windows showing and no gap between the movies. And so the loop goes on.

    By having 2 different names of the same movie I was in complete control of the omxplayer processes running in the background to play another movie on top of this.

    I start off loading both movies by calling making to OMXPlayer instances in pyomxplayer and pausing the second movie:

    self.loop1= OMXPlayer(‘/home/pi/loop1.mp4′, ‘-o local’, start_playback=True, do_dict=False)
    self.loop2 = OMXPlayer(‘/home/pi/loop2.mp4′, ‘-o local’, start_playback=True,do_dict=False)

    In a loop I check when the first video reaches its end position and pause it just before to start the next movie. Since it already loaded, there is no buffering for it to play. Note that the end position needs to be set a little bit before the video exactly ends in order to not get out of the video screen mode.

    position = self.loop1.position/1000000
    if position > 12.8:

    A few seconds later I kill the process of the first movie to start it and pause it for next time.

    os.system(‘pkill -9 -f "/usr/bin/omxplayer.bin -s /home/pi/loop1.mp4 -o local"’)
    os.system(‘pkill -9 -f "/bin/bash /usr/bin/omxplayer -s /home/pi/loop1.mp4 -o local"’)
    self.loop1= OMXPlayer(‘/home/pi/loop1.mp4′, ‘-o local’, start_playback=True, do_dict=False)

    I added a 2 seconds delay in order for the new movie to have time to show and to allow for some time to kill the process.

  • Connect Parallax RFID to Raspberry Pi

    Ellen 15:01 on September 18, 2013 | 5 Permalink | Reply
    Tags: , ,


    To connect a Parallax RFID Reader to the Raspberry Pi you can either use the USB version of the Parallax RFID reader or the pin enabled used in this example. With the pin enabled Parallax version the data is sent to the Raspberry pi serial pins with the pins TXD and RXD pins. With the RFID reader with only need to use RXD as we will only receive data from the RFID reader.

    Wiring setup

    The RFID reader operates on 5V but the Raspberry Pi GPIOs operate on 3.3 V which mean that in order to read the serial data we need to convert it from high volt to low volt. There is circuit available from Sparkfun doing just that. It is called Logic Level Converter and will be part of the wiring between the Raspberry Pi and the RFID reader.

    Below is the schematics for the connections you need to make.

    1. Connect your common ground to both ends of the Logic Level Converter and RFID reader. Note that the Parallax RFID reader needs the Enable pin to be connected to ground in order to read RFID tags. When the LED on the RFID reader turns red it means that it is ready to read. (Black)

    2. Connect the high volt  from 5V pin to HV pin. (Red)

    3. Connect the low volt from 3.3 V pin to LV pin. (Orange)

    4. Connect the SOUT pin to  serial input RXI on the Logic Level Converter. (Blue)

    5. Connect the seriel output RXO to the pin RXD on the Raspberry Pi.

    Screen Shot 2013-09-18 at 3.07.29 PM

    Enable serial port

    To make the serial port available for your own use you need to edit the file /etc/inittab.

    sudo nano /etc/inittab

    Comment out the following line in inittab

    T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

    Like this:

    #T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

    Install minicom for testing

    To read and test your tags on the Raspberry Pi you need a set of packages:
    A great package to test your serial port is to install minicom:

    sudo apt-get install minicom

    To test your serial port you can use mimicom command like this:

    minicom -b 115200 -o -D /dev/ttyAMA0

    Read RFID tags with Python

    To access the serial port from Python install the pySerial package with command line:

    sudo apt-get install python-serial

    Now you can import the serial library on order to access the serial data sent to the Raspberry Pi from the serial port. Note that you can set the timeout of the RFID reader to make the read timeout after a while. The example code below times out the serial read after half a second. This can be useful to set a longer or shorter timeout depending on if you execute other things in your loop or application.

    import serial
    ser = serial.Serial(‘/dev/ttyAMA0′, 2400, timeout=0.5)
    while True:
        string = ser.read(12)  
        if len(string) != 0:
            print string

    Raspberry Pi Lab posted a great Python script on how to check which tag is read in the rfid-test2.py.

  • Clone SD card for Raspberry Pi(Mac)

    Ellen 10:46 on September 16, 2013 | 9 Permalink | Reply
    Tags: , sd card

    Backup SD card

    To clone an SD card setup for your Raspberry Pi on a Mac, do the following:

    Input the SD card you want to clone. Open the Terminal window and type:

    diskutil list

    This will list your connected disks. See the name of your SD card, on mine in looks like this:
    diskutil list on Mac

    Make an image of the content with the following command:

    sudo dd if=/dev/disk1 of=~/Desktop/boot.dmg

    This might take a while and when it is finished you will see how many bytes were transferred.

    Edject your SD card and input the SD card you want to clone to.

    Format new SD card

    If the SD card is not formatted you can open the Disk Utility and select the card(not the volumes) . Click on the “Erase”-tab and select the format “MS-DOS(FAT)”. Name your card and click on the button “Erase”. This will only take a few seconds. The SD card is now formatted in FAT32.

    Screen Shot 2013-09-16 at 11.15.05 AM

    If you want to change the format to FAT16 just go to your Terminal window and type:

    sudo newfs_msdos -F 16 /dev/disk1

    Note that the name of the disk can be different. Run “diskutil list” again to find out.

    Clone SD card

    Now the SD card is prepared to get the cloned image. Unmount the volumes on the SD card before you go ahead with cloning. NOTE! That you should unmount and NOT eject.
    Screen Shot 2013-09-16 at 11.44.26 AM

    To transfer the image you just made before you write in the Terminal window:

    sudo dd if=~/Desktop/boot.dmg of=/dev/disk1

    This can take long depending on the class of your SD card.

    During the process you can to checks that the cloning is progressing. Open a new Terminal window and type:

    ps ax | grep dd

    This will list processes on your computer with “dd” as part of it. At the bottom of the list you will find something like this:

    11502 s002  S+     0:00.01 sudo dd if=~/Desktop/boot.dmg of=/dev/disk1 bs=5
    11503 s002  R+     0:58.27 dd if=~/Desktop/boot.dmg of=/dev/disk1 bs=5
    11524 s003  R+     0:00.00 grep dd

    Note the id of the process and type:

    sudo kill -s SIGINFO 11503

    In the other window where you did your clone command, it will now print out how much data that has been transfered to your SD card in the format seen on success in the below example.

    When the process is finished you will see how many bytes were tranfered and compare it with the bytes when you made the backup.

    60392+1 records in
    60392+0 records out
    30920704 bytes transferred in 132.542963 secs (233288 bytes/sec)

  • Useful Raspberry Pi commands

    Ellen 09:54 on September 12, 2013 | 0 Permalink | Reply
    Tags: commands,

    Autostart desktop

    1. Enter the following on the command line

    sudo raspi-config

    2. Select “3 Enable Boot to Desktop” with your arrow keys and press enter key
    3. Select and press enter key and your are back on the main menu
    4. Select with the tab key
    5. A dialogue saying “Would you like to reboot now?” Select with the tab key


    Enter the following on the command line

    sudo nano /etc/inittab

    Change the line:

    1:2345:respawn:/sbin/getty noclear 38400 tty1

    to this with {USER} as the name of the user you want to auto login with

    1:2345:respawn:/sbin/getty autologin pi  38400 tty1

    Hide mouse

    Install unclutter and it will hide when there is not activity.

    sudo apt-get install unclutter

    Then set a delay for how long it will take before hiding the mouse through the command line:

    unclutter -idle 1

    You can also set it for a specific user

    unclutter -idle 1 -user

    If you always want to hide the mouse, add the code into a shell script and make an auto start file like below:

    Autostart python script

    1. Create a desktop file that will run your python script

    cd /usr/share/applications/
    sudo nano app.desktop

    Add the following content to your desktop file:

    [Desktop Entry]
    Comment=Start application
    Exec=sudo python path_to_your_script.py

    2. Save the file and exit the editor.

    3. Add the desktop file to your autostart directory with this command

    ln -s /usr/share/applications/app.desktop ~/.config/autostart/

    Make sure that you add this to the user you log in to. So if you log in as pi, stand in the directory pi and run the above command. If you use another user it would be /home/username/.config/autostart/

    To double check that your desktop file runs you can run it from /usr/share/applications/ directory.

    4. Reboot and see result

    Kill all processes for one service

    pkill omx

    From Python script:

    os.system(‘pkill omx’)

    Kill a certain process

    To kill a certain process you can pass it the entire command of the process to target just that process.

    pkill -9 -f "/bin/bash /usr/bin/omxplayer -s /home/pi/myfilm.mp4 -o local"

    This can be done directly from Python as well:

    os.system(‘pkill -9 -f "/bin/bash /usr/bin/omxplayer -s /home/pi/myfilm.mp4 -o local"’)

  • How to enable reverb in FMOD iOS

    Ellen 19:40 on May 5, 2013 | 0 Permalink | Reply
    Tags: , iOS

    To enable reverb settings in Fmod Designer click on “Window” > “Reverb Defs”. Select your reverb and click on the play button. The reverb is now active and the project can be built. Notice that for the time being Fmod Designer requires you to always activate this whenever you open your project. This is not done automatically. The name of your reverb, in this case “Reverb00″ is used later on in the code.


    To activate the reverb in the code the follow code needs to be added:

    #import "SoundManager.h"
    #import "mySoundProject.h"
    @implementation SoundManager
    void ERRCHECK(FMOD_RESULT result)
        if (result != FMOD_OK)
            //fprintf(stderr, "FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
    - (id)initWithString:(NSString*)selectedProfile
    system  = NULL;
        eventSystem = NULL;
        FMOD_RESULT result      = FMOD_OK;
        char        buffer[200] = {0};
        FMOD_REVERB_PROPERTIES reverb00;
        result = FMOD::EventSystem_Create(&eventSystem);
        [[NSString stringWithFormat:@"%@/mySoundProject.fev", [[NSBundle mainBundle] resourcePath]] getCString:buffer maxLength:200 encoding:NSASCIIStringEncoding];
        result = eventSystem->load(buffer, NULL, NULL);
        result = eventSystem->getReverbPreset("REVERB00", &reverb00); // Same name as in Fmod Designer.
        result = eventSystem->setReverbProperties(&reverb00);
        result = eventSystem->getGroup("MySoundProject/MySoundProject", FMOD_EVENT_DEFAULT, &group);

  • Send OSC messages from Unity

    Ellen 11:30 on January 31, 2013 | 3 Permalink | Reply

    Many people wrote to me wondering how to send data from Unity through OSC back to Processing and other applications. Well the answer is simple, write the following code:

    oscListener.oscHandler.Send(Osc.StringToOscMessage(”/Your event name”));

compose new post
next post/next comment
previous post/previous comment
show/hide comments
go to top