tag:blogger.com,1999:blog-83151273394830535082015-10-29T16:49:57.621+05:30Random StuffA blog about a variety of random stuff that i do in my free time and during my projects.Sudhir guptahttps://plus.google.com/105460425718553468371noreply@blogger.comBlogger24125tag:blogger.com,1999:blog-8315127339483053508.post-75074251685351505062015-09-28T01:12:00.000+05:302015-09-28T01:13:29.009+05:30Getting data from ADXL345 From USART - ATmega32<div dir="ltr" style="text-align: left;" trbidi="on"><div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/-z3IVnYw8ur8/VghD4sN7QLI/AAAAAAAACrI/nxJJQifVzoA/s1600/adi_adxl345a.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-z3IVnYw8ur8/VghD4sN7QLI/AAAAAAAACrI/nxJJQifVzoA/s1600/adi_adxl345a.jpg" /></a></div><br /><br /><br />A small update on Interfacing ADXL345 with ATmega32, this program will get raw data from ADXL345 working on I2C mode and send the data over USART. <br /><br />To recieve data to PC over USART see <a href="http://www.randomstuff.co.in/2013/10/usart-with-atmega32.html" target="_blank">this</a>.<br /><br /><a name='more'></a><br /><!-- HTML generated using hilite.me --><br /><div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;"><table><tbody><tr><td><pre style="line-height: 125%; margin: 0;"> 1<br /> 2<br /> 3<br /> 4<br /> 5<br /> 6<br /> 7<br /> 8<br /> 9<br /> 10<br /> 11<br /> 12<br /> 13<br /> 14<br /> 15<br /> 16<br /> 17<br /> 18<br /> 19<br /> 20<br /> 21<br /> 22<br /> 23<br /> 24<br /> 25<br /> 26<br /> 27<br /> 28<br /> 29<br /> 30<br /> 31<br /> 32<br /> 33<br /> 34<br /> 35<br /> 36<br /> 37<br /> 38<br /> 39<br /> 40<br /> 41<br /> 42<br /> 43<br /> 44<br /> 45<br /> 46<br /> 47<br /> 48<br /> 49<br /> 50<br /> 51<br /> 52<br /> 53<br /> 54<br /> 55<br /> 56<br /> 57<br /> 58<br /> 59<br /> 60<br /> 61<br /> 62<br /> 63<br /> 64<br /> 65<br /> 66<br /> 67<br /> 68<br /> 69<br /> 70<br /> 71<br /> 72<br /> 73<br /> 74<br /> 75<br /> 76<br /> 77<br /> 78<br /> 79<br /> 80<br /> 81<br /> 82<br /> 83<br /> 84<br /> 85<br /> 86<br /> 87<br /> 88<br /> 89<br /> 90<br /> 91<br /> 92<br /> 93<br /> 94<br /> 95<br /> 96<br /> 97<br /> 98<br /> 99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br />159<br />160<br />161<br />162<br />163<br />164<br />165<br />166<br />167<br />168<br />169<br />170<br />171<br />172<br />173<br />174<br />175<br />176<br />177<br />178<br />179<br />180<br />181<br />182<br />183<br />184<br />185<br />186<br />187<br />188<br />189<br />190<br />191<br />192<br />193<br />194<br />195<br />196<br />197<br />198<br />199<br />200<br />201<br />202<br />203<br />204<br />205<br />206<br />207<br />208<br />209<br />210<br />211<br />212<br />213<br />214<br />215<br />216<br />217<br />218<br />219<br />220<br />221<br />222<br />223<br />224<br />225<br />226<br />227<br />228<br />229<br />230<br />231<br />232<br />233<br />234<br />235<br />236<br />237<br />238<br />239<br />240<br />241<br />242<br />243<br />244<br />245<br />246<br />247<br />248<br />249<br />250<br />251<br />252<br />253<br />254<br />255<br />256<br />257<br />258<br />259<br />260<br />261<br />262<br />263<br />264<br />265<br />266<br />267<br />268<br />269<br />270<br />271<br />272<br />273<br />274<br />275<br />276</pre></td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #557799;">#include<avr/io.h></span><br /><span style="color: #557799;">#include<inttypes.h></span><br /><span style="color: #557799;">#include<util/delay.h></span><br /><span style="color: #557799;">#include<math.h></span><br /><br /><span style="color: #557799;">#define F_CPU 8000000UL</span><br /><span style="color: #557799;">#define error 0</span><br /><span style="color: #557799;">#define success 1</span><br /><br /><span style="color: #888888;">//USART</span><br /><span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">USART_Init</span>( <span style="color: #333399; font-weight: bold;">unsigned</span> <span style="color: #333399; font-weight: bold;">int</span> baud )<br />{<br /> <span style="color: #888888;">/* Set baud rate */</span><br /> UBRRH <span style="color: #333333;">=</span> (<span style="color: #333399; font-weight: bold;">unsigned</span> <span style="color: #333399; font-weight: bold;">char</span>)(baud<span style="color: #333333;">>></span><span style="color: #0000dd; font-weight: bold;">8</span>);<br /> UBRRL <span style="color: #333333;">=</span> (<span style="color: #333399; font-weight: bold;">unsigned</span> <span style="color: #333399; font-weight: bold;">char</span>)baud;<br /> <span style="color: #888888;">/* Enable transmitter and receiver */</span><br /> UCSRB <span style="color: #333333;">=</span> (<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>TXEN)<span style="color: #333333;">|</span>(<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>RXEN);<br /> <span style="color: #888888;">/* Set frame format: 8data, 2stop bit */</span><br /> UCSRC <span style="color: #333333;">=</span> (<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>URSEL)<span style="color: #333333;">|</span>(<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>USBS)<span style="color: #333333;">|</span>(<span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;"><<</span>UCSZ0);<br />}<br /><br /><span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">USART_Transmit_char</span>(<span style="color: #333399; font-weight: bold;">char</span> txdata )<br />{<br /> <span style="color: #888888;">/* Wait for empty transmit buffer */</span><br /> <span style="color: #008800; font-weight: bold;">while</span> ( <span style="color: #333333;">!</span>( UCSRA <span style="color: #333333;">&</span> (<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>UDRE)) )<br /> ;<br /> <span style="color: #888888;">/* Put data into buffer, sends the data */</span><br /> UDR <span style="color: #333333;">=</span> txdata;<br />}<br /><br /><span style="color: #333399; font-weight: bold;">unsigned</span> <span style="color: #333399; font-weight: bold;">char</span> <span style="color: #0066bb; font-weight: bold;">USART_Receive</span>( <span style="color: #333399; font-weight: bold;">void</span> )<br />{<br /> <span style="color: #888888;">/* Wait for data to be received */</span><br /> <span style="color: #008800; font-weight: bold;">while</span> ( <span style="color: #333333;">!</span>(UCSRA <span style="color: #333333;">&</span> (<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>RXC)) );<br /> <span style="color: #888888;">/* Get and return received data from buffer */</span><br /> <span style="color: #008800; font-weight: bold;">return</span> UDR;<br />}<br /><br /><span style="color: #888888;">//This function can only send three digit integers.</span><br /><span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">USART_Transmit_int</span>(<span style="color: #333399; font-weight: bold;">unsigned</span> <span style="color: #333399; font-weight: bold;">int</span> i)<br />{<br /> <span style="color: #333399; font-weight: bold;">unsigned</span> <span style="color: #333399; font-weight: bold;">char</span> h,t,o;<br /> o<span style="color: #333333;">=</span> (i<span style="color: #333333;">%</span><span style="color: #0000dd; font-weight: bold;">10</span>) <span style="color: #333333;">|</span> <span style="color: #005588; font-weight: bold;">0x30</span>;<span style="color: #888888;">//ones</span><br /> i<span style="color: #333333;">/=</span><span style="color: #0000dd; font-weight: bold;">10</span>;<br /> t<span style="color: #333333;">=</span> (i<span style="color: #333333;">%</span><span style="color: #0000dd; font-weight: bold;">10</span>) <span style="color: #333333;">|</span> <span style="color: #005588; font-weight: bold;">0x30</span>;<span style="color: #888888;">//tens</span><br /> i<span style="color: #333333;">=</span>i<span style="color: #333333;">%</span><span style="color: #0000dd; font-weight: bold;">100</span>;<br /> h<span style="color: #333333;">=</span>(i<span style="color: #333333;">/</span><span style="color: #0000dd; font-weight: bold;">10</span>) <span style="color: #333333;">|</span> <span style="color: #005588; font-weight: bold;">0x30</span>;<span style="color: #888888;">//hundreds</span><br /> USART_Transmit_char(h);<br /> USART_Transmit_char(t);<br /> USART_Transmit_char(o);<br />}<br /><span style="color: #888888;">//Can only send xxx.xx type number</span><br /><span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">USART_Transmit_float</span>(<span style="color: #008800; font-weight: bold;">const</span> <span style="color: #333399; font-weight: bold;">float</span> f)<br />{<br /> <span style="color: #333399; font-weight: bold;">unsigned</span> <span style="color: #333399; font-weight: bold;">int</span> v,p;<br /> <span style="color: #333399; font-weight: bold;">long</span> <span style="color: #333399; font-weight: bold;">int</span> num;<br /> num<span style="color: #333333;">=</span>f<span style="color: #333333;">*</span><span style="color: #0000dd; font-weight: bold;">1000</span>;<br /> p<span style="color: #333333;">=</span>num<span style="color: #333333;">%</span><span style="color: #0000dd; font-weight: bold;">1000</span>;<br /> num<span style="color: #333333;">=</span>num<span style="color: #333333;">/</span><span style="color: #0000dd; font-weight: bold;">1000</span>;<br /> v<span style="color: #333333;">=</span>num;<br /><br /> USART_Transmit_int(v);<br /> USART_Transmit_char(<span style="color: #0044dd;">'.'</span>);<br /> USART_Transmit_int(p);<br /><br />}<br /><br /><span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">USART_Transmit</span>(<span style="color: #333399; font-weight: bold;">char</span><span style="color: #333333;">*</span> txdata)<br />{<br /> <span style="color: #333399; font-weight: bold;">int</span> i <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span>;<br /> <span style="color: #008800; font-weight: bold;">while</span>(txdata[i] <span style="color: #333333;">!=</span> <span style="color: #005588; font-weight: bold;">0x00</span>)<br /> {<br /> USART_Transmit_char(txdata[i]);<br /> i<span style="color: #333333;">++</span>;<br /> }<br /><br />}<br /><br /><span style="color: #888888;">//TWI Initialization</span><br /><span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">TWI_Init</span>(<span style="color: #333399; font-weight: bold;">void</span>)<br />{<br /> <span style="color: #888888;">//set SCL to 400kHz</span><br /> TWSR <span style="color: #333333;">=</span> <span style="color: #005588; font-weight: bold;">0x00</span>;<br /> TWBR <span style="color: #333333;">=</span> <span style="color: #005588; font-weight: bold;">0x02</span>;<br /> <span style="color: #888888;">//enable TWI</span><br /> TWCR <span style="color: #333333;">=</span> (<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>TWEN);<br />}<br /><br /><span style="color: #888888;">//TWI Start Singnal</span><br /><span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">TWI_Start</span>(<span style="color: #333399; font-weight: bold;">void</span>)<br />{<br /> TWCR <span style="color: #333333;">=</span> (<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>TWINT)<span style="color: #333333;">|</span>(<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>TWSTA)<span style="color: #333333;">|</span>(<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>TWEN);<br /> <span style="color: #008800; font-weight: bold;">while</span> ((TWCR <span style="color: #333333;">&</span> (<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>TWINT)) <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">0</span>);<br />}<br /><br /><span style="color: #888888;">//TWI fuction tio retrieve the status</span><br /><span style="color: #333399; font-weight: bold;">uint8_t</span> <span style="color: #0066bb; font-weight: bold;">TWI_GetStatus</span>(<span style="color: #333399; font-weight: bold;">void</span>)<br />{<br /> <span style="color: #333399; font-weight: bold;">uint8_t</span> status;<br /> <span style="color: #888888;">//mask status</span><br /> status <span style="color: #333333;">=</span> TWSR <span style="color: #333333;">&</span> <span style="color: #005588; font-weight: bold;">0xF8</span>;<br /> <span style="color: #008800; font-weight: bold;">return</span> status;<br />}<br /><br /><span style="color: #888888;">//Write command for TWI</span><br /><span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">TWI_Write</span>(<span style="color: #333399; font-weight: bold;">uint8_t</span> u8data)<br />{<br /> TWDR <span style="color: #333333;">=</span> u8data;<br /> TWCR <span style="color: #333333;">=</span> (<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>TWINT)<span style="color: #333333;">|</span>(<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>TWEN);<br /> <span style="color: #008800; font-weight: bold;">while</span> ((TWCR <span style="color: #333333;">&</span> (<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>TWINT)) <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">0</span>);<br />}<br /><br /><br /><span style="color: #888888;">//Read NACK for TWI</span><br /><span style="color: #888888;">//Return read data from TWCR</span><br /><span style="color: #333399; font-weight: bold;">uint8_t</span> <span style="color: #0066bb; font-weight: bold;">TWIReadNACK</span>(<span style="color: #333399; font-weight: bold;">void</span>)<br />{<br /> TWCR <span style="color: #333333;">=</span> (<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>TWINT)<span style="color: #333333;">|</span>(<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>TWEN);<br /> <span style="color: #008800; font-weight: bold;">while</span> ((TWCR <span style="color: #333333;">&</span> (<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>TWINT)) <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">0</span>);<br /> <span style="color: #008800; font-weight: bold;">return</span> TWDR;<br />}<br /><br /><span style="color: #333399; font-weight: bold;">uint8_t</span> <span style="color: #0066bb; font-weight: bold;">TWIReadACK</span>(<span style="color: #333399; font-weight: bold;">void</span>)<br />{<br /> TWCR <span style="color: #333333;">=</span> (<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>TWINT) <span style="color: #333333;">|</span> (<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>TWEN) <span style="color: #333333;">|</span> (<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>TWEA);<br /> <span style="color: #008800; font-weight: bold;">while</span>((TWCR <span style="color: #333333;">&</span> (<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>TWINT)) <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">0</span>);<br /><br /> <span style="color: #008800; font-weight: bold;">return</span> TWDR;<br />}<br /><br /><br /><span style="color: #888888;">//Terminate TWI Interface</span><br /><span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">TWI_Stop</span>(<span style="color: #333399; font-weight: bold;">void</span>)<br />{<br /> TWCR <span style="color: #333333;">=</span> (<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>TWINT) <span style="color: #333333;">|</span> (<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>TWEN) <span style="color: #333333;">|</span> (<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>TWSTO);<br /> <span style="color: #008800; font-weight: bold;">while</span>(TWCR <span style="color: #333333;">&</span> (<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>TWSTO));<br />}<br /><br /><br /><span style="color: #888888;">//Function to write to ADXL345-Accelerometer</span><br /><span style="color: #888888;">//CS has to be high for ADXL345 to work in I2C mode</span><br /><span style="color: #888888;">//Supports standard 100KHz and fast 400KHz Mode</span><br /><span style="color: #888888;">//ALT address pin grounded implies 0xA6 for write and 0xA7 for read</span><br /><span style="color: #333399; font-weight: bold;">uint8_t</span> <span style="color: #0066bb; font-weight: bold;">ADXL_write</span>(<span style="color: #333399; font-weight: bold;">uint8_t</span> reg, <span style="color: #333399; font-weight: bold;">uint8_t</span> data)<br />{<br /> TWI_Start();<br /> <span style="color: #008800; font-weight: bold;">if</span>(TWI_GetStatus() <span style="color: #333333;">!=</span> <span style="color: #005588; font-weight: bold;">0x08</span>)<br /> {<br /> <span style="color: #008800; font-weight: bold;">return</span> error;<br /> }<br /> TWI_Write(<span style="color: #0000dd; font-weight: bold;">0</span>b10100110);<br /> <span style="color: #008800; font-weight: bold;">if</span>(TWI_GetStatus() <span style="color: #333333;">!=</span> <span style="color: #005588; font-weight: bold;">0x18</span>)<br /> {<br /> <span style="color: #008800; font-weight: bold;">return</span> error;<br /> }<br /> TWI_Write(reg);<br /> <span style="color: #008800; font-weight: bold;">if</span>(TWI_GetStatus() <span style="color: #333333;">!=</span> <span style="color: #005588; font-weight: bold;">0x28</span>)<br /> {<br /> <span style="color: #008800; font-weight: bold;">return</span> error;<br /> }<br /> TWI_Write(data);<br /> <span style="color: #008800; font-weight: bold;">if</span>(TWI_GetStatus() <span style="color: #333333;">!=</span> <span style="color: #005588; font-weight: bold;">0x28</span>)<br /> {<br /> <span style="color: #008800; font-weight: bold;">return</span> error;<br /> }<br /> TWI_Stop();<br /> <span style="color: #008800; font-weight: bold;">return</span> success;<br />}<br /><br /><span style="color: #888888;">//Write multiple bits to ADXL345</span><br /><span style="color: #333399; font-weight: bold;">uint8_t</span> <span style="color: #0066bb; font-weight: bold;">ADXL_Multi_write</span>(<span style="color: #333399; font-weight: bold;">uint8_t</span> reg, <span style="color: #333399; font-weight: bold;">uint8_t</span> data1, <span style="color: #333399; font-weight: bold;">uint8_t</span> data2)<br />{<br /> TWI_Start();<br /> <span style="color: #008800; font-weight: bold;">if</span>(TWI_GetStatus() <span style="color: #333333;">!=</span> <span style="color: #005588; font-weight: bold;">0x08</span>)<br /> {<br /> <span style="color: #008800; font-weight: bold;">return</span> error;<br /> }<br /> TWI_Write(<span style="color: #0000dd; font-weight: bold;">0</span>b10100110);<br /> <span style="color: #008800; font-weight: bold;">if</span>(TWI_GetStatus() <span style="color: #333333;">!=</span> <span style="color: #005588; font-weight: bold;">0x18</span>)<br /> {<br /> <span style="color: #008800; font-weight: bold;">return</span> error;<br /> }<br /> TWI_Write(data1);<br /> <span style="color: #008800; font-weight: bold;">if</span>(TWI_GetStatus() <span style="color: #333333;">!=</span> <span style="color: #005588; font-weight: bold;">0x28</span>)<br /> {<br /> <span style="color: #008800; font-weight: bold;">return</span> error;<br /> }<br /> TWI_Write(data2);<br /> <span style="color: #008800; font-weight: bold;">if</span>(TWI_GetStatus() <span style="color: #333333;">!=</span> <span style="color: #005588; font-weight: bold;">0x28</span>)<br /> {<br /> <span style="color: #008800; font-weight: bold;">return</span> error;<br /> }<br /> TWI_Stop();<br /> <span style="color: #008800; font-weight: bold;">return</span> success;<br />}<br /><br /><br /><span style="color: #888888;">//Fuction to read data sent from ADXL Accelerometer</span><br /><span style="color: #333399; font-weight: bold;">uint8_t</span> <span style="color: #0066bb; font-weight: bold;">ADXL_read</span>(<span style="color: #333399; font-weight: bold;">uint8_t</span> reg)<br />{<br /> <span style="color: #333399; font-weight: bold;">uint8_t</span> data;<br /> TWI_Start();<br /> <span style="color: #008800; font-weight: bold;">if</span>(TWI_GetStatus() <span style="color: #333333;">!=</span> <span style="color: #005588; font-weight: bold;">0x08</span>)<br /> {<br /> <span style="color: #008800; font-weight: bold;">return</span> error;<br /> }<br /> TWI_Write(<span style="color: #0000dd; font-weight: bold;">0</span>b10100110);<br /> <span style="color: #008800; font-weight: bold;">if</span>(TWI_GetStatus() <span style="color: #333333;">!=</span> <span style="color: #005588; font-weight: bold;">0x18</span>)<br /> {<br /> <span style="color: #008800; font-weight: bold;">return</span> error;<br /> }<br /> TWI_Write(reg);<br /> <span style="color: #008800; font-weight: bold;">if</span>(TWI_GetStatus() <span style="color: #333333;">!=</span> <span style="color: #005588; font-weight: bold;">0x28</span>)<br /> {<br /> <span style="color: #008800; font-weight: bold;">return</span> error;<br /> }<br /> TWI_Start();<br /> <span style="color: #008800; font-weight: bold;">if</span>(TWI_GetStatus() <span style="color: #333333;">!=</span> <span style="color: #005588; font-weight: bold;">0x10</span>)<br /> {<br /> <span style="color: #008800; font-weight: bold;">return</span> error;<br /> }<br /> TWI_Write(<span style="color: #0000dd; font-weight: bold;">0</span>b10100111);<br /> <span style="color: #008800; font-weight: bold;">if</span>(TWI_GetStatus() <span style="color: #333333;">!=</span> <span style="color: #005588; font-weight: bold;">0x40</span>)<br /> {<br /> <span style="color: #008800; font-weight: bold;">return</span> error;<br /> }<br /> data <span style="color: #333333;">=</span> TWIReadNACK();<br /> <span style="color: #008800; font-weight: bold;">if</span>(TWI_GetStatus() <span style="color: #333333;">!=</span> <span style="color: #005588; font-weight: bold;">0x58</span>)<br /> {<br /> <span style="color: #008800; font-weight: bold;">return</span> error;<br /> }<br /> TWI_Stop();<br /> <span style="color: #008800; font-weight: bold;">return</span> data;<br />}<br /><br /><span style="color: #333399; font-weight: bold;">int</span> <span style="color: #0066bb; font-weight: bold;">main</span> (<span style="color: #333399; font-weight: bold;">void</span>)<br />{<br /> <span style="color: #888888;">//initialize USART</span><br /> USART_Init(<span style="color: #0000dd; font-weight: bold;">51</span>);<br /> <span style="color: #888888;">//USART_Transmit_char('H');</span><br /> <span style="color: #888888;">//initialize TWI</span><br /> TWI_Init();<br /> <span style="color: #888888;">//Initailze ADXL345</span><br /> <span style="color: #333399; font-weight: bold;">uint8_t</span> x1,x2,y1,y2,z1,z2;<br /> <span style="color: #888888;">//set ADXL to 400 Hz</span><br /> ADXL_write(<span style="color: #005588; font-weight: bold;">0x2c</span>,<span style="color: #0000dd; font-weight: bold;">0</span>b00001100);<br /> _delay_ms(<span style="color: #0000dd; font-weight: bold;">100</span>);<br /> ADXL_write(<span style="color: #005588; font-weight: bold;">0x31</span>,<span style="color: #0000dd; font-weight: bold;">0</span>b01000010);<br /> _delay_ms(<span style="color: #0000dd; font-weight: bold;">100</span>);<br /> ADXL_write(<span style="color: #005588; font-weight: bold;">0x2D</span>,<span style="color: #005588; font-weight: bold;">0x00</span>);<br /> _delay_ms(<span style="color: #0000dd; font-weight: bold;">100</span>);<br /> ADXL_write(<span style="color: #005588; font-weight: bold;">0x2d</span>,<span style="color: #005588; font-weight: bold;">0x16</span>);<br /> _delay_ms(<span style="color: #0000dd; font-weight: bold;">100</span>);<br /> ADXL_write(<span style="color: #005588; font-weight: bold;">0x2d</span>,<span style="color: #005588; font-weight: bold;">0x08</span>);<br /> _delay_ms(<span style="color: #0000dd; font-weight: bold;">100</span>);<br /> <span style="color: #008800; font-weight: bold;">while</span>(<span style="color: #0000dd; font-weight: bold;">1</span>)<br /> {<br /> x1 <span style="color: #333333;">=</span> ADXL_read(<span style="color: #005588; font-weight: bold;">0x32</span>);<br /> x2 <span style="color: #333333;">=</span> ADXL_read(<span style="color: #005588; font-weight: bold;">0x33</span>);<br /> y1 <span style="color: #333333;">=</span> ADXL_read(<span style="color: #005588; font-weight: bold;">0x34</span>);<br /> y2 <span style="color: #333333;">=</span> ADXL_read(<span style="color: #005588; font-weight: bold;">0x35</span>);<br /> z1 <span style="color: #333333;">=</span> ADXL_read(<span style="color: #005588; font-weight: bold;">0x36</span>);<br /> z2 <span style="color: #333333;">=</span> ADXL_read(<span style="color: #005588; font-weight: bold;">0x37</span>);<br /> x1 <span style="color: #333333;">+=</span> (x2<span style="color: #333333;"><<</span><span style="color: #0000dd; font-weight: bold;">8</span>);<br /> z1 <span style="color: #333333;">+=</span> (z2<span style="color: #333333;"><<</span><span style="color: #0000dd; font-weight: bold;">8</span>);<br /> y1 <span style="color: #333333;">+=</span> (y2<span style="color: #333333;"><<</span><span style="color: #0000dd; font-weight: bold;">8</span>);<br /> USART_Transmit(<span style="background-color: #fff0f0;">"x1 ="</span>);<br /> USART_Transmit_int(x1);<br /> USART_Transmit(<span style="background-color: #fff0f0;">"y1 ="</span>);<br /> USART_Transmit_int(y1);<br /> USART_Transmit(<span style="background-color: #fff0f0;">"z1 ="</span>);<br /> USART_Transmit_int(z1);<br /> USART_Transmit(<span style="background-color: #fff0f0;">"</span><span style="background-color: #fff0f0; color: #666666; font-weight: bold;">\n</span><span style="background-color: #fff0f0;">"</span>);<br /> _delay_ms(<span style="color: #0000dd; font-weight: bold;">100</span>);<br /> }<br />}<br /></pre></td></tr></tbody></table></div><br /><br /><br /></div>Sudhir guptahttps://plus.google.com/105460425718553468371noreply@blogger.com0tag:blogger.com,1999:blog-8315127339483053508.post-16026036518501321542015-09-26T00:53:00.001+05:302015-09-26T00:55:52.604+05:30AVR Dude <div dir="ltr" style="text-align: left;" trbidi="on"><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-L3qynZ4Y6lw/UtJiJPwTvcI/AAAAAAAABUw/cTmb1hVxFt8/s1600/AVR-logo.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://3.bp.blogspot.com/-L3qynZ4Y6lw/UtJiJPwTvcI/AAAAAAAABUw/cTmb1hVxFt8/s1600/AVR-logo.png" /></a></div>AVRDUDE is an excellent program for programming a AVR Atmega series microcontroller. In order to program any microcontroller you need to have a *.hex file which contain the instructions for the microcontroller. Apart from the software you need to have a hardware connection between your PC and the microcontroller which acts as an interface to write the *.hex file into the memory of the microcontroller, from where it run the instuctions in the specified *.hex file. USBasp is an awesome programmer found at cheap cost on almost all online stores these days. So you need a programmer like USBasp, some basic circuit for the ATmega and a PC with AVRDUDE and *.hex file to start the programming the microcontroller.<br /><br /><a name='more'></a><br /><br />Here is the circuit required between the PC and USBasp:<br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://3.bp.blogspot.com/-Bh98nZ6vW7U/VgWamqyzTDI/AAAAAAAACq4/YvFNehVQ-V8/s1600/click.jpeg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="465" src="http://3.bp.blogspot.com/-Bh98nZ6vW7U/VgWamqyzTDI/AAAAAAAACq4/YvFNehVQ-V8/s640/click.jpeg" width="640" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">USBasp and AVR connection details</td><td class="tr-caption" style="text-align: center;"><br /></td></tr></tbody></table><br />Using the AVRdude:<br />I'll be explaining the procedure for linux and is basically same in windows.<br />Open the terminal and check whether AVRDUDE is installed by typing <b>avrdude</b>. If AVRDUDE is installed it will give you a output describing the options available in avrdude.<br />Reading the flash of microcontroller-<br /><b>avrdude -c usbasp -p m32 -u -U flash:r:backup.hex</b><br /><br />Let's understand the above command :-<br /><ul style="text-align: left;"><li>The -c option describes the type of programmer being used.</li><li>The -p option specified the type of microcontroller being used.</li><li>Yhe -u option is to disable safe mode (for noe just accept it)</li><li>The -U option is the last and most improtant, in flash:r:backup.hex - flash is the type of memory, r implies read mode and finally backup.hex implies write the data to backup.hex. </li></ul>Summing up it implies that the flash memory of the microcontroller m32(Atmega32) is to be read and written to a file named backup.hex .<br /><br />Similarly if you want to write the file backup.hex to the microcontroller:-<br /><b>avrdude -c usbasp -p m32 -u -U flash:w:backup.hex</b><br /><br /> I hope this post helps you to understand about avrdude if any clarification is required please comment.<br /><br /><br /><br /></div>Sudhir guptahttps://plus.google.com/105460425718553468371noreply@blogger.com0tag:blogger.com,1999:blog-8315127339483053508.post-34923646452508644042014-01-15T00:01:00.000+05:302014-01-16T00:37:53.592+05:30OpenFOAM - blockMesh<div dir="ltr" style="text-align: left;" trbidi="on"><div style="text-align: justify;">Please read <a href="http://www.randomstuff.co.in/2012/10/openfoam-basics.html" target="_blank">OpenFOAM - Basics</a> before reading this post</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">blockMesh is a mesh generation utility supplied with OpenFOAM. In simple word it generates mesh for the CFD analysis. In the last post it was said that the basic OpenFOAM case directory consists of three folders namely 0, constant and system. The blockMeshDict file in the constant/polyMesh directory of the case file contains the parameter of the geometry and the parameters required for meshing the surface. Now go to the forwardStep directory which is discussed in the previous post and open the blockMeshDict file. In the file u scan see may sections like FoamFile, vertices, blocks, edges, etc.,</div><div style="text-align: justify;"><br /><a name='more'></a><br /></div><div style="text-align: justify;"><b>The FoamFile section :</b> helps OpenFOAM to detect which file it is and for which version of OpenFOAM it is written, format and class ,in this case it is a blocMeshDict file so the object is 'blockMeshDict'. Let's forget about the other for now.<br /><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-RfxD299q-68/UIKo2OTBK7I/AAAAAAAAAug/l3PlmCtVs4U/s1600/blockMeshBox.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="257" src="http://3.bp.blogspot.com/-RfxD299q-68/UIKo2OTBK7I/AAAAAAAAAug/l3PlmCtVs4U/s640/blockMeshBox.png" width="640" /></a></div><br /><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><span style="background-color: white; font-family: inherit; line-height: 18px; text-indent: 18px;">The principle behind </span><span class="cmss-12" style="background-color: white; font-family: inherit; font-style: italic; line-height: 18px; margin: 0px; padding: 0px; text-indent: 18px;">blockMesh </span><span style="background-color: white; font-family: inherit; line-height: 18px; text-indent: 18px;">is to decompose the domain geometry into a set of 1 or more three dimensional, hexahedral blocks. Edges of the blocks can be straight lines, arcs or splines. The mesh is ostensibly specified as a number of cells in each direction of the block, sufficient information for </span><span class="cmss-12" style="background-color: white; font-family: inherit; font-style: italic; line-height: 18px; margin: 0px; padding: 0px; text-indent: 18px;">blockMesh </span><span style="background-color: white; font-family: inherit; line-height: 18px; text-indent: 18px;">to generate the mesh data. - Taken from <a href="http://www.openfoam.org/docs/user/blockMesh.php#x25-1420005.3" target="_blank">link</a></span></div><br /><div style="text-align: justify;"><span style="font-family: inherit;"><br /></span></div><div style="text-align: justify;">Lets start to write the blockMeshDict with a simple example</div><div style="text-align: justify;"><br /></div><div style="text-align: justify;">Assume the geometry to be meshed is a cube with side 1 m located in the first quadrant with origin at one of the vertex as shown in the figure below</div><br /><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"><br /></div><div class="" style="clear: both; text-align: justify;">The vertices section can be written as follows:</div><div class="separator" style="clear: both; text-align: justify;"><span style="text-align: left;"><span style="font-family: Courier New, Courier, monospace;"><br /></span></span></div><div class="separator" style="clear: both; text-align: justify;"><span style="font-family: 'Courier New', Courier, monospace; text-align: left;">vertices</span></div><div class="separator" style="clear: both; text-align: justify;"><span style="text-align: left;"><span style="font-family: Courier New, Courier, monospace;">(</span></span></div><div class="" style="clear: both; text-align: justify;"><span style="text-align: left;"><span style="font-family: Courier New, Courier, monospace;"> (0 0 0) //0</span></span></div><div class="" style="clear: both; text-align: justify;"><span style="text-align: left;"><span style="font-family: Courier New, Courier, monospace;"> (1 0 0) //1</span></span></div><div class="separator" style="clear: both; text-align: justify;"><span style="text-align: left;"><span style="font-family: Courier New, Courier, monospace;"> (1 1 0) //2</span></span></div><div class="" style="clear: both; text-align: justify;"><span style="text-align: left;"><span style="font-family: Courier New, Courier, monospace;"> (0 1 0) //3</span></span></div><div class="" style="clear: both; text-align: justify;"><span style="text-align: left;"><span style="font-family: Courier New, Courier, monospace;"> (0 0 1) //4</span></span></div><div class="separator" style="clear: both; text-align: justify;"><span style="text-align: left;"><span style="font-family: Courier New, Courier, monospace;"> (1 0 1) //5</span></span></div><div class="separator" style="clear: both; text-align: justify;"><span style="text-align: left;"><span style="font-family: Courier New, Courier, monospace;"> (1 1 1) //6</span></span></div><div class="separator" style="clear: both; text-align: justify;"><span style="text-align: left;"><span style="font-family: Courier New, Courier, monospace;"> (0 1 1) //7</span></span></div><div class="separator" style="clear: both; text-align: justify;"><span style="text-align: left;"><span style="font-family: Courier New, Courier, monospace;">);</span></span></div><div class="separator" style="clear: both; text-align: justify;"><span style="text-align: left;"><span style="font-family: Courier New, Courier, monospace;"><br /></span></span></div>Procedure ( Following this is not necessary but it helps to minimize the errors)<br />The zeroth point is the reference point (can be any vertex of the block)<br />Then define a plane using the first vertex and other 3 points such that their normal is outward, these make up the first four points. As for now two dimensions are defined (Here x ,y). The fourth point and first point together specify the third dimension (here the z direction). Using the fourth, fifth, sixth and seventh points construct the opposite parallel plane. This will create the basic wire mesh.<br /><br />There after the the wire is then partition based on the number of cells needed this is a basic geometry and the problem that i am going to explain is quite simple and linear so no many cell are needed (unnecessarily giving a large cell count only increases the computing time) so a 10 x 10 x 10 mesh is quite enough<br /><br /><span style="font-family: inherit;"><span class="cmtt-10" style="background-color: white;">blocks</span><span style="background-color: white;"> </span><br class="fancyvrb" style="background-color: white;" /><a href="http://www.blogger.com/blogger.g?blogID=8315127339483053508" id="x18-51159r78" style="background-color: white;"></a></span><br /><div style="text-align: left;"><span style="font-family: inherit;"><span class="cmtt-10" style="background-color: white;">(</span></span><br /><span style="font-family: inherit;"><span style="background-color: white;"> </span><span class="cmtt-10" style="background-color: white;"> </span><span class="cmtt-10" style="background-color: white;"> </span><span class="cmtt-10" style="background-color: white;"> </span><span class="cmtt-10" style="background-color: white;"> </span><span class="cmtt-10" style="background-color: white;"> </span><span class="cmtt-10" style="background-color: white;"> hex</span><span class="cmtt-10" style="background-color: white;"> (0 1 2 3 4 5 6 7</span><span class="cmtt-10" style="background-color: white;">)</span><span class="cmtt-10" style="background-color: white;"> (10</span><span class="cmtt-10" style="background-color: white;"> 10</span><span class="cmtt-10" style="background-color: white;"> 10)</span><span class="cmtt-10" style="background-color: white;"> simpleGrading</span><span class="cmtt-10" style="background-color: white;"> (1</span><span class="cmtt-10" style="background-color: white;"> 1</span><span class="cmtt-10" style="background-color: white;"> 1)</span><span style="background-color: white;"> </span></span><br /><span style="font-family: inherit;"><span class="cmtt-10" style="background-color: white;">);</span><span style="background-color: white;"> </span></span></div><div style="text-align: left;"><span style="font-family: inherit;"><span style="background-color: white;"><br /></span></span></div><div style="text-align: left;"><span style="font-family: inherit;"><span style="background-color: white;">This will divide the edges (wire) in 10 parts in all directions.</span></span></div><div style="text-align: left;"><span style="font-family: inherit;"><span style="background-color: white;">This will constitute the basic blockMesh file.</span></span></div><div style="text-align: left;"><br /></div><div style="text-align: left;">Type <span style="background-color: #666666;">blockMesh</span><span style="background-color: white;"> </span>in the respective folder where the whole project is located to create the mesh file.</div><div style="text-align: left;">The mesh can be seen by typing <span style="background-color: #666666;">paraFoam</span><span style="background-color: white;">.</span></div><div style="text-align: left;"><span style="background-color: white;"><br /></span></div><div style="text-align: left;"><span style="background-color: white;">Will be posting the next one on solvers.</span></div><a href="http://www.blogger.com/blogger.g?blogID=8315127339483053508" id="x18-51161r79" style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 16px;"></a></div>Sudhir guptahttps://plus.google.com/105460425718553468371noreply@blogger.com0tag:blogger.com,1999:blog-8315127339483053508.post-2081273608181709492014-01-12T12:27:00.001+05:302014-01-12T15:06:47.649+05:30Advanced USART Functions<div dir="ltr" style="text-align: left;" trbidi="on"><div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/-L3qynZ4Y6lw/UtJiJPwTvcI/AAAAAAAABUs/OUTSNDcgTM8/s1600/AVR-logo.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/-L3qynZ4Y6lw/UtJiJPwTvcI/AAAAAAAABUs/OUTSNDcgTM8/s1600/AVR-logo.png" /></a></div><br />In the <a href="http://www.randomstuff.co.in/2013/10/usart-with-atmega32.html" target="_blank">previous post</a> the USART_Transmit_char function can only send one character at a time. If you want to send a whole sentence or an integer or a non-integer you cant use the above function. Here are some code snippets that come in handy while using USART.<br /><a name='more'></a>This function can send multiple characters at a time - <br /><div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;"><table><tbody><tr><td><pre style="line-height: 125%; margin: 0;"> 1<br /> 2<br /> 3<br /> 4<br /> 5<br /> 6<br /> 7<br /> 8<br /> 9<br />10</pre></td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">USART_Transmit</span>(<span style="color: #333399; font-weight: bold;">char</span><span style="color: #333333;">*</span> txdata)<br />{<br /> <span style="color: #333399; font-weight: bold;">int</span> i <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span>;<br /> <span style="color: #008800; font-weight: bold;">while</span>(txdata[i] <span style="color: #333333;">!=</span> <span style="color: #0044dd;">''</span>)<br /> {<br /> USART_Transmit_char(txdata[i]);<br /> i<span style="color: #333333;">++</span>;<br /> }<br /><br />}</pre></td></tr></tbody></table></div>Sending an integer - <br /><blockquote>NOTE : This function can only send three digit integers.</blockquote><div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;"><table><tbody><tr><td><pre style="line-height: 125%; margin: 0;"> 1<br /> 2<br /> 3<br /> 4<br /> 5<br /> 6<br /> 7<br /> 8<br /> 9<br />10<br />11<br />12</pre></td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">USART_Transmit_int</span>(<span style="color: #333399; font-weight: bold;">unsigned</span> <span style="color: #333399; font-weight: bold;">int</span> i)<br />{<br /> <span style="color: #333399; font-weight: bold;">unsigned</span> <span style="color: #333399; font-weight: bold;">char</span> h,t,o;<br /> o<span style="color: #333333;">=</span> (i<span style="color: #333333;">%</span><span style="color: #0000dd; font-weight: bold;">10</span>) <span style="color: #333333;">|</span> <span style="color: #005588; font-weight: bold;">0x30</span>;<span style="color: #888888;">//ones</span><br /> i<span style="color: #333333;">/=</span><span style="color: #0000dd; font-weight: bold;">10</span>;<br /> t<span style="color: #333333;">=</span> (i<span style="color: #333333;">%</span><span style="color: #0000dd; font-weight: bold;">10</span>) <span style="color: #333333;">|</span> <span style="color: #005588; font-weight: bold;">0x30</span>;<span style="color: #888888;">//tens</span><br /> i<span style="color: #333333;">=</span>i<span style="color: #333333;">%</span><span style="color: #0000dd; font-weight: bold;">100</span>;<br /> h<span style="color: #333333;">=</span>(i<span style="color: #333333;">/</span><span style="color: #0000dd; font-weight: bold;">10</span>) <span style="color: #333333;">|</span> <span style="color: #005588; font-weight: bold;">0x30</span>;<span style="color: #888888;">//hundreds</span><br /> USART_Transmit_char(h);<br /> USART_Transmit_char(t);<br /> USART_Transmit_char(o);<br />}</pre></td></tr></tbody></table></div>Sending a float- <br /><blockquote>NOTE : Can only send xxx.xx type number</blockquote><div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;"><table><tbody><tr><td><pre style="line-height: 125%; margin: 0;"> 1<br /> 2<br /> 3<br /> 4<br /> 5<br /> 6<br /> 7<br /> 8<br /> 9<br />10<br />11<br />12<br />13<br />14</pre></td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">USART_Transmit_float</span>(<span style="color: #008800; font-weight: bold;">const</span> <span style="color: #333399; font-weight: bold;">float</span> f)<br />{<br /> <span style="color: #333399; font-weight: bold;">unsigned</span> <span style="color: #333399; font-weight: bold;">int</span> v,p;<br /> <span style="color: #333399; font-weight: bold;">long</span> <span style="color: #333399; font-weight: bold;">int</span> num;<br /> num<span style="color: #333333;">=</span>f<span style="color: #333333;">*</span><span style="color: #0000dd; font-weight: bold;">1000</span>;<br /> p<span style="color: #333333;">=</span>num<span style="color: #333333;">%</span><span style="color: #0000dd; font-weight: bold;">1000</span>;<br /> num<span style="color: #333333;">=</span>num<span style="color: #333333;">/</span><span style="color: #0000dd; font-weight: bold;">1000</span>;<br /> v<span style="color: #333333;">=</span>num;<br /><br /> USART_Transmit_int(v);<br /> USART_Transmit_char(<span style="color: #0044dd;">'.'</span>);<br /> USART_Transmit_int(p);<br /><br />}</pre></td></tr></tbody></table></div></div>Sudhir guptahttps://plus.google.com/105460425718553468371noreply@blogger.com0tag:blogger.com,1999:blog-8315127339483053508.post-45846085090580309722013-10-20T19:08:00.000+05:302015-09-10T00:44:45.758+05:30USART with ATmega32<div dir="ltr" style="text-align: left;" trbidi="on"><div style="text-align: left;"><div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/-L3qynZ4Y6lw/UtJiJPwTvcI/AAAAAAAABUw/cTmb1hVxFt8/s1600/AVR-logo.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-L3qynZ4Y6lw/UtJiJPwTvcI/AAAAAAAABUw/cTmb1hVxFt8/s1600/AVR-logo.png" /></a></div></div><h2>Introduction</h2>The Universal Synchronous and Asynchronous serial Receiver and Transmitter (USART) is a highly flexible serial communication device. It is the easiest way to communicate with a computer. Many softwares such as MATLAB, Scilab, Mathmatica, etc., provide libraries that support serial communication. Real time data logging can be easily done due to its speed and flexibility in features. The USART uses two lines Tx and Rx, the data is transmitted through the Tx line and received through the Rx line. Let's see how to make ATmega32 communicate with a laptop. <br /><a name='more'></a><br /><h3 style="text-align: left;">Setting up the Hardware</h3>Hardware needed : <br /><ol><li><a href="http://www.ebay.com/itm/CP2102-USB-2-0-to-TTL-UART-Module-6Pin-Serial-Converter-STC-Replace-FT232-Module-/161103531292?pt=LH_DefaultDomain_0&hash=item258284cd1c" target="_blank">CP2102</a> module or FT232BM module or any of such kind.</li><li>Atmega32 with its basic circuitry.</li></ol>From the ATmega32's data sheet we can see that <br /><ol><li>PD0 -> RXD</li><li>PD1 -> TXD</li></ol>Connect the data lines of the CP2102 module and ATmega32, then insert the CP2012 module in the USB port of your laptop or PC. <br /><h3 style="text-align: left;">Deciding your System clock</h3><div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-H-W54tSDKBY/UtrVrUunNEI/AAAAAAAABVc/AWWrvR4Bt0E/s1600/1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/-H-W54tSDKBY/UtrVrUunNEI/AAAAAAAABVc/AWWrvR4Bt0E/s1600/1.png" height="385" width="640" /></a></div><br />As you can see in the following picture that at some Baud Rate the error percentage is quite high. So if your application needs high accuracy, baud rate should also be taken into account. In the following post the ATmeag32 has a baud rate of 9600 bps and the CPU is clocked at 8 MHz. <br /><h3 style="text-align: left;"> Initializing the USART</h3><!-- HTML generated using hilite.me --> <br /><div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;"><table><tbody><tr><td><pre style="line-height: 125%; margin: 0;"> 1<br /> 2<br /> 3<br /> 4<br /> 5<br /> 6<br /> 7<br /> 8<br /> 9<br />10</pre></td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">USART_Init</span>( <span style="color: #333399; font-weight: bold;">unsigned</span> <span style="color: #333399; font-weight: bold;">int</span> baud )<br />{<br /> <span style="color: #888888;">/* Set baud rate */</span><br /> UBRRH <span style="color: #333333;">=</span> (<span style="color: #333399; font-weight: bold;">unsigned</span> <span style="color: #333399; font-weight: bold;">char</span>)(baud<span style="color: #333333;">>></span><span style="color: #0000dd; font-weight: bold;">8</span>);<br /> UBRRL <span style="color: #333333;">=</span> (<span style="color: #333399; font-weight: bold;">unsigned</span> <span style="color: #333399; font-weight: bold;">char</span>)baud;<br /> <span style="color: #888888;">/* Enable transmitter and receiver */</span><br /> UCSRB <span style="color: #333333;">=</span> (<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>TXEN)<span style="color: #333333;">|</span>(<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>RXEN);<br /> <span style="color: #888888;">/* Set frame format: 8data, 2stop bit */</span><br /> UCSRC <span style="color: #333333;">=</span> (<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>URSEL)<span style="color: #333333;">|</span>(<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>USBS)<span style="color: #333333;">|</span>(<span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;"><<</span>UCSZ0);<br />}</pre></td></tr></tbody></table></div><div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-qymQrTN2_TM/UtrVrbW8RmI/AAAAAAAABVo/JTE6zQ4CdnM/s1600/2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://3.bp.blogspot.com/-qymQrTN2_TM/UtrVrbW8RmI/AAAAAAAABVo/JTE6zQ4CdnM/s1600/2.png" height="379" width="640" /></a></div><div class="separator" style="clear: both; text-align: center;"><br /></div><ol><li>First of all you need to enable the USART transmission and reception line using the UCSRB register or the they will function as normal i/o mode.</li><li>Next the format in which the we want to send the data like data bits, stop bits, parity, etc., in the UCSRC register.</li><li>Finally, setting the baud rate using the UBBR register. The UBRR value for a certain baud rate for a certain system clock can be found out in the table shown above or by using the following formula. </li></ol><h3><span style="font-size: large;">Sending and Receiving data</span></h3>Now as our ATmega is initialized to use USART, all we need to do now is send or receive the data we need. The can be done using the USART I/O Data Register. <br /><div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;"><table><tbody><tr><td><pre style="line-height: 125%; margin: 0;">1<br />2<br />3<br />4<br />5<br />6<br />7<br />8</pre></td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">USART_Transmit_char</span>(<span style="color: #333399; font-weight: bold;">char</span> txdata )<br />{<br /> <span style="color: #888888;">/* Wait for empty transmit buffer */</span><br /> <span style="color: #008800; font-weight: bold;">while</span> ( <span style="color: #333333;">!</span>( UCSRA <span style="color: #333333;">&</span> (<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>UDRE)) )<br /> ;<br /> <span style="color: #888888;">/* Put data into buffer, sends the data */</span><br /> UDR <span style="color: #333333;">=</span> txdata;<br />}</pre></td></tr></tbody></table></div>The above code can be used to send a character over USART. The explanation of the code can be clearly seen in the comments. In the above code you wait for the transmitter buffer and load the data into the UDR register. Similarly the in the following code you wait for the receiver buffer to get the data and read it from the UDR register. <br /><div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;"><table><tbody><tr><td><pre style="line-height: 125%; margin: 0;">1<br />2<br />3<br />4<br />5<br />6<br />7<br />8</pre></td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #333399; font-weight: bold;">unsigned</span> <span style="color: #333399; font-weight: bold;">char</span> <span style="color: #0066bb; font-weight: bold;">USART_Receive</span>( <span style="color: #333399; font-weight: bold;">void</span> )<br />{<br /><span style="color: #888888;">/* Wait for data to be received */</span><br /><span style="color: #008800; font-weight: bold;">while</span> ( <span style="color: #333333;">!</span>(UCSRA <span style="color: #333333;">&</span> (<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>RXC)) )<br />;<br /><span style="color: #888888;">/* Get and return received data from buffer */</span><br /><span style="color: #008800; font-weight: bold;">return</span> UDR;<br />}</pre></td></tr></tbody></table></div> He is some basic code that returns any data that we send to ATmega32: <br /><div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;"><table><tbody><tr><td><pre style="line-height: 125%; margin: 0;"> 1<br /> 2<br /> 3<br /> 4<br /> 5<br /> 6<br /> 7<br /> 8<br /> 9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43</pre></td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #557799;">#include <avr/io.h></span><br /><br /><span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">USART_Init</span>( <span style="color: #333399; font-weight: bold;">unsigned</span> <span style="color: #333399; font-weight: bold;">int</span> baud )<br />{<br /> <span style="color: #888888;">/* Set baud rate */</span><br /> UBRRH <span style="color: #333333;">=</span> (<span style="color: #333399; font-weight: bold;">unsigned</span> <span style="color: #333399; font-weight: bold;">char</span>)(baud<span style="color: #333333;">>></span><span style="color: #0000dd; font-weight: bold;">8</span>);<br /> UBRRL <span style="color: #333333;">=</span> (<span style="color: #333399; font-weight: bold;">unsigned</span> <span style="color: #333399; font-weight: bold;">char</span>)baud;<br /> <span style="color: #888888;">/* Enable transmitter and receiver */</span><br /> UCSRB <span style="color: #333333;">=</span> (<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>TXEN)<span style="color: #333333;">|</span>(<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>RXEN);<br /> <span style="color: #888888;">/* Set frame format: 8data, 2stop bit */</span><br /> UCSRC <span style="color: #333333;">=</span> (<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>URSEL)<span style="color: #333333;">|</span>(<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>USBS)<span style="color: #333333;">|</span>(<span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;"><<</span>UCSZ0);<br />}<br /><br /><span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">USART_Transmit_char</span>(<span style="color: #333399; font-weight: bold;">char</span> txdata )<br />{<br /> <span style="color: #888888;">/* Wait for empty transmit buffer */</span><br /> <span style="color: #008800; font-weight: bold;">while</span> ( <span style="color: #333333;">!</span>( UCSRA <span style="color: #333333;">&</span> (<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>UDRE)) )<br /> ;<br /> <span style="color: #888888;">/* Put data into buffer, sends the data */</span><br /> UDR <span style="color: #333333;">=</span> txdata;<br />}<br /><br /><span style="color: #333399; font-weight: bold;">unsigned</span> <span style="color: #333399; font-weight: bold;">char</span> <span style="color: #0066bb; font-weight: bold;">USART_Receive</span>( <span style="color: #333399; font-weight: bold;">void</span> )<br />{<br /><span style="color: #888888;">/* Wait for data to be received */</span><br /><span style="color: #008800; font-weight: bold;">while</span> ( <span style="color: #333333;">!</span>(UCSRA <span style="color: #333333;">&</span> (<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>RXC)) )<br />;<br /><span style="color: #888888;">/* Get and return received data from buffer */</span><br /><span style="color: #008800; font-weight: bold;">return</span> UDR;<br />}<br /><br /><span style="color: #333399; font-weight: bold;">int</span> <span style="color: #0066bb; font-weight: bold;">main</span>(<span style="color: #333399; font-weight: bold;">void</span>)<br />{<br /> <span style="color: #333399; font-weight: bold;">char</span> data;<br /> USART_Init(<span style="color: #0000dd; font-weight: bold;">51</span>);<br /> USART_Transmit_char(<span style="color: #0044dd;">'H'</span>);<br /> USART_Transmit_char(<span style="color: #0044dd;">'i'</span>);<br /> <span style="color: #008800; font-weight: bold;">while</span>(<span style="color: #0000dd; font-weight: bold;">1</span>)<br /> {<br /> data<span style="color: #333333;">=</span>USART_Receive();<br /> USART_Transmit_char(data);<br /> }<br />}</pre></td></tr></tbody></table></div><br /> The output can be seen in the following picture:<br /><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/-xYxwSra0SMs/UtrWfHqCaPI/AAAAAAAABVs/-ZxaS_wiBb8/s1600/3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-xYxwSra0SMs/UtrWfHqCaPI/AAAAAAAABVs/-ZxaS_wiBb8/s1600/3.png" /></a></div><div class="separator" style="clear: both; text-align: center;"><br /></div> Sudhir guptahttps://plus.google.com/105460425718553468371noreply@blogger.com0tag:blogger.com,1999:blog-8315127339483053508.post-24695619009048031662013-10-20T11:28:00.002+05:302015-09-10T00:45:38.994+05:30 ADXL345 Accelerometer using ATmega32<div dir="ltr" style="text-align: left;" trbidi="on">The ADXL345 is a tiny, low cost and ultra-low power 3-axis accelerometer which works on both SPI and TWI interfaces. It has use selectable sensitivity and give quite reliable readings considering its cost. The ADLX345 circuit in the IMU has TWI interface. I will be using ATmega32 in the following project clocked at 8MHz using the internal oscillator.<br /><div style="text-align: left;">Here is the circuit diagram of how the ADXL345 accelerometer is connected, also you can see that the slave address is given as 0x53. The address can also be found out from the <a href="http://www.randomstuff.co.in/2013/10/i2c-scanner.html" target="_blank">I2C scanner as shown here</a>.</div><div style="text-align: left;"><div class="separator" style="clear: both; text-align: center;"></div></div><div style="text-align: left;">The ADX345 supports the standard (100 kHz) and the fast (400 kHz) data transfer modes. For more info see datasheet.</div><a name='more'></a><br /><h2 style="text-align: left;">Click here for <span style="color: #999999;"><a href="http://www.analog.com/static/imported-files/data_sheets/ADXL345.pdf" target="_blank"><span style="color: #999999;">ADXL345 datasheet.</span></a></span></h2>The I2C device addressing for ADXL345 can be seen in the datasheet. <br /><div style="text-align: center;"></div><div style="text-align: left;">The ATmega32 acts as a master and the ADXL345 as the slave.</div><div style="text-align: left;">To start communication you need to first configure the connection between ADXL345 and ATmega32 in a mode supported by ADXL345. This can be done as show :</div><div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;"><table><tbody><tr><td><pre style="line-height: 125%; margin: 0;">1<br />2<br />3<br />4<br />5<br />6<br />7<br />8</pre></td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">TWI_Init</span>(<span style="color: #333399; font-weight: bold;">void</span>)<br />{<br /> <span style="color: #888888;">//set SCL to 400kHz</span><br /> TWSR <span style="color: #333333;">=</span> <span style="color: #005588; font-weight: bold;">0x00</span>;<br /> TWBR <span style="color: #333333;">=</span> <span style="color: #005588; font-weight: bold;">0x02</span>;<br /> <span style="color: #888888;">//enable TWI</span><br /> TWCR <span style="color: #333333;">=</span> (<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>TWEN);<br />}</pre></td></tr></tbody></table></div>Inserting the above values of TWBR and TWSR in the following equation results in SCL frequency of 400 kHz when the main CPU is clocked at 8 MHz. <br /><h1 style="text-align: left;"></h1><h2 style="text-align: left;">Single-Byte write:</h2>See the I2C device addressing picture above for the description. <br /><ol><li>Send start condition<!-- HTML generated using hilite.me --><div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;"><table><tbody><tr><td><pre style="line-height: 125%; margin: 0;">1<br />2<br />3<br />4<br />5</pre></td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">TWI_Start</span>(<span style="color: #333399; font-weight: bold;">void</span>)<br />{<br /> TWCR <span style="color: #333333;">=</span> (<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>TWINT)<span style="color: #333333;">|</span>(<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>TWSTA)<span style="color: #333333;">|</span>(<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>TWEN);<br /> <span style="color: #008800; font-weight: bold;">while</span> ((TWCR <span style="color: #333333;">&</span> (<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>TWINT)) <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">0</span>);<br />}</pre></td></tr></tbody></table></div></li><li>Check for Acknowledgement <!-- HTML generated using hilite.me --><div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;"><table><tbody><tr><td><pre style="line-height: 125%; margin: 0;"> 1<br /> 2<br /> 3<br /> 4<br /> 5<br /> 6<br /> 7<br /> 8<br /> 9<br />10<br />11<br />12</pre></td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #333399; font-weight: bold;">uint8_t</span> <span style="color: #0066bb; font-weight: bold;">TWI_GetStatus</span>(<span style="color: #333399; font-weight: bold;">void</span>)<br />{<br /> <span style="color: #333399; font-weight: bold;">uint8_t</span> status;<br /> <span style="color: #888888;">//mask status</span><br /> status <span style="color: #333333;">=</span> TWSR <span style="color: #333333;">&</span> <span style="color: #005588; font-weight: bold;">0xF8</span>;<br /> <span style="color: #008800; font-weight: bold;">return</span> status;<br />}<br /><br /><span style="color: #008800; font-weight: bold;">if</span>(TWI_GetStatus() <span style="color: #333333;">!=</span> <span style="color: #005588; font-weight: bold;">0x08</span>)<br />{<br /> <span style="color: #008800; font-weight: bold;">return</span> error;<br />}</pre></td></tr></tbody></table></div>The status codes can be found out in the ATmega32 datasheet.</li><li>Send the Slave address + Data direction bit (R/W) <div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;"><table><tbody><tr><td><pre style="line-height: 125%; margin: 0;">1<br />2<br />3<br />4<br />5<br />6<br />7<br />8</pre></td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">TWI_Write</span>(<span style="color: #333399; font-weight: bold;">uint8_t</span> u8data)<br />{<br /> TWDR <span style="color: #333333;">=</span> u8data;<br /> TWCR <span style="color: #333333;">=</span> (<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>TWINT)<span style="color: #333333;">|</span>(<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>TWEN);<br /> <span style="color: #008800; font-weight: bold;">while</span> ((TWCR <span style="color: #333333;">&</span> (<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>TWINT)) <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">0</span>);<br />}<br /><br />TWI_Write(<span style="color: #0000dd; font-weight: bold;">0</span>b10100110);</pre></td></tr></tbody></table></div>The last zero in TWI_Write implies the Master write mode</li><li>Check for Acknowledgement <!-- HTML generated using hilite.me --><div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;"><table><tbody><tr><td><pre style="line-height: 125%; margin: 0;">1<br />2<br />3<br />4</pre></td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">if</span>(TWI_GetStatus() <span style="color: #333333;">!=</span> <span style="color: #005588; font-weight: bold;">0x18</span>)<br />{<br /> <span style="color: #008800; font-weight: bold;">return</span> error;<br />}</pre></td></tr></tbody></table></div></li><li>Send the register address and check for Acknowledgement <div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;"><table><tbody><tr><td><pre style="line-height: 125%; margin: 0;">1<br />2<br />3<br />4<br />5</pre></td><td><pre style="line-height: 125%; margin: 0;">TWI_Write(reg);<br /><span style="color: #008800; font-weight: bold;">if</span>(TWI_GetStatus() <span style="color: #333333;">!=</span> <span style="color: #005588; font-weight: bold;">0x28</span>)<br />{<br /> <span style="color: #008800; font-weight: bold;">return</span> error;<br />}</pre></td></tr></tbody></table></div></li><li>Send the data and receive acknowledgement <!-- HTML generated using hilite.me --><div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;"><table><tbody><tr><td><pre style="line-height: 125%; margin: 0;">1<br />2<br />3<br />4<br />5</pre></td><td><pre style="line-height: 125%; margin: 0;">TWI_Write(data);<br /><span style="color: #008800; font-weight: bold;">if</span>(TWI_GetStatus() <span style="color: #333333;">!=</span> <span style="color: #005588; font-weight: bold;">0x28</span>)<br />{<br /> <span style="color: #008800; font-weight: bold;">return</span> error;<br />}</pre></td></tr></tbody></table></div></li><li>Send Stop condition<!-- HTML generated using hilite.me --><div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;"><table><tbody><tr><td><pre style="line-height: 125%; margin: 0;">1</pre></td><td><pre style="line-height: 125%; margin: 0;">TWI_Stop();</pre></td></tr></tbody></table></div></li></ol>Complete code: <br /><div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;"><table><tbody><tr><td><pre style="line-height: 125%; margin: 0;"> 1<br /> 2<br /> 3<br /> 4<br /> 5<br /> 6<br /> 7<br /> 8<br /> 9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25</pre></td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #333399; font-weight: bold;">uint8_t</span> <span style="color: #0066bb; font-weight: bold;">ADXL_write</span>(<span style="color: #333399; font-weight: bold;">uint8_t</span> reg, <span style="color: #333399; font-weight: bold;">uint8_t</span> data)<br />{<br /> TWI_Start();<br /> <span style="color: #008800; font-weight: bold;">if</span>(TWI_GetStatus() <span style="color: #333333;">!=</span> <span style="color: #005588; font-weight: bold;">0x08</span>)<br /> {<br /> <span style="color: #008800; font-weight: bold;">return</span> error;<br /> }<br /> TWI_Write(<span style="color: #0000dd; font-weight: bold;">0</span>b10100110);<br /> <span style="color: #008800; font-weight: bold;">if</span>(TWI_GetStatus() <span style="color: #333333;">!=</span> <span style="color: #005588; font-weight: bold;">0x18</span>)<br /> {<br /> <span style="color: #008800; font-weight: bold;">return</span> error;<br /> }<br /> TWI_Write(reg);<br /> <span style="color: #008800; font-weight: bold;">if</span>(TWI_GetStatus() <span style="color: #333333;">!=</span> <span style="color: #005588; font-weight: bold;">0x28</span>)<br /> {<br /> <span style="color: #008800; font-weight: bold;">return</span> error;<br /> }<br /> TWI_Write(data);<br /> <span style="color: #008800; font-weight: bold;">if</span>(TWI_GetStatus() <span style="color: #333333;">!=</span> <span style="color: #005588; font-weight: bold;">0x28</span>)<br /> {<br /> <span style="color: #008800; font-weight: bold;">return</span> error;<br /> }<br /> TWI_Stop();<br /> <span style="color: #008800; font-weight: bold;">return</span> success;<br />}</pre></td></tr></tbody></table></div> <br /><h2>Single-Byte Read:</h2><div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;"><table><tbody><tr><td><pre style="line-height: 125%; margin: 0;"> 1<br /> 2<br /> 3<br /> 4<br /> 5<br /> 6<br /> 7<br /> 8<br /> 9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36</pre></td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #333399; font-weight: bold;">uint8_t</span> <span style="color: #0066bb; font-weight: bold;">ADXL_read</span>(<span style="color: #333399; font-weight: bold;">uint8_t</span> reg)<br />{<br /> <span style="color: #333399; font-weight: bold;">uint8_t</span> data;<br /> TWI_Start();<br /> <span style="color: #008800; font-weight: bold;">if</span>(TWI_GetStatus() <span style="color: #333333;">!=</span> <span style="color: #005588; font-weight: bold;">0x08</span>)<br /> {<br /> <span style="color: #008800; font-weight: bold;">return</span> error;<br /> }<br /> TWI_Write(<span style="color: #0000dd; font-weight: bold;">0</span>b10100110);<br /> <span style="color: #008800; font-weight: bold;">if</span>(TWI_GetStatus() <span style="color: #333333;">!=</span> <span style="color: #005588; font-weight: bold;">0x18</span>)<br /> {<br /> <span style="color: #008800; font-weight: bold;">return</span> error;<br /> }<br /> TWI_Write(reg);<br /> <span style="color: #008800; font-weight: bold;">if</span>(TWI_GetStatus() <span style="color: #333333;">!=</span> <span style="color: #005588; font-weight: bold;">0x28</span>)<br /> {<br /> <span style="color: #008800; font-weight: bold;">return</span> error;<br /> }<br /> TWI_Start();<br /> <span style="color: #008800; font-weight: bold;">if</span>(TWI_GetStatus() <span style="color: #333333;">!=</span> <span style="color: #005588; font-weight: bold;">0x10</span>)<br /> {<br /> <span style="color: #008800; font-weight: bold;">return</span> error;<br /> }<br /> TWI_Write(<span style="color: #0000dd; font-weight: bold;">0</span>b10100111);<br /> <span style="color: #008800; font-weight: bold;">if</span>(TWI_GetStatus() <span style="color: #333333;">!=</span> <span style="color: #005588; font-weight: bold;">0x40</span>)<br /> {<br /> <span style="color: #008800; font-weight: bold;">return</span> error;<br /> }<br /> data <span style="color: #333333;">=</span> TWI_ReadNACK();<br /> <span style="color: #008800; font-weight: bold;">if</span>(TWI_GetStatus() <span style="color: #333333;">!=</span> <span style="color: #005588; font-weight: bold;">0x58</span>)<br /> {<br /> <span style="color: #008800; font-weight: bold;">return</span> error;<br /> }<br /> TWI_Stop();<br /> <span style="color: #008800; font-weight: bold;">return</span> data;<br />}</pre></td></tr></tbody></table></div><!-- HTML generated using hilite.me --><br /><div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;"><table><tbody><tr><td><pre style="line-height: 125%; margin: 0;">1<br />2<br />3<br />4<br />5<br />6</pre></td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #333399; font-weight: bold;">uint8_t</span> <span style="color: #0066bb; font-weight: bold;">TWIReadNACK</span>(<span style="color: #333399; font-weight: bold;">void</span>)<br />{<br /> TWCR <span style="color: #333333;">=</span> (<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>TWINT)<span style="color: #333333;">|</span>(<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>TWEN);<br /> <span style="color: #008800; font-weight: bold;">while</span> ((TWCR <span style="color: #333333;">&</span> (<span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;"><<</span>TWINT)) <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">0</span>);<br /> <span style="color: #008800; font-weight: bold;">return</span> TWDR;<br />}<br /></pre></td></tr></tbody></table></div>Using these function data can be obtained form ADXL345 accelerometer. I'll be posting a full functional code later.</div>Sudhir guptahttps://plus.google.com/105460425718553468371noreply@blogger.com0tag:blogger.com,1999:blog-8315127339483053508.post-58428103256566182472013-10-15T19:36:00.000+05:302014-01-12T15:13:38.466+05:30I2C Scanner<div dir="ltr" style="text-align: left;" trbidi="on">The fast and easy way to find out the i2c devices connected to arduino. It also helps to find out whether the wiring is correct or not, usually people tend to interchange the SCL and SDA wire and waste a lot of time.<br /><div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/-GT-zpg1WJ1w/Ula1aEg5boI/AAAAAAAABSM/M2wrAlTo_is/s1600/WP_20131010_01020131010193711.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/-GT-zpg1WJ1w/Ula1aEg5boI/AAAAAAAABSM/M2wrAlTo_is/s1600/WP_20131010_01020131010193711.jpg" height="224" width="400" /></a></div><br /><a name='more'></a><br /><br /><div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;"><table><tbody><tr><td><pre style="line-height: 125%; margin: 0;"> 1<br /> 2<br /> 3<br /> 4<br /> 5<br /> 6<br /> 7<br /> 8<br /> 9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53</pre></td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #557799;">#include <Wire.h></span><br /><br /><br /><span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">setup</span>()<br />{<br /> Wire.begin();<br /><br /> Serial.begin(<span style="color: #0000dd; font-weight: bold;">9600</span>);<br /> Serial.println(<span style="background-color: #fff0f0;">"</span><span style="background-color: #fff0f0; color: #666666; font-weight: bold;">\n</span><span style="background-color: #fff0f0;">I2C Scanner"</span>);<br />}<br /><br /><br /><span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">loop</span>()<br />{<br /> byte error, address;<br /> <span style="color: #333399; font-weight: bold;">int</span> nDevices;<br /><br /> Serial.println(<span style="background-color: #fff0f0;">"Scanning..."</span>);<br /><br /> nDevices <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span>;<br /> <span style="color: #008800; font-weight: bold;">for</span>(address <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">1</span>; address <span style="color: #333333;"><</span> <span style="color: #0000dd; font-weight: bold;">127</span>; address<span style="color: #333333;">++</span> )<br /> {<br /> <span style="color: #888888;">// The i2c_scanner uses the return value of</span><br /> <span style="color: #888888;">// the Write.endTransmisstion to see if</span><br /> <span style="color: #888888;">// a device did acknowledge to the address.</span><br /> Wire.beginTransmission(address);<br /> error <span style="color: #333333;">=</span> Wire.endTransmission();<br /><br /> <span style="color: #008800; font-weight: bold;">if</span> (error <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">0</span>)<br /> {<br /> Serial.print(<span style="background-color: #fff0f0;">"I2C device found at address 0x"</span>);<br /> <span style="color: #008800; font-weight: bold;">if</span> (address<span style="color: #333333;"><</span><span style="color: #0000dd; font-weight: bold;">16</span>)<br /> Serial.print(<span style="background-color: #fff0f0;">"0"</span>);<br /> Serial.print(address,HEX);<br /> Serial.println(<span style="background-color: #fff0f0;">" !"</span>);<br /><br /> nDevices<span style="color: #333333;">++</span>;<br /> }<br /> <span style="color: #008800; font-weight: bold;">else</span> <span style="color: #008800; font-weight: bold;">if</span> (error<span style="color: #333333;">==</span><span style="color: #0000dd; font-weight: bold;">4</span>)<br /> {<br /> Serial.print(<span style="background-color: #fff0f0;">"Unknow error at address 0x"</span>);<br /> <span style="color: #008800; font-weight: bold;">if</span> (address<span style="color: #333333;"><</span><span style="color: #0000dd; font-weight: bold;">16</span>)<br /> Serial.print(<span style="background-color: #fff0f0;">"0"</span>);<br /> Serial.println(address,HEX);<br /> } <br /> }<br /> <span style="color: #008800; font-weight: bold;">if</span> (nDevices <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">0</span>)<br /> Serial.println(<span style="background-color: #fff0f0;">"No I2C devices found</span><span style="background-color: #fff0f0; color: #666666; font-weight: bold;">\n</span><span style="background-color: #fff0f0;">"</span>);<br /> <span style="color: #008800; font-weight: bold;">else</span><br /> Serial.println(<span style="background-color: #fff0f0;">"done</span><span style="background-color: #fff0f0; color: #666666; font-weight: bold;">\n</span><span style="background-color: #fff0f0;">"</span>);<br /><br /> delay(<span style="color: #0000dd; font-weight: bold;">5000</span>); <span style="color: #888888;">// wait 5 seconds for next scan</span><br />} </pre></td></tr></tbody></table></div><div><br />Example:<br /><div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-azL1sbY-Jjg/UtJi6-25KdI/AAAAAAAABU0/FXaB0w2G3Bk/s1600/11.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://3.bp.blogspot.com/-azL1sbY-Jjg/UtJi6-25KdI/AAAAAAAABU0/FXaB0w2G3Bk/s1600/11.png" /></a></div><br /><div style="background-color: white; color: #444000; font-family: Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.09375px; margin: 0px; padding: 0px;">Here you can see that four devices are attached to the board and their addresses in hex format.</div><div style="background-color: white; color: #444000; font-family: Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.09375px; margin: 0px; padding: 0px;">Note: The addresses are 7-bit as you can see that the code searches only for addresses between 0 to 127.</div><div style="background-color: white; color: #444000; font-family: Helvetica, Arial, sans-serif; font-size: 13px; line-height: 22.09375px; margin: 0px; padding: 0px;"><br /></div>Source : <a href="http://playground.arduino.cc/Main/I2cScanner" target="_blank">Arduino</a></div></div>Sudhir guptahttps://plus.google.com/105460425718553468371noreply@blogger.com0tag:blogger.com,1999:blog-8315127339483053508.post-18288572799348677402013-10-10T19:44:00.001+05:302014-01-14T23:38:19.665+05:30Interfacing the 10 DOF IMU with Arduino and Atmega<div dir="ltr" style="text-align: left;" trbidi="on"><div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-GT-zpg1WJ1w/Ula1aEg5boI/AAAAAAAABSI/iUcpwWZWpFI/s1600/WP_20131010_01020131010193711.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="IMU,10DOF" border="0" height="179" src="http://3.bp.blogspot.com/-GT-zpg1WJ1w/Ula1aEg5boI/AAAAAAAABSI/iUcpwWZWpFI/s320/WP_20131010_01020131010193711.jpg" title="" width="320" /></a></div><br />Starting to work on the <b>10 DOF Inertial measurement unit</b>. Will be posting the updates regularly <a href="http://www.randomstuff.co.in/" target="_blank">here</a>.<br /><br />Board Specifications:<br /><a name='more'></a><br /><ol style="text-align: left;"><li> <a href="http://www.randomstuff.co.in/2013/10/adxl345-accelerometer-using-atmega32.html" target="_blank"><b>ADXL345</b> </a>- 3 Axis Digital Accelerometer</li><li> <b>BMP085</b> - Digital Pressure Sensor</li><li> <b>L3G4200D</b> - 3 Axis Digital Gyroscope</li><li> <b>HMC5883L</b> - 3 Axis Digital Compass (Magnetometer)</li></ol></div>Sudhir guptahttps://plus.google.com/105460425718553468371noreply@blogger.com0tag:blogger.com,1999:blog-8315127339483053508.post-76541139673966485262013-09-18T20:38:00.002+05:302014-01-14T23:41:25.020+05:30Souce Code formatter for blogger<div dir="ltr" style="text-align: left;" trbidi="on"><div style="text-align: left;"><span style="background-color: white; color: #444000; line-height: 22.09375px;"><span style="font-family: inherit;">Here are some sites that help you to convert your code snippets into html format. The code is converted into a tabular format.</span></span></div><ul style="text-align: left;"><li><span style="font-family: inherit;"><a href="http://codeformatter.blogspot.in/">codeformatter.blogspot.in</a></span></li></ul><ul style="text-align: left;"><li><span style="font-family: inherit;"><a href="http://hilite.me/">http://hilite.me/</a></span></li></ul></div>Sudhir guptahttps://plus.google.com/105460425718553468371noreply@blogger.com0tag:blogger.com,1999:blog-8315127339483053508.post-21697748429171977572013-09-18T20:33:00.001+05:302013-11-23T03:28:16.142+05:30Interfacing HC-SR04 Ultrasonic Module with Arduino Pro Mini<div dir="ltr" style="text-align: left;" trbidi="on">SR04 is a module that can detect distance between 2cm to 400cm by sending out ultrasonic waves and calculating the time between the sent signal and echo received.<br /><div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-cYGx_5RYr2s/UlbSi1O4xhI/AAAAAAAABSY/XyslvMEtyfk/s1600/WP_20131010_01120131010214314.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="222" src="http://3.bp.blogspot.com/-cYGx_5RYr2s/UlbSi1O4xhI/AAAAAAAABSY/XyslvMEtyfk/s400/WP_20131010_01120131010214314.jpg" width="400" /></a></div><br /><br />Steps:<br /><ol style="text-align: left;"><li>Send the trigger signal - a TTL 10us signal</li><li>Wait for the echo pin to get high.</li><li>Calculate the time for which the echo pin is high using a timer.</li><li>Calculate the distance using </li></ol><div style="text-align: center;">Distance = high level time * velocity (340M/S) / 2 </div><div style="text-align: left;"><br /><a name='more'></a><br /><br />Here is the code for Arduino Pro Mini -<br /><br /></div><!-- HTML generated using hilite.me --><br /><div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;"><table><tbody><tr><td><pre style="line-height: 125%; margin: 0;"> 1<br /> 2<br /> 3<br /> 4<br /> 5<br /> 6<br /> 7<br /> 8<br /> 9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24</pre></td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">const</span> <span style="color: #333399; font-weight: bold;">int</span> echo <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">11</span>;<br /><span style="color: #008800; font-weight: bold;">const</span> <span style="color: #333399; font-weight: bold;">int</span> trig <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">10</span>;<br /><span style="color: #333399; font-weight: bold;">long</span> duration;<br /><span style="color: #333399; font-weight: bold;">long</span> dist;<br /><span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">setup</span>()<br />{<br /> pinMode(echo,INPUT);<br /> pinMode(trig,OUTPUT);<br /> Serial.begin(<span style="color: #0000dd; font-weight: bold;">9600</span>);<br />}<br /><br /><span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">loop</span>()<br />{<br /> digitalWrite(trig,HIGH);<br /> delayMicroseconds(<span style="color: #0000dd; font-weight: bold;">10</span>);<br /> digitalWrite(trig,LOW);<br /> duration<span style="color: #333333;">=</span>pulseIn(echo,HIGH);<br /> dist <span style="color: #333333;">=</span> duration <span style="color: #333333;">/</span> <span style="color: #0000dd; font-weight: bold;">58</span>;<br /> Serial.println(dist);<br /> Serial.println(duration);<br /> delay(<span style="color: #0000dd; font-weight: bold;">1000</span>);<br />}<br /> <br /> <br /></pre></td></tr></tbody></table></div><div style="text-align: left;"><br /><br /></div><div style="text-align: left;">The above code is very basic and does not have the out of range or too close feature. Hopefully I will update it in the next post.</div><div style="text-align: left;"><br /></div></div>Sudhir guptahttps://plus.google.com/105460425718553468371noreply@blogger.com0tag:blogger.com,1999:blog-8315127339483053508.post-23706678188048520082013-09-17T23:17:00.001+05:302014-01-12T23:44:04.856+05:30Atmel AVR Fuse Bit Calculator<div dir="ltr" style="text-align: left;" trbidi="on"><div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/-L3qynZ4Y6lw/UtJiJPwTvcI/AAAAAAAABUw/cTmb1hVxFt8/s1600/AVR-logo.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-L3qynZ4Y6lw/UtJiJPwTvcI/AAAAAAAABUw/cTmb1hVxFt8/s1600/AVR-logo.png" /></a></div><br />You can find out the fuse bit setting here without any effort .<br /><a href="http://www.engbedded.com/fusecalc/" target="_blank">Click Here</a><br /><a name='more'></a><br /></div>Sudhir guptahttps://plus.google.com/105460425718553468371noreply@blogger.com0tag:blogger.com,1999:blog-8315127339483053508.post-3540330862220954712013-05-11T19:17:00.000+05:302013-11-23T03:28:16.176+05:30V-USB<div dir="ltr" style="text-align: left;" trbidi="on"><div class="separator" style="clear: both; text-align: center;"><a href="http://www.obdev.at/Images/vusb/vusb-teaser.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://www.obdev.at/Images/vusb/vusb-teaser.png" /></a></div><span style="background-color: white; color: #222233; font-family: 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 14px; line-height: 20px;"><br /></span><span style="background-color: white; color: #222233; font-family: 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 14px; line-height: 20px;"><br /></span><span style="background-color: white; color: #222233; font-family: 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 14px; line-height: 20px;">V-USB is a software-only implementation of a low-speed USB device for </span><a href="http://www.atmel.com/" style="background-color: white; color: #0066bb; font-family: 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 14px; line-height: 20px; text-decoration: none;" target="_blank">Atmel’s</a><span style="background-color: white; color: #222233; font-family: 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 14px; line-height: 20px;"> AVR</span><span class="superscript" style="background-color: white; bottom: 0.5em; color: #222233; font-family: 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 0.7em; line-height: 20px; position: relative;">®</span><span style="background-color: white; color: #222233; font-family: 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 14px; line-height: 20px;"> microcontrollers, making it possible to build USB hardware with almost any AVR</span><span class="superscript" style="background-color: white; bottom: 0.5em; color: #222233; font-family: 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 0.7em; line-height: 20px; position: relative;">®</span><span style="background-color: white; color: #222233; font-family: 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 14px; line-height: 20px;"> microcontroller, not requiring any additional chip.</span><br /><span style="background-color: white; color: #222233; font-family: 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 14px; line-height: 20px;"><br /></span><span style="background-color: white; color: #222233; font-family: 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 14px; line-height: 20px;">More Info can be found out <a href="http://www.obdev.at/products/vusb/index.html" target="_blank">here</a></span><br /><a name='more'></a></div>Sudhir guptahttps://plus.google.com/105460425718553468371noreply@blogger.com0tag:blogger.com,1999:blog-8315127339483053508.post-80823486729671468352013-02-26T14:46:00.001+05:302013-11-23T03:28:16.220+05:30Schileren Visualization of a Double Divergent Section<div dir="ltr" style="text-align: left;" trbidi="on"><div class="separator" style="clear: both; text-align: center;"><object width="320" height="266" class="BLOGGER-youtube-video" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" data-thumbnail-src="https://ytimg.googleusercontent.com/vi/ToITEIi1M8w/0.jpg"><param name="movie" value="https://www.youtube.com/v/ToITEIi1M8w?version=3&f=user_uploads&c=google-webdrive-0&app=youtube_gdata" /><param name="bgcolor" value="#FFFFFF" /><param name="allowFullScreen" value="true" /><embed width="320" height="266" src="https://www.youtube.com/v/ToITEIi1M8w?version=3&f=user_uploads&c=google-webdrive-0&app=youtube_gdata" type="application/x-shockwave-flash" allowfullscreen="true"></embed></object></div><div style="text-align: center;">Schileren Visualization of a Double Divergent Section</div><div style="text-align: center;">@APLD lab IIST</div></div>Sudhir guptahttps://plus.google.com/105460425718553468371noreply@blogger.com0tag:blogger.com,1999:blog-8315127339483053508.post-6674368217592900812012-11-18T12:03:00.000+05:302014-01-21T22:00:34.135+05:30Monocopter...<div dir="ltr" style="text-align: left;" trbidi="on">Recently started working on a hovering model of a <a href="http://en.wikipedia.org/wiki/Monocopter" target="_blank">monocopter</a><br /><div><br />First try<br /><br /><br /></div><div><div class="separator" style="clear: both; text-align: center;"><object class="BLOGGER-youtube-video" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" data-thumbnail-src="https://ytimg.googleusercontent.com/vi/NcCHRHB-9bE/0.jpg" height="266" width="320"><param name="movie" value="https://www.youtube.com/v/NcCHRHB-9bE?version=3&f=user_uploads&c=google-webdrive-0&app=youtube_gdata" /><param name="bgcolor" value="#FFFFFF" /><param name="allowFullScreen" value="true" /><embed width="320" height="266" src="https://www.youtube.com/v/NcCHRHB-9bE?version=3&f=user_uploads&c=google-webdrive-0&app=youtube_gdata" type="application/x-shockwave-flash" allowfullscreen="true"></embed></object></div><br />Based on model by Evan R.Ulrich<br /><br /><a name='more'></a><br /><br /><br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-DlIFKE86eaA/UMBxCtq-ZVI/AAAAAAAAAyw/jitp25AfOHQ/s1600/poster99.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/-DlIFKE86eaA/UMBxCtq-ZVI/AAAAAAAAAyw/jitp25AfOHQ/s640/poster99.png" height="640" width="452" /></a></div><br /></div></div>Sudhir guptahttps://plus.google.com/105460425718553468371noreply@blogger.com0tag:blogger.com,1999:blog-8315127339483053508.post-49521087682426536752012-11-11T10:02:00.001+05:302014-01-12T23:44:52.889+05:30BEAM Robotics<div dir="ltr" style="text-align: left;" trbidi="on">BEAM (Biology Electronics Aesthetics and Mechanics) Robotics , it is an approach to robotics using simple analog circuits rather than using micro-processors or micro-controllers. This concept uses a type of circuit configuration which mainly consists of a neural network referred as "Nervous Net" or "Nv Net" whose element are none other than artificial neurons.<br /><br /><span style="font-size: large;">Why??</span><br />Reduce the cost and complexity of the design. It takes less time to build a Beam-Robot rather than designing traditional machines, also the size of Beam Robots are smaller than traditional robots.<br /><br /><span style="font-size: large;">Nv Neuron ???</span><br />Artificial neurons are made of a resistor, capacitor and a NOT gate.<br /><div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/-JJ4cc-dNggs/UJ8pVhVgftI/AAAAAAAAAx4/OSEK6YICgSM/s1600/Nv+Neuron.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-JJ4cc-dNggs/UJ8pVhVgftI/AAAAAAAAAx4/OSEK6YICgSM/s400/Nv+Neuron.png" height="250" width="400" /></a></div><div class="separator" style="clear: both; text-align: center;"></div><a name='more'></a><br /><br /><div class="separator" style="clear: both; text-align: left;">The above type of arrangement form a differential element in a circuit (since input is couple via capacitor) and is called a Nv Neuron.</div><div class="separator" style="clear: both; text-align: left;"><br /></div><div class="separator" style="clear: both; text-align: left;"><span style="font-size: large;">How Does it Work??</span></div><div class="separator" style="clear: both; text-align: left;">When a positive raising voltage is applied to the input, the voltage at the other side of the capacitor instantly raises to 5V (assuming you applying 5V) , the Nv inverter output drops to 0 in just a few nano-seconds. Then the capacitor charges and the voltage at the other side of the capacitor starts to decay exponentially with respect to time and goes to zero when the capacitor get fully charged. During this the input to the inverter (the NOT gate) crosses the threshold causing the inverter output going to 5V resulting in a positive voltage transition.</div><div class="separator" style="clear: both; text-align: left;"><br /></div><div class="separator" style="clear: both; text-align: left;"><span style="font-size: large;">Creating a Logic Using Nv Neurons</span></div><div class="separator" style="clear: both; text-align: left;">A single neuron is useless, you have to connect multiple neurons in order to create some logic to achieve the response required for your application. The core concept is the timing with which it responds to the voltage change. A simple way how the respond can be checked by designing the circuit and attach LED's to the output pins and see how the pattern is. These are generally referred to a bicore, tricore, quadcore.... based on the number of neurons used.</div></div>Sudhir guptahttps://plus.google.com/105460425718553468371noreply@blogger.com0tag:blogger.com,1999:blog-8315127339483053508.post-87537101684416833422012-11-01T22:45:00.005+05:302014-01-16T00:31:34.563+05:30ATmega32's Internal EEPROM<div dir="ltr" style="text-align: left;" trbidi="on"><div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/-L3qynZ4Y6lw/UtJiJPwTvcI/AAAAAAAABUw/cTmb1hVxFt8/s1600/AVR-logo.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-L3qynZ4Y6lw/UtJiJPwTvcI/AAAAAAAABUw/cTmb1hVxFt8/s1600/AVR-logo.png" /></a></div><br />The EEPROM is an area of read/write memory that is non-volatile i.e., the stored data is not lost even if you power off the device.<br /><br />The ATmega32 has a inbuilt EEPROM in it . Before starting to learn about using the internal EEPROM, let's get to know about the risk's that involve in using a Internal EEPROM.<br /><br /><ol style="text-align: left;"><li>Internal EEPROM might get corrupted while the power is being switched off.</li><li>Supply voltages are likely to rise or fall slowly during power up or down, this causes the device to operate at a voltage lower than the specified minimums voltage for the clock frequency used. This might lead to an unintentional write of the EEPROM.<a name='more'></a></li></ol><div>Although the EEPROM memory memory may be both read and write, it is seldom used for general variable storage. The reason being the EEPROM memory being very slow to write, it can take up to a millisecond to complete a write operation one byte of memory. So an extensive use of this memory would slow down the processor appreciably.In order to avoid this a specific procedure is to be followed. Also, EEPROM can only withstand a only a limited number of read and write cycles. So knowing the risk factors and disadvantages let's see how to use the internal EEPROM of ATmega32.</div><div><br /></div><div>The ATmega32 contains 1 kilobyte of internal memory which has a endurance of about 100000 write/erase cycles. This memory can be totally controlled using three registers in ATmega32.</div><div><ol style="text-align: left;"><li>The EEPROM address register - EEARH and EEARL (note: this is a 16 bit register)</li><li>The EEPROM data register - EEDR</li><li>The EEPROM control register - EECR</li></ol><div><div>The EEARH and EEARL used to specify the address of the 1024 bytes of EEPROM memory. The EEARH is the higher byte of the register while EEARL is the lower byte of the register. So why a 16 bit register ?? (If you didn't get it please read the basics)</div></div></div><div><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-Z0kbR5XosDk/UJKA6gTjERI/AAAAAAAAAxA/nmslwTr5hc4/s1600/eeprom.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="106" src="http://4.bp.blogspot.com/-Z0kbR5XosDk/UJKA6gTjERI/AAAAAAAAAxA/nmslwTr5hc4/s400/eeprom.png" width="400" /></a></div><div class="separator" style="clear: both; text-align: center;"><br /></div><div>Anyway as there are 1024 bytes (2^10) and each should have a unique address, which implies 1024 addresses in binary system a minimum of 10 digits are needed in order to specify all the addresses.</div><div>The rest of the 6 bits are always read as zero. </div><div><br /></div><div>So, if you want to write some value to #15 address the EEARL should be set to 0b00001111 and the EEARH should be set to 0b00000000.</div><div><br /></div><div>The EEDR register is linked to the data to be written or to be read form a specified address in the EEPROM i.e, during a read operation the data can be retrieved from the EEDR register and during the write process the EEDR register is to be set to the value that is to be written in a specified address inn the EEPROM.<br /><br />The EECR register is the control register (can be understood by the name itself)<br /><div class="separator" style="clear: both; text-align: center;"><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/--rfIXMkdqaQ/UJKgmwbMtLI/AAAAAAAAAxU/THzvRhbDelU/s1600/eeprom2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="58" src="http://2.bp.blogspot.com/--rfIXMkdqaQ/UJKgmwbMtLI/AAAAAAAAAxU/THzvRhbDelU/s400/eeprom2.png" width="400" /></a></div><br /><br /></div><div>Here each bit of the register has a specific purpose<br /><br />The EERE bit (bit 0 - EEPROM Read Enable) if this bit is set to high the data from the specified address set in EEAR is read.<br /><br />IMP : when this read action takes place, the CPU is halted for four cycles before it executes the next step.<br /><br />The EEWE ( bit 1 - EEPROM Write Enable) it is the counter bit of EERE for write operation.<br />But in order to make the EEWE bit work the EEMWE bit must be set, otherwise setting the EEWE bit to high doesn't effect anything.<br /><br />About EERIE nothing much to say about it, can be clearly understood from the datasheet.<br /><br />Here is a the C code for writing data into EEPROM<br /><br /><blockquote class="tr_bq">void EEPROM_write(unsigned int uiAddress, unsigned char ucData)<br />{<br /><span style="color: lime;">/* Wait for completion of previous write */</span><br />while(EECR & (1<<EEWE))<br />;<br /><span style="color: lime;">/* Set up address and data registers */</span><br />EEAR = uiAddress;<br />EEDR = ucData;<br /><span style="color: lime;">/* Write logical one to EEMWE */</span><br />EECR |= (1<<EEMWE);<br /><span style="color: lime;">/* Start eeprom write by setting EEWE */</span><br />EECR |= (1<<EEWE);<br />}</blockquote><br /><div>C Code for Reading</div><div><br /></div><div><blockquote class="tr_bq">unsigned char EEPROM_read(unsigned int uiAddress)<br />{<br /><span style="color: lime;">/* Wait for completion of previous write */</span><br />while(EECR & (1<<EEWE))<br />;<br /><span style="color: lime;">/* Set up address register */</span><br />EEAR = uiAddress;<br /><span style="color: lime;">/* Start eeprom read by writing EERE */</span><br />EECR |= (1<<EERE);<br /><span style="color: lime;">/* Return data from data register */</span><br />return EEDR;<br />}</blockquote></div><div><br /></div><br /><br /></div></div>Sudhir guptahttps://plus.google.com/105460425718553468371noreply@blogger.com0tag:blogger.com,1999:blog-8315127339483053508.post-26724089778315277392012-10-25T01:00:00.006+05:302014-01-16T00:27:28.779+05:30PWM with ATMEGA 32<div dir="ltr" style="text-align: left;" trbidi="on"><div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/-L3qynZ4Y6lw/UtJiJPwTvcI/AAAAAAAABUw/cTmb1hVxFt8/s1600/AVR-logo.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-L3qynZ4Y6lw/UtJiJPwTvcI/AAAAAAAABUw/cTmb1hVxFt8/s1600/AVR-logo.png" /></a></div><br />PWM - Pulse Width Modulation.<br /><br />The basics about PWM can be read <a href="http://en.wikipedia.org/wiki/Pulse-width_modulation" target="_blank">here</a><br /><br />Why PWM??<br />Suppose you have a motor with a certain torque and RPM, and you want to change the RPM. This can be done easily by reducing the voltage supplied, but due to this even the torque of the motor reduces. So, how to control the RPM of the motor without compromising on torque ???<br />The answer is PWM - Pulse Width Modulation<br /><br /><a name='more'></a><br /><br />However PWM can be used in a lot other application too like controlling the brightness of an LED, generating various sound with a buzzer, etc.,<br /><br />How to generate a PWM??<br />PWM uses a square wave whose duty cycle is modulated resulting in variation of the average value of the wave form.<br /><br />See the following two pictures, here t is the duty cycle.<br />In the first picture the signal is high for 75% of the duty cycle leading to a higher average value than the second one which is high for only 25% of the duty cycle.<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/-UTLg0VbZZzY/UIg5evbOz1I/AAAAAAAAAvg/xx2CLtBYxUc/s1600/11.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="143" src="http://2.bp.blogspot.com/-UTLg0VbZZzY/UIg5evbOz1I/AAAAAAAAAvg/xx2CLtBYxUc/s320/11.png" width="320" /></a></div><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/-MVfwrW7Xbcg/UIg5fVt2keI/AAAAAAAAAvk/0zxlBDuKMXA/s1600/22.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="166" src="http://1.bp.blogspot.com/-MVfwrW7Xbcg/UIg5fVt2keI/AAAAAAAAAvk/0zxlBDuKMXA/s320/22.png" width="320" /></a></div><br />Here is a small LED dimmer application using PWM<br /><br />As PWM is based on timing, obviously a timer should be used. You can see from the ATMEGA 32 datasheet that ATMEGA 32 has four PWM channels any one of the channels can be used to generate the PWM output.<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/-dss_v9urIMM/UIg7gi6s6sI/AAAAAAAAAvw/kMg_rh4Dhjs/s1600/33.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="281" src="http://1.bp.blogspot.com/-dss_v9urIMM/UIg7gi6s6sI/AAAAAAAAAvw/kMg_rh4Dhjs/s640/33.png" width="640" /></a></div><div class="separator" style="clear: both; text-align: left;"><br /></div>Lets do it with TIMER 0<br /><br />While using TIMER 0 to generate PWM the PB3 pin of the Atmega32 is to be used as the output for the PWM signal, the OC0 pin.<br /><br /><ol style="text-align: left;"><li>Connect the output to LED. </li><li>Set the PB3 pin high as the timer starts</li><li>PB3 pin is cleared as the value of TCNT0 becomes equal to OCR0. This is the compare match.</li><li>As TCNT0 reaches maximum value the TIMER 0 overflows. At the instance the PB3 pin is set to high.</li></ol><div>Thus the PB3 pin remains High during TCNT0 = 0 and TCNT0<OCR0 and Low during TCNT0>OCR0 and TCNT0<255 ( as TCNT0 is single byte register 2^8 - 1 = 255 which is the max value). So by changing the value of OCR0 we can change the average value.</div><div>Here i use the Fast PWM mode to generate the signal</div><div><br /></div><div>CODE:</div><div><br /></div><blockquote class="tr_bq">#include<avr/io.h><br />#include<avr/interrupt.h><br />int main(void)<br />{<br /> DDRB = 0x08; <span style="color: lime;">//Use only PB3 as Output</span><br /> PORTB = 0xF7; <br /> OCR0 = 10; <span style="color: lime;">//Set Compare Value</span><br /> TIMSK = _BV(1); <span style="color: lime;">//Enable compare match interrupt for Timer 0</span><br /> TCCR0 = _BV(0)|_BV(1)|_BV(6)|_BV(3)|_BV(5); <span style="color: lime;">//Start Timer0 using 64 prescalar (bit 0,1),Fast PWM mode(bit 6,3),Clear OC0 pin on compare match (bit5)</span><br /> sei(); <span style="color: lime;">//enable Global Interrupts</span><br /> while(1)<br /> {<br /> asm("nop");<br /> }<br /> return 0;<br />}<br />SIGNAL(SIG_OUTPUT_COMPARE0)<br />{<br /> OCR0++<br /> if(OCR0 >= 250)<br /> {<br /> OCRO = 10;<br /> }<br />}</blockquote>So now the LED get brighter an then gets dull and cycle continues</div>Sudhir guptahttps://plus.google.com/105460425718553468371noreply@blogger.com0tag:blogger.com,1999:blog-8315127339483053508.post-60431772914353548222012-10-21T16:56:00.000+05:302013-11-23T03:28:16.206+05:30HK-922MG Digital Metal Gear Servo<div dir="ltr" style="text-align: left;" trbidi="on">Recently bought this <a href="http://www.hobbyking.com/hobbyking/store/uh_viewitem.asp?idproduct=14279&aff=605444" target="_blank">HK-922MG Digital Metal Gear Servo</a><br /><div>What i like about the servo are</div><div><a name='more'></a></div><div><ol style="text-align: left;"><li>Strong arms</li><li>No Jitter</li><li>Hard Casing unlike many other HK low cost servos</li><li>Comes in well packed box</li><li>No play</li><li>Digital Servo with metal gear only for $10</li></ol><div>Cons - Short wire to the receiver</div><div><br /></div><div>Going to use it in a tricopter going to post the build log soon..</div></div><div><br /></div><div class="separator" style="clear: both; text-align: center;"><object width="320" height="266" class="BLOG_video_class" id="BLOG_video-b66c3ce327566431" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="movie" value="//www.youtube.com/get_player"><param name="bgcolor" value="#FFFFFF"><param name="allowfullscreen" value="true"><param name="flashvars" value="flvurl=http://redirector.googlevideo.com/videoplayback?id%3Db66c3ce327566431%26itag%3D5%26source%3Dblogger%26app%3Dblogger%26cmo%3Dsensitive_content%3Dyes%26ip%3D0.0.0.0%26ipbits%3D0%26expire%3D1455655062%26sparams%3Dip,ipbits,expire,id,itag,source%26signature%3D26755F18B1DCD4FF3F842A50FBEC2007CDE65FED.8CED16953D2A360069A62C9C4547CB7F395D6072%26key%3Dck2&iurl=http://video.google.com/ThumbnailServer2?app%3Dblogger%26contentid%3Db66c3ce327566431%26offsetms%3D5000%26itag%3Dw160%26sigh%3DGbiQSqr50IVkTsHARNtCw4akTkA&autoplay=0&ps=blogger"><embed src="//www.youtube.com/get_player" type="application/x-shockwave-flash" width="320" height="266" bgcolor="#FFFFFF" flashvars="flvurl=http://redirector.googlevideo.com/videoplayback?id%3Db66c3ce327566431%26itag%3D5%26source%3Dblogger%26app%3Dblogger%26cmo%3Dsensitive_content%3Dyes%26ip%3D0.0.0.0%26ipbits%3D0%26expire%3D1455655062%26sparams%3Dip,ipbits,expire,id,itag,source%26signature%3D26755F18B1DCD4FF3F842A50FBEC2007CDE65FED.8CED16953D2A360069A62C9C4547CB7F395D6072%26key%3Dck2&iurl=http://video.google.com/ThumbnailServer2?app%3Dblogger%26contentid%3Db66c3ce327566431%26offsetms%3D5000%26itag%3Dw160%26sigh%3DGbiQSqr50IVkTsHARNtCw4akTkA&autoplay=0&ps=blogger" allowFullScreen="true" /></object></div><div><br /></div><div><br /></div><div><div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-wHYJVdv7z-U/UIPZ-xJkMCI/AAAAAAAAAvM/Fu4UKvEUPEA/s1600/IMAG0138.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" height="320" src="http://4.bp.blogspot.com/-wHYJVdv7z-U/UIPZ-xJkMCI/AAAAAAAAAvM/Fu4UKvEUPEA/s320/IMAG0138.jpg" width="212" /></a></div><a href="http://4.bp.blogspot.com/-eeI6C3-9LQk/UIPYw7ARJQI/AAAAAAAAAu8/MSBd9MhR1GU/s1600/IMAG0136.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em; text-align: center;"></a><a href="http://1.bp.blogspot.com/-SzxskQQ6y2I/UIPYy4z9lNI/AAAAAAAAAvE/yuNx7OLZm5o/s1600/IMAG0137.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><br /></a> </div><div><br /></div><div><div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/-SzxskQQ6y2I/UIPYy4z9lNI/AAAAAAAAAvE/yuNx7OLZm5o/s1600/IMAG0137.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="212" src="http://1.bp.blogspot.com/-SzxskQQ6y2I/UIPYy4z9lNI/AAAAAAAAAvE/yuNx7OLZm5o/s320/IMAG0137.jpg" width="320" /></a></div></div></div>Sudhir guptahttps://plus.google.com/105460425718553468371noreply@blogger.com0tag:blogger.com,1999:blog-8315127339483053508.post-66146249498860234672012-10-18T20:26:00.002+05:302013-11-23T03:28:16.210+05:30Processing - Open Source Programming language<div dir="ltr" style="text-align: left;" trbidi="on"><br /><div>Accidentally came across this new language Processing (weird name), mainly based on graphics programming and really simple to use. Processing is built by the electronic arts and the visual design communities with the purpose of teaching computer programming in the visual context. Though built on the Java platform the syntax is drastically simplified.</div><div><br /></div><div>Here are some images of a snowflake fractal made using processing</div><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: right;"><tbody><tr><td style="text-align: center;"><a href="http://4.bp.blogspot.com/-bL8YKAMc9uE/UIAYDI4hHXI/AAAAAAAAAso/fTxCJx-8CIs/s1600/4.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="320" src="http://4.bp.blogspot.com/-bL8YKAMc9uE/UIAYDI4hHXI/AAAAAAAAAso/fTxCJx-8CIs/s320/4.png" width="318" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">4 Iteration</td></tr></tbody></table><br /><a name='more'></a><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://4.bp.blogspot.com/-Wiq7gjhVB9U/UIAYCgqbktI/AAAAAAAAAsg/QU1kh4TEGUs/s1600/3.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="320" src="http://4.bp.blogspot.com/-Wiq7gjhVB9U/UIAYCgqbktI/AAAAAAAAAsg/QU1kh4TEGUs/s320/3.png" width="320" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">3 Iterations</td></tr></tbody></table><br />Mandelbrot :<div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-5XvyLT2y_ZQ/UIAkD3NLlcI/AAAAAAAAAs8/BkvthE8_Te4/s1600/1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="318" src="http://4.bp.blogspot.com/-5XvyLT2y_ZQ/UIAkD3NLlcI/AAAAAAAAAs8/BkvthE8_Te4/s640/1.png" width="640" /></a></div><div><br /></div><div><div><br /></div><div><br /></div></div></div>Sudhir guptahttps://plus.google.com/105460425718553468371noreply@blogger.com0tag:blogger.com,1999:blog-8315127339483053508.post-81897154332124351142012-10-14T09:40:00.001+05:302013-11-23T03:28:16.225+05:30Mandelbrot<div dir="ltr" style="text-align: left;" trbidi="on"><div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-uVOC6JPWBAo/UHo5zA28KdI/AAAAAAAAApw/qRp8IXJrUw0/s1600/mandel.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="358" src="http://4.bp.blogspot.com/-uVOC6JPWBAo/UHo5zA28KdI/AAAAAAAAApw/qRp8IXJrUw0/s640/mandel.png" width="640" /></a></div><div style="text-align: center;">Mandelbrot set plotted in Matlab<br /><br /><a name='more'></a></div><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-QegxKWHbXOI/UHo5bNdttQI/AAAAAAAAApo/uoI1xgrPJIc/s1600/Screenshot+-+10082012+-+01:16:37+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="356" src="http://3.bp.blogspot.com/-QegxKWHbXOI/UHo5bNdttQI/AAAAAAAAApo/uoI1xgrPJIc/s640/Screenshot+-+10082012+-+01:16:37+PM.png" width="640" /></a></div><br /><div style="text-align: center;">Mandelbrot set plotted in Scilab<br /><div style="text-align: left;"><br /><br /></div><div style="text-align: left;"><span style="font-size: large;">Matlab Code:</span></div><div style="text-align: left;"><br /></div><blockquote class="tr_bq"><pre style="color: #222222; font-family: 'Andale Mono', 'Courier New', Courier, monospace; font-size: 14px; line-height: 22px; text-align: -webkit-auto;"><code style="font-family: 'Andale Mono', 'Courier New', Courier, monospace;">close all;<br />clc;<br />clear all;<br />xmin = -0.3;<br />xmax = 0.1;<br />ymin = -1.0;<br />ymax = -0.6;<br />spacing = 1000;<br />x = linspace(xmin,xmax,spacing);<br />y = linspace(ymin,ymax,spacing);<br />[X,Y] = meshgrid(x,y);<br />Z = X + 1i*Y;<br />maxIter = 500;<br />c = ones(size(Z));<br />C = Z;<br />for n = 1:maxIter<br />Z = Z.^2 + C;<br />mag = abs(Z) <=2;<br />c = c + mag; <br />end<br />surfc(X,Y,c);<br />shading interp</code></pre></blockquote><br /></div></div>Sudhir guptahttps://plus.google.com/105460425718553468371noreply@blogger.com0tag:blogger.com,1999:blog-8315127339483053508.post-56470141306724791712012-10-13T02:59:00.002+05:302014-01-16T00:28:10.675+05:30OpenFOAM - BASICS<div dir="ltr" style="text-align: left;" trbidi="on"><div dir="ltr" style="text-align: left;" trbidi="on"><div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-sbRr1LyUXug/UHiJahJAPuI/AAAAAAAAAos/CctEZbs6EIU/s1600/6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" height="217" src="http://3.bp.blogspot.com/-sbRr1LyUXug/UHiJahJAPuI/AAAAAAAAAos/CctEZbs6EIU/s400/6.png" width="400" /></a></div><br /><br /> CFD - Computational Fluid Dynamics is a branch of fluid mechanics that uses numerical methods to solve and analyze problems related to fluid flows. More information on CFD can be found on the <a href="http://en.wikipedia.org/wiki/Computational_fluid_dynamics" target="_blank">Wikipedia page</a>. There are many CFD software available in the market but OpenFOAM is an open source CFD toolbox so it is free of cost and also provides accurate results on par with many of the commercial CFD software. <br /><a name='more'></a>The only drawback that many users feel is the lack of GUI and no support for windows (ya works only on Linux). Another thing that i felt is that it would be really helpful if someone provided with some basic tutorials to start of with, so this post is mainly based on the basic stuff needed to get started with OpenFOAM. From now on the text highlighted in grey are that commands to be typed in the terminal.<br /><br /><div><br /></div><div>The installation details can be found on <a href="http://www.openfoam.org/download/">http://www.openfoam.org/download/</a>. To check if it is installed correctly type <span style="background-color: #666666;">icoFoam -help</span> in the terminal window. If the "Usage" message appears then it is installed correctly.</div><div><br /></div><div>There are a lot of examples provided in the OpenFOAM package itself but still understanding it might take some time. The tutorials can be found in the home folder if you have done all the steps provided in the installation page of the OpenFOAM website. Now type the following in the terminal window:</div><blockquote class="tr_bq"><span style="background-color: #666666;">cd $FOAM_RUN/tutorials<br />ls</span></blockquote>Now a list of the content of the tutorials folder is shown<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-uCqg1bGEiig/UHh9j_saahI/AAAAAAAAAn8/wtNyi7t8ANE/s1600/1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://3.bp.blogspot.com/-uCqg1bGEiig/UHh9j_saahI/AAAAAAAAAn8/wtNyi7t8ANE/s1600/1.png" /></a></div><div class="separator" style="clear: both; text-align: center;"><br /></div><div class="separator" style="clear: both; text-align: left;">These folder name refer to the type of problem that is implemented. A tutorial based on icoFoam solver can be found in the User Guide. So i'll be starting with another one. Now go to the Forward Step problem which is located in compressible/sonicFoam/laminar/</div><div class="separator" style="clear: both; text-align: left;"><br /></div><blockquote class="tr_bq"><span style="background-color: #666666;">cd compressible/sonicFoam/laminar/forwardStep</span></blockquote><div class="separator" style="clear: both; text-align: left;">Now you can see that this folder consists of three folders named:</div><div class="separator" style="clear: both; text-align: left;"></div><div><ul><li><b><u>0</u></b>: The 0 folder consists of the initial conditions and the boundary condition of the problem.</li><li><u style="font-weight: bold;">constant:</u> The constant folder consists of the parameters that are kept constant throughout the simulation like viscosity , molecular weight, etc. Within the constant folder there is another folder named polymesh which contains the geometry of the body that is to be simulated. The blockMeshDict file contains the in formation regarding the geometry. blockMesh is the most commonly used utility in OpenFOAM used for meshing.</li><li><u style="font-weight: bold;">system:</u> The system folder consist of the time information like Start time, Stop Time, Time Interval etc.,</li></ul><div>I'll describe each of the files associated in detail later but for now lets see how to run this example program.</div><div>The first thing to do is to mesh, this is done by using the blockMesh utility. So, now type <span style="background-color: #666666;">blockMesh</span> in the terminal window. (make sure you are in the forwardStep folder and not in constat or 0 or system folders)<br /><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-PNUxRcCzCJg/UHiE-jGDZ7I/AAAAAAAAAoM/LOwCAu0vIPs/s1600/2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="464" src="http://4.bp.blogspot.com/-PNUxRcCzCJg/UHiE-jGDZ7I/AAAAAAAAAoM/LOwCAu0vIPs/s640/2.png" width="640" /></a></div><div class="separator" style="clear: both; text-align: center;"><br /></div><div>If the meshing is successful the End command should appear, if there is an error in the bolckMeshDict file in the constant/polyMesh folder an error shows up. The checkMesh utility inspects the mesh and gives the information about the mesh like the number of points, faces, patches used, etc., if the mesh is good it returns a " Mesh OK" dialogue in the end.<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/-p8fqWaXtY9A/UHjlFyGBrhI/AAAAAAAAApE/pJwXrx2U0DQ/s1600/8.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="601" src="http://2.bp.blogspot.com/-p8fqWaXtY9A/UHjlFyGBrhI/AAAAAAAAApE/pJwXrx2U0DQ/s640/8.png" width="640" /></a></div><br /></div><div>After meshing run the solver i.e. type <span style="background-color: #666666;">sonicFoam</span><br />sonicFoam is a Transient solver for trans-sonic/supersonic, laminar or turbulent flow of a compressible gas.(The list of the solvers can be found in the users guide)<br /><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/-axLFbaiDes8/UHiGTG2DsyI/AAAAAAAAAoU/AWScB13Vf4E/s1600/3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="516" src="http://1.bp.blogspot.com/-axLFbaiDes8/UHiGTG2DsyI/AAAAAAAAAoU/AWScB13Vf4E/s640/3.png" width="640" /></a></div><div><br />The end time is specified 10 you can see that the solver stops computing after that specified time is reached. sonicFoam</div><div><br /></div><div>To view the results a third-party software <a href="http://www.paraview.org/" target="_blank">ParaView</a> is used. Now to view the computed result type <span style="background-color: #666666;">paraFoam</span> or <span style="background-color: #666666;">optirun paraFoam</span><span style="background-color: black;"><span style="color: white;"> (see http</span></span>://timepass-backwas.blogspot.in/2012/10/bumblebee-nvidia-optimus-technology-in.html to know what optirun does). The following screen appears<br /><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-3c3ygsL2FIU/UHiHl9CrseI/AAAAAAAAAoc/bonWwFNU4y4/s1600/4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="348" src="http://4.bp.blogspot.com/-3c3ygsL2FIU/UHiHl9CrseI/AAAAAAAAAoc/bonWwFNU4y4/s640/4.png" width="640" /></a></div><div><br />Now click apply (green color button in the left toolbar)</div><div><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/-tyw3dRDULyo/UHiH56se-oI/AAAAAAAAAok/la7ObjSyVeo/s1600/5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="348" src="http://1.bp.blogspot.com/-tyw3dRDULyo/UHiH56se-oI/AAAAAAAAAok/la7ObjSyVeo/s640/5.png" width="640" /></a></div><div><br />Now you can see the geometry. Explore and try to get used to the paraview software. Select Wireframe in the drop-down menu where "Surface" is selected in the above figure to view the mesh. To see the velocity and pressure values select the respective form the drop-down menu where "Solid Color" is selected at present and press the play button to see the variation of the values with time</div><div><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-sbRr1LyUXug/UHiJahJAPuI/AAAAAAAAAos/CctEZbs6EIU/s1600/6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="348" src="http://3.bp.blogspot.com/-sbRr1LyUXug/UHiJahJAPuI/AAAAAAAAAos/CctEZbs6EIU/s640/6.png" width="640" /></a></div><div>Figure showing the velocity over the surface. Search for color maps and legend and try to modify according to your preference.<br /><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/-uh3MYxmPty0/UHiKLp_4rZI/AAAAAAAAAo0/a_dZvJp05A0/s1600/7.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="348" src="http://1.bp.blogspot.com/-uh3MYxmPty0/UHiKLp_4rZI/AAAAAAAAAo0/a_dZvJp05A0/s640/7.png" width="640" /></a></div><div><br />Figure showing the pressure profile over the surface. The above two figures show results at 10 sec.<br /><br /><br /></div><div><ol></ol></div></div></div><script type="text/javascript">ch_fluidH = 1; ch_nump = "7"; ch_client = "sudhiruday31"; ch_width = 600; ch_height = "auto"; ch_type = "mpu"; ch_sid = "Chitika Default"; ch_color_site_link = "0000CC"; ch_color_title = "0000CC"; ch_color_border = "FFFFFF"; ch_color_text = "000000"; ch_color_bg = "FFFFFF"; </script><script src="http://scripts.chitika.net/eminimalls/amm.js" type="text/javascript"></script></div>Sudhir guptahttps://plus.google.com/105460425718553468371noreply@blogger.com0tag:blogger.com,1999:blog-8315127339483053508.post-29506918013028122462012-10-12T21:41:00.000+05:302014-01-16T00:28:32.495+05:30Fractal Gallery<div dir="ltr" style="text-align: left;" trbidi="on"><div class="separator" style="clear: both; text-align: left;"><span style="font-family: inherit;"><span style="background-color: white; line-height: 19px; text-align: -webkit-auto;">Fractals are typically self-similar</span><span style="background-color: white; line-height: 19px; text-align: -webkit-auto;"> patterns or self-replicating images, where self-similar means they are "the same from near as from far". Here are some Fractals made by me i'll post the C code in another post in which i'll give a detailed explanation.</span></span></div><div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/-8POwJDqtt2E/UHg-P4742LI/AAAAAAAAAms/S3xGo7BbfLo/s1600/162861_189608064384644_2920596_n.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="277" src="http://1.bp.blogspot.com/-8POwJDqtt2E/UHg-P4742LI/AAAAAAAAAms/S3xGo7BbfLo/s320/162861_189608064384644_2920596_n.jpg" width="320" /></a></div><div style="text-align: center;"><span style="font-family: inherit;">MandelBrot </span><br /><a name='more'></a></div><div style="text-align: center;"><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/-piy8I9PJmXU/UHg-QsvyPXI/AAAAAAAAAm0/c-5zuyT0N4I/s1600/165789_190153024330148_8033428_n.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="245" src="http://1.bp.blogspot.com/-piy8I9PJmXU/UHg-QsvyPXI/AAAAAAAAAm0/c-5zuyT0N4I/s320/165789_190153024330148_8033428_n.jpg" width="320" /></a></div><div style="text-align: center;"> Sierpinski Triangle</div><div style="text-align: center;"><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-nS-ox-CNrHg/UHg-Rz0DM9I/AAAAAAAAAm8/QoCdAQNv_0E/s1600/168150_190613570950760_1959502_n.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="193" src="http://4.bp.blogspot.com/-nS-ox-CNrHg/UHg-Rz0DM9I/AAAAAAAAAm8/QoCdAQNv_0E/s320/168150_190613570950760_1959502_n.jpg" width="320" /></a></div><div style="text-align: center;"> Mandelbrot using different coloring algorithm</div><div style="text-align: center;"><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/-bSaFGOnGAI0/UHg-TJI1N9I/AAAAAAAAAnA/-Pafqfi_W30/s1600/168620_189608164384634_6020323_n.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="218" src="http://2.bp.blogspot.com/-bSaFGOnGAI0/UHg-TJI1N9I/AAAAAAAAAnA/-Pafqfi_W30/s320/168620_189608164384634_6020323_n.jpg" width="320" /></a></div><div style="text-align: center;"> Julia Set</div><div style="text-align: center;"><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-FJRQAlGtEc8/UHg-TwerT5I/AAAAAAAAAnM/KrNFKcQk6fw/s1600/180933_199671370044980_4397601_n.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="232" src="http://4.bp.blogspot.com/-FJRQAlGtEc8/UHg-TwerT5I/AAAAAAAAAnM/KrNFKcQk6fw/s320/180933_199671370044980_4397601_n.jpg" width="320" /></a></div><div style="text-align: center;"> Dragon Curve</div><div style="text-align: center;"><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/-DQbKigyIKN8/UHg-VDCk3uI/AAAAAAAAAnQ/8eJvbsUF2Vg/s1600/180933_199671376711646_6986516_n.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="218" src="http://2.bp.blogspot.com/-DQbKigyIKN8/UHg-VDCk3uI/AAAAAAAAAnQ/8eJvbsUF2Vg/s320/180933_199671376711646_6986516_n.jpg" width="320" /></a></div><div style="text-align: center;"> Pheonix Fractals</div><div style="text-align: center;"><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-uRFpTMrk2tM/UHg-V5XW67I/AAAAAAAAAnY/1O3wNSMljJs/s1600/181951_199697696709014_5704804_n.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="169" src="http://3.bp.blogspot.com/-uRFpTMrk2tM/UHg-V5XW67I/AAAAAAAAAnY/1O3wNSMljJs/s320/181951_199697696709014_5704804_n.jpg" width="320" /></a></div><div style="text-align: center;"> MandelBrot Orbital Trap coloring Algorithm</div><div style="text-align: center;"><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/-Qx4Smx2781A/UHg-W_HMk6I/AAAAAAAAAnk/Dqz50pt5Le4/s1600/183327_200947823250668_7384954_n.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="218" src="http://1.bp.blogspot.com/-Qx4Smx2781A/UHg-W_HMk6I/AAAAAAAAAnk/Dqz50pt5Le4/s320/183327_200947823250668_7384954_n.jpg" width="320" /></a></div><div style="text-align: center;">Glynn Julia Set Fractal 1</div><div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-ikrKd5mTwW8/UHg-Xw4iIZI/AAAAAAAAAno/-g8E2GyY8HI/s1600/183327_200947829917334_1784209_n.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="218" src="http://3.bp.blogspot.com/-ikrKd5mTwW8/UHg-Xw4iIZI/AAAAAAAAAno/-g8E2GyY8HI/s320/183327_200947829917334_1784209_n.jpg" width="320" /></a></div><div class="separator" style="clear: both; text-align: center;">Glynn Julia Set Fractal 2</div><br /></div>Sudhir guptahttps://plus.google.com/105460425718553468371noreply@blogger.com0tag:blogger.com,1999:blog-8315127339483053508.post-70833957431362506042012-10-12T20:04:00.002+05:302014-01-16T00:28:58.973+05:30My First Coro Built R/C plane<div dir="ltr" style="text-align: left;" trbidi="on">Since a long time i've been gathering information to design a R/C aircraft and yeah after a lot of effort its ready. For beginners it is better for an ARF or RTF version to begin with because if u don't know to fly even if you build a aircraft with good flying characteristics you are going to crash it some how and start building all again. Generally people lose their interest in the hobby due to this, as they work hard to complete the model an at last just goes into the bin, using simulators is an other option but flying in simulators is far different from flying a real R/C aircraft.<br /><br /><a name='more'></a><br /><br /><br />The first thing to do to get started with this hobby is to surf through a lot of forums ,then start learning the basics of the parts involved like Kv of the motor, what does mAH of a battery specify, the C rating of a battery, etc., then get familiar with the R/C shops around you or if you prefer online shop's browse the net ( <a href="http://www.hobbyking.com/" target="_blank">HobbyKing</a> is one of the best international shop i have seen).Then u can go for building a plane or buying a ARF or RTF.<br /><br />One more most important thing is the selection of the radio, if you are going to really stick to the hobby go for a branded radio.The difference between a branded and cheap one i'll cover it in a later post.<br /><br />Ok, then i'll get started with my build though it dosen't look that good it fly's well:-<br /><br />Parts: -<br />ESC: TowerPro w18A Brushless Speed Cotroller<br />Battery: 11.1V 1800mAh<br />Servo: Emax 9g servo<br />Motor: <a href="http://www.hobbyking.com/hobbyking/store/uh_viewitem.asp?idproduct=5354&aff=605444" target="_blank">Emax CF 2822</a><br /><br /><br />Specifications:-<br />Span: 800mm<br />Chord: 140mm<br />Distance from leading edge to motor mount(firewall): 110mm<br />Fuse length : 690mm<br />AUW(All Up Weight): 550gms<br /><br />Here are some pics of the build : -<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-gV20LkncRxo/UHgqGikt1XI/AAAAAAAAAmc/upVZ_vn-slw/s1600/IMAG0279.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="241" src="http://4.bp.blogspot.com/-gV20LkncRxo/UHgqGikt1XI/AAAAAAAAAmc/upVZ_vn-slw/s320/IMAG0279.jpg" width="320" /></a><a href="http://2.bp.blogspot.com/-cbJAPRMRla8/UHgqFxQpZzI/AAAAAAAAAmU/PgLU-o2jIPw/s1600/IMAG0278.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="http://2.bp.blogspot.com/-cbJAPRMRla8/UHgqFxQpZzI/AAAAAAAAAmU/PgLU-o2jIPw/s320/IMAG0278.jpg" width="241" /></a></div><span style="background-color: #f4f5ff; color: #222222; font-family: MyndraineRegular; font-size: 14px; line-height: 18px; text-align: -webkit-auto;"><br /></span><span style="background-color: #f4f5ff; color: #222222; font-family: MyndraineRegular; font-size: 14px; line-height: 18px; text-align: -webkit-auto;"><br /></span><span style="background-color: #f4f5ff; color: #222222; font-family: MyndraineRegular; font-size: 14px; line-height: 18px; text-align: -webkit-auto;"><br /></span><span style="background-color: #f4f5ff; color: #222222; font-family: MyndraineRegular; font-size: 14px; line-height: 18px; text-align: -webkit-auto;"><br /></span><span style="background-color: #f4f5ff; color: #222222; font-family: MyndraineRegular; font-size: 14px; line-height: 18px; text-align: -webkit-auto;"><br /></span><span style="background-color: #f4f5ff; color: #222222; font-family: MyndraineRegular; font-size: 14px; line-height: 18px; text-align: -webkit-auto;"><br /></span><br /><div class="separator" style="clear: both; text-align: center;"><object class="BLOGGER-youtube-video" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" data-thumbnail-src="http://i.ytimg.com/vi/r1zjkKiZhsg/0.jpg" height="266" width="320"><param name="movie" value="http://www.youtube.com/v/r1zjkKiZhsg?version=3&f=user_uploads&c=google-webdrive-0&app=youtube_gdata" /><param name="bgcolor" value="#FFFFFF" /><param name="allowFullScreen" value="true" /><embed width="320" height="266" src="http://www.youtube.com/v/r1zjkKiZhsg?version=3&f=user_uploads&c=google-webdrive-0&app=youtube_gdata" type="application/x-shockwave-flash" allowfullscreen="true"></embed></object></div><span style="background-color: #f4f5ff; color: #222222; font-family: MyndraineRegular; font-size: 14px; line-height: 18px; text-align: -webkit-auto;"><br /></span><br /><div class="separator" style="clear: both; text-align: center;"><object class="BLOGGER-youtube-video" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" data-thumbnail-src="http://i.ytimg.com/vi/mGo2eieDSaE/0.jpg" height="266" width="320"><param name="movie" value="http://www.youtube.com/v/mGo2eieDSaE?version=3&f=user_uploads&c=google-webdrive-0&app=youtube_gdata" /><param name="bgcolor" value="#FFFFFF" /><param name="allowFullScreen" value="true" /><embed width="320" height="266" src="http://www.youtube.com/v/mGo2eieDSaE?version=3&f=user_uploads&c=google-webdrive-0&app=youtube_gdata" type="application/x-shockwave-flash" allowfullscreen="true"></embed></object></div><span style="background-color: #f4f5ff; color: #222222; font-family: MyndraineRegular; font-size: 14px; line-height: 18px; text-align: -webkit-auto;"><br /></span></div>Sudhir guptahttps://plus.google.com/105460425718553468371noreply@blogger.com0tag:blogger.com,1999:blog-8315127339483053508.post-72720006304530400772012-10-12T19:27:00.002+05:302012-10-15T15:18:55.128+05:30<div dir="ltr" style="text-align: left;" trbidi="on">Hi and welcome to Timepass Backwas, a blog in which i decided to post my small projects that i do in college and free time.<br /><br />The content might be mostly related to R/C stuff, Robotics, AVR programming, Matlab/Scilab programming ....<br /><br />Please be patient while reading this blog and if any mistake please feel free to comment.<br />Hope you'll enjoy reading this blog.</div>Sudhir guptahttps://plus.google.com/105460425718553468371noreply@blogger.com0