Ferraganchos & Pinchos

Or how to rip all this stuff out of my head…

Printing labels with Python

If you want to print custom labels taking full control of what and where to print things PyFpdf comes to rescue. PyFpdf is a simple but powerful PDF generation library ported from PHP.

Whit this simple script I was able to programmatically define margins, cols, rows, and cell size in order to fill a whole A4 page with incrementing serial numbers.

from fpdf import FPDF

pdf = FPDF(orientation='L',unit='mm',format='A4')
# define one column and one row margins
pdf.set_margins(297.0/14.0,210.0/20.0)
pdf.set_font('Arial','B',7)

pdf.add_page()
#define total rows containing labels
rows=20-2-1-1
# define total columns containing labels
cols=12
#define column size and tweak it empirically :)
columnsize=(297.0/14.0)+5.0/12.0

print columnsize
print columnsize*14

# define serial number start
serial=0

for i in range(rows):

	for j in range(cols):
		text="SN: 00-%03i" % serial
		serial+=1
		pdf.set_font('Arial','B',8)
		pdf.cell(columnsize,0,text, align="C")
	pdf.ln()
	for j in range(cols):
		pdf.set_font('Arial','B',6)
		pdf.cell(columnsize,7,"|B|F|D|O|C|L|V|", align="C")
	pdf.ln()
	for j in range(cols):
		pdf.cell(columnsize,(210/20)-6,"")
	pdf.ln()

pdf.output('labels.pdf','F')

And here is the PDF output.

PDF output

OpenPipe Breakout & Arduino Musical Shield

UPDATE (October, 1st 2012)!!! We’ve moved to www.openpipe.cc.

If you want to use OpenPipe Breakout as a MIDI controller you need some sort of synthesizer. You could use generic synths with custom sound samples (GarageBand, Reason) or specific synths like UniversalPiper, but all of them need a PC (or smartphone) to run.

If you want something “portable” you need to use a specific hardware synthesizer. The guys from Sparkfun designed an Arduino Shield based on VLSI VS1053b chip (Music Instrument Shield). This chip is a CODEC with support for several audio formats, and It can also play real-time MIDI. I was wondering how good the sound synth inside this chip is, so I bought one.

Connecting OpenPipe breakout board and Arduino UNO is quite simple:

  • OpenPipe GND: Arduino GND
  • OpenPipe VCC: Arduino 3.3V
  • OpenPipe I2C SDA: Arduino Analog 4
  • OpenPipe I2C SCL: Arduino Analog 5

OpenPipe & Arduino Shield connectios

Then connect a sound amplifier or headphones to the jack audio output.

OpenPipe, Arduino Musical Shield and Headphones

Here is the code I’ve used. It’s basically the same for OpenPipe MIDI, but with some changes in the MIDI command functions, because this shield uses SoftwareSerial library.

I’ve tested several instruments (Bagpipe, Oboe, Church Organ, Clarinet, Trumpet, …) and the sound is good, but It’s not amazing.

You can draw your own conclusions from the video: our lovely geek (me) making noise… again…

Pinax deployment with gunicorn and supervisor

Here is my recipe for Pinax deployment using Python tools as much as possible.

Create virtualmenv and activate it.

virtualenv –no-site-packages myenv
cd myenv/
source bin/activate

Install Pinax from GitHub.

pip install git+git://github.com/pinax/pinax.git

Setup basic pinax project.

pinax-admin setup_project -b basic mypinax

Test the project.

cd mypinax/
python manage.py syncdb
python manage.py runserver

Install gunicorn and test the installation

pip install gunicorn
gunicorn wsgi:application

Setup supervisor.

sudo apt-get install supervisor

Configure mypinax app in /etc/supervisor/conf.d/mypinax.conf

[program:mypinax]
command=/home/xulioc/virtualenv/myenv/bin/gunicorn wsgi:application
directory=/home/xulioc/virtualenv/myenv/mypinax/
user=xulioc
autostart=true
autorestart=true
redirect_stderr=True

Restart supervisor.

sudo /etc/init.d/supervisor/stop
sudo /etc/init.d/supervisor/start

Enjoy!

OpenPipe breakout MIDI over USB with Arduino

UPDATE (October, 1st 2012)!!! We’ve moved to www.openpipe.cc.

Playing OpenPipe with PWM sound is amazing :) but I got tired too soon. So the next step was to send MIDI commands in order to connect to a more realistic sound sampler/synthsizer like Garageband, Reason, etc.

OpenPipe breakout connected to Arduino Mega

There are several ways to address “Arduino sending MIDI commands” issue:

  • Send MIDI commands using MIDI DIN connector (MIDI Shield, etc.). A bit outdated?
  • Send MIDI commands using USB serial port and translate It to MIDI commands using PC software app. You can search “serial to MIDI” in Google. It’s OK but cumbersome.
  • Implement USB MIDI compliant class in Arduino. “The USB-HID specification has a specific type for MIDI input and MIDI output, which nearly all commercial musical controllers on the market use for class-compliant (driverless!) MIDI I/O.” (source)

