Jul 9, 2012

Getting ATTINY45 to work at 8MHz with Arduino-1.0.1 and USBtinyISP

Working on a project to get an IR remote to work with an ATTINY45. The stock '45 comes with fuses set for 1Mhz.
I had a problem with the remote codes not being recognized and needed a way to see exactly what was going on. ATTINY doesn't natively support SoftwareSerial, but you can include the library for that. Problem is, the lib wants to run at 8Mhz or above. There is a way to easily change the fuses so the '45 runs at 8MHz,  using the 1.0.1 IDE and an add-on mentioned by the Hi Low Tech Group of MIT (here).
Make SURE you get a version of the ATTINY download that contains the folders variants and boards.txt and place them in the folders mentioned in the Hi Low blog above. Start arduino-1.0.1.  On my Ubuntu system, I need to run the USBtinyISP under sudo, so I navigate to the folder the arduino program lives in and type in sudo arduino-1.0.1 from the command line to start the IDE. Plug in  the USBtinyISP and set it in Tools\Programmer. Follow the instructions on the blog to "Burn Bootloader" after choosing Tools\Board\ATTINY45 (internal 8MHz clock). This normally won't show the results of the fuse burning command. To verify the fuses are being burned, before running "Burn Bootloader",  under File\Preferences, check the box for "Show verbose output during    upload".
To get the fuses and program burned onto the ATTINY45 chip, I mount the chip on a small breadboard and attach the pins to the USBtinyISP like so (from Maarten Damen's blog):
  • ATtiny Pin 2 to USBTinyISP SCK
  • ATtiny Pin 1 to USBTinyISP MISO
  • ATtiny Pin 0 to USBTinyISP MOSI
  • ATtiny RST pin to USBTinyISP RESET
and +5v to Vcc. GND to GND.
Here are pinouts for the ATTINY45 and the USBtinyISP. The pinout shown is for the ATTINY25, which is the same as the '45/'85.


Attiny25-pinout


Adafruit_usbtinyisp_pinout_6and10pinstd

To show where the *.hex program is located after a compile, check the box in File\Preferences\"Show verbose output during compile". On my Ubuntu system, this is located in /tmp/buildnnn.tmp/program_name.cpp.hex (where nnn = some alpha-numeric identifier). I compile from the command line like so:
user@mybox:/tmp/build3204698977405188542.tmp$ sudo avrdude -c usbtiny -p t45 -U flash:w:program-name.cpp.hex
If everything went well, you should see something like this:
sudo avrdude -c usbtiny -p t45 -U flash:w:attiny45_serial_example.cpp.hex
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.01s
avrdude: Device signature = 0x1e9206
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "attiny45_serial_example.cpp.hex"
avrdude: input file attiny45_serial_example.cpp.hex auto detected as Intel Hex
avrdude: writing flash (3894 bytes):
Writing | ################################################## | 100% 11.50s

avrdude: 3894 bytes of flash written
avrdude: verifying flash memory against attiny45_serial_example.cpp.hex:
avrdude: load data flash data from input file attiny45_serial_example.cpp.hex:
avrdude: input file attiny45_serial_example.cpp.hex auto detected as Intel Hex
avrdude: input file attiny45_serial_example.cpp.hex contains 3894 bytes
avrdude: reading on-chip flash data:
Reading | ################################################## | 100% 7.21s

avrdude: verifying ...
avrdude: 3894 bytes of flash verified
avrdude: safemode: Fuses OK
avrdude done.  Thank you.













Jul 6, 2012

Making Two-Sided PDFs with a Single-Sided Scanner

The Canon Automatic Document Feeder (ADF) on my MP-830 is pretty good, has the capability of scanning double-sided pages into a PDF document. However, I was having trouble scanning a large, dog-eared document - it kept jamming after a few pages. I could still scan single-sided pages OK, but that only got me every other page in the document. What to do?
Use the wonderful pdftk, available here for most OS platforms.
The process is as follows:
  1. Scan the ODD pages first, just putting the document through the ADF in the normal reading order. Face up, this will be a stack like: Page 1, 3, 5, .... etc. Save the resulting file as something like doc_odd.pdf
  2. Scan the EVEN pages next. Take the document and TURN IT OVER, so the last page is on TOP. Take the last page and start a new stack with the EVEN side face up. Stack the EVEN pages one-by-one on top of this stack. For example, if you have a 40 page document, page 40 will be on the bottom of this stack, then 38, 36, etc. up to page 2 on the top. It's actually easier to do than describe... Put this stack through the scanner and name the file doc_even.pdf
  3. Put both of the new PDF documents in the same directory
  4. Burst the pages for each of the documents and merge them with the following code:
pdftk doc_odd.pdf burst output doc_pg%04d_A.pdf
pdftk doc_even.pdf burst output doc_pg%04d_B.pdf
pdftk doc_pg*.pdf cat output final_merged_doc_name.pdf
The pages will be combined in the order of: 1A/1B, 2A/2B and so on, giving the correct odd/even ordering.

There is a script for this documented here.