Raspberry Pi experiments

Registrácia Prihlásenie Odhlásiť Odhlasujem...


Obyčajné prihlásenie | OpenID alebo GMail Prihlasovacie meno

Čakajte prosím, požiadavka sa spracúva...


Ak máte OpenID alebo GMail, nemusíte sa registrovať - môžete sa rovno prihlásiť.
Údaje označené hviezdičkou sú povinné!

Prihlasovacie meno*

(môže obsahovať iba písmená anglickej abecedy, číslice, podčiarkovník a musí mať 4 - 10 znakov vrátane)


(musí byť dlhé aspoň 8 znakov)

Heslo na overenie ešte raz*

(heslá sa musia zhodovať)

Dokážte, že ste človek!* Čakajte prosím, generujem otázku...


(BUDE dostupný ostatným používateľom ale ochránený pomocou CAPTCHA)
Varovanie: bez uvedenia e-mailu neexistuje spôsob, ako obnoviť vaše heslo - ak ho zabudnete, je to váš problém!

Zobrazované meno

(bude sa všade zobrazovať namiesto nicku)

Prehlasujem, že pokiaľ nie je explicitne uvedené inak, ja osobne, dobrovoľne neposkytnem zadané údaje tretej strane. (ale neručím že údaje nebudú v záznamoch servera a/alebo zneužité administrátorom a/alebo kýmkoľvek, kto sa k ním dostane bez môjho dovolenia) Registrujete sa na vlastné nebezpečie!
Kliknutím na tlačítko "Odoslať" potvrdzujete, že ste si toho vedomí a že s tým súhlasíte.

Čakajte prosím, požiadavka sa spracúva...
2. 6. 2012


If you didn't know, Raspberry Pi is very small sized, cheap, low power ARM computer. I won't write more about this - you can read it on official page. So Wednesday I wanted to go shopping and I remembered my Pi is on the way (I've got email informing about it), so I looked into mailbox and almost screamed... :) I gave up on shopping and started hacking.

Raspberry Pi was packed in nice little box.

At first, I've connected SD card with already prepared Debian image, some cables and then power from my HTC phone charger (provides 1A current, which is enough).

Cables: S-Video (I neither had HDMI capable device nor HDMI-to-whatever converter), USB mouse and keyboard

Setting up

It booted and then auto restarted and booted to shell (I was talking to my best friend, @DominikZajicek, who is programmer too, and wasn't reading all messages, so I don't know why it restarted). I have logged in (default user: pi; password: raspberrypi) changed my password (using passwd command) and started installing my favourite packages:

Unfortunately I had broken keyboard - it randomly didn't send keydown/keyup event to Pi. In result, it didn't write character, or worse, it behaved like I was holding the key. It was very annoying so I set up ssh server (command: sudo service ssh start) and logged in from my PC. (I wanted to set it up eighter) BTW, yesterday I had problem with screen in Progressbar hackerspace but I could use ssh. So my big advice: always set up ssh, because you never know, when it will save your ass Raspberry Pi!

It was lunch time, while I was doing it and suddenly our friend, @xmnicky, wrote me. He suggested us to go lunch together and we agreed. (Interesting things sometimes happen - we didn't meet for quite long time. How it's possible, we met that day?) After lunch, he came to our apartment to hack with us.

One of the first things I wanted to set up was sound, because re-connecting jack between our laptops was annoying and we have already damaged one cable. I've installed my favourite sound player (mplayer) but it didn't work. After some googling, I've find out I have to load kernel module snd_bcm2835 (command: sudo modprobe snd_bcm2835). Then run alsa (command: sudo service alsa-utils start) and finally pulseaudio (command: pulseaudio --start). After this, it worked - but only for a while. Music was too loud and when I turned volume down, it messed up whole sound (don't try this at home, if you have nervous people around!). The worst thing was, it remembered the (wrong) setting and it remained screwed up after restarting player. Fortunately, solution is quite simple: command rm -rf ~/.mplayer ~/pulse* restores default settings.


After that, I wanted to try out GPIO (General Purpose Input/Output). I connected RGB LED to 3.3V power and ground pins and it shined. I've googled two good sites about GPIO specification and GPIO setup, then I connected LED to pins 4, 17 and 18. For simplification, I used floppy cable, so I could just insert LED pins into holes. If you'll try this, be aware of twisted wires in the middle of the cable. I connected it in way, I didn't have to think about, how it's twisted (I was too lazy :D) but for more serious applications I'd use cable designed by Adafruit Industries specialy for this purpose.

As someone said, electronic equivalent of "Hello World!" program is blinking LED diode. (While I was doing my stuff, Dominik already coded and tried Hello world in C on Pi. :)) I've exported pins as tutorial suggested and written simple bash script:

