Camera Hack

December 18, 2013 § Leave a comment

I have got a couple of webcams, those seems useless to me.

Sometimes i dream to have a binocular which can do video recording and zoom further away just like the spy movies ha ha. So this story is an attempt to make such thing. Not actually the camera in the spy movies, somewhat close to that what i want to build.

So that is the idea, and i started with a couple of magnifying glasses and arranged in series in a line through my window, and started projecting the objects that i can see through my window on a white sheet of paper.

Most of the camera’s uses the same technology to project an image on a slide of film or on a CCD/CMOS camera sensor.

Then I’ve bought a webcam, disassembled it opened the lens and put my magnifying glass on the CMOS sensor and started playing with that level of zoom 😀 . It gave me an awesome result but also have caused some problem.

The magnifying glass combination was not perfect for me cause i can’t customize their magnifying factor/customized magnifying glasses are not available in the local market, the distance of the glass and sensor can not be controllable via electronics(though controllable by hand)/it is hard to make such hardware for me and it is not compact. So, i have searched for a long time to find commercially available zoom lenses/lense used in SLR camera.

But, those are too pricey for me to use in a project. I kept on searching.

One day my digital camera has some problem and repaired it in local camera repairing store. I asked them would they have any damaged/faulty camera and if they want to sell it. They answered no. it was quite hard for me to hear that answer. They told me that sometimes the old camera parts is very useful for them to repair a new one.

I had a scope. I asked them that if there was any such old camera that’s parts cannot reusable then i am going to buy it. They asked me what i want to do with it. I answered about my project. and they gave me a lens of an old handycam.

I opened it, It has some lenses, two stepper motors, and two sensors(i mean infrared limit switch).

I’ve put my webcam on the CCD slot of the lens unit. For this, i had to cut down my webcam motherboard a little bit. If you are going to do this project then you must understand what parts of your webcam motherboard is safest to cut down. Then i removed the two steppers and started playing with the lens unit.

It gave me awesome result. Maybe 20X zoom capability 😀 .

And i started to make a project in arduino to control the steppers by a computer.

It was another story, I will tell you later. Till then………..

Atmega32 usbasploader-3

December 15, 2013 § Leave a comment

Description about the hardware part:

DSC00629done

I’m sorry i can’t give you the exact circuit diagram because i have made this project before one year and that was a trial and error based project so no exact schematic had been made. After having success on this project, i was so excited that i had no time to draw a complete circuit diagram. But i will give you some clue and results. The main theory is just combine the usbasploader(here) hardware with my pinouts.

As written in the code,

#define USB_CFG_IOPORTNAME D
#define USB_CFG_DMINUS_BIT 1
#define USB_CFG_DPLUS_BIT  2

That means the D+ pin is PD2
And the D- pin is PD1 of the Atmega32 microcontroller.

And the board is made on a double layer veroboard 😀 . Actually it is not a double layer veroboard. It is a bit made of two different slices of veroboard. And i have cut a big hole inside of the top layer to insert the crystal and other parts. I have cut it for my fun only, it’s not essential.  If you can put the crystal and other things on the reverse side of the top layer, then it will be perfect. I have mounted the whole microcontroller circuit on the top layer and added the essential parts to able to run it without the bottom layer.

DSC00617done DSC00619done

The bottom layer has the USB voltage driver/dropper circuit from vusb with a couple of zener diodes, some resistors, a USB-B mini port and some resistors. I mean the USB-B female port is very much essential here. We know that the 4th pin of the USB-B mini port is unused. And we also know that we need a jumper for usbasploader. So,I have disassembled the USB data cable and shorted the 4th pin with the 5th pin or easily saying that 4th pin to ground and the 4th pin of the female jack of the USB-B mini on the circuit board is connected with PD0 as says the following line of the configuration code.

#define JUMPER_BIT 0

So, whenever you inserted the cable, after pressing the reset button, the microcontroller automatically goes to programming mode. Isn’t the feature beautiful and essential? And after removing the cable, the microcontroller always goes to run mode.

DSC00626done DSC00627done DSC00631done DSC00625done DSC00624done

Atmega32 usbasploader-2

December 14, 2013 § 1 Comment

Now I will describe the bootloader software part.

I have faced and i know that almost everyone faces problem with the boot-loader. The boot-loader/hardware miss-configuration makes it impossible to work and falls us into frustration. It takes 3 months for me to have a success.

I have compiled these with WINAVR in windows xp/7 successfully.

Download the Winavr from sourceforge, install it. Download the usbasp package, unzip it.

Then you only need to make the following files. The files will be exactly look like-

1. bootloaderconfig.h

</pre>
/* Name: bootloaderconfig.h
 * Project: USBaspLoader
 * Author: Christian Starkjohann
 * Creation Date: 2007-12-08
 * Tabsize: 4
 * Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
 * License: GNU GPL v2 (see License.txt)
 * This Revision: $Id: bootloaderconfig.h 729 2009-03-20 09:03:58Z cs $
 */