IMHO the last option is the one because you need no additional software nor drivers (at least for Linux and Mac). How does it works?

Traditionally, Arduino boards used FTDI chip in order to translate UART to USB virtual serial port. Recent Arduinos changed this FTDI chip for an Atmel IC (atmega8u2, atmega16u2) capable of running UART-USB firmware (default) but also some other cool firmwares (ladyada wrote a good FAQ on this point). Flashing different firmwares your Arduino could act as a mouse, a keyboard, a MIDI device, and so on… (darran is doing a good job compiling this LUFA based firmwares for Arduino). The only drawback is that you need to reflash the Atmel IC  again if you want to update the Arduino sketch (You can’t please everyone… so far).

So here is the spet-by-step guide sumarizing how I proceeded with my Arduino Mega.

Download USB-MIDI firmware (Mega and UNO), demo and source from here. You can upload demo sketch (.pde) to the Arduino board as usual. Then we need to update atmega8u2 firmware (.hex).

Here you can find detailed information about flashing atmega8u2. Basically you need to reset atmega8u2 in order to enter DFU mode and the use dfu-programmer (sudo apt-get install dfu-programmer). In order to reset atmega8u2 connect RESET and GND pins in ISP header. The Arduino Mega pins are located the same way as Arduino UNO (see picture).

You can check that atmega8u2 is in DFU mode executing ‘lsusb’ after and before reset. The USB ID should have changed. Then flash Arduino-usbmidi-0.2-mega2560.hex.

sudo dfu-programmer at90usb82 erase

sudo dfu-programmer at90usb82 flash Arduino-usbmidi-0.2-mega2560.hex

sudo dfu-programmer at90usb82 reset

Now you can check if everything is working fine. Disconnect the Arduino and connect it again in order to boot as a MIDI device. Executing lsusb you shoud see somethin similar to:

Bus 003 Device 002: ID 03eb:2048 Atmel Corp. LUFA MIDI Demo Application

At this moment you have demo firmware running on Arduino, sending notes using UART, and atmega8u2 running MIDI device firmware translating UART commands to MIDI over USB protocol. Connecting a MIDI sniffer  (I’ve used KMidimon) you should see NOTE ON and NOTE OFF MIDI events.

Everything looks fine, so we are ready to flash OpenPipe breakout firmware…. but we need to restore atmega8u2 default firmware (the usbserial) before. Default firmware is located at /usr/share/arduino/hardware/arduino/firmwares/arduino-usbserial. In order to reflash again, enter DFU mode and then execute:

sudo dfu-programmer at90usb82 erase

sudo dfu-programmer at90usb82 flash Arduino-usbserial-mega.hex

sudo dfu-programmer at90usb82 reset

Now we can upload OpenPipe breakout sketch. I’ve mixed darran demo and OpenPipe breakout PWM code here. Then change atmega8u2 firmware again…

So the development process is:

  1. With default atmega8u2 firmware upload Arduino sketch
  2. Reset and flash atmega8u2 with MIDI firmware
  3. Reset the board and use It as MIDI device
  4. Reflash default firmware to atmega8u2
  5. GOTO 1

I’m sure we will be able to have composite firmwares with SERIAL and MIDI soon :)

Here is a geek playing galician bagpipes themes with several MIDI instruments in GarageBand…

Openpipe breakout

UPDATE (October, 1st 2012)!!! We’ve moved to www.openpipe.cc.

The past summer I discovered MPR121 Capacitive Sensor Controller searching cool stuff at Sparkfun and suddenly, mixed feelings came to my mind related to one of my past hobbies: mixing bagpipes and electronics.

Back in 2000 I developed a galician MIDI bagpipe chanter based on PIC16F84, and it was really funny.

MIDI bagpipe chanter electronics

MIDI bagpipe chanter electronics

MIDI bagpipe chanter HMI

MIDI bagpipe chanter HMI

In 12 years a lot has changed related to DIY electronics, especially related to Open Source Hardware, Arduino, etc., so I decided to give it a new try.

First thing to do was to test MPR121 capacitive touch controller, as I have related in a previous post.

Then I decided to move on PCB design (Eagle) and manufacture (Eurocircuits) in order to learn the whole precess from a DIY approach. Based on SparkFun breakout board I designed a new PCB with flute finger layout.

The two layer SMD design was focused to Eurocircuits default technology.

Openpipe breakout schematic

There is only one new feature regard MPR121 breakout from Sparkfun, and It is the 3.3V regulator, in order to allow connecting with 5V boards.

Openpipe breakout PCB layout

The layout is quite simple. Finger pads are located this way to facilitate routing. Pull-up resistors have solder jumpers, in case you need to disable them.

Openpipe breakout 3D

Eurocircuits PCB service is easy, fast and “cheap”. I was really surprised how easy It was to manufacture the boards.

Eurocircuits delivery

Next step is reflow. If you think you can solder QFN20 with a soldering iron… try it :).

