2013-03-31

serjtag patches for avrdude-5.11.1


I needed to update firmware of AVR-USBasp-B (original USBasp's page) which I bought at Akihabara

avrdude: Warning: Found USB device "USBasp" with old VID/PID! Please update firmware of USBasp!
avrdude: warning: cannot set sck period. please check for usbasp firmware update.

But I don't have another writer (Arduino runs in another project, so I don't use Arduino-ISP). I tried to use FTDI BitBang AVR-Writer with FT232R.

I needed to apply patches to avrdude for using FTDI BitBang AVR-Writer but the original avrdude-serjtag patches don't support avrdude-5.11.1 (latest version). So I edited the patches and created github repository: laclefyoshi/avrdude-serjtag · GitHub.

After building and installing avrdude (read README.md), I succeeded to update firmware of AVR-USBasp-B.



$ sudo kextunload /System/Library/Extensions/FTDIUSBSerialDriver.kext


$ avrdude -C /opt/usr/avrdude/etc/avrdude.conf -c diecimila -P ft0 -p m8 -v

avrdude: Version 5.11.1, compiled on Mar 30 2013 at 17:18:59
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "/opt/usr/avrdude/etc/avrdude.conf"
         User configuration file is "/Volumes/Macintosh HD/Users/yoshiyasu/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : ft0
         Using Programmer              : diecimila
avrdude: BitBang OK
avrdude: pin assign miso 3 sck 5 mosi 6 reset 7
avrdude: drain OK
         AVR Part                      : ATMEGA8
         Chip Erase delay              : 10000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom         4    20   128    0 no        512    4      0  9000  9000 0xff 0xff
           flash         33    10    64    0 yes      8192   64    128  4500  4500 0xff 0x00
           lfuse          0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           lock           0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           calibration    0     0     0    0 no          4    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : ft245r
         Description     : FT232R Synchronous BitBang

 ft245r:  bitclk 230400 -> ft baud 115200
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9307
avrdude: safemode: lfuse reads as EF
avrdude: safemode: hfuse reads as D9

avrdude: safemode: lfuse reads as EF
avrdude: safemode: hfuse reads as D9
avrdude: safemode: Fuses OK

avrdude done.  Thank you.


$ avrdude -C /opt/usr/avrdude/etc/avrdude.conf -c diecimila -P ft0 -p m8 -U flash:w:usbasp.atmega8.2011-05-28.hex:i
avrdude: BitBang OK
avrdude: pin assign miso 3 sck 5 mosi 6 reset 7
avrdude: drain OK

 ft245r:  bitclk 230400 -> ft baud 115200
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9307
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
 ft245r:  bitclk 230400 -> ft baud 115200
avrdude: reading input file "usbasp.atmega8.2011-05-28.hex"
avrdude: writing flash (4700 bytes):

Writing | ################################################## | 100% 2.25s



avrdude: 4700 bytes of flash written
avrdude: verifying flash memory against usbasp.atmega8.2011-05-28.hex:
avrdude: load data flash data from input file usbasp.atmega8.2011-05-28.hex:
avrdude: input file usbasp.atmega8.2011-05-28.hex contains 4700 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 1.29s



avrdude: verifying ...
avrdude: 4700 bytes of flash verified

avrdude: safemode: Fuses OK

avrdude done.  Thank you.

$ avrdude -C /opt/usr/avrdude/etc/avrdude.conf -c diecimila -P ft0 -p m8 -U hfuse:w:0xC9:m  # read http://www.fischl.de/usbasp/Readme.txt

$ sudo kextload /System/Library/Extensions/FTDIUSBSerialDriver.kext

I read Atmega8 with USBasp.

$ avrdude -C /opt/usr/avrdude/etc/avrdude.conf -c usbasp -P ft0 -p m8  -v