#ifndef __bootloaderconfig_h_included__
#define __bootloaderconfig_h_included__

/*
General Description:
This file (together with some settings in Makefile) configures the boot loader
according to the hardware.

This file contains (besides the hardware configuration normally found in
usbconfig.h) two functions or macros: bootLoaderInit() and
bootLoaderCondition(). Whether you implement them as macros or as static
inline functions is up to you, decide based on code size and convenience.

bootLoaderInit() is called as one of the first actions after reset. It should
be a minimum initialization of the hardware so that the boot loader condition
can be read. This will usually consist of activating a pull-up resistor for an
external jumper which selects boot loader mode.

bootLoaderCondition() is called immediately after initialization and in each
main loop iteration. If it returns TRUE, the boot loader will be active. If it
returns FALSE, the boot loader jumps to address 0 (the loaded application)
immediately.

For compatibility with Thomas Fischl's avrusbboot, we also support the macro
names BOOTLOADER_INIT and BOOTLOADER_CONDITION for this functionality. If
these macros are defined, the boot loader usees them.
*/

/* ---------------------------- Hardware Config ---------------------------- */

#define USB_CFG_IOPORTNAME D
/* This is the port where the USB bus is connected. When you configure it to
 * "B", the registers PORTB, PINB and DDRB will be used.
 */
#define USB_CFG_DMINUS_BIT 1
/* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected.
 * This may be any bit in the port.
 */
#define USB_CFG_DPLUS_BIT 2
/* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected.
 * This may be any bit in the port. Please note that D+ must also be connected
 * to interrupt pin INT0!
 */
#define USB_CFG_CLOCK_KHZ (F_CPU/1000)
/* Clock rate of the AVR in MHz. Legal values are 12000, 16000 or 16500.
 * The 16.5 MHz version of the code requires no crystal, it tolerates +/- 1%
 * deviation from the nominal frequency. All other rates require a precision
 * of 2000 ppm and thus a crystal!
 * Default if not specified: 12 MHz
 */

/* ----------------------- Optional Hardware Config ------------------------ */

/* #define USB_CFG_PULLUP_IOPORTNAME D */
/* If you connect the 1.5k pullup resistor from D- to a port pin instead of
 * V+, you can connect and disconnect the device from firmware by calling
 * the macros usbDeviceConnect() and usbDeviceDisconnect() (see usbdrv.h).
 * This constant defines the port on which the pullup resistor is connected.
 */
/* #define USB_CFG_PULLUP_BIT 4 */
/* This constant defines the bit number in USB_CFG_PULLUP_IOPORT (defined
 * above) where the 1.5k pullup resistor is connected. See description
 * above for details.
 */

/* ------------------------------------------------------------------------- */
/* ---------------------- feature / code size options ---------------------- */
/* ------------------------------------------------------------------------- */

#define HAVE_EEPROM_PAGED_ACCESS 1
/* If HAVE_EEPROM_PAGED_ACCESS is defined to 1, page mode access to EEPROM is
 * compiled in. Whether page mode or byte mode access is used by AVRDUDE
 * depends on the target device. Page mode is only used if the device supports
 * it, e.g. for the ATMega88, 168 etc. You can save quite a bit of memory by
 * disabling page mode EEPROM access. Costs ~ 138 bytes.
 */
#define HAVE_EEPROM_BYTE_ACCESS 1
/* If HAVE_EEPROM_BYTE_ACCESS is defined to 1, byte mode access to EEPROM is
 * compiled in. Byte mode is only used if the device (as identified by its
 * signature) does not support page mode for EEPROM. It is required for
 * accessing the EEPROM on the ATMega8. Costs ~54 bytes.
 */
#define BOOTLOADER_CAN_EXIT 1
/* If this macro is defined to 1, the boot loader will exit shortly after the
 * programmer closes the connection to the device. Costs ~36 bytes.
 */
#define HAVE_CHIP_ERASE 0
/* If this macro is defined to 1, the boot loader implements the Chip Erase
 * ISP command. Otherwise pages are erased on demand before they are written.
 */
//#define SIGNATURE_BYTES 0x1e, 0x93, 0x07, 0 /* ATMega8 */
/* This macro defines the signature bytes returned by the emulated USBasp to
 * the programmer software. They should match the actual device at least in
 * memory size and features. If you don't define this, values for ATMega8,
 * ATMega88, ATMega168 and ATMega328 are guessed correctly.
 */

/* The following block guesses feature options so that the resulting code
 * should fit into 2k bytes boot block with the given device and clock rate.
 * Activate by passing "-DUSE_AUTOCONFIG=1" to the compiler.
 * This requires gcc 3.4.6 for small enough code size!
 */
