Friday, February 22, 2013

Your Python-Fu is Strong

PYPTUG

This coming monday, I'll be talking about Python-Fu, or "The Gimp: how to write a plugin in 10 minutes" at the next PYPTUG meeting:

PYPTUG meeting, Monday February 25th @ 5:30pm
Wake Forest University, Manchester 241

Graphical Apps Scripting


The Gimp is not the only graphical package to have support for Python. Blender, Dia, Scribus and Maya are a few of them. I will probably cover a few of those in the future.

François
@f_dion

Friday, February 15, 2013

Python in Europe

From:

Python trademark at risk in Europe

"For anyone who works in a company that has an office in a EU Community member state, we need your help."

So if you work for a company who uses Python, in Europe, do follow the link above and read up about how a company is trying to hijack the Python name, and what you can do to help.

François
@f_dion

Wednesday, February 13, 2013

Minecraft Pi Edition available

The RaspberryPi edition download

minecraft-pi-0.1.1.tar.gz

The install

fdion@raspberrypi ~ $ gunzip minecraft-pi-0.1.1.tar.gz
fdion@raspberrypi ~ $ tar -xvf minecraft-pi-0.1.1.tar

More detail

Mojang.com
pi.minecraft.net

Python


So, before we get started in writing some python (such as the code I put here: minecraft python ), let's check out block.py in the mcpi/api/python/mcpi directory. It contains the types of materials that can be used:

AIR                 = Block(0)
STONE               = Block(1)
GRASS               = Block(2)
DIRT                = Block(3)
COBBLESTONE         = Block(4)
WOOD_PLANKS         = Block(5)
SAPLING             = Block(6)
BEDROCK             = Block(7)
WATER_FLOWING       = Block(8)
WATER               = WATER_FLOWING
WATER_STATIONARY    = Block(9)
LAVA_FLOWING        = Block(10)
LAVA                = LAVA_FLOWING
LAVA_STATIONARY     = Block(11)
SAND                = Block(12)
GRAVEL              = Block(13)
GOLD_ORE            = Block(14)
IRON_ORE            = Block(15)
COAL_ORE            = Block(16)
WOOD                = Block(17)
LEAVES              = Block(18)
GLASS               = Block(20)
LAPIS_LAZULI_ORE    = Block(21)
LAPIS_LAZULI_BLOCK  = Block(22)
SANDSTONE           = Block(24)
BED                 = Block(26)
COBWEB              = Block(30)
GRASS_TALL          = Block(31)
WOOL                = Block(35)
FLOWER_YELLOW       = Block(37)
FLOWER_CYAN         = Block(38)
MUSHROOM_BROWN      = Block(39)
MUSHROOM_RED        = Block(40)
GOLD_BLOCK          = Block(41)
IRON_BLOCK          = Block(42)
STONE_SLAB_DOUBLE   = Block(43)
STONE_SLAB          = Block(44)
BRICK_BLOCK         = Block(45)
TNT                 = Block(46)
BOOKSHELF           = Block(47)
MOSS_STONE          = Block(48)
OBSIDIAN            = Block(49)
TORCH               = Block(50)
FIRE                = Block(51)
STAIRS_WOOD         = Block(53)
CHEST               = Block(54)
DIAMOND_ORE         = Block(56)
DIAMOND_BLOCK       = Block(57)
CRAFTING_TABLE      = Block(58)
FARMLAND            = Block(60)
FURNACE_INACTIVE    = Block(61)
FURNACE_ACTIVE      = Block(62)
DOOR_WOOD           = Block(64)
LADDER              = Block(65)
STAIRS_COBBLESTONE  = Block(67)
DOOR_IRON           = Block(71)
REDSTONE_ORE        = Block(73)
SNOW                = Block(78)
ICE                 = Block(79)
SNOW_BLOCK          = Block(80)
CACTUS              = Block(81)
CLAY                = Block(82)
SUGAR_CANE          = Block(83)
FENCE               = Block(85)
GLOWSTONE_BLOCK     = Block(89)
BEDROCK_INVISIBLE   = Block(95)
STONE_BRICK         = Block(98)
GLASS_PANE          = Block(102)
MELON               = Block(103)
FENCE_GATE          = Block(107)
GLOWING_OBSIDIAN    = Block(246)
NETHER_REACTOR_CORE = Block(247)

That's a lot. So, next post I'll try to build something using Python with all the materials, to get a feel for what they are.

François
@f_dion

Audio numerique sur RaspberryPi

Audiophile

Pour que le Raspberry Pi coute le moins possible, certaines décisions on du être prise. Par exemple, il n'y a pas de CODEC analogique - numérique. De sorte que l'audio se joue par soit:

1) le port HDMI - audio numérique passée directement au téléviseur ou a l'ampli intégré avec décodeur DTS, dolby digital, master audio etc... Si on utilise le Raspberry Pi comme serveur de media, c'est parfait. Mais si on ne peut utiliser le port HDMI?