avrdude: Version 5.11.1, compiled on Mar 30 2013 at 17:18:59
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "/opt/usr/avrdude/etc/avrdude.conf"
         User configuration file is "/Volumes/Macintosh HD/Users/yoshiyasu/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : ft0
         Using Programmer              : usbasp
         AVR Part                      : ATMEGA8
         Chip Erase delay              : 10000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom         4    20   128    0 no        512    4      0  9000  9000 0xff 0xff
           flash         33    10    64    0 yes      8192   64    128  4500  4500 0xff 0x00
           lfuse          0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           lock           0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           calibration    0     0     0    0 no          4    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : usbasp
         Description     : USBasp, http://www.fischl.de/usbasp/

avrdude: auto set sck period (because given equals null)
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9307
avrdude: safemode: lfuse reads as DF
avrdude: safemode: hfuse reads as CA

avrdude: safemode: lfuse reads as DF
avrdude: safemode: hfuse reads as CA
avrdude: safemode: Fuses OK

avrdude done.  Thank you.

USBasp is small and good programmer. Recently, sometimes, I want to take time away from Arduino and use AVR microcontrollers.

Thanks.

2013-02-09

controlling digital camera with Arduino and light


I bought a digital camera: EOS Kiss X6i last year.

This camera has an interface for remote controller. On examination, I knew this plug is 2.5mm stereo mini plug and has very simple mechanism. So I connected the camera and Arduino.

This page provides me with useful information.

Arduino read Analog-Pin 1 (connecting with a light sensor input). If the value of Analog-Pin 1 exceeds a certain value, Arduino outputs Digital-Pin 2 (focus) and 3 (shutter).




I think that taking pictures continuously is to place excessive strain on camera, so I set 30 seconds of delay.



The light sensor can replace other sensors or triggers. For example, Ethernet shield can be connected. I enjoy the extension of my camera's release.

Thanks.

2012-10-21

using Source Code Pro in emacs


I used Anonymous Pro in emacs previously. But I saw Adobe's blog and I was interested in this new font.

Hiragino Kaku Gothic Pro is a font included Mac OS X for Japanese.




There is a very well-recognized distinction between "0", "O", "1", "I" and "l" certainly.

Thanks.

2012-10-13

Google Chrome supports MathML


According to this post, Google Chrome (Canary build) supprts MathML.

The version of Google Chrome Canary build is 24.0.1293.0 currently. The version of Google Chrome Stable build is 22.0.1229.94.

Firstly, I wrote MathML file with LibreOffice formula editor and saved as a MathML 1.01 file (math.mml). I think that MathML is not much better format by hand than LaTeX.

The gist is here.


When I opened this mml file with Google Chrome Stable, it was shown as below. Chrome knew the file is XML document but couldn't read MathML.


When I opened it with Google Chrome Canary, it was shown as below. Chrome could read MathML approximately right.


MathML can be written in XHTML document. After this, the web browser can interpret numeral information and mathematical formula. For example when I open a web page providing statistical information, the web browser will be able to show me the richer information.

Thanks.

2012-09-08

measuring the similarity between two images


When I searched methods for measuring the similarity between two images, I found two implementations: libpuzzle and pHash. libpuzzle specializes in the comparison of images. pHash supports the comparison of images, audios and movies.

These can be installed with homebrew. I compared these libraries.

libpuzzle


The license of libpuzzle is BSD license. It depends on gd library.

$ brew info libpuzzle
libpuzzle: stable 0.11
http://libpuzzle.pureftpd.org/project/libpuzzle
Depends on: gd
Not installed
https://github.com/mxcl/homebrew/commits/master/Library/Formula/libpuzzle.rb

