Friday, September 20, 2013

Donate for sheet music

If you would like to donate some money to support my efforts in creating free sheet music, please use the button below:


Saturday, September 14, 2013

LilyPond vs. MuseScore in polyphony

I had a hard time when wanted to typeset the polyphonic parts of BWV 572 with MuseScore 1.2.



So I gave LilyPond (version 2.16.2) a try:

\score {
 <<
 \new Staff <<
 \new Voice = "one" \relative c' {  
 \clef treble
 \key g \major
 \time 2/2 
 \voiceOne
 r2 g'' ~ g4 g fis e d1
 }
 \new Voice = "two" \relative c' {  \voiceTwo  r2 b'2 ~ b4 b a2 ~ a4 a g fis}
 \new Voice = "three" \relative c' {  \voiceThree r2 d'2 c1 ~ c4 c b2 }
 >>
>>
} 



Much better default output, mainly due to the default offset of the middle voice (which is a disadvantage in the 8th bar), but still needs tweaks from the first measure - which is much easier in MuseScore. So this use case again proves my experience: automated engraving is unfortunately more of a myth. It is better to tweak every measure visually than to tweak every second measure via a text interface. With MuseScore in 2 minutes I could arrive at the tweaked version:

Wednesday, September 11, 2013

DFU programming the atmega16u2 on the Arduino UNO R3

If you don't know what the title means, then probably you don't need this information :)

I wanted to have my own MIDI instrument, so I had to reprogram the atmega16u2 chip on my Arduino UNO R3 board. There is a somewhat outdated tutorial for that, but to completely do that, and easily I had to gather information from various blogs, forums, projects.
Though actually the process is very easy and fast, you can write a .bat file or shell script to change the firmware in seconds.

Programming with the dfu-programmer tool is very easy, for me seems easier than any other options. So these are the steps - written for Linux, but with some straightforward adjustments should apply to Windows as well - mainly the difference is that on Windows you need only the dfu-programmer package, no other installation/compiling needed - and to run dfu-programmer you don't need sudo.


Install necessary software
Download latest dfu-programmer (which knows about the atmega16u2 on the R3 Uno) from http://sourceforge.net/projects/dfu-programmer

On Linux you need to install some extra:
- sudo apt-get install libusb-1.0

On Windows you might get a 'libusb0.dll missing' error - in that case you need to install http://sourceforge.net/projects/libusb-win32/ - from the zip file you can download, unzip bin/x86/libusb_x86.dll to the same folder as dfu-programmer.exe and rename the dll to libusb0.dll
Also, on Windows - after you put the Arduino into DFU mode - you need the USB drivers for the atmega16u2 - the best is to get it from atmel's Flip programmer, there you find an Atmel\Flip 3.4.7\usb folder - so go to Device Manager (in Windows Control Panel), select Install Software for your "Unknown Device" - then set this folder as driver source - it will be installed correctly.

Unzip the downloaded file. On Windows you can use it straight away. On Linux you need some extra steps (and might need to install gcc and others tools, see compiler messages.)

To unzip and install on Linux: 
- tar xzvf ~/Downloads/dfu-programmer….tar.gz
- cd into the unzipped directory
- run ./configure
- run make
- run sudo make install

Programming a new firmware consists of the following steps:
  1. Put the atmega16u2 chip into DFU mode
  2. Erase the atmega16u2 flash memory
  3. Upload the new content for the atmega16u2 flash memory
  4. Reset the atmega16u2
  5. Plug off and in the Arduino



Put Arduino into DFU mode
First connect the Arduino to the computer using the USB port.
To reprogram the atmega16u2, you must put the chip into DFU (Device Firmware Update) mode. 
On the Arduino R3 that's very easy: shortcut briefly the 2 leftmost ICSP headers next to the USB port. 


Led on pin 13 will flash. (Might not flash if the firmware installed doesn’t do that.)
running lsusb should now show 03eb:2fef Atmel Corp., that is the Arduino is no longer visible as Arduino.
At this point you have not changed anything on the board, if you want to abort the process, just plug off and in the board.


Put new firware
First erase: sudo dfu-programmer atmega16u2 erase
Then flash the new one: sudo dfu-programmer atmega16u2 flash MYFIRMWARE.hex
Reset the chip: sudo dfu-programmer atmega16u2 reset
pull out the usb cable then put it back


Put back old firmware
To put back the original firmware, you must locate it first in your arduino installation, it is Arduino-COMBINED-dfu-usbserial-atmega16u2-Uno-Rev3.hex
You must first erase the flash (see previous section), then flash the new one with one more special parameter:

sudo dfu-programmer atmega16u2 flash ~/prog/arduino-1.0.4/hardware/arduino/firmwares/atmegaxxu2/Arduino-COMBINED-dfu-usbserial-atmega16u2-Uno-Rev3.hex --suppress-bootloader-mem

Then reset the chip (see previous section) and replug the Arduino.

Running lsusb should now show Arduino SA Uno R3 (CDC ACM)