2) le port 3.5mm analogique - l'audio est générée par PWM (Pulse Width Modulation). Avec une fréquence suffisamment élevée, on peut arriver a 16 bit de résolution, comme les convertisseurs plus conventionnels. Dans le cas du Raspberry Pi toutefois, la résolution est un peu moindre. En plus, il y a un problème avec le pilote ALSA, de sorte que le son n'est pas vraiment... a la hauteur.

USB

Tout n'est pas perdu. En effet, on peut se procurer une carte son sur USB:
Mini PCM2704 USB sur ebay (A noter que le prix est a la hausse, de $4.00 par rapport a ce que j'ai payé ...).

C'est géré par le Raspberry Pi: 

$ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 08bb:2704 Texas Instruments Japan

Et ça donne une sortie analogique 3.5mm de qualité (super sur casque d’écoute), une sortie SPDIF rca numérique et une TOSLink optique numérique.
de USB a SPDIF, TOSLink et 3.5mm analogique

Illusion d'optique

Dans mon cas, je saute le DAC. J'utilise la carte son comme interface numérique optique, qui se relie a un processeur de son numérique Technics SH-AC500D (qui lui se branche a un ampli):

Le processeur de son est sur le dessus

La lumiere au bout ... de la fibre
On branche la fibre sur un des ports TOSlinks

Le soft


mpg123, aplay et d'autres lecteurs audio qui utilisent ALSA vont fonctionner avec la carte, mais il faut effectuer un changement a un fichier de configuration:

$ sudo vi /etc/modprobe.d/alsa-base.conf

et sur la derniere ligne, on change le -2 par un 1:

options snd-usb-audio index=-2
devient
options snd-usb-audio index=0 nrpacks=1
et on reboot.

François
@f_dion

Thursday, February 7, 2013

sudo ./laserpulse.py

Tron, Laser, Lissajous, RaspberryPi


Am I throwing together random words for titles now, in a weird captcha induced moment? No,  just condensing my interest in lasers in a few words.

You might have seen the laser digitizer in Tron: Legacy


However, in my case, what triggered my interest in laser, was the original Tron laser digitizer


A few years later, I had the chance to play with a good old HeNe red laser, pumping a mighty 5mW (well, in the 80s, it was impressive) in the college lab. One of the things I did with it was to draw Lissajous figures (or curves) on a wall (a large wall outside, at night - even cooler), using two little speakers and mirrors I had brought (the lab was set up to only do prism and mirror experiments).

Googling, I see a nearby school (Appalachian State) has one such kit in their physics dept:
http://www1.appstate.edu/dept/physics/demos2/oscillations/3a80_40.html


Anyway, fun stuff, making math and physics a lot more interesting...

Electronica


There was the artistic connection that also further fueled my interest in lasers. There is a lot to talk about here, since I've composed and performed electronic music for many years (still write some) and hosted a radio show for about 10 years etc, so that'll be for another time.

I will bring up one point right now though: you cant talk about lasers in music shows, without mentioning Jean Michel Jarre.

Jean Michel Jarre, Houston TX 1986
From his incredible live outdoor shows with lasers, lights and fireworks (one, a tribute to oceanographer Cousteau, had an attendance of over 2 million people in France in 1990) to his laser harp. Jarre without lasers wouldn't be the same.

On the road


The Raspberry Pi has a lot of appeal by itself, but I figured that it would probably be a good idea to add a laser in the mix. Since I had a presentation at PyCarolinas, I figured I'd write a script with Python (laserpulse.py, hence the title of this article) and build a little rig to project interesting patterns on the wall behind me.

My 50mW laser rig (also 500mW for day use)

The code for the pulsing is basically what is found in the RPI.GPIO dot dash article, and for the motor, in the 2bit H bridge article and PWM article.

So, using a laser in presentations, does it work? Well, at PyCarolinas, I got a lot of feedback on this, both during the presentation, after the presentation and even during other talks (heard during another talk "so we've learned today that lasers are cool")

In the audience: "I just want to say that this is the coolest command, ever."

On twitter:

Calvin Spealman
@ironfroggy
sudo laserpulse.py with actual lasers! #pycarolinas
08:45 PM - 21 Oct 12

And so on and so forth. The conclusion is this: Science needs some showmanship. But please, be careful when playing with lasers!


Video


So I'll leave you with a video of my little rig above controlled by the Raspberry Pi, going to the music of a very British band, doing a cover of the theme of a very British TV show. Very apropos, since the Raspberry Pi is a very British computer, afterall.





Youtube video (Music by Orbital, Doctor? live at BBC)

[edit] I fixed the youtube link



François
@f_dion

L'autoréplication


de RaspberryPi a SD


Il y a un certain challenge a faire une carte SD pour le Raspberry Pi.

Ceci est du en partie a la grande variété de systèmes d’opération et d'ordinateurs (et leur matériel). D'autre part, beaucoup de personnes n'ont que le Raspberry Pi comme ordinateur, les autres étant hors de portée du au prix.

Il y a certains groupes d'usagers ici et la qui se débrouillent pour aider les usagers a faire leur propre carte SD, alors que d'autres doivent acheter des cartes SD avec le système d’opération déjà installé. Mais comment faire pour faire une copie de cette carte SD, n'est on pas de retour a la case départ?

Le lecteur


En fait, une fois que l'on a un système d’opération  sur la carte SD, on peut alors faire de l'autoréplication. Quésaco? me direz vous... Et bien, c'est quand un système d’opération peut se répliquer lui même (faire une copie de carte SD seulement avec le Raspberry Pi).

Pour ce faire, il faut un lecteur de carte SD, car le Pi n'a qu'une seule fente SD. Un lecteur comme celui ci, par exemple (ici, avec une carte 16GB, mais on peut faire 4GB ou 8GB ou plus, de la même façon):




Et on le branche (avec un câble ou en direct) au port USB.



dd


La version la plus recente de Raspbian Wheezy est de Decembre 2012:
http://files.velocix.com/c1410/images/raspbian/2012-12-16-wheezy-raspbian/2012-12-16-wheezy-raspbian.zip

Ici, les instructions se basent sur une version plus vieille, mais c'est le meme principe. Il suffit de remplacer l'url http://www.gtlib.gatech.edu/pub/raspberrypi/images/raspbian/2012-09-18-wheezy-raspbian/2012-09-18-wheezy-raspbian.zip par une de cette liste ici (choisir un serveur plus pres de soi): http://downloads.raspberrypi.org/download.php?file=/images/raspbian/2012-12-16-wheezy-raspbian/2012-12-16-wheezy-raspbian.zip


Avant de commencer, il faut s'assurer d'avoir au moins 2.5GB de libre (df -h me donne 2.9G ici). On insere la carte SD vide dans le lecteur et on verra apparaitre /dev/sda ou sdb.



fdion@raspberrypi ~ $ df -h
Filesystem      Size  Used Avail Use% Mounted on
rootfs           15G   11G  2.9G  80% /
/dev/root        15G   11G  2.9G  80% /
devtmpfs        109M     0  109M   0% /dev
tmpfs            22M  248K   22M   2% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs            44M     0   44M   0% /run/shm
/dev/mmcblk0p1   56M   35M   22M  62% /boot
fdion@raspberrypi ~ $ wget http://www.gtlib.gatech.edu/pub/raspberrypi/images/raspbian/2012-09-18-wheezy-raspbian/2012-09-18-wheezy-raspbian.zip
fdion@raspberrypi ~ $ unzip 2012-09-18-wheezy-raspbian.zip
fdion@raspberrypi ~ $ ls /dev/sd*
ls: cannot access /dev/sd*: No such file or directory
fdion@raspberrypi ~ $ ls /dev/sd*
ls: cannot access /dev/sd*: No such file or directory
fdion@raspberrypi ~ $ ls /dev/sd*
/dev/sda  /dev/sda1
fdion@raspberrypi ~ $ ls *.img
2012-09-18-wheezy-raspbian.img


Ici, le lecteur de carte avec SD est /dev/sda (si c'est sdb, il faut ajuster la commande ci dessous avec of=/dev/sdb). On est pret a faire la copie de l'image de la carte SD (le fichier .img), a partir du Pi (on peut aussi utiliser bs=4M qui va beaucoup plus vite avec certaines cartes):


fdion@raspberrypi ~ $ sudo dd bs=1M if=2012-09-18-wheezy-raspbian.img of=/dev/sda
1850+0 records in
1850+0 records out
1939865600 bytes (1.9 GB) copied, 428.218 s, 4.5 MB/s
fdion@raspberrypi ~ $ sudo sync


Le sudo sync est très important. Si on ne le fait pas, ça ne fonctionnera pas.

Et c'est tout! On peut maintenant donner cette copie a une autre personne. Tres pratique pour les clubs.

Il existe aussi une méthode pour faire une copie, sans utiliser de fichier .img, mais cela sera pour une autre fois...


François
@f_dion

Tuesday, February 5, 2013

Improved Pi-A-Sketch video

Mighty RaspberryPi drawing

I've made a new video of the Pi-A-Sketch:




youtube page

Not quite as circular

One thing you will notice is that the circles have a kink on each sides (at the interface of each quadrant). With time, it appears that the compensation factor for the slop has to be adjusted. I've demoed this so much that I guess there is a little less slop than there was before. That is quite curious. It also means that I will have to add a calibration mode, perhaps a little jumper or switch, and when the Pi boots, it will run the calibration mode instead of the drawing mode.

This will definitely increase the code in a significant way (currently less than 200 lines of Python)

François
@f_dion