$ brew install libpuzzle
Warning: It appears you have MacPorts or Fink installed.
Software installed with other package managers causes known problems for
Homebrew. If a formula fails to build, uninstall MacPorts/Fink and try again.
==> Installing libpuzzle dependency: libpng
==> Downloading http://downloads.sf.net/project/libpng/libpng15/1.5.12/libpng-1.5.12.tar.gz
######################################################################## 100.0%
==> ./configure --prefix=/opt/homebrew/Cellar/libpng/1.5.12
==> make install
/opt/homebrew/Cellar/libpng/1.5.12: 14 files, 1.0M, built in 15 seconds
==> Installing libpuzzle
==> Downloading http://download.pureftpd.org/pub/pure-ftpd/misc/libpuzzle/releases/libpuzzle-0.11.tar.bz2
######################################################################## 100.0%
==> ./configure --prefix=/opt/homebrew/Cellar/libpuzzle/0.11
==> make install
/opt/homebrew/Cellar/libpuzzle/0.11: 12 files, 104K, built in 17 seconds

I wrote a simple C code using libpuzzle.



$ gcc -L/opt/homebrew/lib -I/opt/homebrew/include -lpuzzle test_libpuzzle.c
$ otool -L ./a.out 
./a.out:
        /opt/homebrew/lib/libpuzzle.1.dylib (compatibility version 2.0.0, current version 2.0.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)

$ ./a.out tokyo_skytree.jpg tokyo_skytree.jpg
distance: 0

I prepared five pictures from flickr for testing.

  • tokyo_skytree.jpg: original (960 × 1280)
  • tokyo_skytree_500.jpg: reduced (375 × 500)
  • tokyo_skytree_75.jpg: reduced and cut (75 × 75)
  • tokyo_skytree_thumbnail.jpg: reduced (75 × 100)
  • wrong_image.jpg: non-related (640 × 960)

$ time for i in `/bin/ls *.jpg`; do  for j in `/bin/ls *.jpg`; do  echo -ne "$i <-> $j\t:\t"; ./a.out $i $j; done; done

tokyo_skytree.jpg <-> tokyo_skytree.jpg :       distance: 0
tokyo_skytree.jpg <-> tokyo_skytree_500.jpg     :       distance: 0.0981159
tokyo_skytree.jpg <-> tokyo_skytree_75.jpg      :       distance: 0.549193
tokyo_skytree.jpg <-> tokyo_skytree_thumbnail.jpg       :       distance: 0.290368
tokyo_skytree.jpg <-> wrong_image.jpg   :       distance: 0.710145
tokyo_skytree_500.jpg <-> tokyo_skytree.jpg     :       distance: 0.0981159
tokyo_skytree_500.jpg <-> tokyo_skytree_500.jpg :       distance: 0
tokyo_skytree_500.jpg <-> tokyo_skytree_75.jpg  :       distance: 0.547736
tokyo_skytree_500.jpg <-> tokyo_skytree_thumbnail.jpg   :       distance: 0.272873
tokyo_skytree_500.jpg <-> wrong_image.jpg       :       distance: 0.715105
tokyo_skytree_75.jpg <-> tokyo_skytree.jpg      :       distance: 0.549193
tokyo_skytree_75.jpg <-> tokyo_skytree_500.jpg  :       distance: 0.547736
tokyo_skytree_75.jpg <-> tokyo_skytree_75.jpg   :       distance: 0
tokyo_skytree_75.jpg <-> tokyo_skytree_thumbnail.jpg    :       distance: 0.56704
tokyo_skytree_75.jpg <-> wrong_image.jpg        :       distance: 0.716492
tokyo_skytree_thumbnail.jpg <-> tokyo_skytree.jpg       :       distance: 0.290368
tokyo_skytree_thumbnail.jpg <-> tokyo_skytree_500.jpg   :       distance: 0.272873
tokyo_skytree_thumbnail.jpg <-> tokyo_skytree_75.jpg    :       distance: 0.56704
tokyo_skytree_thumbnail.jpg <-> tokyo_skytree_thumbnail.jpg     :       distance: 0
tokyo_skytree_thumbnail.jpg <-> wrong_image.jpg :       distance: 0.756318
wrong_image.jpg <-> tokyo_skytree.jpg   :       distance: 0.710145
wrong_image.jpg <-> tokyo_skytree_500.jpg       :       distance: 0.715105
wrong_image.jpg <-> tokyo_skytree_75.jpg        :       distance: 0.716492
wrong_image.jpg <-> tokyo_skytree_thumbnail.jpg :       distance: 0.756318
wrong_image.jpg <-> wrong_image.jpg     :       distance: 0