#if USE_AUTOCONFIG
# undef HAVE_EEPROM_PAGED_ACCESS
# define HAVE_EEPROM_PAGED_ACCESS (USB_CFG_CLOCK_KHZ >= 16000)
# undef HAVE_EEPROM_BYTE_ACCESS
# define HAVE_EEPROM_BYTE_ACCESS 1
# undef BOOTLOADER_CAN_EXIT
# define BOOTLOADER_CAN_EXIT 1
# undef SIGNATURE_BYTES
#endif /* USE_AUTOCONFIG */

/* ------------------------------------------------------------------------- */

/* Example configuration: Port D bit 3 is connected to a jumper which ties
 * this pin to GND if the boot loader is requested. Initialization allows
 * several clock cycles for the input voltage to stabilize before
 * bootLoaderCondition() samples the value.
 * We use a function for bootLoaderInit() for convenience and a macro for
 * bootLoaderCondition() for efficiency.
 */

#ifndef __ASSEMBLER__ /* assembler cannot parse function definitions */

#define JUMPER_BIT 0 /* jumper is connected to this bit in port D, active low */

#ifndef MCUCSR /* compatibility between ATMega8 and ATMega88 */
# define MCUCSR MCUSR
#endif

static inline void bootLoaderInit(void)
{
 PORTD |= (1 << JUMPER_BIT); /* activate pull-up */
 if(!(MCUCSR & (1 << EXTRF))) /* If this was not an external reset, ignore */
 leaveBootloader();
 MCUCSR = 0; /* clear all reset flags for next time */
}

static inline void bootLoaderExit(void)
{
 PORTD = 0; /* undo bootLoaderInit() changes */
}

#define bootLoaderCondition() ((PIND & (1 << JUMPER_BIT)) == 0)

#endif /* __ASSEMBLER__ */

/* ------------------------------------------------------------------------- */

#endif /* __bootloader_h_included__ */
<pre>

2. Makefile

</pre>
/* Name: bootloaderconfig.h
 * Project: USBaspLoader
 * Author: Christian Starkjohann
 * Creation Date: 2007-12-08
 * Tabsize: 4
 * Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
 * License: GNU GPL v2 (see License.txt)
 * This Revision: $Id: bootloaderconfig.h 729 2009-03-20 09:03:58Z cs $
 */

#ifndef __bootloaderconfig_h_included__
#define __bootloaderconfig_h_included__

/*
General Description:
This file (together with some settings in Makefile) configures the boot loader
according to the hardware.

This file contains (besides the hardware configuration normally found in
usbconfig.h) two functions or macros: bootLoaderInit() and
bootLoaderCondition(). Whether you implement them as macros or as static
inline functions is up to you, decide based on code size and convenience.

bootLoaderInit() is called as one of the first actions after reset. It should
be a minimum initialization of the hardware so that the boot loader condition
can be read. This will usually consist of activating a pull-up resistor for an
external jumper which selects boot loader mode.

bootLoaderCondition() is called immediately after initialization and in each
main loop iteration. If it returns TRUE, the boot loader will be active. If it
returns FALSE, the boot loader jumps to address 0 (the loaded application)
immediately.

For compatibility with Thomas Fischl's avrusbboot, we also support the macro
names BOOTLOADER_INIT and BOOTLOADER_CONDITION for this functionality. If
these macros are defined, the boot loader usees them.
*/

/* ---------------------------- Hardware Config ---------------------------- */

#define USB_CFG_IOPORTNAME D
/* This is the port where the USB bus is connected. When you configure it to
 * "B", the registers PORTB, PINB and DDRB will be used.
 */
#define USB_CFG_DMINUS_BIT 1
/* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected.
 * This may be any bit in the port.
 */
#define USB_CFG_DPLUS_BIT 2
/* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected.
 * This may be any bit in the port. Please note that D+ must also be connected
 * to interrupt pin INT0!
 */
#define USB_CFG_CLOCK_KHZ (F_CPU/1000)
/* Clock rate of the AVR in MHz. Legal values are 12000, 16000 or 16500.
 * The 16.5 MHz version of the code requires no crystal, it tolerates +/- 1%
 * deviation from the nominal frequency. All other rates require a precision
 * of 2000 ppm and thus a crystal!
 * Default if not specified: 12 MHz
 */

/* ----------------------- Optional Hardware Config ------------------------ */

/* #define USB_CFG_PULLUP_IOPORTNAME D */
/* If you connect the 1.5k pullup resistor from D- to a port pin instead of
 * V+, you can connect and disconnect the device from firmware by calling
 * the macros usbDeviceConnect() and usbDeviceDisconnect() (see usbdrv.h).
 * This constant defines the port on which the pullup resistor is connected.
 */