while :;
echo 0 > /sys/devices/virtual/gpio/gpio4/value
echo 1 > /sys/devices/virtual/gpio/gpio17/value
sleep 0.1

echo 1 > /sys/devices/virtual/gpio/gpio4/value
echo 0 > /sys/devices/virtual/gpio/gpio17/value
sleep 0.1

And it worked!

Blinking LED is fun but it doesn't have any other purpose, so I've decided to change colors based on system load. After some experimenting I came out with this script:


ledOn() {
echo 0 > /sys/devices/virtual/gpio/gpio$1/value

ledOff() {
echo 1 > /sys/devices/virtual/gpio/gpio$1/value


while :;
LOAD=`top -b -n 2 -d 0.5 | grep Cpu | sed 's/^Cpu(s): *//' | sed 's/\..%us.*$//' | tail -1`

ledOff $RED
ledOff $GREEN
ledOff $BLUE

test $LOAD -lt 20 && ledOn $GREEN
test $LOAD -ge 20 && test $LOAD -lt 50 && ledOn $BLUE
test $LOAD -ge 50 && ledOn $RED

sleep 1

It parses data from top and changes LED color. Green for less than 20%, blue for more but less then 50%, red for more. Also I found annoying, when I rebooted Pi (my friends experiments caused Kernel panic :D) and had to set up pins again, so I have written another script:


OUTPINS="4 17 18"

gpio-admin export $PIN

for PIN in $OUTPINS;
echo out > /sys/devices/virtual/gpio/gpio$PIN/direction

Dominik has created very simple program to load CPU, for testing my script:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(int argc, char ** argv) {
int pause = 500, times = 10000, i = 0;
if(argc == 3){
pause = atoi(argv[1]);
times = atoi(argv[2]);

struct timespec a = { 0, pause * 1000};

while (1) {
for (i = 0; i < times; ++i){
nanosleep(&a, NULL);

return 0;

I could write more about it but one video is more than thousand words. :)

After this, I decided to try setup pulseaudio as sound server. At first I was trying to do it using shell but it didn't work. I've installed program paprefs and issued command startx GUI was quite slow but somehow I managed to configure sound server. (check all boxes on "Network server" tab) After that, I was able to stream sounds from my laptop. At least until I shut down X server. I believe X server is not needed, so I'll have to find out way how to run sound server without it.

The only thing I did next day with Raspberry Pi was showing it to people in Progressbar. Some people thinks programmers have no life but it isn't true - at least for me. I've choosen spending night with friends over coding. :)

After hard work during Friday, I wanted to play some game. Involving Raspberry Pi of course! I've successfuly compiled Urban Terror dedicated game server (nothing special is needed - it works just like on ia32) but had to run it with 128M limit (command: UrbanTerror/ioUrTded.armv6l +set com_hunkmegs 128 +set com_zonemegs 32 +exec server.cfg). It worked OK but with many lags.


To my disappointment, work with Pi is not as easy as I expected but it's still fun. The biggest problem is sound - I can't control volume without messing it up (Flash player is an exception). Second is two kernel panics I've got. Broken keyboard was horrible (I couldn't type my password), if I want to stream sound X server must run and lack of processing power spoils game experience. Hopefuly, one day all the problems will be solved but it won't be until I finish this school year. If you find out solutions, feel free to write me e-mail (martin dot habovstiak at gmail), tweet it (@kixunil) or post a comment on my Google+ profile

Plans to the future

I look forward to explore Raspberry Pi more deeply and create some good stuff. One of my biggest plans is connecting IR LED to GPIO and control air condition (which acts also like heating) with it over Internet. I imagine, one hot day I'll come into apartment, cooled thanks to Pi. :) Next important features are good DHCP server (that on my router is total crap), NAS, VPN, VoIP... and whatever else funny/interesting/practical. If you have any interesting ideas, let me know, maybe I'll implement them. :)

All the code published here is released under MIT license. (do whatever you want but give credit to original author)



I've successfully managed to connect DS18B20 temperature sensor to GPIO pins. Now I can measure temperature in my room. This is useful, when I'm not there and want to turn off air condition. (I still didn't connect IR LED but it's fun anyway.) If you are interested, you can use this tutorial and/or see simple demo. (I don't guarantee that Raspberry is online.)

Komentáre Pridať komentár


Čakajte prosím, komentár sa odosiela... Zrušiť

Ak sa vám článok páčil, môžete ma podporiť kliknutím:

RSS RSS kanál blogu [Valid RSS]

Prepnúť štýl na konzola
Creative Commons License
Túto stránku vytvoril Martin Habovštiak a je zverejnená pod licenciou Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.