real    0m1.118s
user    0m0.963s
sys     0m0.100s




orig

500

75

thumbnail

wrong

orig

0

0.0981159

0.549193

0.290368

0.710145

500

0.0981159

0

0.547736

0.272873

0.715105

75

0.549193

0.547736

0

0.56704

0.716492

thumbnail

0.290368

0.272873

0.56704

0

0.756318

wrong

0.710145

0.715105

0.716492

0.756318

0

If the two images are similar, the distance approaches 0 (if these are different, the distance approaches 1). When the different images are compared, it appears that the distance is more than 0.7.

phash


The license of pHash is GPLv3. It depends on CImg for processing images.

$ brew info phash
phash: stable 0.9.4
http://www.phash.org/
Depends on: cimg, ffmpeg, libsndfile, libsamplerate, mpg123
Not installed
https://github.com/mxcl/homebrew/commits/master/Library/Formula/phash.rb
==> Options
--disable-audio-hash
        Disable audio hash
--disable-video-hash
        Disable video hash
--disable-image-hash
        Disable image hash

$ brew install phash --disable-audio-hash --disable-video-hash
Warning: It appears you have MacPorts or Fink installed.
Software installed with other package managers causes known problems for
Homebrew. If a formula fails to build, uninstall MacPorts/Fink and try again.
==> Installing phash dependency: cimg
==> Downloading http://downloads.sourceforge.net/cimg/CImg-1.5.0.zip
######################################################################## 100.0%
/opt/homebrew/Cellar/cimg/1.5.0: 425 files, 31M, built in 6 seconds
==> Installing phash
==> Downloading http://www.phash.org/releases/pHash-0.9.4.tar.gz
######################################################################## 100.0%
==> Patching
patching file src/cimgffmpeg.cpp
==> ./configure --prefix=/opt/homebrew/Cellar/phash/0.9.4 --enable-shared --disable-video-hash --disable-audio-hash
==> make install
/opt/homebrew/Cellar/phash/0.9.4: 10 files, 900K, built in 47 seconds

I wrote a simple C++ code using pHash.



$ g++ -L/opt/homebrew/lib -I/opt/homebrew/include -lpHash test_phash.cpp
$ otool -L a.out 
a.out:
        /opt/homebrew/lib/libpHash.0.dylib (compatibility version 1.0.0, current version 1.0.0)
        /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 56.0.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)

$ ./a.out tokyo_skytree.jpg tokyo_skytree.jpg
distance: 0

$ time for i in `/bin/ls *.jpg`; do  for j in `/bin/ls *.jpg`; do  echo -ne "$i <-> $j\t:\t"; ./a.out $i $j; done; done

tokyo_skytree.jpg <-> tokyo_skytree.jpg :       distance: 0
tokyo_skytree.jpg <-> tokyo_skytree_500.jpg     :       distance: 8
tokyo_skytree.jpg <-> tokyo_skytree_75.jpg      :       distance: 22
tokyo_skytree.jpg <-> tokyo_skytree_thumbnail.jpg       :       distance: 8
tokyo_skytree.jpg <-> wrong_image.jpg   :       distance: 30
tokyo_skytree_500.jpg <-> tokyo_skytree.jpg     :       distance: 8
tokyo_skytree_500.jpg <-> tokyo_skytree_500.jpg :       distance: 0
tokyo_skytree_500.jpg <-> tokyo_skytree_75.jpg  :       distance: 20
tokyo_skytree_500.jpg <-> tokyo_skytree_thumbnail.jpg   :       distance: 2
tokyo_skytree_500.jpg <-> wrong_image.jpg       :       distance: 30
tokyo_skytree_75.jpg <-> tokyo_skytree.jpg      :       distance: 22
tokyo_skytree_75.jpg <-> tokyo_skytree_500.jpg  :       distance: 20
tokyo_skytree_75.jpg <-> tokyo_skytree_75.jpg   :       distance: 0
tokyo_skytree_75.jpg <-> tokyo_skytree_thumbnail.jpg    :       distance: 20
tokyo_skytree_75.jpg <-> wrong_image.jpg        :       distance: 32
tokyo_skytree_thumbnail.jpg <-> tokyo_skytree.jpg       :       distance: 8
tokyo_skytree_thumbnail.jpg <-> tokyo_skytree_500.jpg   :       distance: 2
tokyo_skytree_thumbnail.jpg <-> tokyo_skytree_75.jpg    :       distance: 20
tokyo_skytree_thumbnail.jpg <-> tokyo_skytree_thumbnail.jpg     :       distance: 0
tokyo_skytree_thumbnail.jpg <-> wrong_image.jpg :       distance: 32
wrong_image.jpg <-> tokyo_skytree.jpg   :       distance: 30
wrong_image.jpg <-> tokyo_skytree_500.jpg       :       distance: 30
wrong_image.jpg <-> tokyo_skytree_75.jpg        :       distance: 32
wrong_image.jpg <-> tokyo_skytree_thumbnail.jpg :       distance: 32
wrong_image.jpg <-> wrong_image.jpg     :       distance: 0

real    0m3.215s
user    0m3.007s
sys     0m0.173s




orig

500

75

thumbnail

wrong

orig

0

8

22

8

30

500

8      

0      

20      

2      

30      

75      

22      

20      

0      

20      

32      

thumbnail

8      

2      

20      

0      

32      

wrong

30      

30      

32      

32      

0      

If the two images are similar, the distance approaches 0 (if these are different, the distance is large number). When the different images are compared, it appears that the distance is more than 30.

The result of libpuzzle and pHash are similar. But the processing time of pHash takes 3 times longer than libpuzzle. I will use libpuzzle for my task.

Thanks.

2012-06-16

getting unused port number


A simple way to get unused port number on local machine is creating a socket.

I wrote a Python code.



But in Jython, this behavior is a bit different.



I think that the behavior of Python is correct.

Thanks.

2012-06-01

verifying keys with openssl


For verifying that a private key and a public key are right combination, we can use Modules field of the keys.


I got a private key of Yahoo! from Yahoo! Axis. And the Axis extension for Google Chrome includes a public key field.

I checked the two keys were right combination.



$ python check_keys.py 
warning [YAxis_Chrome_v1_0_20120520.crx]:  306 extra bytes at beginning or within zipfile
  (attempting to process anyway)
Public key modulus:   D609E9C990D38EFADFB21AFBD227EDBAFCFE4C2E6A9ECE84B0A95DF9914E93DC832B7A70BF07FFE1D29317544EE57B6F249E740707919C364340FFD05F1EB2E2A5C321D8447BFBC4D18FA97C5E6ABB24AF3D60F0C37E46D2C820522EE2BE1ECB0D528B7A2A9C9309EC1E542A06BCFAFF2A3239C0F739F8C54E7BD9C5B52BEA65
Private key modulus:  D609E9C990D38EFADFB21AFBD227EDBAFCFE4C2E6A9ECE84B0A95DF9914E93DC832B7A70BF07FFE1D29317544EE57B6F249E740707919C364340FFD05F1EB2E2A5C321D8447BFBC4D18FA97C5E6ABB24AF3D60F0C37E46D2C820522EE2BE1ECB0D528B7A2A9C9309EC1E542A06BCFAFF2A3239C0F739F8C54E7BD9C5B52BEA65
match!

Unfortunately (?), the keys are right. Thus, we can create certified extensions as Yahoo!.

It seems that the Axis development team uses ant for building the extension. Because the sources and product were in same location, an incident like this occurred. There may not be a person with much knowledge about Google Chrome extensions in the team.

Thanks.