/* #define USB_CFG_PULLUP_BIT 4 */
/* This constant defines the bit number in USB_CFG_PULLUP_IOPORT (defined
 * above) where the 1.5k pullup resistor is connected. See description
 * above for details.
 */

/* ------------------------------------------------------------------------- */
/* ---------------------- feature / code size options ---------------------- */
/* ------------------------------------------------------------------------- */

#define HAVE_EEPROM_PAGED_ACCESS 1
/* If HAVE_EEPROM_PAGED_ACCESS is defined to 1, page mode access to EEPROM is
 * compiled in. Whether page mode or byte mode access is used by AVRDUDE
 * depends on the target device. Page mode is only used if the device supports
 * it, e.g. for the ATMega88, 168 etc. You can save quite a bit of memory by
 * disabling page mode EEPROM access. Costs ~ 138 bytes.
 */
#define HAVE_EEPROM_BYTE_ACCESS 1
/* If HAVE_EEPROM_BYTE_ACCESS is defined to 1, byte mode access to EEPROM is
 * compiled in. Byte mode is only used if the device (as identified by its
 * signature) does not support page mode for EEPROM. It is required for
 * accessing the EEPROM on the ATMega8. Costs ~54 bytes.
 */
#define BOOTLOADER_CAN_EXIT 1
/* If this macro is defined to 1, the boot loader will exit shortly after the
 * programmer closes the connection to the device. Costs ~36 bytes.
 */
#define HAVE_CHIP_ERASE 0
/* If this macro is defined to 1, the boot loader implements the Chip Erase
 * ISP command. Otherwise pages are erased on demand before they are written.
 */
//#define SIGNATURE_BYTES 0x1e, 0x93, 0x07, 0 /* ATMega8 */
/* This macro defines the signature bytes returned by the emulated USBasp to
 * the programmer software. They should match the actual device at least in
 * memory size and features. If you don't define this, values for ATMega8,
 * ATMega88, ATMega168 and ATMega328 are guessed correctly.
 */

/* The following block guesses feature options so that the resulting code
 * should fit into 2k bytes boot block with the given device and clock rate.
 * Activate by passing "-DUSE_AUTOCONFIG=1" to the compiler.
 * This requires gcc 3.4.6 for small enough code size!
 */
#if USE_AUTOCONFIG
# undef HAVE_EEPROM_PAGED_ACCESS
# define HAVE_EEPROM_PAGED_ACCESS (USB_CFG_CLOCK_KHZ >= 16000)
# undef HAVE_EEPROM_BYTE_ACCESS
# define HAVE_EEPROM_BYTE_ACCESS 1
# undef BOOTLOADER_CAN_EXIT
# define BOOTLOADER_CAN_EXIT 1
# undef SIGNATURE_BYTES
#endif /* USE_AUTOCONFIG */

/* ------------------------------------------------------------------------- */

/* Example configuration: Port D bit 3 is connected to a jumper which ties
 * this pin to GND if the boot loader is requested. Initialization allows
 * several clock cycles for the input voltage to stabilize before
 * bootLoaderCondition() samples the value.
 * We use a function for bootLoaderInit() for convenience and a macro for
 * bootLoaderCondition() for efficiency.
 */

#ifndef __ASSEMBLER__ /* assembler cannot parse function definitions */

#define JUMPER_BIT 0 /* jumper is connected to this bit in port D, active low */

#ifndef MCUCSR /* compatibility between ATMega8 and ATMega88 */
# define MCUCSR MCUSR
#endif

static inline void bootLoaderInit(void)
{
 PORTD |= (1 << JUMPER_BIT); /* activate pull-up */
 if(!(MCUCSR & (1 << EXTRF))) /* If this was not an external reset, ignore */
 leaveBootloader();
 MCUCSR = 0; /* clear all reset flags for next time */
}

static inline void bootLoaderExit(void)
{
 PORTD = 0; /* undo bootLoaderInit() changes */
}

#define bootLoaderCondition() ((PIND & (1 << JUMPER_BIT)) == 0)

#endif /* __ASSEMBLER__ */

/* ------------------------------------------------------------------------- */

#endif /* __bootloader_h_included__ */
<pre>

Then run command prompt, cd to the folder where you unzipped, then type the commands and press enter.
1. To Compile And Upload To Microcontroller-
make flash
2. To Set Fusebits
make fuse
3. To Set Lockbits.
make lock
Issue these commands and enjoy. I will come later with the circuit diagram. But it’s already written in the codes. 😀

Ok, And for better help(also less explaining for me :p ) I uploaded complete package zipped, Click here to download it. The .bat scripts helps to avoid the damn command prompt.  You can play with them but be careful(they can blow your PC off :p ).

Where Am I?

You are currently viewing the archives for December, 2013 at khairulhasanmd.

%d bloggers like this: