Shutter Actuation Count using gPhoto2

This method can be used to obtain the shutter actuation count on the following cameras:

  • Canon 1D Mark II
  • Canon 50D
  • Canon 5D Mark II
  • Canon 5D Mark III
  • Canon 7D
  • Canon T2i

There may be a few other compatible cameras too. Let me know if you have confirmed another model which works using this method.

Jump to instructions for: Mac | Linux | Windows

Mac OS X

gPhoto2 can be installed using MacPorts or Homebrew. This is how to do it using MacPorts. You’ll need to be connected to the internet while you do this.

  1. Install XCode Developer Tools for your version of OS X from the Apple Developer web site. Skip this if you already have it installed.
  2. Visit the MacPorts web site and download the .pkg installer. Run the installer and follow the instructions and install it to your computer.
  3. Open the Terminal.
  4. Update macports if needed, by running the command sudo port -v selfupdate
  5. Install the gphoto2 package by running the command sudo port install gphoto2
  6. Test whether gphoto2 is properly installed by typing gphoto2 --version
  7. Connect your camera to the USB port, using a USB cable
  8. Wait a few seconds after connecting your camera, and type killall PTPCamera – every time you replug your camera to the computer, you’ll need to type this before using gphoto2. This is needed, to kill any running processes connected to the USB device.
  9. To check the number of actuations, on the attached camera, type gphoto2 --get-config /main/status/shuttercounter
  10. If your camera is compatible, the shutter actuation count will be displayed.

Linux

Install gPhoto2 using package manager of our distribution.

For Centos, RHEL and other distributions which use the yum package manager:

yum install gphoto2

For Debian, Ubuntu and other distributions which use the apt package manager:

apt-get install gphoto2

Some Linux distributions may not have gphoto2 as precompiled package in which case you’ll need to download and compile it from source.

Windows

Using a LiveCD

This is the simplest way for non tech heads. Download the live CD, I have created and write it to a CD or DVD. You can do this by right clicking on the ISO file in Windows Explorer and selecting “Burn disc image”.

Reboot your computer boot from the CD. To boot your computer from a CD, there is usually key you can press to change the boot device (e.g F12). This usually flashes up on the monitor when it boots up.

Alternatively, you can enter the BIOS settings and change the boot order, and set the CD/DVD drive as the first device.

Once you have rebooted, it should start up in Debian (on the live CD), and a command prompt will be shown along with a message.

live_cdPlug the camera into the computer using a USB cord, some messages may be displayed on scren as you do this. You can check whether the computer has detected the camera by typing dmesg.

To check shutter count, type shuttercounter, to read camera information, you can type camerainfo, this will display information such as the camera’s serial number. These commands shortcuts to the gphoto2 program. You can also run all other gphoto2 commands if needed. See the full features by typing man gphoto2.

Using a Virtual Machine

If you have experience using virtualisation software such as Virtualbox or VMWare Workstation, then another way is to install or use an existing virtual Linux installation of your choice. Install gphoto2 from inside the virtual machine.

Moving WordPress blog across domains using the shell

Here’s a rundown, or more accurately a set of personal notes I made, for moving a WordPress blog from one domain name to another. This will also work when moving from one web host to another.

First you’ll need to know some details of your old database:

  • database host name, e.g mysql.yourdomain.com or localhost
  • database name
  • username
  • password

You can find these details in wp-config.php on the old WordPress site.

Create a new database on the new web host, and an appropriate user account which can be used to manage the database. You may need to do this in a web interface, e.g cPanel, as some web hosting companies only allow database creation and deletion via a web interface. Make note of these details of the new database, you’ll need these new details for the new site.

We’ll assume here that on your web host, web served files are stored in a subdirectory named the same as the domain name.

Old Blog

Save WordPress files from the old blog to blog_old.tar.gz:

tar -zcvf blog_old.tar.gz -C OLDDOMAIN.COM .

Save the old database to blog_db_old.sql. Use the details from the old database here.

mysqldump -uUSERNAME -p -h DBSERVER DBNAME --quick > blog_db_old.sql

Check the database dump is okay, we’ll just read the first couple of lines just to make sure all is well.

head blog_db_old.sql

New blog

Now we get to work on the new site. First up the archive of the WordPress files and database dump, move those onto the new server if required.

Write to new database and WordPress directory

Import the dumped SQL file from the old database, into the new database. You’ll need to type in here the details of the new database that was just created, and use a appropriate path to the archive files (the .tar.gz and .sql files).

mysql -h DB_SERVER -uUSERNAME -p DB_NAME < blog_db_old.sql

Extract contents of WordPress install into the new domain.

