Saturday, January 26, 2013

First python program

I am new to python, so I first want to create the traditional "hello world" program in python and see if it works.
On my raspberry pi, python was already installed and added to the path.
There are different Version installed (standard 2.7 and the newer 3.2). Check your version:
python --version
Open an editor and type the following program:
#!/usr/bin/python
print "hello world"
Save as "test.py". It can be executed either by calling the python binary or making the file executable (asuming you are in the same directory as the python script file):
python test.py
chmod +x test.py   //sets the executable flag
./test.py
Or if you want to run it as phyton 3.2:
python3.2 test.py
This will output an error, because in the 3.x version of python the "print" command is a function and so we have to use it with parenthesis like this:
print("Hello world")
 Now it should work and print "Hello world" to stdout. Nice.

Thursday, January 24, 2013

Text to speech engine

Now we make the raspberry speak. I tried two different text-two-speak engines:
In the end I think espeak is the better choice, because it works more stable and the voice sounds better.
Installing is quite simple:
sudo apt-get install espeak
sudo apt-get install festival
Now for testing:
espeak "hello world"
espeak -f readFile

echo "hello world" | festival --tts
festival --tts readFile
The standard voice is english and male with a speed of 175. You can change that - for example:
espeak -s 150 -v german "hallo welt"
This changes the speed of the voice and sets the language to German.
If you have problems with the audio output, try running the command with sudo.
To check if it is a problem with your audio configuration or just with espeak, try playing a test audio file:
sudo aplay /usr/share/sounds/alsa/Front_Center.wav
Still no audio? Check your mixer settings - you can force an output channel:
sudo amixer cset numid=3 <n>
n=0 auto, n=1 analog, n=2 hdmi



To get the sound over HDMI working with my TV (LG 32LH2000) I also had to change the config.txt file in the boot directory. Add/uncomment the following line and restart the raspberry pi:
hdmi_drive=2
Still not working for some reason hmpf? Try loading the sound driver:
sudo modprobe snd_bcm2835

Removing a package
Since the festival package is not needed anymore, we remove it:
sudo apt-get remove --purge festival
sudo apt-get clean

Linux commands & stuff

Since I am not to used to using gnu/linux, here is a list of some commands/programs that are used often:

apt-get install <xxx> - install a new package
apt-get update - update the package list
apt-get upgrade - install new version of your packages
ls - list files/dirs
mv - moves a file
cp - copies a file
rn - renames a file
startx - start X-session (desktop)
nano - simple editor (ctrl+O = save, ctrl+X = close)
groups - print the groups a user is in
chmod - Changes the permission of a file

and many more...
A lot of times problems occure due to permission issues, so try "sudo" infront of the command before becoming furious. Also make sure that you have the rights to read/write a file, otherwise it won´t work.



Shutdown & restart
sudo shutdown -h now - shutsdown the raspberry pi now
sudo shutdown -r now - restarts the raspberry pi now
As suggested here: http://raspberrypi.stackexchange.com/questions/381/how-do-i-turn-off-my-raspberry-pi it might be a good idea to leave the rasperry pi connected to the power supply cable and use a plug board with a power switch - to limit the number of insert/disconnect cycles. If you are a little princess.


Config files & services
In linux most of settings/programs can be configured by editing their specific config files. After changing the config files you have to restart the pi or restart the specific service. This can be achieved like this:
sudo service <serviceName> restart/stop/start

First boot

If everything works, the raspberry pi should boot and you have a picture on your HDMI Screen. On the first start, the "raspi-config" script should start automatically: http://elinux.org/RPi_raspi-config


Her you can edit basic settings. If you want to run the script again later, just type in your command line:
sudo raspi-config
 My settings:
  • expand_rootfs - to use the full sd card size (otherwise the full size is not recognized)
  • Set time/date, keyboard layout & change default password (Username: pi Password: raspberry)
  • SSH server starts automatically
  • Do not start the Desktop
  • memory_split - 64MB for graphics is enough, since I won´t use the desktop/games etc.
You can start the desktop later by simply typing:
 startx
  
As you can see there are already some programs pre-installed. The desktop environment is LXDE: http://lxde.org/ which looks pretty nice, but as I said before it does not matter since I am nit going to use the desktop.
For webbrowsing you have midori, but it is pretty slow. You can install other browsers if you want to but firefox won´t run fast. Chromium might run better.

The main programming language for the raspberry pi is python. Since I am new to Python, I am looking forward to use it & learn!

Now it is time to update our system and remove all not needed programs:
sudo apt-get update
sudo apt-get upgrade
This will update the package list and install new versions of our packages.At least if you have already a working internet connection. I simply connected the raspberry pi with an ethernet cable to my router. Since I am using static IPs, I have to manually configure an IP adresse.

Configure static IP, Subnet mask, gateway:

You can use some tools or ifconfig to configure the network options, but the fastest way is to directly change the config file:
sudo nano /etc/network/interfaces
Here you have to set the specific interface to static (disable dhcp). Then you enter the following lines right underneath (remove the "<>" signs):
iface eth0 inet static
address <your IP here>
netmask <SubnetMask>
gateway <Standard gateway>
Afterwards reboot the pi and test your internet connection:
ping raspberrypi.org




Start

Hello,
This is my blog about my raspberry pi experiences and projects.
I got my Pi (Model B) some weeks ago and I am very happy with it. Yeah, playing!
If you have any suggestions or like something, please leave a comment. Since I am not a native english speaker, ignore any spelling- or grammer mistakes ;-)


Setup & Installing

Things you need before starting:
  • Raspberry Pi
  • Power supply (5V, 700mA min.)
  • SD card (I am using a SanDisk Ultra SDHC 16GB Class 10)
  • HDMI cable
  • Screen with HDMI connector
  • USB Keyboard, mouse
  • Ethernet cable or usb wifi (if you want network/internet). If you want to use an usb wifi adapter make sure it works under Linux/Raspberry Pi.
Before you can use your raspberry pi, you need to download and install an operating system on the SD card.
I choose the standard Raspbian "wheezy" image (based on Debian).
Download here: http://www.raspberrypi.org/downloads
Note: I am using the hard-float version, since it is faster. Right now (January, 2013) if you want to use Java, you have to use the soft-float version (at least for the Oracle/Sun Version as far as I know).

After downloading I followed this guide: http://elinux.org/RPi_Easy_SD_Card_Setup for formating & copying the image to my SD card.

Now just insert the SD Card, connect all the cables/keyboard etc. and start the raspberry pi by plugging the power supply in.
Note: I had to connect the HDMI cable and start the screen prior to starting the raspberry pi, otherwise there was no picture.