maanantai 14. joulukuuta 2009

From Ubuntu to Fedora

There are lot of distros to choose for Linux users and I've been a loyal Ubuntu user since the beginning of the Ubuntu saga. Until now. Ubuntu is doing great work enabling "out-of-a-box" experience for novice users. But when you are not a novice user any more, this approach starts to annoy a little bit. So it was time switch from comfort zone to Fedora.


Why Fedora?
According to Paul Frields (Fedora's project leader) Fedora is intended "first and foremost for users interested in and capable of contributing to open source." I would really like to count myself to those users. In addition, Fedora is a bleeding edge distro and Red Hat is a big contributor to Linux kernel.

So Fedora just seems right for me :)


In practise
Of course I had tried several distros earlier but now I wanted to convert my work PC to another system and that is something that you I'm not willing to do very often. I've listed some differences that I had to deal with:


Selinux
Selinux is an additional security layer and it can drive you crazy. I did not remember that Fedora has this on by default. I spent whole one day trying to get PostgreSQL and Apache working nicely. Finally I realised what was causing the trouble up and I turned the selinux off.

http://www.crypt.gen.nz/selinux/disable_selinux.html

PHP Development
There are some differences in PHP settings between Ubuntu and Fedora.
I need PHP's xml and mbstring modules for my development. In ubuntu these are included by default, but in fedora they can be found as a separate packakeges: php-xml and php-mbstring. In fedora, PHP's errors are logged to file instead of showing them. That's good for production server but not for a development server. Not a big deal, just small edit in php.ini file.

display_errors = On


Yum
Yum is Fedora's "apt". It is little bit slower that Apt in Debian or Ubuntu, but it is also more verbal by default. The speed is really not an issue, at least for me. Yum install XXX, yum remove XXX, yum update, not big differences here.


Multimedia
By default Fedora does not find any closed codecs like MP3. Luckily there is a RPM Fusion. Just install RPM from the Fusion site and codecs are found when you try to play those unneeded closed formats.


Software Development
So far I haven't found any significant differences here. Make, scons, SVN and CVS just do their work like expected.

DWM
DWM is the window manager I'm using and can't live without. Downloaded source, compiled and it was working. So no complaints!

http://dwm.suckless.org/

torstai 5. marraskuuta 2009

Beagleboard running!

I finally got my Beagleboard running! It took time but now I'm satisfied :)

EBVBeagle

I ordered EBVBeagle, which is Beagleboard with out-of-the-box functionality. It comes with a SD card that has Angstrom distribution in it.

I had no previous experience of embedding Linux and I was very unsure of how things worked. But finally I got it booting and got display working. But things still did not work very well. The problem was that I was not able to login graphically. X died every time after login screen. I decided to try with a newer version of Angstrom. But how?

Making it running


Luckily there is http://elinux.org/BeagleBoard.
So, I followed loo-oong directions in http://elinux.org/BeagleBoard and I managed to get the new Angstrom demo image running. It booted and I could use BeagleBoard through serial connection but now I lost mouse and keyboard. Next I tried Ubuntu's arm version (http://elinux.org/BeagleBoardUbuntu). I got it running but again, no mouse or keyboard.

I thought that maybe I'm just not geeky enough and maybe I should leave these to real geeks :(

But I don't like the idea of giving up, so I tried one more thing: I updated the U-boot. The update process seemed to be a little bit scary operation since it means changing the content of board's flash memory. But that solved the problem, I have now mouse and keyboard in XFCE Ubuntu BeagleBoard box.

So why did I have to update the U-Boot? Because:

The kernel your running (2.6.29 series) is expecting the usb pins to be setup in U-boot..
source

Directions for updating the U-Boot:
http://elinux.org/BeagleBoardUbuntu#Upgrade_U-Boot

perjantai 15. toukokuuta 2009

Blender and Physical Computing


During a Physical Computing class here at the University of Jyväskylä, I made a small experiment with Blender and Arduino. I build a very simple prototype called CHEEX (Cheap Exhibition Expander).

The idea is that instead of traditional exhibition posters or information kiosks, one could use any part of the exhibition room as a display by using data projector and servo-controlled mirror. By using sensors it is possible to react visitors and show them more information when they get near objects.

The Blender part


Blender has a virtual camera which is pointing to a target object. This target object is then animated and the camera naturally follows it. The rotations of the camera are then sent to Arduino, which controls two axis servo system which has a mirror attached to it.

Inside Blender I have a normal scene with camera, the target object and some other objects. Blender scene can be modelled according the exhibition room so that virtual camera and mirror points to same spot. Then it is possible to combine physical space with virtual space.

Technicalities


Technically system is very simple. I used very simple protocol between Blender and Arduino. By sending sequences of three bytes, I could quite easily send rotations to Arduino. First Blender sends "255" and then angle for root servo and then angle for head servo. Arduino is reading serial port and when it receives 255, it knows that following two bytes are the angles for the servos.

System also has one ultrasonic sensor and value from that sensor is send back to Blender every time Blender sends the angle values for servos. This way everything stays in sync and there is no problems with serial port buffer overflows.

System has still one major problem. Servos are connected directly to Arduino and they are using too much power. This makes the readings from the ultrasonic sensor unreliable when servos are moving (at least I *think* that is causing this). I sort of resolved the problem by taking an average of several values but that can be considered a hack. I'll order a motorshield for Arduino and test if using it will resolve the problem.

maanantai 20. huhtikuuta 2009

/dev/Arduino