tar xvf blog_old.tar.gz -C NEWDOMAIN.COM/

Edit wp-config.php and enter in the new database details.

cd NEWDOMAIN.COM
vim wp-config.php

Search and replace operation on database

The database still references the old domain in its URLs. So we need to replace the domain name and URLs in database. There is a PHP script by interconnectit you can use, as a search and replace tool.

Download this handy database search and replace tool, unzip the single PHP file, and rename it:

wget http://www.interconnectit.com/wp-content/uploads/2011/05/searchreplacedb21.zip
unzip searchreplacedb21.zip
mv searchreplacedb2.php sr.php

Visit your new domain http://NEWDOMAIN.COM/sr.php to run the search and replace script.

  1. Select script to obtain database parameters from wp-config.php. Use this option, only if you have already edited wp-config.php on the new site with the new database details.
  2. Select all tables to perform the search and replace in.
  3. Type your search and replace parameters. Search for your old URLs and replace with your new URL. Take note of www. at the start of addresses. Some sites use it and some don’t (normally set in cPanel or equivalent interface). For example when I was moving sites from my old domain to this one, I searched for http://micro.gock.net and replace it with http://agock.com.
  4. Check your web site on the new domain and check all is working fine.

Remove the search and replace script once completed. Don’t leave this script on your web site.

rm sr.php

Alternate method

As an alternate method to using the above PHP script, we could have performed a search and replace on the SQL dump file, or peformed some search and replace commands directly on the databse using SQL queries.

Test web site

After performing the search and replace, the new site should work as normal. All media and user accounts should be as before. Visit your new site and check that it is all working fine.

Redirect the old domain

Once we know the new domain is working okay, we can remove the old files (remember you still backups from earlier). Make sure you’re in the right directory before doing the mass delete!

cd OLDDOMAIN.COM
rm -rf *

Set up a .htaccess file for the old domain.

touch .htaccess
vim .htaccess

Insert the following but replace with your site domain names:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !newdomain.com$ [NC]
RewriteRule ^(.*)$ http://newdomain.com/$1 [L,R=301]

Test the redirection, by visiting an old URL, your browser should automatically redirect to the new domain name. This will redirect all pages. Search engines crawling your site should recognise this 301 redirect code, and update its indexes appropriately.

Finishing up

You can now delete the old database as well. This can be done via cPanel or similar web host interface, if that is the only method your web host allows.

Copy your old site archive (.tar.gz) and database dump (.sql) somewhere for safekeeping.

If you were using Google Analytics, remember to go and change the settings in there, you are able to change the site name and URL for a Google Analytics account / property. Also fix any linking with Google Webmaster Tools.

New Base Conversion Tool

I just wanted to share a little tool I recently created. An online number base conversion tool. I know there are quite a few of them around. I created this mainly for myself and as a Javascript learning exercise, and I thought it might be useful to someone. It is very fast with “update as you type” ability and also a button for copying results to the clipboard. It converts between decimal, hexadecimal and binary.

base_converter_screenshotYou can visit the site at base-converter.gock.net

USB Datalogging on the Turnigy Accucel 6 Hobby Charger

After owning this great little hobby charger for some time, I wanted to use the data logging capabilities of the Turnigy Accucel-6 unit. In particular, the aim is the plot  some discharge curves of some particular batteries.

accucel

A quick search on Google found some articles, but a lot of conflicting information on how to connect the charger to a computer. I decided to perform a few tests on the charger, to see what was really going on, and work out how to connect it to a computer.

Here is what I found out. On the left side of the unit, there is a three pin connector, which doubles up as both a temperature sensor and a serial output. When in serial mode, it sends TTL serial data on the middle pin at 5V levels. The baudrate is 9600 bps, 8 bits, no parity, 1 stop bit (9600-8N1).

To set the charger to send serial data, you’ll need to set it in the menu and make sure USB mode is enabled.

To connect it to a computer, you’ll need a serial TTL to USB connector. There are quite a few options available, some googling shows some advice of the use of cheap Silab chip converters, but personally I prefer to use the more industry standard FTDI chip based adapters. These adapters are pretty cheap, are are based on the FT232 chip, and in some cases,  the newer FT231X part. The one I use is called Foca and it’s under 10 USD from Itead Studios. This unit has a switch that can select between 3.3V and 5V TTL levels. If you use your own adapter, make sure it supports 5V TTL.

foca

accucel_pinout

