Braille E-Book Reader Lane Detection Laser Tracker Grid Follower Field Strength Detector

Thursday, December 11, 2014

Interfacing SD-Card with AVR ATMEGA16: Part 2

     Hello friends, In this part of the tutorial, we will see how SD-Card is wired with ATMEGA16. SD-Card requires a 3.3 V supply, so we will first make a circuit for the same purpose. You can use  voltage regulators like LM117(fixed 3.3 V output) or variable one like the popular LM317. There is no need to heat sink these IC's for present application, as the power dissipation is quite small. I prefer using LM317 (TO-223 pacakage) ;It can be easily soldered, is easily available and the circuit needs only a few supplementary passive components.Go ahead with the following circuit.

 Tested with R2=360 Ohm and R1=240 Ohm.
    If you get an output voltage with about deviation under 200 milivolts from 3.3 V, its perfect! Else, try tweaking the values of the resistors a little bit until you get that. Well, we now constructed a  power supply for the card. The next step is to build a logic converter circuit to interface AVR with SD Card. Its not always necessary to have an interface circuit, however it's essential if the AVR is operating at a voltage other than 3.3 V. When not working with same voltage, the SD Card needs a logic level converter to convey its 3.3 V signal to  AVR and vice versa.
    There are a couple of methods to build one, however we will be going with voltage divider method, as I think it's far simpler and works almost all of the time. However, you can explore other methods like the pull resistor method or you would be lucky to get  a readymade IC for the purpose.

Voltage divider method:

 With Vs as the primary supply voltage to system, calculation of R2 and R1 is pretty simple:

Now lets say your microcontroller is working on 5 V, then ratio R2 comes out to be twice of R1. 

Try R2 and R1 as per your convenience, in range of 1 KOhm - 50 KOhm. I had successfully tested this circuit with R2 = 2.2 KOhm , R1 = 1.1 KOhm.

    Having done that, power the SD Card with 3.3 V power supply,  which we had made using LM317. You can even design both the circuits(supply and logic converter) on same board, it will be actually  simple that way
     Usually, we don’t get 9 Pin MMC card in market nowadays as they have become obsolete. However, there are a variety of microSD cards available, which are compatible with cellphones, mp3 players and other such sort of devices. So, we can comfortably use such a microSD card with adapter(the black one) to serve our purpose .This  adapter needs  another card socket, which requires great care in soldering. Also, its SMD soldering pads are very fine and delicate. 

microSD with Adapter

SD Card Adapter Socket

     Well here's a trick if dont't want to mess up with SMD connector. It could save your time and efforts(and frustration too!). Solder a 9 X 1 male  berg strip to pinouts of adapter as shown in the figure below. Solder a 9 X 1 female berg strip as you pin out on the interface circuit. This method allows easy plug-in and out of adapter without damaging it.

     With this we complete the hardware designing  part.  I understand that hardware part will be challenging for some of you, as you might not have access to quality components or required testing instruments. I faced those problem too, but don't lose hope and search for alternatives and they would also work fine.If you face any problems with the circuits, feel free to contact me and I would see what can I do for you!
     In the next tutorial we will be dealing with the firmware which needs to dumped into the micro-controller. Have a nice day!

Tuesday, September 30, 2014

Interfacing SD-Card with AVR ATMEGA16: Part 1

     Hello friends, this is the first part in the tutorial series which will teach you to use a simple SD Card for your cool projects with AVR ATMEGA. Secure Disk Card (SDC) is a versatile and compact storage peripheral. It is widely used for file storage, owing to its small size and compatibly with almost all of the digital devices. Application of SD-CARD can be extended to overcome data storage limits in embedded systems. In this tutorial, we will be seeing how to interface SD-Card with AVR family microcontroller .  We will be using the popular ATMEGA 16  for demonstration, but the method can be extended to any 8 bit MCU. However, as a prerequisite , I urge you to brush up your C programming and go through datasheet of ATMEGA16 (particularly the SPI part).   
     So, let’s have a quick review of the basics of SD card. SDC is the upgraded standard of Multimedia Card with improved compatibility with numerous digital devices and has remarkably higher storage capacity. It contains array of flash memory and  inbuilt microcontroller to handle data requests. SDC supports two protocols; SD and SPI (Serial Peripheral Interface). We will be using the SPI protocol, as it easy and provides  speed about 100 KHz-500 Kz, which is sufficient for various application on ATMEGA16.
     Although older versions of Multimedia Cards( MMC)  are out of fashion, recent SD-Card follows the same pin connections for SPI . microSD is widely used today due to its convenient design which suits most of the digital devices and can be easily adopted for SD interface using a suitable adapter. As we will be using SPI mode, we have to be only concerned about four SPI and two power supply  pin, no matter which type of card is used.

Diagram shows pinouts of microSD, SD and MMC card. MicroSD can be easily turned into SD with Adapter.

SPI Mode

     Serial Peripheral Interface(SPI) enables synchronous communication between two devices supporting this protocol with efficient speed. ATMEGA16(acts as master) communicates with microcontroller in SDC(acts as slave) using SPI protocol. This mode is characterized by MISO, MOSI, CS and SCLK (refer datasheet ATMEGA16 ) :

Master In Slave Out (MISO):  Data  transferred from slave to master device.
Master Out Slave In (MOSI):  Data transferred from master to slave device.
CS: Active Low chip selection of slave by master.
SCLK: Clock Line provided by master to slave for maintaining synchronization between the two.

                SDC works on 3.3V logic and also needs same supply voltage. ATMEGA16 can operate on 3.3V and in such case we can directly connect both the peripherals.
But in most of the applications, ATMEGA16 is powered by 5V DC supply. So there is a need of logic conversion circuitry in between the two peripherals . There are several methods of building one, you can search on internet. However,I personally would suggest  the simple resistor network circuit , as I have myself tested it.  
                    Okay, that's enough of the introduction ,we needed to get started. We will be seeing how to make a interface circuit in the next part of this tutorial. Bye for now and have a nice day!
Please visit maxembedded if you are more curious about SPI.

Monday, September 22, 2014


Hit and trial method for thresholding the region of interest is a time consuming method, specially in case of run time thresholding (ie in case of live video feed). OPENCV provides useful GUI tool for tackling this problem, called TRACKBARS.

Video Tutorial 1:Introduction to OPENCV and Image Processing


This is introductory tutorial to Intel's image processing library OpenCV and Visual Studio 2010.
In this tutorial, we will learn:
1) How to link Opencv libraries with Visual Studio 2010.
2) How to load and display a image file using OpenCV functions.