I noticed that if I unplugged Arduino from my Ubuntu-box and then plugged it back, the /dev name for Arduino changed from /dev/ttyUSB0 to /dev/ttyUSB1. Fortunately this was easy to fix. The problem was solved by adding a file 97-arduino.rules in /etc/udev/rules.d/ and adding the following rule (all in one line):

kernel=="ttyUSB*", SYSFS{idVendor}=="0403",
SYSFS{idProduct}=="6001",
SYMLINK="Arduino"


So now I can always trust that Arduino is in /dev/Arduino. If you have two Arduinos,you can use serial numbers in order to recognize them (see link below).

Original source:
http://www.arduino.cc/playground/Linux/Udev

perjantai 17. huhtikuuta 2009

Bouncing virtual ball with Arduino (and Blender)

UPDATED 20.4.2009






I'm quite new on this Arduino stuff and I may have misunderstood something. But anyway, here are some observations of using Arduino and Blender's game engine.

It's easy!

It is really easy to get values from Arduino to Blender. Here is a simple setup for reading photo-resistor's values from Blender:
from Blender.Mathutils import Vector import serial 
port = '/dev/ttyUSB0' 
pin = 0 
try: 
    GameLogic.SerialPort 
except: 
    GameLogic.SerialPort = serial.Serial(port,9600) 

# read data 
valo = GameLogic.SerialPort.readline() 
val = float(valo)/200 

# BLENDER stuff 

objs = GameLogic.getCurrentScene().getObjectList() 
cube = objs["OBbox"] 
cube.setPosition([1.0,1.0,val])


Here I'm reading photoresistor values and then tell Blender's game-engine to change "box" object's position according that value. The arduino code looks like this:

/* Arduino reading photo resistor to serial * * */ 
int analogPin=0; 
int analogVal=0; 
void setup() { Serial.begin(9600); } 
void loop() { 
    // get the value from photoresistor 
    analogVal = analogRead(analogPin); 
    Serial.println(analogVal); 
    //delay(100);
}


Not so fast!



There is a one catch when reading data from Arduino to Blender. And that's the fact that python scripts are executed on every frame and that mean that you'll read data from serial port approx. 60 times per second.

However, Arduino is sending data much faster. As a result, you'll see a horrible delay in Blender. That's because the data arduino sent is buffered and you are actually reading from buffer. So you'll get "historical" values from serial port, not the current values. And for interactive application that is not wanted.

There are couple of ways to fix this:

The simplest way is to program Arduino to send data more rarely. You could use delay function if there is nothing else that Arduino should do (delay halts everything in Arduino).

Request/response model


Better and more predictable way is to tell Arduino when we want to get a value. So when we want a value, we send a signal to arduino to send data and then we read the value. This way we'll always get the current values no matter of how high or low our frame rates are.

(I *think* that it would be also possible to run a separate python thread for Arduino input and just read values from that thread)


port = '/dev/Arduino' 
pin = 0 
 
try: 
    GameLogic.SerialPort 
except: 
    try: 
        GameLogic.SerialPort = serial.Serial(port,9600,timeout=1)  
        print 'Port ' + port + 'found!' 
         
        #ok, we have a port. Let's test if we can write to it 
        try: 
            GameLogic.SerialPort.write('x') 
            GameLogic.serialRead = False 
            GameLogic.serialOk = True 
              
        except: 
            GameLogic.serialOk = False 
            print 'could not write to port ' + port + '!' 
         
         
    except: 
        GameLogic.serialOk = False 
        print 'no port ' + port + ' found!' 
     
 
 
# do stuff if serial port is OK 
if GameLogic.serialOk: 
    if GameLogic.serialRead: 
        valo = GameLogic.SerialPort.readline() 
        val = float(valo)/100 
        GameLogic.serialRead = False     
    else: 
        GameLogic.SerialPort.write('a') 
        GameLogic.serialRead = True     
     
 
    # BLENDER stuff 
    if GameLogic.serialRead == False: 
        objs = GameLogic.getCurrentScene().getObjectList() 
        cube = objs["OBbox"] 
        cube.setPosition([1.0,1.0,val])


When Blender is ready to receive a value from Arduino, it send character "a" to the Arduino. Arduino sent one value and that is read next round. Arduino code is very simple:
int analogPin=0;
int analogVal=0;

void setup() {
  Serial.begin(9600);
}

void loop() {
  if ( Serial.available()) {
    char ch = Serial.read();
    if ('a'==ch) {
      analogVal = analogRead(analogPin);
      Serial.println(analogVal);
    }
  }
}

Here is a very simple demo using photoresistor to control a box's position. A top of box there is a ball so you can bounce the ball with adjusting the amount of light.





That's it!

sunnuntai 5. huhtikuuta 2009

Arduino and schematic views



Want to make a nice shematic diagram from your Arduino-based system? Interaction Design Lab at the University of Applied Sciences Potsdam have developed a really nice tool called Fritzing that can do that and even more. It can also make PCB (Printed Circuit Board) diagram for you.

You make your connections via drag-drop and then you can just switch between different kind of views (breadboard, schematic and PCB).




Fritzing is Free Softaware and there are version for Linux, Mac and Windows. You can find downloads and more info here:

http://fritzing.org/welcome/

lauantai 4. huhtikuuta 2009

Blog

This is a blog for opendimension.org.

This blog will serve a) as a extension memory for myself by storing short notes about different kind of things (I have lousy memory) and b) as place for publishing small tutorials I think could be useful for other persons too.

What are the main topics?


If it runs on Linux, if it's free software and if it somehow could be used in the field of cultural heritage, then I'm surely interested!