To connect to the adapter, connect GND pins from the adapter to charger, and the adapters RX pin to the chargers TX pin. I use some of these female to female jumpers, I think they’re more versatile than the recommended fixed configuration adapters I’ve read on a few forums. They’re only about $3 delivered for 40pcs on eBay. Connect the USB cable and plug it into the computer. The charger only sends data while it charging or discharging so set it to do one of these things. The data is sent in bursts around 1.5 seconds apart, 76 bytes in length. If you look on the USB-Serial adapter, if it has a TX and TX LEDs on it, you might see a burst a data every 1.5 seconds.

Using a terminal program, connect it to the appropriate serial port of the adapter, and you should be able to see the actual data being sent. It is binary data, so you won’t be able to read it straight away. On Windows, you can use some free software like Realterm or TeraTerm. On Mac OS X, I like to use CoolTerm. Remember to connect at 9600 8N1.

Here’s a screenshot of a dump in RealTerm when displaying in Hex+ASCII mode.

realterm_screen

You’ll see the data packets are start with a ‘{‘ and end with a ‘}’ char. Here’s a hex dump of a typical packet.

00000000: 7b 9c 84 84 d0 81 80 e4  80 88 85 80 81 8a 85 80 |{...............|
00000010: 81 80 80 8a 81 8c 83 84  81 80 81 81 80 80 8c e4 |................|
00000020: 80 80 8a 86 90 80 80 80  80 8c 92 80 92 80 80 80 |................|
00000030: 80 80 80 80 80 80 80 80  80 80 80 80 80 80 80 80 |................|
00000040: 80 80 80 80 80 80 8a 8f  a4 31 35 7d             |.........15}|

It could take some time to decode this, but Niobos has already spent the time and done most of it on his blog. He has decoded a lot of the data, but I’m only really interested in using the data I need for plotting a discharge curve. This means voltage, current, and capacity. Note that these chargers can only discharge a maximum current of 1A.

I’d like to take this data and save it as a CSV file, so we can plot it and analyse it later on.

On that note, I should mention there is a piece of software called LogView which can read this data. It is a nice piece of software in German, with a somewhat usable English translation. It’s a little old and a bit hard to find the English download, but the site is over here. You’ll need to find the latest version, as I must warn you, if the software detects it has an outdated version and you choose not to update it, it will just close down and not let you use it… bizarre.

To read the serial data, I wrote a Python script, which reads the data through the serial port, and sends CSV data to stdout. You’ll need pyserial installed. Download the script here on GitHub.

To run this program, and view the output on your screen, just pass the serial port as the argument to the script. For example on my Windows machine:

python log.py COM14

You should get an output on the screen similar to this:

Time(s),Minutes,Voltage(V),Current(A),Charge(mAh)
0,45,6.14,0.1,76
1.487,45,6.14,0.1,76
2.974,45,6.14,0.1,76
4.446,45,6.13,0.1,76
5.934,45,6.14,0.1,76
7.405,45,6.14,0.1,76
8.878,45,6.14,0.1,76
10.35,46,6.14,0.1,76
11.837,46,6.14,0.1,76
13.324,46,6.14,0.1,76
14.796,46,6.14,0.1,76
16.283,46,6.14,0.1,76
17.755,46,6.14,0.1,76
19.242,46,6.14,0.1,76

To cancel the running script, press Ctrl+C.

To view the data and save it to a file as well, you can use a program called “tee”. On Windows, this might be part of a Cygwin install, or simply download wintee. For example, on Linux you might want to use use:

python log.py /dev/ttyUSB0 | tee log_file.txt

On Windows, you may have to replace “tee” with “wtee”.

The above should also work with other similar “4 button chargers” like the Imax B6, Bantam e-Station etc, as they all run similar (if not identical) firmware.

Update: It’s been reported by Joe Rosevear who has a HobbyKing Eco Six charger, that the data stream for that unit is a little different from this. He has written a C program to parse the data stream from that particular HobbyKing charger.

Coming soon, I’ll show you how I’ll graph the data using gnuplot.

avr-uart 0.4 released – Atmel AVR UART Serial Library

Please visit the GitHub project page for the most up to date information, and sample code.

https://github.com/andygock/avr-uart

I’ve just updated the avr-uart library to version 0.4. It is designed for use on Atmel AVR microcontrollers. This is free and open source for all to use and is derived from original code by Peter Fluery and Tim Sharpe. Some changes include:
* Supports ring buffers over 256 bytes in size (use the -DUSART1_LARGER_BUFFER in your compiler switches to enable it for USART1 etc). Each USART can have large buffer support turned on or off independently.
* Modified code to use easier to read and understand “uint16_t” type instead of “unsigned int”.
* Some code cleanup You can download

Version 0.4 over here on GitHub. (GitHub project)