In order to reflow QFN20 I used soldering iron to put some tin over the pads, then I carefully located the IC over the pads and then I used a high-tech reflow station (a.k.a. toaster).

I covered the “reflow station” with a glass ovenproof dish…

And surprisingly It worked like a charm!!! Remaining SMD components was soldered by hand.

I was very happy with the toaster reflow station, but I wanted to improve a bit the assembly process, so I ordered a polyester stencil to http://www.smtstencil.co.uk/. Stencil works fine for all components except for QFN20. I can’t manage to put the needed solder paste so every reflow I get bad QFN20 connections. So I’m currently putting QFN20 tin by hand and using the stencil for the remaining components. The following image shows QFN20 after reflow.

QFN20 after reflow

The electronics is OK, now the mechanics…

I soldered M3 hexagonal spacers to the finger pads. I used screws for testing.

Soldered M3 hexagonal spacers

Then I bought PVC pipe from a hardware store and made one 3mm hole for each spacer.

PVC pipe

Some wires and the Openpipe breakout board is ready to connecto to Arduino using I2C.

Openpipe breakout connected to Arduino Mega

The hardware is OK. What about the software?

I wrote an Arduino Mega sketch that reads MPR121 pads and uses PWM for sound generation. Quite simple and powerful enough for validation.

And here is the final result!!!

If you are interested in the Openpipe breakout please drop me a line to xulioc at gmail.com. I think I could manage to send you the “kit”.

MPR121 capacitive keyboard with Arduino Mega

UPDATE (October, 1st 2012)!!! We’ve moved to www.openpipe.cc.

I’ve got some MPR121 breakout boards from SparkFun in order to test latency and play a bit with this IC.

The setup is quite simple: eight drawing pins on a breadboard connected to the MPR121 breakout.

Then connect power and I2C signals to Arduino Mega. Be sure power is 3.3V because MPR121 is not a 5V IC.

I’ve attached a 16 Ohm speaker to PWM output (PIN 9 lower, PIN10 higher).

And here is the result.

And here is the code: http://dl.dropbox.com/u/196184/mpr121.zip. Use at your own risk ;)

Code is based on:

CDC Bootloader on (Dealextreme) Teensy

The bootloader provided by Dealextreme in Teensy boards is not compatible with Teensy Loader (At least the boards I have with loader 1.06).
In order to have a better (non-proprietary) bootloader we can choose from three provided by LUFA:
  • CDC Class, AVR109 protocol compatible (AVRDude)
  • DFU Class, Atmel DFU protocol compatible (Atmel FLIPdfu-programmer)
  • HID Class, with an included custom cross-platform loader application (Teensy Loader compatible???)
From an Arduino point of view, CDC is the best choice now, but DFU procedure is similar.
I’ve used an avrdragon with avrdude. Here is the connection between Teensy and avrdragon ISP connector:
And now the software part:
MCU=at90usb162
BOARD= TEENSY
F_CPU = 16000000
FLASH_SIZE_KB = 16
  • make
  • WOW!!! We have BootloaderCDC.hex
  • upload
sudo avrdude -v -pusb162 -cdragon_isp -Pusb -Uflash:w:BootloaderCDC.hex
Using ‘lsusb’ you should see something like:
Bus 003 Device 004: ID 03eb:204a Atmel Corp. LUFA CDC Class Bootloader
Now we can upload code using CDC bootloader:
sudo avrdude -v -pusb162 -cavr109 -P/dev/ttyACM0 -Uflash:w:blink.hex
Due to reset circuit on Teensy 1.0 you must repower the board in order to launch the uploaded app (reset button always enters to bootloader mode).

Fix NTFS partition

Mounting NTFS partition from macos and ubuntu I sometimes get:

‘$MFTMirr does not match $MFT (record 0)’

And here is how to fix it in Linux:

sudo apt-get install ntfsprogs
sudo ntfsfix /dev/sda6

CodeWarrior 10 Eclipse, USB P&E Multilink and Ubuntu 10.10

To properly flash using USB P&E Multilink I found:

http://forums.freescale.com/t5/CodeWarrior-General/CodeWarrior-10-Eclipse-Linux-Getting-USB-P-amp-E-Multilink/m-p/60785

/PATH/TO/CODEWARRIOR_MCU_10.0/Drivers/pemicro$ sudo sh setup.sh  (reinstall drivers)
/PATH/TO/CODEWARRIOR_MCU_10.0/eclipse sudo ./cwide  (execute CW10 with root privilages)

but setup.sh failed until I changed following files:

configure:    echo “#include <generated/autoconf.h>” >> hello.c
configure.usb:            echo “#include <generated/utsrelease.h>” > hello.c
configure.wd:            echo “#include <generated/utsrelease.h>” > hello.c

Clone VirtualBox Image

Get rid of duplicated UUID using:

VBoxManage clonevdi <existing UUID> clone.vdi

Cloned image will be stored in .VirtualBox folder in your home.

Post Navigation

Follow

Get every new post delivered to your Inbox.