tag:blogger.com,1999:blog-80148885559557639902024-03-18T12:46:46.569+05:30Design with MicrocontrollersDharmaniTech - Blog with circuit designs and ideas around microcontrollers!!CC Dharmanihttp://www.blogger.com/profile/13217855743473839524noreply@blogger.comBlogger25125tag:blogger.com,1999:blog-8014888555955763990.post-19077625813006372232022-01-26T20:58:00.014+05:302022-01-30T17:45:47.823+05:30String and File Encryption with AES - Code Testing on Raspberry Pi Pico<p><span> </span><a href="https://blogger.googleusercontent.com/img/a/AVvXsEhK3x2pz5Serl0OuWMZKs7V4Z4d3liKzEBzDH0f9-pDt9dlvb02DAcVpresiAe95Pgww2Exq-cDcSRO9J2TSKmD8IVewGy6GJRp45dVBSUFqdHIEqr3JVFqxLqVcSPc5jOSdm8eNpK-2S694mmXESE0w5LytVrkETUq6WAXg6wyJ5cm9gZw4WIrmfk7=s497" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" data-original-height="175" data-original-width="497" height="225" src="https://blogger.googleusercontent.com/img/a/AVvXsEhK3x2pz5Serl0OuWMZKs7V4Z4d3liKzEBzDH0f9-pDt9dlvb02DAcVpresiAe95Pgww2Exq-cDcSRO9J2TSKmD8IVewGy6GJRp45dVBSUFqdHIEqr3JVFqxLqVcSPc5jOSdm8eNpK-2S694mmXESE0w5LytVrkETUq6WAXg6wyJ5cm9gZw4WIrmfk7=w640-h225" width="640" /></a></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEjVHadt9mOUgB2D5KrRNthwElDrgm9EnFdWLf9oBXtbJFFjUHlBZ13Ietb7ZjalUiwfZ6WzUIVnnTJl5WDGBKZ81hoU_hoiT0ygmMuns3kHGHYkgYIjJco696PSth3VGYLqkt-cEoCtN6URqH3uR-r6EKMbmo_OY4cxSNE7iqiFL46HBEVlznml6U1F=s600" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="262" data-original-width="600" height="175" src="https://blogger.googleusercontent.com/img/a/AVvXsEjVHadt9mOUgB2D5KrRNthwElDrgm9EnFdWLf9oBXtbJFFjUHlBZ13Ietb7ZjalUiwfZ6WzUIVnnTJl5WDGBKZ81hoU_hoiT0ygmMuns3kHGHYkgYIjJco696PSth3VGYLqkt-cEoCtN6URqH3uR-r6EKMbmo_OY4cxSNE7iqiFL46HBEVlznml6U1F=w400-h175" width="400" /></a></div><div style="font-size: large; font-weight: bold;"><b><span style="font-size: medium;"><br /></span></b></div><div style="font-weight: bold;"><b><span><u>On this page</u>:</span></b></div><div><ul style="text-align: left;"><ul><li><span style="font-family: inherit;"><i><a href="#Introduction">Introduction</a></i></span></li><li><span style="font-family: inherit;"><i><a href="#Case 1">Case 1: Mbed AES Lib</a></i></span></li><li><span style="font-family: inherit;"><i><a href="#Case 2">Case 2: Arduino AESLib Library</a></i></span></li><li><span style="font-family: inherit;"><i><a href="#Case 3">Case 3: MbedTLS Library</a></i></span></li><li><span style="font-family: inherit;"><i><a href="#Case 4">Case 4: tiny-AES Library </a></i></span></li><li><span style="font-family: inherit;"><i><a href="#Comparison">Comparison Summary</a></i></span></li><li><span style="font-family: inherit;"><i><a href="#File Encryption">File Encryption/ Decryption with MbedTLS Library</a></i></span></li></ul></ul></div><div style="font-size: large; font-weight: bold;"><b><span style="font-size: medium;"><br /></span></b></div><span style="font-size: medium; font-weight: bold;"><a id="Introduction"><u>Introduction</u></a></span><br /><div class="separator" style="clear: both; text-align: center;"><br /></div><div class="separator" style="clear: both; text-align: left;"><span style="text-align: left;"> <span style="font-size: medium;">Data Encryption has become an absolute necessity in today's world of internet. In embedded systems also, it has become an integrated part due to the wide spread of IoT and other online systems. Sometimes we also need files to be encrypted on local storage like built-in flash or memory cards, etc. to protect certain information. There are various algorithms to encrypt files. Here, we are going to compare some library implementation examples of the most used standard today, AES. </span></span></div><p><span style="font-size: medium;"> The Advance Encryption Standard (AES) is a block cipher, which uses 128 or 192 or 256 bit key to encrypt or decrypt 128 bit (16 byte) block of input data. So, the input file (or data string) is processed in blocks of 16 bytes each, as per the Block Cipher mode of operation (see the <a href="https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation" target="_blank">wiki here</a>). In addition, based on the mode of operation, Initialization Vector (IV) is also required for AES, which is unique (usually generated run time) for each encryption operation.</span></p><p><span style="font-size: medium;"> I was checking out some libraries to use for file encryption in a project. So, I decided to test them mainly for the speed of encryption/ decryption, which is the subject of this post. The resultant test codes with terminal outputs are given here. These may serve purpose of example/ demo code for newcomers interested in checking out AES functionality in their programs. For testing these code examples, only hardware required is a Raspberry Pi Pico board and the USB programming cable, and you are ready to go with a laptop/PC loaded with IDE (PlatformIO or Arduino).</span></p><p><span style="font-size: medium;"><span><span> </span>Here, I'm comparing four AES libraries, tested on Raspberry Pi Pico, to check out mainly the speed and code size for the implementation. These four libraries are:</span><br /></span></p><span style="font-size: xx-small;"><br /></span><ol style="text-align: left;"><ol><li><a href="https://os.mbed.com/users/neilt6/code/AES/" target="_blank"><span style="font-size: medium;"><span><b>Mbed AES Lib, </b>by Neil </span>Thiessen</span></a></li><li><a href="https://github.com/suculent/thinx-aes-lib" target="_blank"><span style="font-size: medium;"><b>Arduino AES Lib, </b>by Matej Sychra</span></a></li><li><a href="https://github.com/ARMmbed/mbedtls" target="_blank"><span style="font-size: medium;"><b>MbedTLS Lib, </b>by ARMmbed</span></a></li><li><a href="https://github.com/kokke/tiny-AES-c" target="_blank"><span style="font-size: medium;"><b>tiny-AES-c Lib,</b> by kokke</span></a></li></ol></ol><br /><div><span style="font-size: medium;"> All these libraries are tested here using almost same main code, with same input character string (plain text), same key and same IV. 128-bit and 256-bit AES (CBC mode) testing is done for all libraries. The key in the code is kept 256 bit long, so that the 128/192/256 AES can be selected just by changing a macro in the file. The encryption and decryption times are measured and displayed on terminal.</span></div><div><span style="font-size: medium;"><span><span> </span>Please note that these key and IV are only for the testing only, not for practical usage. In reality, usually the key is secret and IV is different for each string/file.</span><br /></span></div><div><span style="font-size: medium;"> The codes are tested in PlatformIO IDE, Raspberry Pi Pico-Arduino platform, which is the Arduino-Mbed package. These codes can be run in Arduino IDE as well, selecting the <i>"Arduino Mbed OS RP2040 Board"</i> in the board manager. The codes can be easily adopted to any other 32bit controller/IDE as well with minimum modifications.<br /></span></div><div><span style="font-size: medium;"><br /></span></div><div><span style="font-size: medium;"><b>Note</b>: For PlatformIO, create new project and copy the downloaded files (from .zip) into the project folder. In Arduino, use main.cpp as a sketch (after renaming with .ino extension) and put the library files into the library folder of your arduino sketchbook and ignore the platformio.ini file.</span></div><div><span style="font-size: medium;"><br /></span></div><div><span style="font-size: medium;"><br /></span></div><div><b><u><span style="font-size: medium;"><i><a id="Case 1">Case 1</a></i>: Mbed AES Lib (by Neil Thiessen)</span></u></b></div><div><span style="font-size: medium;"><br /></span></div><div><span style="font-size: medium;"> This library is posted in the Mbed repository, as a light-weight <span style="font-family: inherit;"><span>AES implementation with Cipher Block Chaining and Ciphertext Stealing (url:<a href=" https://os.mbed.com/users/neilt6/code/AES/" target="_blank"> </a></span></span><a href=" https://os.mbed.com/users/neilt6/code/AES/" target="_blank">https://os.mbed.com/users/neilt6/code/AES/</a>). </span></div><div><span style="font-size: medium;">(I had done minor modifications, mainly defining char as uint8_t, in the variable/function declarations to remove some compiler errors/warnings, during earlier testing on Mbed-Studio IDE. The same files have been used here). </span></div><div><span style="font-size: medium;"><span> (AES-128/192/256 option is selected here by setting AES::KEY_XXX, where XXX is the 128/192/256, in the arguments of the function aes.setup(), before encrypt and decrypt functions)</span><br /></span></div><div><span style="font-size: medium;"><br /></span></div><div><i><span style="font-size: medium;">Code (aesTest1):</span></i></div><div style="height: 400px; overflow: auto; width: auto;"><script src="https://gist.github.com/CC-Dh/9e941c032d7ba1781eddb6dcb13f828b.js"></script></div><div><br /></div><div><br /></div><div><b><u><span style="font-size: medium;">Results</span></u></b></div><div><span style="font-size: medium;"><br /></span></div><div><span style="font-size: medium;"><i>Compiler Output:</i></span></div><div><div style="background-color: #1e1e1e; line-height: 22px;"><div style="line-height: 22px;"><span style="color: #d4d4d4; font-family: Consolas, Courier New, monospace; font-size: x-small;"><span style="white-space: pre;">RAM: [== ] 15.2% (used 41076 bytes from 270336 bytes)
Flash: [ ] 0.2% (used 4134 bytes from 2097152 bytes)</span></span></div></div></div><div><span><br /></span></div><div><span style="font-size: medium;"><i>Terminal Output (AES-128):</i></span></div><div><div style="background-color: #1e1e1e; line-height: 22px;"><div style="line-height: 22px;"><span style="color: #d4d4d4; font-family: Consolas, Courier New, monospace; font-size: x-small;"><span style="white-space: pre;">INPUT: AES_Test_1 - Hello! Testing AES Encryption here
Cipher Text: D56B041BF7AEEA37818A98F224F38376ECB83D9F56A3354A64DFFA05D87704F7E4B86DF2E64197B66843BE995B
Encryption Time (us): 1305
Plain Text: AES_Test_1 - Hello! Testing AES Encryption here
Decryption Time (us): 2337
SUCCESS</span></span></div></div></div><div><span><br /></span></div><div><span style="font-size: medium;"><i>Terminal Output (AES-256):</i></span></div><div><div style="background-color: #1e1e1e; line-height: 22px;"><div style="line-height: 22px;"><span style="color: #d4d4d4; font-family: Consolas, Courier New, monospace; font-size: x-small;"><span style="white-space: pre;">INPUT: AES_Test_1 - Hello! Testing AES Encryption here
Cipher Text: ACAC7D235752782F65C4C9ABB5AA5BD60D2B5DECDD0E94035CA2B49785C295132885FD282A96C32C7A95184931ED4E
Encryption Time (us): 1842
Plain Text: AES_Test_1 - Hello! Testing AES Encryption here
Decryption Time (us): 3338
SUCCESS</span></span></div></div></div><div><br /></div><div><b><span style="font-size: medium;">Download Code files:</span></b></div><div><ul style="text-align: left;"><li><span style="font-size: medium;"><b><a href="https://storage.googleapis.com/www.dharmanitech.com/aesTest1.zip">aesTest1.zip</a></b> (main.cpp, AES_lib.cpp, AES_lib.h and platformio.ini) </span></li></ul></div><div><span style="font-size: medium;"><br /></span></div><div><b><u><span style="font-size: medium;"><i><a id="Case 2">Case 2</a></i>: Arduino AESLib Library (by Matej Sychra)</span></u></b></div><div><b><u><span style="font-size: medium;"><br /></span></u></b></div><div><span style="font-size: medium;"> <span> This library is part of Arduino libraries (</span><a href="https://www.arduino.cc/reference/en/libraries/aeslib/">AESLib - Arduino Reference</a>), as a<span style="background-color: white;"><span style="font-family: inherit;">n ESP32/ESP8266 library for Arduino IDE to wrap AES encryption with Base64 support. This works on Pi Pico as well. Repository url is: </span></span><a href="https://github.com/suculent/thinx-aes-lib">https://github.com/suculent/thinx-aes-lib</a>. The library files are used as downloaded without any changes.</span></div><div><span style="font-size: medium;"><span> </span> (AES-128/192/256 option is selected here by setting AES_XXX, where XXX is the 128/192/256, in the arguments of the function calls aesLib.encrypt64() and aesLib.decrypt64(). Appropriate macros are already defined at the top part of the code).</span></div><div><span style="font-size: medium;"><br /></span></div><div><i><span style="font-size: medium;">Code (aesTest2):</span></i></div><div style="height: 400px; overflow: auto; width: auto;"><script src="https://gist.github.com/CC-Dh/836c432adc527bc8a18004bc53fb853f.js"></script></div><div><br /></div><div><br /></div><div><div><b><u><span style="font-size: medium;">Results</span></u></b></div><div><span style="font-size: medium;"><br /></span></div><div><span style="font-size: medium;"><i>Compiler Output:</i></span></div><div><div style="background-color: #1e1e1e; line-height: 22px;"><div style="line-height: 22px;"><span style="color: #d4d4d4; font-family: Consolas, Courier New, monospace; font-size: x-small;"><span style="white-space: pre;">RAM: [== ] 17.4% (used 47100 bytes from 270336 bytes)
Flash: [ ] 0.2% (used 4546 bytes from 2097152 bytes)</span></span></div></div></div><div><span><i><br /></i></span></div><div><span style="font-size: medium;"><i>Terminal Output (AES-128):</i></span></div><div><div style="background-color: #1e1e1e; line-height: 22px;"><div style="line-height: 22px;"><span style="color: #d4d4d4; font-family: Consolas, Courier New, monospace; font-size: x-small;"><span style="white-space: pre;">INPUT: AES_Test_2 - Hello! Testing AES Encryption here
Cipher Text: 6368354D2F51637A744E694D7A344D4B4F67382B6230467A58752F53624636516979577A6371756C7A545430344E422B41747A5861364D6E5370774962452F766A356663575369335576645A794B765562795372337366455A78484856754F59674D5167736E4674372B6B3D
Encryption Time (us): 456
Plain Text: AES_Test_2 - Hello! Testing AES Encryption here
Decryption Time (us): 820
SUCCESS</span></span></div></div></div><div><span><i><br /></i></span></div><div><span style="font-size: medium;"><i>Terminal Output (AES-256):</i></span></div><div><div style="background-color: #1e1e1e; line-height: 22px;"><div style="line-height: 22px;"><span style="color: #d4d4d4; font-family: Consolas, Courier New, monospace; font-size: x-small;"><span style="white-space: pre;">INPUT: AES_Test_2 - Hello! Testing AES Encryption here
Cipher Text: 43304A6C774347356D7745484D3534666D4537792B6F4132494342354858734C724C5663705645666D36772B6F677058736C4A474374767973694A6C714E5961546F375532476737516752376936364861683557783173364C746243726E41757130334546622F38725A303D
Encryption Time (us): 604
Plain Text: AES_Test_2 - Hello! Testing AES Encryption here
Decryption Time (us): 1093
SUCCESS</span></span></div></div></div><div><br /></div><div><b><span style="font-size: medium;">Download Code files:</span></b></div><div><ul style="text-align: left;"><li><span style="font-size: medium;"><b><a href="https://storage.googleapis.com/www.dharmanitech.com/aesTest2.zip">aesTest2.zip</a></b> (main.cpp, AESLib library folder and platformio.ini) </span></li></ul></div><div><span style="font-size: medium;"><br /></span></div></div><div><b><u><span style="font-size: medium;"><i><a id="Case 3">Case 3</a></i>: MbedTLS Library (by ARMmbed)</span></u></b></div><div><b><u><span style="font-size: medium;"><br /></span></u></b></div><div><span style="font-size: medium;"> <span style="font-family: inherit;"><span style="background-color: white;"> </span><span style="background-color: white;">Mbed TLS is a C library that implements cryptographic primitives, X.509 certificate manipulation and the SSL/TLS and DTLS protocols. Its small code footprint makes it suitable for embedded systems. (Ref: </span></span><a href="https://github.com/ARMmbed/mbedtls">https://github.com/ARMmbed/mbedtls</a>). We are using here only the AES functions of this library. As this library is part of the Mbed-OS, no need to separately download/add, we just need to include the relevant file in the code and call the functions.</span></div><div><span style="font-size: medium;"> <span> </span>(AES-128/192/256 option is selected here by setting AES_XXX, where XXX is the 128/192/256, in the arguments of the function calls mbedtls_aes_setkey_enc() and mbedtls_aes_setkey_dec(). Appropriate macros are already defined at the top part of the code). </span></div><div><span style="font-size: medium;"><br /></span></div><div><i><span style="font-size: medium;">Code (aesTest3):</span></i></div><div style="height: 400px; overflow: auto; width: auto;"><script src="https://gist.github.com/CC-Dh/e38a7a4b7cca3fd6c971f06178ecf6be.js"></script></div><div><br /></div><div><br /></div><div><div><b><u><span style="font-size: medium;">Results</span></u></b></div><div><span style="font-size: medium;"><br /></span></div><div><span style="font-size: medium;"><i>Compiler Output:</i></span></div><div><div style="background-color: #1e1e1e; line-height: 22px;"><div style="line-height: 22px;"><span style="color: #d4d4d4; font-family: Consolas, Courier New, monospace; font-size: x-small;"><span style="white-space: pre;">RAM: [== ] 15.3% (used 41320 bytes from 270336 bytes)
Flash: [ ] 0.2% (used 4082 bytes from 2097152 bytes)</span></span></div></div></div><div><span><i><br /></i></span></div><div><span style="font-size: medium;"><i>Terminal Output (AES-128):</i></span></div><div><div style="background-color: #1e1e1e; line-height: 22px;"><div style="line-height: 22px;"><span style="color: #d4d4d4; font-family: Consolas, Courier New, monospace; font-size: x-small;"><span style="white-space: pre;">INPUT: AES_Test_3 - Hello! Testing AES Encryption here
Cipher Text: FB934B82E7CA12EAD35C017948AB881A3CEAB6A58C1BED4B2C1CF6D9B79F2EF691488A1E98D6F36CB51EE15F0FFAE42
Encryption Time (us): 170
Plain Text: AES_Test_3 - Hello! Testing AES Encryption here
Decryption Time (us): 161
SUCCESS</span></span></div></div></div><div><span><i><br /></i></span></div><div><span style="font-size: medium;"><i>Terminal Output (AES-256):</i></span></div><div><div style="background-color: #1e1e1e; line-height: 22px;"><div style="line-height: 22px;"><span style="color: #d4d4d4; font-family: Consolas, Courier New, monospace; font-size: x-small;"><span style="white-space: pre;">INPUT: AES_Test_3 - Hello! Testing AES Encryption here
Cipher Text: 22BFF69B724C3F5CCDCA0D930823F2662ED857E0F1617808AAEA51F7592E6B3F72B262D801AF52FE4911B3B2B
Encryption Time (us): 215
Plain Text: AES_Test_3 - Hello! Testing AES Encryption here
Decryption Time (us): 207
SUCCESS</span></span></div></div></div><div><br /></div><div><br /></div><div><b><span style="font-size: medium;">Download Code files:</span></b></div><div><ul style="text-align: left;"><li><span style="font-size: medium;"><b><a href="https://storage.googleapis.com/www.dharmanitech.com/aesTest3.zip">aesTest3.zip</a></b> (main.cpp and platformio.ini)</span></li></ul><span style="font-size: medium;"><i>(<span style="color: red;"><u>Note</u></span>: While testing in Arduino IDE, if you are <b>not</b> using</i><i>"Arduino Mbed OS RP2040 Board"</i> in the board manager<i>, you will need to download the <a href="https://github.com/ARMmbed/mbedtls" target="_blank">mbedtls</a> library as well and put it in the library folder for this code to work).</i></span></div></div><div><span style="font-size: medium;"><br /></span></div><div><b><u><span style="font-size: medium;"><i><a id="Case 4">Case 4</a></i>: tiny-AES Library (by kokke)</span></u></b></div><div><span style="font-size: medium;"><br /></span></div><div><span style="font-size: medium;"> <span style="font-family: inherit;"><span><span style="background-color: white;"> </span><span style="background-color: white;"><span>This is a small and portable implementation of the AES </span><span style="color: black;"><a href="https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Electronic_Codebook_.28ECB.29" rel="nofollow" style="box-sizing: border-box; text-decoration-line: none;">ECB</a><span>, </span><a href="https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Counter_.28CTR.29" rel="nofollow" style="box-sizing: border-box; text-decoration-line: none;">CTR</a><span> and </span><a href="https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Cipher_Block_Chaining_.28CBC.29" rel="nofollow" style="box-sizing: border-box; text-decoration-line: none;">CBC</a></span><span> encryption algorithms written in C (Ref: </span></span></span><a href="https://github.com/kokke/tiny-AES-c">https://github.com/kokke/tiny-AES-c</a>). </span></span></div><div><span style="font-size: medium;"><span> </span><span> </span>(<span style="font-family: inherit;">AES-128/192/256 option is selected here by<span style="background-color: white;"> defining the symbols AES128 or AES192 or AES256 in</span><a href="https://github.com/kokke/tiny-AES-c/blob/master/aes.h" style="background-color: white; box-sizing: border-box; text-decoration-line: none;"><code style="border-radius: 6px; box-sizing: border-box; margin: 0px; padding: 0.2em 0.4em;">aes.h</code></a><span style="background-color: white;">. Default setting AES128 is already defined there.</span></span></span></div><div><span style="background-color: white; font-size: medium;"><br /></span></div><div><i><span style="font-size: medium;">Code (aesTest4):</span></i></div><div style="height: 400px; overflow: auto; width: auto;"><script src="https://gist.github.com/CC-Dh/07e509a5b16fe663e1ab6d92c0434a37.js"></script></div><div><br /></div><div><br /></div><div><div><div><b><u><span style="font-size: medium;">Results</span></u></b></div><div><span style="font-size: medium;"><br /></span></div><div><span style="font-size: medium;"><i>Compiler Output:</i></span></div><div><div style="background-color: #1e1e1e; line-height: 22px;"><div style="line-height: 22px;"><span style="color: #d4d4d4; font-family: Consolas, Courier New, monospace; font-size: x-small;"><span style="white-space: pre;">RAM: [== ] 15.1% (used 41000 bytes from 270336 bytes)
Flash: [ ] 0.2% (used 4082 bytes from 2097152 bytes)</span></span></div></div></div><div><span><i><br /></i></span></div><div><span style="font-size: medium;"><i>Terminal Output (AES-128):</i></span></div><div><div style="background-color: #1e1e1e; line-height: 22px;"><div style="line-height: 22px;"><span style="color: #d4d4d4; font-family: Consolas, Courier New, monospace; font-size: x-small;"><span style="white-space: pre;">INPUT: AES_Test_4 - Hello! Testing AES Encryption here
Cipher Text: 997E26867A8D10145EDA12F1FBBE45B2794929C45E2086F6172801AB0ABE711AEE0EBF548A958B928E851BF96E5A4
Encryption Time (us): 246
Plain Text: AES_Test_4 - Hello! Testing AES Encryption here
Decryption Time (us): 463
SUCCESS</span></span></div></div></div><div><span><i><br /></i></span></div><div><span style="font-size: medium;"><i>Terminal Output (AES-256):</i></span></div><div><div style="background-color: #1e1e1e; line-height: 22px;"><div style="line-height: 22px;"><span style="color: #d4d4d4; font-family: Consolas, Courier New, monospace; font-size: x-small;"><span style="white-space: pre;">INPUT: AES_Test_4 - Hello! Testing AES Encryption here
Cipher Text: 2461EC62971158335F198DE6A3478E9B459A1AED7BFF647BAAF031B132EF094BE4C9B3EEA2177D52858FF329ED7662
Encryption Time (us): 345
Plain Text: AES_Test_4 - Hello! Testing AES Encryption here
Decryption Time (us): 622
SUCCESS</span></span></div></div></div><div><br /></div><div><br /></div><div><b><span style="font-size: medium;">Download Code files:</span></b></div><div><ul><li><span style="font-size: medium;"><b><a href="https://storage.googleapis.com/www.dharmanitech.com/aesTest4.zip">aesTest4.zip</a></b> (main.cpp, tiny-AES library folder and platformio.ini) </span></li></ul></div><div><span style="font-size: medium;"><br /></span></div></div></div><div><b><u><span style="font-size: medium;"><a id="Comparison">Comparison Summary:</a></span></u></b></div><div style="text-align: center;"><br /></div><div><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; text-align: center;">
<tbody><tr style="height: 33.7pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td rowspan="2" style="background: rgb(217, 217, 217); border: 1pt solid windowtext; height: 33.7pt; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 25.55pt;" width="34">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm;"><b><span style="font-family: inherit;">Sr. <o:p></o:p></span></b></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm;"><span style="font-family: inherit;"><b>No.</b><b><o:p></o:p></b></span></p>
</td>
<td rowspan="2" style="background: rgb(217, 217, 217); border-left: none; border: 1pt solid windowtext; height: 33.7pt; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 78.45pt;" width="105">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm;"><span style="font-family: inherit;"><b>Library</b><b><o:p></o:p></b></span></p>
</td>
<td colspan="2" style="background: rgb(217, 217, 217); border-left: none; border: 1pt solid windowtext; height: 33.7pt; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 101.8pt;" width="136">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; text-align: center;"><span style="font-family: inherit;"><b>AES-128 Time (µs)</b><b><o:p></o:p></b></span></p>
</td>
<td colspan="2" style="background: rgb(217, 217, 217); border-left: none; border: 1pt solid windowtext; height: 33.7pt; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 102.05pt;" width="136">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; text-align: center;"><span style="font-family: inherit;"><b>AES-256 Time (µs)</b><b><o:p></o:p></b></span></p>
</td>
<td colspan="2" style="background: rgb(217, 217, 217); border-left: none; border: 1pt solid windowtext; height: 33.7pt; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 101.95pt;" width="136">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; text-align: center;"><span style="font-family: inherit;"><b>Pi-Pico Usage (KB)</b><b><o:p></o:p></b></span></p>
</td>
</tr>
<tr style="height: 33.7pt; mso-yfti-irow: 1;">
<td style="background: rgb(217, 217, 217); border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; height: 33.7pt; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 50.8pt;" width="68">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; text-align: center;"><span style="font-family: inherit;"><b>Encrypt</b><b><o:p></o:p></b></span></p>
</td>
<td style="background: rgb(217, 217, 217); border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; height: 33.7pt; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 51pt;" width="68">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; text-align: center;"><span style="font-family: inherit;"><b>Decrypt</b><b><o:p></o:p></b></span></p>
</td>
<td style="background: rgb(217, 217, 217); border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; height: 33.7pt; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 51.05pt;" width="68">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; text-align: center;"><span style="font-family: inherit;"><b>Encrypt</b><b><o:p></o:p></b></span></p>
</td>
<td style="background: rgb(217, 217, 217); border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; height: 33.7pt; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 51pt;" width="68">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; text-align: center;"><span style="font-family: inherit;"><b>Decrypt</b><b><o:p></o:p></b></span></p>
</td>
<td style="background: rgb(217, 217, 217); border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; height: 33.7pt; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 51.05pt;" width="68">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; text-align: center;"><span style="font-family: inherit;"><b>RAM</b><b><o:p></o:p></b></span></p>
</td>
<td style="background: rgb(217, 217, 217); border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; height: 33.7pt; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 50.9pt;" width="68">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; text-align: center;"><span style="font-family: inherit;"><b>FLASH</b><b><o:p></o:p></b></span></p>
</td>
</tr>
<tr style="height: 33.7pt; mso-yfti-irow: 2;">
<td style="background: rgb(217, 217, 217); border-top: none; border: 1pt solid windowtext; height: 33.7pt; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 25.55pt;" width="34">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; margin-left: 1.35pt; margin-right: 0cm; margin-top: 0cm; margin: 0cm 0cm 0cm 1.35pt;"><span style="font-family: inherit;">1.<o:p></o:p></span></p>
</td>
<td style="border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; height: 33.7pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 78.45pt;" width="105">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm;"><b><span style="font-family: inherit;">Mbed AES
lib, <o:p></o:p></span></b></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm;"><span style="font-family: inherit;">by Neil
T.<o:p></o:p></span></p>
</td>
<td style="background: rgb(217, 226, 243); border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; height: 33.7pt; mso-background-themecolor: accent1; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 50.8pt;" width="68">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; text-align: center;"><span style="font-family: inherit;">1305<o:p></o:p></span></p>
</td>
<td style="border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; height: 33.7pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 51pt;" width="68">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; text-align: center;"><span style="font-family: inherit;">2337<o:p></o:p></span></p>
</td>
<td style="background: rgb(217, 226, 243); border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; height: 33.7pt; mso-background-themecolor: accent1; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 51.05pt;" width="68">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; text-align: center;"><span style="font-family: inherit;">1842<o:p></o:p></span></p>
</td>
<td style="border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; height: 33.7pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 51pt;" width="68">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; text-align: center;"><span style="font-family: inherit;">3338<o:p></o:p></span></p>
</td>
<td style="background: rgb(217, 226, 243); border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; height: 33.7pt; mso-background-themecolor: accent1; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 51.05pt;" width="68">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; text-align: center;"><span style="font-family: inherit;">41.076<o:p></o:p></span></p>
</td>
<td style="border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; height: 33.7pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 50.9pt;" width="68">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; text-align: center;"><span style="font-family: inherit;">4.134<o:p></o:p></span></p>
</td>
</tr>
<tr style="height: 33.7pt; mso-yfti-irow: 3;">
<td style="background: rgb(217, 217, 217); border-top: none; border: 1pt solid windowtext; height: 33.7pt; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 25.55pt;" width="34">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; margin-left: 1.35pt; margin-right: 0cm; margin-top: 0cm; margin: 0cm 0cm 0cm 1.35pt;"><span style="font-family: inherit;">2.<o:p></o:p></span></p>
</td>
<td style="border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; height: 33.7pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 78.45pt;" width="105">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm;"><b><span style="font-family: inherit;">Arduino
AESLib,<o:p></o:p></span></b></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm;"><span style="font-family: inherit;">by Matej
S.<o:p></o:p></span></p>
</td>
<td style="background: rgb(217, 226, 243); border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; height: 33.7pt; mso-background-themecolor: accent1; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 50.8pt;" width="68">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; text-align: center;"><span style="font-family: inherit;">456<o:p></o:p></span></p>
</td>
<td style="border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; height: 33.7pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 51pt;" width="68">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; text-align: center;"><span style="font-family: inherit;">820<o:p></o:p></span></p>
</td>
<td style="background: rgb(217, 226, 243); border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; height: 33.7pt; mso-background-themecolor: accent1; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 51.05pt;" width="68">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; text-align: center;"><span style="font-family: inherit;">604<o:p></o:p></span></p>
</td>
<td style="border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; height: 33.7pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 51pt;" width="68">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; text-align: center;"><span style="font-family: inherit;">1093<o:p></o:p></span></p>
</td>
<td style="background: rgb(217, 226, 243); border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; height: 33.7pt; mso-background-themecolor: accent1; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 51.05pt;" width="68">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; text-align: center;"><span style="font-family: inherit;">47.100<o:p></o:p></span></p>
</td>
<td style="border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; height: 33.7pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 50.9pt;" width="68">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; text-align: center;"><span style="font-family: inherit;">4.546<o:p></o:p></span></p>
</td>
</tr>
<tr style="height: 33.7pt; mso-yfti-irow: 4;">
<td style="background: rgb(217, 217, 217); border-top: none; border: 1pt solid windowtext; height: 33.7pt; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 25.55pt;" width="34">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; margin-left: 1.35pt; margin-right: 0cm; margin-top: 0cm; margin: 0cm 0cm 0cm 1.35pt;"><span style="font-family: inherit;">3.<o:p></o:p></span></p>
</td>
<td style="border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; height: 33.7pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 78.45pt;" width="105">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm;"><b><span style="font-family: inherit;">MbedTLS,<o:p></o:p></span></b></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm;"><span style="font-family: inherit;">by
ARMmbed<o:p></o:p></span></p>
</td>
<td style="background: rgb(217, 226, 243); border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; height: 33.7pt; mso-background-themecolor: accent1; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 50.8pt;" width="68">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; text-align: center;"><span style="color: #6aa84f; font-family: inherit;"><b>170<o:p></o:p></b></span></p>
</td>
<td style="border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; height: 33.7pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 51pt;" width="68">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; text-align: center;"><span style="color: #6aa84f; font-family: inherit;"><b>161<o:p></o:p></b></span></p>
</td>
<td style="background: rgb(217, 226, 243); border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; height: 33.7pt; mso-background-themecolor: accent1; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 51.05pt;" width="68">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; text-align: center;"><span style="color: #6aa84f; font-family: inherit;"><b>215<o:p></o:p></b></span></p>
</td>
<td style="border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; height: 33.7pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 51pt;" width="68">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; text-align: center;"><span style="font-family: inherit;"><b><span style="color: #6aa84f;">207</span></b><o:p></o:p></span></p>
</td>
<td style="background: rgb(217, 226, 243); border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; height: 33.7pt; mso-background-themecolor: accent1; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 51.05pt;" width="68">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; text-align: center;"><span style="font-family: inherit;">41.320<o:p></o:p></span></p>
</td>
<td style="border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; height: 33.7pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 50.9pt;" width="68">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; text-align: center;"><span style="font-family: inherit;">4.082<o:p></o:p></span></p>
</td>
</tr>
<tr style="height: 33.7pt; mso-yfti-irow: 5; mso-yfti-lastrow: yes;">
<td style="background: rgb(217, 217, 217); border-top: none; border: 1pt solid windowtext; height: 33.7pt; mso-background-themecolor: background1; mso-background-themeshade: 217; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 25.55pt;" width="34">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; margin-left: 1.35pt; margin-right: 0cm; margin-top: 0cm; margin: 0cm 0cm 0cm 1.35pt;"><span style="font-family: inherit;">4.<o:p></o:p></span></p>
</td>
<td style="border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; height: 33.7pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 78.45pt;" width="105">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm;"><b><span style="font-family: inherit;">tiny-AES,<o:p></o:p></span></b></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm;"><span style="font-family: inherit;">by kokke<o:p></o:p></span></p>
</td>
<td style="background: rgb(217, 226, 243); border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; height: 33.7pt; mso-background-themecolor: accent1; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 50.8pt;" width="68">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; text-align: center;"><span style="font-family: inherit;">246<o:p></o:p></span></p>
</td>
<td style="border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; height: 33.7pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 51pt;" width="68">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; text-align: center;"><span style="font-family: inherit;">463<o:p></o:p></span></p>
</td>
<td style="background: rgb(217, 226, 243); border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; height: 33.7pt; mso-background-themecolor: accent1; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 51.05pt;" width="68">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; text-align: center;"><span style="font-family: inherit;">345<o:p></o:p></span></p>
</td>
<td style="border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; height: 33.7pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 51pt;" width="68">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; text-align: center;"><span style="font-family: inherit;">622<o:p></o:p></span></p>
</td>
<td style="background: rgb(217, 226, 243); border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; height: 33.7pt; mso-background-themecolor: accent1; mso-background-themetint: 51; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 51.05pt;" width="68">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; text-align: center;"><span style="font-family: inherit;">41.000<o:p></o:p></span></p>
</td>
<td style="border-bottom: 1pt solid windowtext; border-left: none; border-right: 1pt solid windowtext; border-top: none; height: 33.7pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt; width: 50.9pt;" width="68">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; text-align: center;"><span style="font-family: inherit;">4.082</span><o:p></o:p></p>
</td>
</tr>
</tbody></table></div><div style="text-align: center;"><br /></div><div style="text-align: center;"><br /></div><div><span> <span style="font-size: medium;"> From the above comparison, it is clearly seen that the No.3, MbedTLS AES, is fastest among all the four. Flash and RAM consumption is also low. (Note: In these examples, major chunk of RAM, >40KB, is occupied by the background processes of Mbed OS itself).</span></span><span style="font-size: medium;"><br /></span></div><div><span style="font-size: medium;"><span><span> MbedTLS is also feature-rich, when you go further into encryption, for applications like IoT. It's a good library to practice with, for future expansion of the hobby projects. Considering that, </span></span>I'm also adding here an example of encrypting/ decrypting a file using MbedTLS functions.</span></div><div><span><span style="font-size: medium;"><br /></span></span></div><div><span><span style="font-size: medium;"><b><u><a id="File Encryption">File Encryption/ Decryption with MbedTLS Library</a></u></b>:</span></span></div><div><span><span style="font-size: medium;"><br /></span></span></div><div><span><span><span style="font-size: medium;"> Here, we're going to encrypt and decrypt a small file from the on-board Flash memory of Pi Pico. LittleFileSystem and BlockDevice (FlashIAPBlockDevice) libraries built into the Mbed-OS are used here for creating and accessing the files. As onboard memory is used, no extra component is required apart from Pi Pico + Programming cable setup used in the above AES examples. </span></span></span></div><div><span><span><span style="font-size: medium;"> The file encryption/ decryption function (fileAES()) is adopted from the main() function of <a href="https://github.com/ARMmbed/mbedtls/blob/development/programs/aes/crypt_and_hash.c" target="_blank">crypt_and_hash.c</a> file of mbedtls library. </span></span></span></div><div><span><span><span style="font-size: medium;"><br /></span></span></span></div><div><span><span style="font-size: medium;"><span> While encrypting, t</span>his function reads the input file (plain text) and AES key, generates Initialization Vector (IV), then hashes the IV and AES key together to setup AES context and generate <a href="https://en.wikipedia.org/wiki/HMAC" target="_blank">HMAC</a> (Hash Message Authentication Code). Then it carries out encryption (cipher update) block-by-block (block size: 128 bits/16 bytes). The output file (named here as cipherFile.aes) is created in the format: </span></span></div><div><span><span> <span><span style="font-family: courier;"><span style="font-size: x-small;"> </span>Output File: </span><span style="font-family: courier;">IV (16 bytes) + encrypted file blocks + HMAC/Hash (64 bytes)</span></span><br /></span></span></div><div><span><span><span style="font-size: x-small;"><span style="font-family: courier;"><br /></span></span></span></span></div><div><span><span><span> </span><span style="font-size: medium;">While decrypting, the cipher file is input along with the AES key, the IV is read from cipher file, the hashing is done similar to as done during encryption, then decryption is carried out block-by-block, and finally the Hash is compared with what is stored in the cipher file to confirm the validity of decrypted output file. </span></span></span></div><div><span><span style="font-size: medium;"><span> The AES key is declared in the main.cpp file for the demo purpose, not for use in actual project. A fixed text string is used repeatedly for creating the input file. These can be modified in the main.cpp.</span><br /></span></span></div><div><span><span style="font-size: medium;"><br /></span></span></div><div><span><span style="font-size: medium;"><i><u>Code (littleFsAes)</u>:</i></span></span></div><div><span><span style="font-size: medium;"><br /></span></span></div><div><span><span style="font-size: medium;"><span> </span>Following is the main file where filesystem is mounted and input (with data to be ecrypted), cipher (empty) and output(empty) files are created. After creating these files, the fileAES function is called with arguments for encryption and then decryption. The time is measured in miliseconds to display on terminal. The file system used here is LittleFileSystem from Mbed-OS. The input and output files can be printed on terminal by enabling the relevant commented out section of the code.</span></span></div><div><span><span style="font-size: medium;"><br /></span></span></div><div><i><span style="font-size: medium;">main.cpp</span></i></div><div style="height: 400px; overflow: auto; width: auto;"><script src="https://gist.github.com/CC-Dh/5a6f7e923999286ef42a84bfe82d9ec5.js"></script></div><div><span><span><br /></span></span></div><div><span><span><br /></span></span></div><div><span><span style="font-size: medium;">Following is the header file for using with fileAES.cpp.</span></span></div><div><span><span style="font-size: medium;"><br /></span></span></div><div><span><span style="font-size: medium;"><i>fileAES.h</i></span></span></div><div style="height: 400px; overflow: auto; width: auto;"><script src="https://gist.github.com/CC-Dh/8d292652eeee0e96d09ff36f80cc2e40.js"></script></div><div><span><span><br /></span></span></div><div><span><span><br /></span></span></div><div><span><span><span> </span><span style="font-size: medium;">Following is the fileAES.cpp file where fileAES() function is implemented. This file is originally taken from MbedTLS library, <a href="https://github.com/ARMmbed/mbedtls/blob/development/programs/aes/crypt_and_hash.c" target="_blank">crypt_and_hash.c</a>. Minor modifications are done to convert existing main() function in it into fileAES() function, which is called from main() function given above. As file access functions of the original file are same in LittleFS as well, modifications are minimum. </span></span></span></div><div><span><span style="font-size: medium;"><br /></span></span></div><div><span><span style="font-size: medium;"><i>fileAES.cpp</i></span></span></div><div style="height: 400px; overflow: auto; width: auto;"><script src="https://gist.github.com/CC-Dh/deef9cd1fa1d3272c72bc46964f318d4.js"></script></div><div><span><span><br /></span></span></div><div><div><b><u><span style="font-size: medium;">Results</span></u></b></div><div><span style="font-size: medium;"><br /></span></div><div><span style="font-size: medium;"><i>Compiler Output:</i></span></div><div><div style="background-color: #1e1e1e; line-height: 22px;"><div style="line-height: 22px;"><span style="color: #d4d4d4; font-family: Consolas, Courier New, monospace; font-size: x-small;"><span style="white-space: pre;">RAM: [== ] 15.3% (used 41380 bytes from 270336 bytes)
Flash: [ ] 0.2% (used 4534 bytes from 2097152 bytes)</span></span></div></div></div><div><span><i><br /></i></span></div><div><span style="font-size: medium;"><i>Terminal Output (Input File with 10 lines, 630 Bytes):</i></span></div><div><div style="background-color: #1e1e1e; line-height: 22px;"><div style="line-height: 22px;"><span style="color: #d4d4d4; font-family: Consolas, Courier New, monospace; font-size: x-small;"><span style="white-space: pre;">AES File Encryption (using Mbedtls) on Raspberry Pi Pico (mbed-arduino)
Flash BD Initialized!
FileSystem mounted!
File Size (W): 630
Encryption Done, Time taken: 2343 ms
Decryption Done, Time taken: 2338 ms
Example Done!</span></span></div></div></div><div><span><i><br /></i></span></div><div><span style="font-size: medium;"><span><i>Terminal Output </i></span><i> (Input File with 100 lines, 6300 Bytes):</i></span></div><div><div style="background-color: #1e1e1e; line-height: 22px;"><div style="line-height: 22px;"><span style="color: #d4d4d4; font-family: Consolas, Courier New, monospace; font-size: x-small;"><span style="white-space: pre;">AES File Encryption (using Mbedtls) on Raspberry Pi Pico (mbed-arduino)
Flash BD Initialized!
FileSystem mounted!
File Size (W): 6300
Encryption Done, Time taken: 2425 ms
Decryption Done, Time taken: 2429 ms
Example Done!</span></span></div></div></div><div><br /></div><div><span> <span style="font-size: medium;">File size here is in Bytes. T</span></span><span style="font-size: medium;">he increased file size does not increase the time significantly for small file size, as the AES context setup part dominates the time taken as compared to the time taken in encryption/ decryption. Also, the Flash memory is faster. When the file is stored in external memory devices like SD card, the serial interface speed as well as the device library being used affect the encryption/ decryption time w.r.t. change in the file size. </span></div><div><span style="font-size: medium;"><br /></span></div><div><b><span style="font-size: medium;">Download Code files:</span></b></div><div><ul><li><span style="font-size: medium;"><b><a href="https://storage.googleapis.com/www.dharmanitech.com/littleFsAes.zip">littleFsAes.zip</a></b> (main.cpp, fileAES.cpp, fileAES.h and platformio.ini) </span></li></ul></div><div><span style="font-size: medium;"><br /></span></div></div><div><span><span style="font-size: medium;"><span> If you have more jobs to be done which are time critical, the time consuming job of file encryption/ decryption can be given to the second core of Pi Pico, which will significantly free up the first core. In my future post, I'll add the code examples for file encryption on SD cards as well as the multicore implementation.</span><br /></span></span></div><div><span><span><span style="font-size: medium;"><br /></span></span></span></div><div><span style="font-size: medium;">Happy coding!</span></div><div><br /></div><p></p>CC Dharmanihttp://www.blogger.com/profile/13217855743473839524noreply@blogger.com16tag:blogger.com,1999:blog-8014888555955763990.post-10670827996778258862022-01-09T21:42:00.009+05:302022-05-02T21:16:49.381+05:30Raspberry Pi Pico - A Tiny Power-Packed Development Board<p><span style="font-size: medium;"> </span></p><div class="separator" style="clear: both; text-align: center;"><span style="font-size: medium;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEgxyUassClS_9uLVqXNZ3EWx-Ug53gyaRTvUxyMZP68WWweNUHcA3dAZbnj6ZXNB3F15oS56jk6ucb34Zgh4ZFAREd_R1vhYWbZwpLM92GRw2ucLpp6ZmYYCCKCFofrQq5tz3FVWj346y5YFlZ36wDVzdw3kCzkjLt501zQ6uDeFLaBT8HoHrrR50Qj=s4592" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="3536" data-original-width="4592" height="492" src="https://blogger.googleusercontent.com/img/a/AVvXsEgxyUassClS_9uLVqXNZ3EWx-Ug53gyaRTvUxyMZP68WWweNUHcA3dAZbnj6ZXNB3F15oS56jk6ucb34Zgh4ZFAREd_R1vhYWbZwpLM92GRw2ucLpp6ZmYYCCKCFofrQq5tz3FVWj346y5YFlZ36wDVzdw3kCzkjLt501zQ6uDeFLaBT8HoHrrR50Qj=w640-h492" width="640" /></a></span></div><span style="font-size: medium;"><br /></span><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEg0WkPsUv18sftuyYGqqyU_5L066Nw7y0dQ4dPhD2BXjSDQ-T_kIBvXCy7bs-MOXUXJKHBDeTBDO6ero18NTG5QClYVD_2rFzPUc-obC6HWuhxpRRdG_SD8nK0ZQ6r_jWyYxLcbgtyGAcKyUzkHnwnycfuplfLjFdXHoX7ip7TItekRV3r2sCzYk5Z0=s741" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="278" data-original-width="741" height="240" src="https://blogger.googleusercontent.com/img/a/AVvXsEg0WkPsUv18sftuyYGqqyU_5L066Nw7y0dQ4dPhD2BXjSDQ-T_kIBvXCy7bs-MOXUXJKHBDeTBDO6ero18NTG5QClYVD_2rFzPUc-obC6HWuhxpRRdG_SD8nK0ZQ6r_jWyYxLcbgtyGAcKyUzkHnwnycfuplfLjFdXHoX7ip7TItekRV3r2sCzYk5Z0=w640-h240" width="640" /></a></div><br /><div class="separator" style="clear: both; text-align: center;"><br /></div><p></p><p></p><p><span style="font-size: medium;">Raspberry Pi Pico is a relatively new, tiny but powerful development board designed by the Raspberry Pi (UK), which is based upon RP2040 microcontroller chip, developed in-house by Raspberry Pi. The microcontroller has dual-core Arm Cortex- M0+ Processor, running at clock up to 133MHz, with 264KB internal RAM and supports up to 16MB of external Flash. Multicore operation is supported by a pair of four entry FIFOs (one in each direction between the cores).</span></p><p><span style="font-size: medium;">The Pi Pico board has 2MB of on-board QSPI Flash, which is programmable through USB Mass Storage Device mode or using Serial Wire Debug port. It also features wide range of flexible I/Os, like GPIO, UART, I2C, SPI, USB and also Programmable I/O (PIO), which is unique to this board. The board has small footprint with solderable headers. It is very cost-effective, available from large number of vendors, may be available in your nearest electronic shop, too. This opens doors for utilization towards a wide range of applications for novices as well as experts.</span></p><p><span style="font-size: medium;">Detailed information on Raspberry Pi Pico is available here:</span></p><p style="text-align: left;"></p><ul style="text-align: left;"><li><span style="font-size: medium;"><a href="https://www.raspberrypi.com/products/raspberry-pi-pico/" target="_blank"><b>Product homepage of Raspberry Pi Pic</b>o</a> (with product information)</span></li><li><span style="font-size: medium;"><a href="https://projects.raspberrypi.org/en/projects/getting-started-with-the-pico/0" target="_blank"><b>Getting started with Raspberry Pi Pico</b></a> (with start-up project)</span></li></ul><p></p><p><span style="font-size: medium;">Following image with Pin-diagram of Pi Pico gives idea about various I/Os of the device: (courtesy- Raspberry Pi website):</span></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEj_DxhvT3cCSBJNgoVDYwkHh_uKDG_JVM68YOjC9nwWEoj7UcS4Joizqn41WQ_qkMexAnYGPdq0VdCC-X8-vDDlhuKhzn8z-9od_eeQJbHcFgFUpwb49KjGZJknjhk8jn2KBA6q3nW1rg9Ks0kTlIqLFMd0vkXCtBeybVtU33_1PKbfQneY1LAt9O9x=s1387" style="margin-left: 1em; margin-right: 1em;"><span style="font-size: medium;"><img border="0" data-original-height="952" data-original-width="1387" height="440" src="https://blogger.googleusercontent.com/img/a/AVvXsEj_DxhvT3cCSBJNgoVDYwkHh_uKDG_JVM68YOjC9nwWEoj7UcS4Joizqn41WQ_qkMexAnYGPdq0VdCC-X8-vDDlhuKhzn8z-9od_eeQJbHcFgFUpwb49KjGZJknjhk8jn2KBA6q3nW1rg9Ks0kTlIqLFMd0vkXCtBeybVtU33_1PKbfQneY1LAt9O9x=w640-h440" width="640" /></span></a></div><span style="font-size: medium;"><br /></span><p><span style="font-size: medium;">The Pi Pico can be programmed in C/C++ (SDK support is provided by Raspberry Pi), Arduino or MicroPython. A lot of resources have already been made available in such a short time, for this board. That actually shows the rapid growth of interest in Pi Pico and usage by hobbyists/ professionals together. New libraries, packages and platform supports are getting added at quite a fast pace.</span></p><p><span style="font-size: medium;">I've liked this board so much that I'm literally hooked to it 😊. The purpose of my this post is just to put up an introduction with resource pointers, which I wanted to do for quite some time, before I start posting experimental codes also, using it.</span></p><p><span style="font-size: medium;"><br /></span></p><p><span style="font-size: medium;"><b><u>The Pico-SDK</u></b>: This is official SDK from Raspberry Pi team, for writing C/C++ or assembly language code for Pi Pico, full with headers, libraries and build system, designed to provide an API and programming environment. Multicore support examples are also given.</span></p><p><span style="font-size: medium;"><a href="https://github.com/raspberrypi/pico-sdk" target="_blank"><b>Pico-SDK GitHub page</b></a> provides detailed description and links for documentation for using the SDK projects. The SDK can be easily<b> <a href="https://www.electronicshub.org/program-raspberry-pi-pico-with-visual-studio-code/" target="_blank">setup with VS Code</a></b> for programming the Pi Pico. It also has the example projects to demonstrate the use of SDK for various peripherals/ interfaces of the device.</span></p><p><span style="font-size: medium;">(You can also visit the <a href="https://github.com/Wiz-IO/wizio-pico" target="_blank"><b>wizio-pico </b></a>project page on github, for faster way of getting started with installation and usage of pico-sdk on PlatformIO with VS Code) <br /></span></p><p><span style="font-size: medium;"><br /></span></p><p><span style="font-size: medium;"><b><u>The Pico-Arduino</u></b>: The addition of the Arduino support has made Pi Pico even more easier to use for any newcomer who wants to get hands-on experience with it. </span></p><p><span style="font-size: medium;">There are two packages, shown in Arduino Boards Manager, "<i>Arduino Mbed OS RP2040 Boards</i>" and "<i>Raspberry Pi Pico/RP2040</i>" as shown here:</span></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEiUr-cDU56B_xfg2P1E6YYSKFTuJS9QA2IllqH85CaQMlN5FjfX0f5nNb0-kD7LJBsr9V6htDd0Qd56dPx-gs6BbVxCUC3HbymxpzC3A7GkVx7q-z8_6_0fvFumc5zRyJERTqA6EzN-gjTyWRJNBWsqnmZk9rJV-6CQO3HefHZIZTbfQrM1uevndKC7=s1171" style="margin-left: 1em; margin-right: 1em;"><span style="font-size: medium;"><img border="0" data-original-height="502" data-original-width="1171" height="274" src="https://blogger.googleusercontent.com/img/a/AVvXsEiUr-cDU56B_xfg2P1E6YYSKFTuJS9QA2IllqH85CaQMlN5FjfX0f5nNb0-kD7LJBsr9V6htDd0Qd56dPx-gs6BbVxCUC3HbymxpzC3A7GkVx7q-z8_6_0fvFumc5zRyJERTqA6EzN-gjTyWRJNBWsqnmZk9rJV-6CQO3HefHZIZTbfQrM1uevndKC7=w640-h274" width="640" /></span></a></div><span style="font-size: medium;"><br /></span><div class="separator" style="clear: both; text-align: center;"><span style="font-size: medium;"><br /></span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-size: medium;">Both these board support Pico-SDK functions also. <a href="https://github.com/earlephilhower/arduino-pico" target="_blank"><b>Raspberry Pi Pico/RP2040 GitHub page</b></a> shows detailed information on installation and usage of the package with Arduino. <a href="https://arduino-pico.readthedocs.io/_/downloads/en/latest/pdf/" target="_blank"><b>Arduino Pico Document</b></a> provides detailed information on writing the code, with examples. This document by Earle F. Philhower, III, is getting updated, like, every other day! :) This board also supports multicore programming using additional setup() and loop() functions (named setup1() and loop1()).</span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-size: medium;"><br /></span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-size: medium;">The <a href="https://github.com/arduino/ArduinoCore-mbed" target="_blank"><b>Arduino Mbed OS RP2040 Boards</b></a> package supports Pico with <i>Mbed RTOS</i> for Arduino. This is really powerful. The <a href="https://os.mbed.com/" target="_blank"><b>Mbed OS</b></a> is already being used widely in ARM Cortex devices, and support for the same in Pico Arduino makes things even more versatile and mighty by providing access to the various Mbed APIs inside Arduino.</span></div><div class="separator" style="clear: both; text-align: left;"><span style="font-size: medium;"><br /></span></div><p><span style="font-size: medium;"><b><u>With PlatformIO for VS Code</u></b>:<b> </b><a href="https://platformio.org/" target="_blank"><b>PlatformIO</b></a> is a powerful IDE, which can be used for Pi Pico Arduino. The "Raspberry Pi Pico" board is shown in the Board Explorer of PlatformIO home menu. This is same as "Arduino Mbed OS RP2040 Boards" in Arduino IDE. The platfomIO provides professional features of code editing, auto code-completion suggestions / intelliSense, debug options, etc., which are not available currently in Arduino IDE.</span></p><p><span style="font-size: medium;">Both the above Arduino packages have different default pin assignments for I2C, SPI, etc. Hence, interchangeability of the code has to be properly checked before changing the board setting. As lot of work is currently going on, I suppose there will be a single combined package in the future, which will do away with some of the initial confusion while programming.</span></p><p><span style="font-size: medium;"><br /></span></p><p><span style="font-size: medium;"><b><u>Pi Pico with MicroPython</u></b>: Pi Pico can also be used with MicroPython (or CircuitPython) interpreters, which make programming still easier for newbies who want to avid C/C++, or for programmers already experienced in Python.</span></p><p><span style="font-size: medium;"><a href="http://docs.micropython.org/en/latest/rp2/quickref.html" target="_blank"><b>Micropython.org page for Pi-Pico</b></a> provides quick-start reference on installation and usage of micropython on Pi Pico. Also, <a href="https://datasheets.raspberrypi.com/pico/raspberry-pi-pico-python-sdk.pdf" target="_blank"><b>Raspberry Pi official Datasheet of Python SDK</b></a> is filled with detailed info on coding with micropython, with examples. <b><a href="https://github.com/raspberrypi/pico-micropython-examples" target="_blank">This GitHub page</a></b> also provides ready to use examples in micropython.</span></p><p><span style="font-size: medium;"><a href="https://thonny.org/" target="_blank"><b>Thonny</b></a> is easy to use, light-weight Python IDE for beginners. The <a href="https://projects.raspberrypi.org/en/projects/getting-started-with-the-pico/2" target="_blank"><b>Raspberry Pi page here</b></a> provides getting started with micropython using Thonny IDE. The <a href="https://learn.adafruit.com/circuitpython-libraries-on-micropython-using-the-raspberry-pi-pico/thonny-setup" target="_blank"><b>Adafruit page</b></a> provides details on configuring Thonny with CircuitPython for Pi Pico.</span></p><p><span style="font-size: medium;"><br /></span></p><p><span style="font-size: medium;"><b><u>Supporting Base Boards</u></b>: Raspberry Pi Pico is easy to use on breadboard itself for initial prototyping or testing work, great for hobbyists. But if you need some proto board with ready connections for experiments, the <b><a href="https://www.cytron.io/p-maker-pi-pico-base" target="_blank">Maker Pi Pico Base board</a></b> looks great. It has got LEDs already mounted on each GPIO pin, providing visual feedback on the code functioning. It has also got other peripherals like microSD card, buzzer (speaker), audio jack, pushbuttons and also connector for ESP32 device for adding WiFi to the project. It's also available online, I think at most places. Here is my board:</span></p><p></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEiWRM1xkxTNCw73317sM7Irqzh8f95SaRB_MuGNHbELgGH_MerMMaPJvDmZU4o7_BXxoFqyORTtRWLcBfAvbW_x6jqYdCpiqFqhOKNjVeDXDArgLKslk-E2IMdtYfVRu_ULtoKsM-BobswdOTyvEqYl0U8siIRifPKnlWf90NHnkgbqKjfHbEBlrMmC=s2596" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="2596" data-original-width="2227" height="276" src="https://blogger.googleusercontent.com/img/a/AVvXsEiWRM1xkxTNCw73317sM7Irqzh8f95SaRB_MuGNHbELgGH_MerMMaPJvDmZU4o7_BXxoFqyORTtRWLcBfAvbW_x6jqYdCpiqFqhOKNjVeDXDArgLKslk-E2IMdtYfVRu_ULtoKsM-BobswdOTyvEqYl0U8siIRifPKnlWf90NHnkgbqKjfHbEBlrMmC=w324-h276" width="324" /></a></div><br /><p></p><p><span style="font-size: medium;">You can also opt for a simple GPIO extension boards, like these:</span></p><div class="separator" style="clear: both; text-align: left;"><div class="separator" style="clear: both; text-align: right;"><div class="separator" style="clear: both; text-align: center;"><img border="0" data-original-height="400" data-original-width="500" height="222" src="https://blogger.googleusercontent.com/img/a/AVvXsEhJhb0es5Sgal7w14-JhjwDHSwOglxsBo5zq5NxMrP1-_-WmjMyC4BK-3oLPGXK7IYQ1Fjdn0q8XR4GgNf0Wn3ZsL1NHKdmyujVm5PJrWWR2f5Z-YIIuul7LpORQJYaVeX0Zbd0Y0s1SmORLRvEAgZ5Or2B4xaoJFqWjmJOf3bsWQ9QQPNN8Px0bQs6=w278-h222" width="278" /><a href="https://blogger.googleusercontent.com/img/a/AVvXsEjU0wjMD-tLHYVOriFF7t6rV_hyHS1v8vhh1hw4FJ5N9hAwp1hu38UVoONocJhSwQB6PhGMd67gYTvDMrPHmcOuikXnViQ_-A61oEknjotehzlG_bQC-G1M-8wFw28JtmM5WrQOLzaeKLuipO_z-DtjtUbdLSqTqtvzkfGuC5B0sSYruNl2t5x5sXS5=s1034" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="774" data-original-width="1034" height="237" src="https://blogger.googleusercontent.com/img/a/AVvXsEjU0wjMD-tLHYVOriFF7t6rV_hyHS1v8vhh1hw4FJ5N9hAwp1hu38UVoONocJhSwQB6PhGMd67gYTvDMrPHmcOuikXnViQ_-A61oEknjotehzlG_bQC-G1M-8wFw28JtmM5WrQOLzaeKLuipO_z-DtjtUbdLSqTqtvzkfGuC5B0sSYruNl2t5x5sXS5=w317-h237" width="317" /></a></div><a href="https://blogger.googleusercontent.com/img/a/AVvXsEhJhb0es5Sgal7w14-JhjwDHSwOglxsBo5zq5NxMrP1-_-WmjMyC4BK-3oLPGXK7IYQ1Fjdn0q8XR4GgNf0Wn3ZsL1NHKdmyujVm5PJrWWR2f5Z-YIIuul7LpORQJYaVeX0Zbd0Y0s1SmORLRvEAgZ5Or2B4xaoJFqWjmJOf3bsWQ9QQPNN8Px0bQs6=s500" style="margin-left: 1em; margin-right: 1em;"><br /></a><br /></div></div><p><span style="font-size: medium;">These board are available on amazon, needs to just search for Pi Pico. You'll also get these or similar easily from your local suppliers, too. (In my recent experience during the chip shortage period, I've found getting Pi Pico boards far easier than many other development boards. That's one more incentive to use them!)</span></p><p><span style="font-family: inherit; font-size: medium;"><b><u>Summary</u></b>:</span></p><p><span style="font-family: inherit; font-size: medium;">I hope this gives you the idea of how easy it is to get started with Pi Pico board. The board is really cute, beautifully manufactured! Once you hold it in your hand, may be you'll fall in love with it, too!!😊 Small and yet, it is so powerful for such a size! Go ahead and grab one, you won't regret it.! 👍</span></p><p><span style="font-size: medium;"><br /></span></p><p><span style="font-size: medium;"><b><u>Further Reading/ References</u></b>:</span></p><p></p><ol style="text-align: left;"><li><span style="font-size: medium;"><a href="https://datasheets.raspberrypi.com/pico/getting-started-with-pico.pdf" target="_blank"><b>Raspberry Pi Pico Getting Started</b></a> (Intro to setting up development environment, programming and loading the code into the board)</span></li><li><span style="font-size: medium;"><a href="https://datasheets.raspberrypi.com/rp2040/rp2040-datasheet.pdf" target="_blank"><b>RP2040 Microcontroller Datasheet</b></a> (device datasheet of the chip itself)</span></li><li><span style="font-size: medium;"><a href="https://datasheets.raspberrypi.com/pico/pico-datasheet.pdf" target="_blank"><b>Pi Pico Board Datasheet</b></a> (Pico board details with electrical, mechanical specs, powering, components, schematics and application briefs)</span></li><li><span style="font-size: medium;"><a href="https://datasheets.raspberrypi.com/pico/Pico-R3-A4-Pinout.pdf" target="_blank"><b>Pi Pico Pinout</b></a> (Pinout with alternative functions)</span></li><li><span style="font-size: medium;"><a href="https://datasheets.raspberrypi.com/rp2040/hardware-design-with-rp2040.pdf" target="_blank"><b>Pi Pico Hardware Design Reference</b></a> (Must read before you go ahead with making more hardware connections, other than blinking LEDs!)</span></li><li><span style="font-size: medium;"><a href="https://datasheets.raspberrypi.com/pico/raspberry-pi-pico-c-sdk.pdf" target="_blank"><b>Pi Pico C/C++ SDK</b></a> (C/C++ API function/interface details)</span></li><li><span style="font-size: medium;"><a href="https://datasheets.raspberrypi.com/pico/raspberry-pi-pico-python-sdk.pdf" target="_blank"><b>Pi Pico Python SDK</b></a> (Python API function/interface details)</span></li><li><a href="https://raspberrypi.github.io/pico-sdk-doxygen/" target="_blank"><span style="font-size: medium;"><b>Pico-SDK Documentation (doxygen)</b></span></a></li><li><span style="font-size: medium;"><a href="https://arduino-pico.readthedocs.io/_/downloads/en/latest/pdf/" target="_blank"><b>Arduino Pico documentation</b></a> (details of Arduino API implementation)</span></li><li><a href="http://docs.micropython.org/en/latest/rp2/quickref.html" target="_blank"><span style="font-size: medium;"><b>MicroPython Quick Reference for Pi Pico</b></span></a></li><li><span style="font-size: medium;"><b><a href="https://files.seeedstudio.com/wiki/Grove_Shield_for_Pi_Pico_V1.0/Begiinner%27s-Guide-for-Raspberry-Pi-Pico.pdf" target="_blank">Beginner's Guide for R-Pi Pico</a></b> (A nice starting guide with hardware setup and programming in MicroPython, from seeedstudio.com)</span></li></ol><p></p><p> You can also check out my <a href="https://www.dharmanitech.com/2022/01/string-and-file-encryption-with-aes.html">next post on Raspberry Pi Pico with AES encryption example codes</a>.<br /></p>CC Dharmanihttp://www.blogger.com/profile/13217855743473839524noreply@blogger.com18tag:blogger.com,1999:blog-8014888555955763990.post-86045810201093898452018-07-04T01:47:00.058+05:302022-01-27T00:16:26.427+05:30UART or SD Card based 8-Channel Data-logger with temperature log<div class="separator" style="clear: both; text-align: center;">
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://lh3.googleusercontent.com/--2dXhOo1RWg/YVCE4hjb9lI/AAAAAAAAM2E/Up67Z-qifpkJq_C0iEV8Jgd_Xy2RmaiJACLcBGAsYHQ/SD_Logging_2.JPG" style="margin-left: 1em; margin-right: 1em;"><img alt="" data-original-height="1601" data-original-width="2048" height="500" src="https://lh3.googleusercontent.com/--2dXhOo1RWg/YVCE4hjb9lI/AAAAAAAAM2E/Up67Z-qifpkJq_C0iEV8Jgd_Xy2RmaiJACLcBGAsYHQ/w640-h500/SD_Logging_2.JPG" width="640" /></a><a href="https://2.bp.blogspot.com/-aTx6A9gGJmk/WzutBRq4NsI/AAAAAAAABA0/osvbJ6qtvhEC3dBCh259eiCRgDftyLpkgCLcBGAs/s1600/DSC_1023.JPG" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1148" data-original-width="1376" height="531" src="https://2.bp.blogspot.com/-aTx6A9gGJmk/WzutBRq4NsI/AAAAAAAABA0/osvbJ6qtvhEC3dBCh259eiCRgDftyLpkgCLcBGAs/s640/DSC_1023.JPG" width="640" /></a></div>
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://4.bp.blogspot.com/-iRscjCvhbew/WzutOch2ndI/AAAAAAAABA4/WkyjKQbPhocUKablFraewKD1BTz2r4iaACLcBGAs/s1600/DSC_1033.JPG" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="738" data-original-width="1024" height="287" src="https://4.bp.blogspot.com/-iRscjCvhbew/WzutOch2ndI/AAAAAAAABA4/WkyjKQbPhocUKablFraewKD1BTz2r4iaACLcBGAs/s400/DSC_1033.JPG" width="400" /></a></div>
<br />
Hi Friends,<br />
here is one more data-logger circuit, which will be useful for some who have not much ventured into the ADC for datalogging or RTC or i2c communication, etc. This one is based on ATmega32. It has 8-channel 10-bit ADC. Hence, providing us with 8-channels with 0 to 5V voltage level measurement. The circuit also has on-board RTC (based on DS1307) to log the data with time-stamp. Data is logged via UART or using microSD card. The circuit has 3-pin UART connector, which can be used to connect to PC/laptop using UART(TTL) to USB serial converter, commonly available in electronic markets (UART setting: 38400-1-N-1).<br />
Also, there is a thermometer IC, DS1621, which is connected via i2c (along with the RTC IC) and provides temperature measurement from -55 to +125 Deg. C. The temperature is also sent along with the voltages to the UART for logging.<br />
(<i>The logging with microSD card is added later in this post).</i><br />
The circuit schematic is given in the following figure (pdf file can be downloaded from <a href="https://storage.googleapis.com/www.dharmanitech.com/DataLoggerM32_Sch.pdf" target="_blank"><b>here</b></a>):<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://4.bp.blogspot.com/-OL1NwoVXBJk/WzuvDfH3zEI/AAAAAAAABBI/ew9Adr8hkz4AS_18tkrfR_YtAX7rAffjgCLcBGAs/s1600/DataloggerUART_Sch.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1334" data-original-width="1600" height="532" src="https://4.bp.blogspot.com/-OL1NwoVXBJk/WzuvDfH3zEI/AAAAAAAABBI/ew9Adr8hkz4AS_18tkrfR_YtAX7rAffjgCLcBGAs/s640/DataloggerUART_Sch.png" width="640" /></a></div>
<br />
At power on, the current date and time are displayed on the first raw of LCD. The temperature and the logging ON/OF status is displayed on the second raw. A green LED is also turned ON as an additional status of the proper power-up of the microcontroller .<br />
The data measurement can be started anytime by pressing the 'SET' button (keep pressed till the red LED turns ON). The recording ON status is displayed on LCD as well as by the glowing red LED. During this recording, at a regular interval (as defined in the code), the microcontroller gets the temperature from DS1621, measures the 8 voltages connected to 8 of its screw-terminals, w.r.t GND on the 9th terminal (as shown in the schematic), and forms a string which includes line number, time (hh:mm:ss format), temperature and the 8 voltage values, in a comma separated format. This string is then sent to UART, which can be logged into a file or seen on a terminal program in the PC/laptop using the serial-to-usb converter.<br />
The operation is shown in the following screen-shot of the Proteus simulation (in the simulation, the temperature set in the IC and displayed by the LCD has difference of 1.5C, as the code applies the correction factors read from the IC to the temperature reading and then displays it, which represents the actual temperature):<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://3.bp.blogspot.com/-kUcOon9huN8/WzvMGKAjuEI/AAAAAAAABBs/hSLJhjJtQfcxzEk9M-utBjgDCdFDkDVbwCLcBGAs/s1600/M32_UART_DL.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="912" data-original-width="1294" height="450" src="https://3.bp.blogspot.com/-kUcOon9huN8/WzvMGKAjuEI/AAAAAAAABBs/hSLJhjJtQfcxzEk9M-utBjgDCdFDkDVbwCLcBGAs/s640/M32_UART_DL.png" width="640" /></a></div>
<br />
(Note: The Proteus simulation files are included in the source code folder download at the end of the post).<br />
<br />
The circuit in operation, with logging ON and OFF, is shown the following pics:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://4.bp.blogspot.com/-oFylwC2qejI/WzvOiej6yMI/AAAAAAAABB4/Jse0PD4LVywzEjmORYOHtDh861XYixA3ACLcBGAs/s1600/DSC_1034_1.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="612" data-original-width="1600" height="244" src="https://4.bp.blogspot.com/-oFylwC2qejI/WzvOiej6yMI/AAAAAAAABB4/Jse0PD4LVywzEjmORYOHtDh861XYixA3ACLcBGAs/s640/DSC_1034_1.jpg" width="640" /></a></div>
<br />
<br />
<a href="https://2.bp.blogspot.com/-bfTnn128nrU/WzvO6tahD-I/AAAAAAAABCM/YIRrGz0djQoXgN5hJvf2GnblAVHYTD3UwCLcBGAs/s1600/terminal.png" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="1018" data-original-width="1017" height="400" src="https://2.bp.blogspot.com/-bfTnn128nrU/WzvO6tahD-I/AAAAAAAABCM/YIRrGz0djQoXgN5hJvf2GnblAVHYTD3UwCLcBGAs/s400/terminal.png" width="398" /></a><p><br />
The actual UART output captured on a terminal of the Atmel Studio during the logging ON, is shown in the left side image, where temperature shown is 30.3 C, channel-2 was connected with +5V (VCC) and channel-7 was connected with the Li battery cell of the RTC. Rest of the channels were kept open at the screw-terminals.<br />
<br />
The RTC date and time can be changed using the three push-buttons, similar to the procedure shown in my previous post of the <a href="https://www.dharmanitech.com/2018/06/relay-timer-circuit-with-rtc-for-auto.html">RTC based relay-control</a>. The procedure is given here:<br />
<br />
<br />
<br />
<br />
<br />
<br />
<i style="background-color: white; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 14px;"><u><br /></u></i><br />
<i style="background-color: white; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 14px;"><u> </u></i></p><p><i style="background-color: white; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 14px;"><u>For setting RTC Date/Time</u>:</i><br />
</p><ol style="background-color: white; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 14px;">
<li style="margin: 0px 0px 0.25em; padding: 0px;">Press 'SET' button and Power ON the circuit, keeping the button pressed while the circuit is starting.</li>
<li style="margin: 0px 0px 0.25em; padding: 0px;">"RTC Setting.." message will be displayed on the first row of the LCD.</li>
<li style="margin: 0px 0px 0.25em; padding: 0px;"> Release the 'SET' button "Date: XX" will be displayed on the second row of the LCD, where XX is the existing current date as per the RTC.</li>
<li style="margin: 0px 0px 0.25em; padding: 0px;"> Press 'UP' or 'DOWN' button to increase or decrease the Date. When desired date is displayed, press 'SET' button to store it</li>
<li style="margin: 0px 0px 0.25em; padding: 0px;">"Month: XX" message will be displayed, where XX is the current month as per the RTC</li>
<li style="margin: 0px 0px 0.25em; padding: 0px;">Press 'UP' or 'DOWN' button to increase or decrease the Month. When desired month is displayed, press 'SET' button to store it</li>
<li style="margin: 0px 0px 0.25em; padding: 0px;">"Year: XXXX" will be displayed, use 'UP'/ 'DOWN' buttons to change the year and then press 'SET' button to store the year value</li>
<li style="margin: 0px 0px 0.25em; padding: 0px;">Then "Hour: XX" will be displayed, set it as per the previous steps and also set next "Minutes: XX" similarly, and store using 'SET' button.</li>
<li style="margin: 0px 0px 0.25em; padding: 0px;">When the Minutes is set, "RTC Setting" mode is over and normal operation resumes, where the LCD will display Date and time in the first row and temperature and log:OFF status in the second row.</li></ol><p> </p><div style="text-align: left;"><ul style="text-align: left;"><li><span style="font-size: large;"><u><b>Data-logging with SD card </b></u></span></li></ul></div><p> <span> </span><span> <span style="color: red;"> </span></span><span style="color: red;">(Updated: Sep 2021)</span><br /></p><div style="text-align: center;"><div class="separator" style="clear: both; text-align: center;"><a href="https://lh3.googleusercontent.com/--2dXhOo1RWg/YVCE4hjb9lI/AAAAAAAAM2E/Up67Z-qifpkJq_C0iEV8Jgd_Xy2RmaiJACLcBGAsYHQ/SD_Logging_2.JPG" style="margin-left: 1em; margin-right: 1em;"><img alt="" data-original-height="1601" data-original-width="2048" height="313" src="https://lh3.googleusercontent.com/--2dXhOo1RWg/YVCE4hjb9lI/AAAAAAAAM2E/Up67Z-qifpkJq_C0iEV8Jgd_Xy2RmaiJACLcBGAsYHQ/w400-h313/SD_Logging_2.JPG" width="400" /></a></div></div><div style="text-align: center;"><br /></div><div style="text-align: center;"><br /></div><p>Above image shows the logging with microSD card. A commonly available microSD card module (mostly used with Arduino) is used here. Please note that this module interferes with programming of the board on AVRISP port (which is not a problem with Arduino as it uses the USB bootloader programming and not AVRISP), so it's necessary to remove the card while loading the code. You can find solutions/modules online to overcome this issue. </p><p>Following images show the generated .csv file in the SD card and also opened file in MS-Excel. The logging was done without any voltages connected to the ADC channels, so the voltages are 0, but the temperature log can be seen along with the time stamp. You can view another log file <b><a href="https://storage.googleapis.com/www.dharmanitech.com/26092101.CSV" target="_blank">here</a></b>, where I've connected the 8 channels to 3V RTC battery and VCC (~5V) line one by one (cross-coupling of signal to nearby free channel is also logged there).<br /></p><p></p><div class="separator" style="clear: both; text-align: center;"><a href="https://lh3.googleusercontent.com/-ki8rNeVVXi8/YVB8JTk5QdI/AAAAAAAAM1g/p9-93tEd4WIeX_AZ8_21hofaBVlVW60FwCLcBGAsYHQ/sd_log.png" style="margin-left: 1em; margin-right: 1em;"><img alt="" data-original-height="858" data-original-width="2334" height="236" src="https://lh3.googleusercontent.com/-ki8rNeVVXi8/YVB8JTk5QdI/AAAAAAAAM1g/p9-93tEd4WIeX_AZ8_21hofaBVlVW60FwCLcBGAsYHQ/w640-h236/sd_log.png" width="640" /></a></div><p><br />The file name format is: DDMMYYNN.CSV, where DDMMYY is the date of logging and NN is the file number. After power on, the file number is set to 00. Every time logging is started and then stopped, the file number increments, hence, new file is created. As file number is a 2 digit value, max 100 (00 to 99) log files can be created after power on in a day, after that it will send error message. I guess you may not need to do the logging ON and OFF more than 100 times a day (after single power ON), but if you do, the file name string can be tweaks as necessary.<br /></p><p>After Power off and on, when datalogging is started, the code looks if the filename is already existing or not, if it is, it will change the log-file number (and hence, name) to next available number, and so on. So, always a new file is created whenever logging is started.</p><ul style="text-align: left;"><li><span style="font-size: medium;"><u><b>SD card datalogging using FatFS library</b></u></span></li></ul><p>I'm also uploading here the data-logging project code with a more generic <a href="http://elm-chan.org/fsw/ff/00index_e.html" target="_blank"><b>FatFs</b></a> library, which has been highly standardized and is officially supported/included by many IDEs/ Development boards/ Platforms (like Arduino, mbed, STM32, Keil, etc..). I've just replaced my FAT32 (and SD routines) libraries with FatFs modules. This also has been tested and the project folder is included in the downloads (Sr.No.2).</p><p>The datalogging and RTC setting procedures are same for all the above options, as explained in the earlier paragraphs. Functionality or user operations are same, only internal library change is there. Data-logging option with only <i>UART</i> or only <i>SD card</i> or <i>both</i> can be selected by proper macro selection in the <i>main.h </i>file. </p><p><b>Note</b>: You can connect UART while operating if you need to see the status/error messages for any troubleshooting. Otherwise, UART is not necessary if logging is done in SD card.<br /></p><p></p><div style="text-align: left;"><div><span face=""arial" , "tahoma" , "helvetica" , "freesans" , sans-serif" style="font-size: small;"><span>The circuit hardware is not much complicated, can be assembled on a general purpose PCB also. I'm including here the Gerber files also, along with the other downloads, if it's required.</span></span></div><div>
<span face=""arial" , "tahoma" , "helvetica" , "freesans" , sans-serif"><span style="font-size: 14px;"><br /></span></span></div><div>
<br /></div><div><span face=""arial" , "tahoma" , "helvetica" , "freesans" , sans-serif"><b><u>Downloads</u><span style="font-size: 14px;">:</span></b></span></div>
<div>
</div>
<ol><li><span style="font-family: inherit; font-size: medium;"><span face=""arial" , "tahoma" , "helvetica" , "freesans" , sans-serif"><span><b><a href="https://storage.googleapis.com/www.dharmanitech.com/dataloggerSD_Ver2.1.zip" target="_blank">Source Code for SD/UART Logging (with FAT32 Lib)</a> </b><span style="font-size: small;">(Atmel Studio-7 project)</span></span></span></span></li><li><span style="font-family: inherit; font-size: medium;"><span face=""arial" , "tahoma" , "helvetica" , "freesans" , sans-serif"><span><b><span><a href="https://storage.googleapis.com/www.dharmanitech.com/Datalogger_SD_Ver3.0.zip" target="_blank"><span style="font-family: inherit; font-size: medium;"><span face=""arial" , "tahoma" , "helvetica" , "freesans" , sans-serif"><span><b>Source Code for SD/UART Logging</b></span></span></span> (with FatFs Lib)</a> </span></b><span style="font-size: small;">(Atmel Studio-7 project)</span></span></span></span></li><li><span style="font-family: inherit; font-size: medium;"><span face=""arial" , "tahoma" , "helvetica" , "freesans" , sans-serif"><span><b><a href="https://storage.googleapis.com/www.dharmanitech.com/dataloggerSD_Proteus.zip" target="_blank"><span>Proteus Simulation for UART datalogging </span></a></b><br /></span></span></span></li><li>
<span style="font-family: inherit; font-size: medium;"><span face=""arial" , "tahoma" , "helvetica" , "freesans" , sans-serif"><b><a href="https://storage.googleapis.com/www.dharmanitech.com/DataLoggerM32_EAGLE.zip" target="_blank">EAGLE Schematic and Board files</a></b></span></span></li><li>
<span style="font-family: inherit; font-size: medium;"><span face=""arial" , "tahoma" , "helvetica" , "freesans" , sans-serif"><b><a href="https://storage.googleapis.com/www.dharmanitech.com/Gerber%20DataloggerM32.zip" target="_blank">Gerber Files</a></b></span></span></li></ol>
<div>
<span face=""arial" , "tahoma" , "helvetica" , "freesans" , sans-serif"><span style="font-size: 14px;"><b>Datasheets: </b><a href="http://ww1.microchip.com/downloads/en/DeviceDoc/doc2503.pdf">ATmega32</a>, <a href="https://datasheets.maximintegrated.com/en/ds/DS1307.pdf">DS1307</a>, <a href="https://pdfserv.maximintegrated.com/en/ds/DS1621.pdf">DS1621</a></span></span></div><div><span face=""arial" , "tahoma" , "helvetica" , "freesans" , sans-serif"><span style="font-size: 14px;"> </span></span></div>
<div>
<span face=""arial" , "tahoma" , "helvetica" , "freesans" , sans-serif"><span style="font-size: 14px;">You may also check out my post <u><b><a href="https://www.dharmanitech.com/2009/01/sd-card-interfacing-with-atmega8-fat32.html">here</a>,</b></u> where I started on SD cards, for more info/ further reading/ references.<br /></span></span></div><div><span face=""arial" , "tahoma" , "helvetica" , "freesans" , sans-serif"><span style="font-size: 14px;"><br /></span></span></div>
<div>
<span face=""arial" , "tahoma" , "helvetica" , "freesans" , sans-serif"><span style="font-size: 14px;">Enjoy!!</span></span></div>
<div>
<span face=""arial" , "tahoma" , "helvetica" , "freesans" , sans-serif"><span style="font-size: 14px;"><br /></span></span></div>
<div>
<span face=""arial" , "tahoma" , "helvetica" , "freesans" , sans-serif"><span style="font-size: 14px;">Regards,</span></span></div>
<div>
<span face=""arial" , "tahoma" , "helvetica" , "freesans" , sans-serif"><span style="font-size: 14px;"><br /></span></span></div>
<div>
<span face=""arial" , "tahoma" , "helvetica" , "freesans" , sans-serif"><span style="font-size: 14px;">CC Dharmani</span></span></div>
<div>
<span face=""arial" , "tahoma" , "helvetica" , "freesans" , sans-serif"><span style="font-size: 14px;">ccd@dharmanitech.com</span></span></div>
<div>
<span face=""arial" , "tahoma" , "helvetica" , "freesans" , sans-serif"><span style="font-size: 14px;"><br /></span></span></div>
</div>CC Dharmanihttp://www.blogger.com/profile/13217855743473839524noreply@blogger.com153tag:blogger.com,1999:blog-8014888555955763990.post-6713801405745761902018-06-23T23:36:00.001+05:302021-09-26T14:48:10.506+05:30Relay-Timer Circuit with RTC (for auto-operating appliances) using AtmelStudio or Arduino<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: left;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://3.bp.blogspot.com/-1iD9Mol3MWQ/W6PaWnUXDiI/AAAAAAAABEI/pyjnM12CqVIAGkkiQqqxk8eLrTtIa8GWwCLcBGAs/s1600/DSC_1267.JPG" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="640" data-original-width="1024" height="400" src="https://3.bp.blogspot.com/-1iD9Mol3MWQ/W6PaWnUXDiI/AAAAAAAABEI/pyjnM12CqVIAGkkiQqqxk8eLrTtIa8GWwCLcBGAs/s640/DSC_1267.JPG" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://4.bp.blogspot.com/-OdqT0ZVqYgQ/W6PazQqwlOI/AAAAAAAABEQ/YMGHlu4MYa4HnhhnfSIWnybjsl0qlr3MgCLcBGAs/s1600/RT-Board.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="968" data-original-width="1600" height="386" src="https://4.bp.blogspot.com/-OdqT0ZVqYgQ/W6PazQqwlOI/AAAAAAAABEQ/YMGHlu4MYa4HnhhnfSIWnybjsl0qlr3MgCLcBGAs/s640/RT-Board.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Hi friends,</div>
<div class="separator" style="clear: both; text-align: left;">
it's been years since I put up a new post here. So, starting again with a simple circuit, based on ATmega8, might be useful for newbies in AVR, RTC, Relay, etc.This is RTC based relay operating circuit to automatically power ON/OFF any electrical device/appliance at a preset time. </div>
<div class="separator" style="clear: both; text-align: left;">
The necessity behind it was this: I had started taking a 230V AC electrical Tiffin (lunch) box to office a few months back, which takes minimum 30 minutes to very slowly heat up the food (it's kept slow heating as the idea is to just heat the food without re-cooking it). That means it's necessary to turn the box ON 30 minutes before lunch-time. And it happened quite a lot of time that I simply forgot or could not power on due to a meeting in another building. So, one day I quickly cooked up this circuit as I was already having all the required components (including an ATmega8 development board and a relay module, to minimize the soldering job).</div>
<div class="separator" style="clear: both; text-align: left;">
Before anything further, if you try to make this circuit, <b>WARNING!! High Voltages are involved here, extreme care is necessary while testing/operation. Ensure proper insulation for the high-voltage lines.</b></div>
<div class="separator" style="clear: both; text-align: left;">
This circuit can be used for powering any electrical device by setting start and stop time, which is stored in EEPROM of ATmega8, so no need to set again upon power off. RTC (based on DS1307) is used for similar reasons, no need to keep the circuit ON when not necessary, or during power off, it will maintain the date/time running (with the help of the common 3v Li button-cell). RTC setting or start/stop time setting can be changed anytime using three push-buttons provided onboard.</div>
<div class="separator" style="clear: both; text-align: left;">
Now, the main components: The microcontroller is AVR ATmega8, small enough and with sufficient flash for the code required here. Initially (before making the custom-made PCB shown in the above pics), I used a off-the-shelf available <a href="http://store.extremeelectronics.co.in/28-PIN-AVR-Development-Board.html">28-pin AVR Development board</a> from Extreme Electronics. The board is shown here:</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-oT_6NrWVwws/Wy5kbO_pexI/AAAAAAAAA4Q/TPky5Flh8wwtZ6omiRJYTUQw2aHcnNnkwCLcBGAs/s1600/AVR28DEVmain.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="520" data-original-width="790" height="262" src="https://1.bp.blogspot.com/-oT_6NrWVwws/Wy5kbO_pexI/AAAAAAAAA4Q/TPky5Flh8wwtZ6omiRJYTUQw2aHcnNnkwCLcBGAs/s400/AVR28DEVmain.jpg" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
Using such a board avoids soldering the IC base, power supply components, ISP connector, etc. And it's having some user area for soldering, which was sufficient for this project.</div>
<div class="separator" style="clear: both; text-align: left;">
The <a href="http://embeddedmarket.com/products/Relay-Board-Dual-Interfacing/">Dual-channel Relay board</a> used initially is from EmbeddedMarket.com:</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://3.bp.blogspot.com/-GLEWknaVaFA/Wy5nD6kRnRI/AAAAAAAAA4s/3l5WuAVz_NkRchwNPJ5PqlwZFRTG8NQtwCLcBGAs/s1600/RelayModule3.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="693" data-original-width="1566" height="176" src="https://3.bp.blogspot.com/-GLEWknaVaFA/Wy5nD6kRnRI/AAAAAAAAA4s/3l5WuAVz_NkRchwNPJ5PqlwZFRTG8NQtwCLcBGAs/s400/RelayModule3.jpg" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
</div>
This module is having two independent relays with transistor circuits for activation. The VCC supply line of the coils here are connected with 9V or 12 V DC (as per the DC adapter used to power the development board) and the AVR port lines are connected to RL1 and RL2 terminals. Two devices can be independently operated with this module by connecting the AC live input to the NO (Normally Open) terminal of the Relay and taking the output from C (common) terminal to the electrical device live input. The return line of the electrical device can directly go from device to the mains, without connecting to this unit. (Note: As I was having only one device to control, I passed the Phase (Live) through one relay and Neutral through the another relay. The program operates both the relays simultaneously to power the electrical device, i.e.Tiffin-box in this case).<br />
Here is the Proteus simulation screen-shot (during simulation, LEDs are used in place of the relays to check the functionality and the serial terminal is unused):<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://3.bp.blogspot.com/-bboSb2RohGY/Wy5qwLILZPI/AAAAAAAAA5Q/_x-1ewB1WI0st7L1zBs0MPjRirb__zjFQCLcBGAs/s1600/relayTimerSim.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="786" data-original-width="709" height="640" src="https://3.bp.blogspot.com/-bboSb2RohGY/Wy5qwLILZPI/AAAAAAAAA5Q/_x-1ewB1WI0st7L1zBs0MPjRirb__zjFQCLcBGAs/s640/relayTimerSim.png" width="576" /></a></div>
<br />
<br />
Following is the simulation using ATmega328 (Arduino):<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-UR8VRA-XH6w/XWz8irT_uhI/AAAAAAAADyc/B-dq95IPGW8DhNg4-Ke5kO0KiaRPv2rRgCLcBGAs/s1600/relayTimer_m328.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="902" data-original-width="1292" height="446" src="https://1.bp.blogspot.com/-UR8VRA-XH6w/XWz8irT_uhI/AAAAAAAADyc/B-dq95IPGW8DhNg4-Ke5kO0KiaRPv2rRgCLcBGAs/s640/relayTimer_m328.png" width="640" /></a></div>
<br />
(The Proteus simulation files are included in the source code download at the end of the post).<br />
<br />
As shown, upon powering on, after displaying a welcome message, the LCD displays current date and time, and the output status (via two relays). The output ON is also indicated using a Red LED on the circuit. The terminal (UART) in the circuit is kept extra, in case someone wants to use terminal instead of LCD and push-buttons to display/set timings (This further reduces the hardware onboard, it will add only a UART-USB converter module for PC/laptop connection, which are quite commonly available).<br />
The program reads the set-time in EEPROM by checking for a valid EEPROM signature. If time is not set, it sets default time of 1230 HRS for start time and 1300 HRS for stop time. Whenever a new time is set, it's stored in the EEPROM and used during operation thereafter.<br />
The quickly made proto of the circuit with whatever came handy is shown here (underneath the LCD are the AVR and relay boards with the rest of the circuitry):<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-YgnmoiGndHI/XWz-4fA7FbI/AAAAAAAADy0/Q2ykePFtZYUmTrlfi-CGjQH_DsLuYQUCACLcBGAs/s1600/relayTimer_1.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="566" data-original-width="1600" height="225" src="https://1.bp.blogspot.com/-YgnmoiGndHI/XWz-4fA7FbI/AAAAAAAADy0/Q2ykePFtZYUmTrlfi-CGjQH_DsLuYQUCACLcBGAs/s640/relayTimer_1.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
The 230V lines are properly screwed and totally insulated using glue-gun inside the box, including the relay terminals, so that not even a single strand of the wire comes out of the insulation.<br />
Of course, the circuit can be totally tested (or time can be set/ changed) without connecting the 230V lines, as we can confirm the continuity of the relay line by checking with multimeter. The high voltage line is necessary only during the actual operation.<br />
Later on, the schematic and layout of the PCB were designed using KiCad (latest version 5.0), as KiCad has recently become a really great tool (and free, too!), as compared to my quite earlier experience with it. I instantly liked it even better then the EAGLE lite, which I had been using so far.<br />
The schematic is given here (when using Arduino, replace ATmega8 with ATmega328 in the circuit, in the same PCB):<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://2.bp.blogspot.com/-fxxp8e7CM_8/W6PdsP81FoI/AAAAAAAABEw/_iRALZmidsQQV_RMPEseT_gghuMx_SFuwCLcBGAs/s1600/RT_Schematic.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1104" data-original-width="1600" height="440" src="https://2.bp.blogspot.com/-fxxp8e7CM_8/W6PdsP81FoI/AAAAAAAABEw/_iRALZmidsQQV_RMPEseT_gghuMx_SFuwCLcBGAs/s640/RT_Schematic.png" width="640" /></a></div>
<br />
The PDF schematic can be downloaded from <b><a href="https://drive.google.com/file/d/1v3u_sgkUy7marXVQVxUVa8x4yQJgX012/view?usp=sharing">here</a></b>.<br />
<br />
The operation of the circuit is described here:<br />
<br />
<b>Circuit Operation:</b><br />
--------------------------------------------<br />
<i><u>For setting RTC Date/Time</u>:</i><br />
<ol>
<li>Press 'SET' button and Power ON the circuit, keeping the button pressed while the circuit is starting.</li>
<li>"RTC Setting.." message will be displayed on the first row of the LCD.</li>
<li> Release the 'SET' button "Date: XX" will be displayed on the second row of the LCD, where XX is the existing current date as per the RTC.</li>
<li> Press 'UP' or 'DOWN' button to increase or decrease the Date. When desired date is displayed, press 'SET' button to store it</li>
<li>"Month: XX" message will be displayed, where XX is the current month as per the RTC</li>
<li>Press 'UP' or 'DOWN' button to increase or decrease the Month. When desired month is displayed, press 'SET' button to store it</li>
<li>"Year: XXXX" will be displayed, use 'UP'/ 'DOWN' buttons to change the year and then press 'SET' button to store the year value</li>
<li>Then "Hour: XX" will be displayed, set it as per the previous steps and also set next "Minutes: XX" similarly, and store using 'SET' button.</li>
<li>When the Minutes is set, "RTC Setting" mode is over and normal operation resumes, where the LCD will display Date and time in the first row and O/P: ON/OFF status in the second row.</li>
</ol>
<i> <u>Normal Operation</u>:</i><br />
<ol>
<li> When the circuit is powered ON without pressing the 'SET' button, it
displays "Welcome, -Relay timer-" message for two seconds and then directly enters
into the normal mode</li>
<li>During the normal operation, the LCD display will be as per the above step 9. The Date and time are continuously updated on the display every second</li>
<li>In the normal operation, whenever the RTC time matches with the Start Time, the Relays are energized, connecting the output lines with the respective input lines. </li>
<li>When the output is ON, as soon as the RTC time matches with the Stop time, the relays are turned OFF, cutting off the output</li>
<li>The output ON and OFF are displayed on the LCD as well as indicated by Red LED ON and OFF, respectively</li>
</ol>
<u><i>Setting Start/ Stop time</i></u>:<br />
<ol>
<li> Start and Stop time can be changed anytime during the normal operation</li>
<li> Pressing the 'SET' button during normal operation displays currently set values of Start and Stop (End) times in "S:HH:MM E:HH:MM" format in the second row, where 'S' indicates Start time and 'E' indicates End (Stop) time. 'HH' and 'MM' are hours and minutes, respectively. The first row continues to display current date and time.</li>
<li>During step 2, if 'SET' button is pressed again, display goes back to normal operation. But if 'UP' or 'DOWN' button is pressed instead, the program enters into the Start/Stop time setting mode, where "Start Hour: XX" is displayed in the second row.</li>
<li>Use the 'UP'/'DOWN' and 'SET' keys to adjust Start Hour, followed by Start Min (Minutes), then Stop Hour and Stop Min. Each value is stored by pressing the 'SET' button.</li>
<li>After the Step 4, the new values are stored in EEPROM and normal operation resumes.</li>
</ol>
Here are two more views of the operational unit:<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://3.bp.blogspot.com/-lR1rVKhDhVo/W6PfbyNthVI/AAAAAAAABFI/iiyGkNyPYawzNp-_k5BAydKTX6_7aPaTgCLcBGAs/s1600/RT-Board-Box.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="553" data-original-width="1600" height="220" src="https://3.bp.blogspot.com/-lR1rVKhDhVo/W6PfbyNthVI/AAAAAAAABFI/iiyGkNyPYawzNp-_k5BAydKTX6_7aPaTgCLcBGAs/s640/RT-Board-Box.png" width="640" /></a></div>
<u><br /></u>
<u> Notes:</u><br />
<ul>
<li>After RTC and Start/stop times are set, no intervention is required for circuit operation</li>
<li>Whenever necessary, the circuit can be switched off, the date/time settings will be maintained</li>
<li>If the circuit power is OFF and the start time is missed before the power is ON, the circuit will not set the o/p even if the Stop time is still quite away. It will set the o/p only when the next start time match with RTC. (This can be changed by minor modification in the code, if necessary).</li>
<li>Warning again, proper insulation and extreme care from high voltage line is must!! Never keep you high voltage outlet pins 'Male' type, always use socket type. Use 'male' types only for the high voltage 'inlet' pins.</li>
</ul>
So, for last couple of months, I connect the Tiffin with the circuit (first thing after reaching office), using standard 230V AC plug, and power ON the circuit, check the display for normal operation and then continue with my work. The Tiffin gets ON and OFF as per the set time before lunch. At lunch time, I turn off the power (coz it's not necessary till next morning) and enjoy the hot meal!! The power can be kept ON also, if desired. For example, in case if you want to water your plants periodically by turning on the electrical motor, whether you are available nearby or not.<br />
<br />
Here is the complete source code in AtmelStudio7 and Arduino project files along with the Proteus simulation files (please ensure programming the fuse bites for proper clock frequency values). When using Arduino, ATmega8 needs to be replaced with ATmega328:<br />
<br />
<h3>
<u>
Downloads</u>: </h3>
<h3>
<a href="https://drive.google.com/file/d/0B53C_HLwEgi-b29tdGFER00zSHc/view?usp=sharing&resourcekey=0-9wdj753SAyW8jAu3kOEU1A"><span style="font-size: small;">Source Code (AtmelStudio) and Simulation Download</span></a> (<span style="font-size: x-small;">ATmega8, @8 MHz internal clock)</span></h3>
<div>
<h3>
<a href="https://drive.google.com/file/d/1puUm0jszlZVFBu_2Lyq90y7rq8l6QEgu/view?usp=sharing"><span style="font-size: small;">Source Code (Arduino) and Simulation Download</span></a> (<span style="font-size: x-small;">ATmega328, @16 MHz External clock)</span></h3>
</div>
<h3>
<b><a href="https://drive.google.com/file/d/1JvK6nppKU8M-GwO91MmacOzGFNdgonEA/view?usp=sharing"><span style="font-size: small;">KiCad Project Schematic, PCB and Gerber files</span></a></b></h3>
<div>
<br /></div>
<b style="font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 14px;">Datasheets/ Links: </b><a href="http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-2486-8-bit-AVR-microcontroller-ATmega8_L_datasheet.pdf"><span face=""arial" , "tahoma" , "helvetica" , "freesans" , sans-serif"><span style="font-size: 14px;">ATmega</span></span>8</a><span face=""arial" , "tahoma" , "helvetica" , "freesans" , sans-serif" style="font-size: 14px;">, <a href="http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-7810-Automotive-Microcontrollers-ATmega328P_Datasheet.pdf">ATmega328</a>, </span><a href="https://datasheets.maximintegrated.com/en/ds/DS1307.pdf" style="font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 14px;">DS1307</a>, <a href="https://www.arduino.cc/">Arduino Website</a><br />
<br />
<br />
<span style="font-size: small;">Enjoy!!</span><br />
<br />
<span style="font-size: small;">Thanks & Regards,</span><br />
<span style="font-size: small;">CC Dharmani </span><br />
<span style="font-size: small;">-------------------------------- </span>CC Dharmanihttp://www.blogger.com/profile/13217855743473839524noreply@blogger.com236Pune, Maharashtra, India18.5204303 73.85674369999992518.2795358 73.534020199999929 18.7613248 74.17946719999992tag:blogger.com,1999:blog-8014888555955763990.post-56360912504586278632011-05-10T17:59:00.004+05:302022-01-27T00:17:08.801+05:30microSD ATmega32 Data-Logger<a href="http://2.bp.blogspot.com/-l9JKUVyDmMo/TclFJoxMGuI/AAAAAAAAAb8/8CSYpK02UI0/s1600/excel-sheet.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><br /></a><a href="http://3.bp.blogspot.com/-Npy76Fg2q7s/Tckv94oIuXI/AAAAAAAAAbM/aLuxyXetW5A/s1600/dl1.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5605063951458548082" src="https://3.bp.blogspot.com/-Npy76Fg2q7s/Tckv94oIuXI/AAAAAAAAAbM/aLuxyXetW5A/s400/dl1.JPG" style="cursor: pointer; display: block; height: 345px; margin: 0px auto 10px; text-align: center; width: 400px;" /></a><br />
<a href="http://1.bp.blogspot.com/-iH_CCznFHTE/TclOCMJ1DuI/AAAAAAAAAcE/EgQg_qpw6kk/s1600/dl_off.JPG"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5605097010768449250" src="https://1.bp.blogspot.com/-iH_CCznFHTE/TclOCMJ1DuI/AAAAAAAAAcE/EgQg_qpw6kk/s400/dl_off.JPG" style="cursor: pointer; display: block; height: 400px; margin: 0px auto 10px; text-align: center; width: 356px;" /></a>Hi friends,<br />
<br />
aim of this project is to present a way to store a large quantity of data into microSD card in files with FAT32 format. Here, ATmega32 is used for data collection and microSD interface. The data is received from in-build 8-channel ADC of ATmega32. One channel is used for reading temperature from LM35 sensor and remaining channels are used for simply reading voltages and storing them.<br />
<br />
This project can be used to interface 8 different sensors with ADC of ATmega32, similar to the LM35 used here. The data is stored in CSV (comma separated values) format, which can be read using a PC/Laptop with Microsoft Excel or other compatible software. A snapshot of the excel file is given later in this post.<br />
<br />
This project is an example of how to use the microSD FAT32 library presented in my <a href="http://www.dharmanitech.com/2009/01/sd-card-interfacing-with-atmega8-fat32.html">earlier post</a>. In that post, the files were created using hyper-terminal and entering data with the PC keyboard, since that demonstrates the file creation and it's easy to debug. But many users have requested to make the file creation independent of the terminal, done inside the microcontroller, so I'm showing here how to use those functions independent of terminal. If you have directly landed on this page, it would be more helpful if you visit the <a href="http://www.dharmanitech.com/2009/01/sd-card-interfacing-with-atmega8-fat32.html">original post</a> first as it would be a better starting place for learning SD or FAT32 functions (also Check out my <b><a href="https://www.dharmanitech.com/2018/07/uart-based-8-channel-data-logger-with.html">this post for updated version</a></b> of this project with 16x2 LCD and DS1621 temperature sensor<br />
<br />
Here is the schematic (click on the images for larger view or <a href="https://drive.google.com/file/d/0B53C_HLwEgi-UHZWbzZCb0M0RlU/view?usp=sharing&resourcekey=0-tbNMzZDKhnohYn7cea7f6g">download PDF</a>):<br />
<br />
<a href="http://1.bp.blogspot.com/-8pF9QoLX39Y/Tck0H7F6TeI/AAAAAAAAAbc/dTQ4aCwXnB0/s1600/sd_dl_sch1.JPG"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5605068521965506018" src="https://1.bp.blogspot.com/-8pF9QoLX39Y/Tck0H7F6TeI/AAAAAAAAAbc/dTQ4aCwXnB0/s400/sd_dl_sch1.JPG" style="display: block; height: 400px; margin: 0px auto 10px; text-align: center; width: 391px;" /></a>The project contains RTC interface (for date and time storage), RS232 (for connection with PC) and a microSD module. Here, the hyper-terminal connection is required only for setting RTC date and time. Once the date/time are set, the RS232 connection is not required anymore for normal data-logging operation (It can be used for debugging purpose if there is a problem).<br />
<br />
The microSD module used here is from <a href="http://store.extremeelectronics.co.in/home.php">eXtreme Electronics</a>.<a href="http://3.bp.blogspot.com/-UWZlsCNg_WY/Tck5bEw7WSI/AAAAAAAAAbk/GdJkALHshzk/s1600/MicroSDBreakoutIso.jpg"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5605074348537501986" src="https://3.bp.blogspot.com/-UWZlsCNg_WY/Tck5bEw7WSI/AAAAAAAAAbk/GdJkALHshzk/s320/MicroSDBreakoutIso.jpg" style="cursor: pointer; float: right; height: 188px; margin: 0pt 0pt 10px 10px; width: 218px;" /></a><br />
The module is shown in the figure here. Other than the microSD socket, this low-cost module also contains on-board 3.3v regulator for the microSD card, a 5v-3.3v level converter and other safety features required for the card. This module is used here as it provides a stable interface and makes the the card compatible with 5v supply and 5v signals of microcontroller.<br />
<br />
The module is available at: <a href="http://store.extremeelectronics.co.in/MicroSD-TF-Module.html">http://store.extremeelectronics.co.in/MicroSD-TF-Module.html</a><br />
<br />
The schematic also shows two LEDs and a push-button. The LEDs are used for indications of power and recording and the push-button is used to start-stop recording.<br />
<br />
<span style="font-weight: bold;">Operation of the circuit:</span><br />
-----------------------------------------------<br />
<span color="rgb(102 , 0 , 204)" style="font-weight: bold;">For setting RTC date/time (or for debugging mode):</span><br />
<ul>
<li>Connect the microSD module, insert the microSD card</li>
<li>Connect the RS232 cable with the circuit. Set-up hyper terminal with 19200 baud, no parity, 8-bit data, 1 stop-bit and flow-control as 'None'</li>
<li>Connect the power cable and power on the circuit <span style="font-weight: bold;">while keeping the push-button pressed</span></li>
<li>Green LED will glow in the circuit board</li>
<li>A menu will be displayed on the Hyper terminal as shown in the figure below. Select desired option and follow the displayed instructions</li>
<li>When date/time is set or debugging done, select option '0' to come out of the menu and start functioning a s data-logger</li>
<li>At this point, the RS232 cable can be removed</li>
</ul>
<br />
<a href="http://4.bp.blogspot.com/-xd1D29KoVps/Tck9zqQukpI/AAAAAAAAAb0/MEpcNUBogVE/s1600/menu.JPG"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5605079168966365842" src="https://4.bp.blogspot.com/-xd1D29KoVps/Tck9zqQukpI/AAAAAAAAAb0/MEpcNUBogVE/s400/menu.JPG" style="cursor: pointer; display: block; height: 198px; margin: 0px auto 10px; text-align: center; width: 357px;" /></a><br />
<span color="rgb(102 , 0 , 204)" style="font-weight: bold;">Operation as Data-Logger:</span><br />
<ul>
<li>Connect the power cable and power on the circuit</li>
<li>Green LED will glow</li>
<li>Whenever the data-logging is required, press the push-button</li>
<li>Red LED will glow, indicating that the recording has started</li>
<li>To stop recording, press the push-button again, recording will stop and red LED will turn off</li>
<li>Files stored in the card can be read using a PC card-reader or using hyper-terminal with the circuit started in debugging mode</li>
</ul><p>
<br />
The operation is very simple as it uses just one push-button and an LED indication. In case of any error in accessing the card, red LED will blink continuously. In such a case, you can start circuit in debug mode (with terminal) and see the error messages.<br />
<br />
Files are stored with the date as a name and .CSV extension. For example, data-logging done on 10 May 2011 would be stored in "10052011.CSV" file. Since the date is the name of file, everyday a single file is created and all the data recording done in a day goes into single file, no matter how many times the recording is stopped/started. First column of the file shows date, second shows time and next 8 columns show data from the 8 channels.<br />
<br />
A file created during testing is shown in the figure below, where 5 sec interval was set for measurements (click on the image to enlarge it). Here channel-0 was used for LM35 temperature sensor, and remaining channels measure voltage. 5v was connected to channel-1 and 3v Li cell was connected to channel-3 (Channel 2 & 4 show some small voltages due to noise from voltages connected to nearby channels, which can be corrected by using bypass caps).<br />
<br />
<a href="http://2.bp.blogspot.com/-l9JKUVyDmMo/TclFJoxMGuI/AAAAAAAAAb8/8CSYpK02UI0/s1600/excel-sheet.JPG"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5605087243104164578" src="https://2.bp.blogspot.com/-l9JKUVyDmMo/TclFJoxMGuI/AAAAAAAAAb8/8CSYpK02UI0/s400/excel-sheet.JPG" style="cursor: pointer; display: block; height: 400px; margin: 0px auto 10px; text-align: center; width: 383px;" /></a><br />
The interval between two measurement cycles is defined in main.c file, which can be set as per the user requirement. Basically, the program forms a dataString in every measurement cycle and appends this string to the file, if the file already exists or it creates a new file (for example, during the first recording in a day). You may go through the comments in the source code file for more info.<br />
<br />
Note: Make sure that RTC circuit is properly connected, otherwise the code will simply hang waiting for receiving date & time from RTC</p><p><u><b>New Version</b></u>: Check out my <b><a href="https://www.dharmanitech.com/2018/07/uart-based-8-channel-data-logger-with.html">this post for updated version</a></b> of this project with 16x2 LCD and DS1621 temperature sensor. Project Code with FatFs library is also shared there.<br />
<br />
<span style="font-weight: bold;">Download project files</span><br />
--------------------------------------<br />
The source code is written in AVR-GCC format using winAVR with AVRStudio-4, complete AVRStudio project folder can be downloaded from here:<br />
<br />
- <a href="https://drive.google.com/file/d/0B53C_HLwEgi-dDd0TkNpTkJtZzA/view?usp=sharing&resourcekey=0-9m2fGJ_7FF5OCE-KsnnVMw"><span style="font-weight: bold;">Download Source Code</span></a><br />
<br />
Download schematic:<br />
- <a href="https://drive.google.com/file/d/0B53C_HLwEgi-UHZWbzZCb0M0RlU/view?usp=sharing&resourcekey=0-tbNMzZDKhnohYn7cea7f6g">Schematic (PDF)</a><br />
- <a href="https://drive.google.com/file/d/0B53C_HLwEgi-ZW11WXludHVjcGs/view?usp=sharing&resourcekey=0-q1MODDeqZtmH1Sv2X_xoIg">Schematic (EAGLE)</a><br />
<br />
<span style="font-weight: bold;">References:</span><br />
--------------<br />
Visit my <a href="http://www.dharmanitech.com/2009/01/sd-card-interfacing-with-atmega8-fat32.html">earlier post </a>for the references on SD card & FAT32 which are given at the end of the post</p>CC Dharmanihttp://www.blogger.com/profile/13217855743473839524noreply@blogger.com320tag:blogger.com,1999:blog-8014888555955763990.post-64509714618736016472010-12-08T11:28:00.001+05:302021-09-26T14:56:45.341+05:30microSD FAT32 testing using Visual C++<a href="http://1.bp.blogspot.com/_zqABT3suzXE/TQze-z0rWoI/AAAAAAAAAZ8/Zqn7xKq1C8Q/s1600/2.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5552057611285387906" src="https://1.bp.blogspot.com/_zqABT3suzXE/TQze-z0rWoI/AAAAAAAAAZ8/Zqn7xKq1C8Q/s400/2.JPG" style="cursor: pointer; display: block; height: 250px; margin: 0px auto 10px; text-align: center; width: 400px;" /></a><br />
Hi friends,<br />
<br />
this post presents a way for testing and learning the FAT32 system on microSD/ SDHC cards without building the hardware with microcontroller, thanks to <span style="font-weight: bold;">Henry Yiu</span>.<br />
<br />
This project uses the FAT32 library available in my <a href="http://www.dharmanitech.com/2009/01/sd-card-interfacing-with-atmega8-fat32.html">previous post</a>, but does away with the microcontroller part. So, you can use this code with a PC and USB card reader and get insight of the FAT32 data structure by accessing data from the card in raw as well as in FAT format.<br />
<br />
This code can be used as a confidence building step for those who are not comfortable with directly building the hardware part. Once the FAT is understood, one can go ahead with development of hardware and customization of the software.<br />
<br />
This may look like hardcore software thing, but it's not so. It can be tested by anybody with little knowledge of programming and determination to understand the FAT / sd card formats.<br />
<br />
Step by step procedure for testing of the code is explained later.<br />
<br />
<span color="rgb(0 , 0 , 153)" style="font-weight: bold;">Here are the Henry's words for the project:</span><br />
-----------------------------------------------------------------------<br />
When trying to build a microcontroller to access an SD card, I came across this web site which details the hardware and software of how to use an Atmel AVR microcontroller to access an SD card. But I wanted to test out the FAT32 file system code before actually building the hardware. Therefore, I wrote this code to run on Visual C++ to enable me to test the FAT32 code without actually building the hardware.<br />
<br />
Tracing the code can reveal many compatibility problems between how the official FAT32 documentation and how Microsoft Windows actually implement the FAT32 system. There are a few interesting things I found for Windows XP. Maybe you can find more using various trace methods and many different brands of SD cards.<br />
<br />
The things I found are, for example:<br />
<br />
1. After adding or deleting files in Windows XP, the FSinfo next free cluster upper 16-bit is always zero.<br />
2. Adding new files in Windows XP updates the directory structure, but does not set the next entry to empty.<br />
3. Deleting files in Windows XP does not set the FSinfo structure next free cluster to a lower numbered cluster of the deleted file.<br />
<br />
Recommended software:<br />
---------------------------------------------------------------------------------<br />
<span style="font-size: small;"><span style="font-family: inherit;"><span style="font-family: "georgia" , "times new roman" , serif;"><span color="rgb(51 , 51 , 255)"><i>Microsoft Visual C++ Expres</i>s</span>: Not available anymore, but it has been replaced with<span style="font-size: x-small;"><span style="font-family: "times" , "times new roman" , serif;"> <span style="font-size: small;"><span style="font-family: Georgia, "Times New Roman", serif;"><span style="background-color: white; color: #222222; display: inline; float: none; font-style: normal; font-weight: 400; letter-spacing: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><a href="https://visualstudio.microsoft.com/vs/community/">Visual Studio Community Edition</a>. (For comparison details with Visual Studio Express,please visit <a href="https://spreadsheeto.com/visual-studio-community/">this spreadsheet</a>).</span></span></span></span></span></span></span></span><br />
<span style="font-family: "georgia" , "times new roman" , serif;"><span style="background-color: white; color: #222222; display: inline; float: none; font-size: x-small; font-style: normal; font-weight: 400; letter-spacing: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><br /></span></span>
<span style="font-family: "georgia" , "times new roman" , serif;"><a href="http://mh-nexus.de/en/hxd/" style="color: #3333ff;">HxD Hex Editor and Disk Editor</a></span><br />
<span style="font-family: "georgia" , "times new roman" , serif;"><a href="http://support.microsoft.com/kb/311272" style="color: #3333ff;">The DevCon command-line utility functions</a></span><br />
<br />
How to use: Only five files:<br />
MAIN.CC, SDCARD.CC, FAT32.CC, FAT32.H, GLOBAL.H.<br />
<br />
Use Microsoft Visual C++ Express to build these files with the default built option. Then you can step through the program to learn the boot record structure, the FAT table, and how clusters are linked together. You can also use HxD Hex Editor (Extras -> Open Physical Disk) to study the SD card content. Since data is cached in Windows, you need to unplug and plug the USB card reader for write or delete command to be visible in Windows. The DevCon utility allows you to do so without the need to actually do a hardware plug and unplug. Then you can test the FAT32 system using a batch file.<br />
<br />
Enjoy<br />
BR - Henry Yiu<br />
<br />
You can download the complete project folder from here:<br />
<a href="https://drive.google.com/file/d/1PR-GVVNbjnX7YJzMJhcWtlUueOQqtvn7/view?usp=sharing" style="color: #3333ff; font-weight: bold;">microSD-FAT32 with Visual C++ </a><br />
<br />
Many thanks to Henry for allowing to share his work<br />
<br />
<span color="rgb(0 , 0 , 153)" style="font-weight: bold;">Here is the step-by-step procedure of how to use the code:</span><br />
----------------------------------------------------------------------------------------<br />
(well, this assumes that you have already done some basic background study on FAT32 and microSD cards, may be by reading a few articles on them, since some theoretical knowledge would really help in making sense of the results you get)<br />
<br />
(the folder which you download already contains the .exe file, but we'll assume that it is not there, to make the procedure complete)<br />
<br />
1. Install and open VC++ express<br />
<br />
2. Create a new project (select 'empty project' when asked). Enter the location and project-name. Here we'll select project-name as 'sdcard', and location as desktop<br />
<br />
3. Project window will open. Now, go back to desktop and copy the 5 files (MAIN.CC, SDCARD.CC, FAT32.CC, FAT32.H, GLOBAL.H) from the downloaded folder, into the folder created by the VC++<br />
<br />
4. Go back to VC++ window and add the header files and source files into respective categories displayed at left side window panel. The panel will now look like this (here main file is open):<br />
<br />
<a href="http://3.bp.blogspot.com/_zqABT3suzXE/TP9iYtmDjGI/AAAAAAAAAZE/l_Sg1DFCLCI/s1600/1.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5548261442639334498" src="https://3.bp.blogspot.com/_zqABT3suzXE/TP9iYtmDjGI/AAAAAAAAAZE/l_Sg1DFCLCI/s400/1.JPG" style="cursor: pointer; display: block; height: 271px; margin: 0px auto 10px; text-align: center; width: 435px;" /></a><br />
5. Now, from the top menu-line, under 'debug', select 'build solution'. This will build the project files. The build window at the bottom of the page is shown in this figure:<br />
<br />
<a href="http://3.bp.blogspot.com/_zqABT3suzXE/TP9jSp6r7WI/AAAAAAAAAZM/KmYw9Vhupys/s1600/2.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5548262438084537698" src="https://3.bp.blogspot.com/_zqABT3suzXE/TP9jSp6r7WI/AAAAAAAAAZM/KmYw9Vhupys/s400/2.JPG" style="cursor: pointer; display: block; height: 263px; margin: 0px auto 10px; text-align: center; width: 422px;" /></a><br />
6. Now, select 'start debugging' under the same 'debug' menu. This is to make sure that the .exe file is generated. Okay, now you are ready with the .exe file. It will be stored in the 'debug' folder inside the project directory. In our case directory is 'sdcard' on the desktop.<br />
<br />
7. It's time to test the .exe file. So, connect the USB card reader, insert a microSD card (make sure the card is already formatted with FAT32, you can also store some files for checking the read feature of the code)<br />
<br />
8. Open windows command prompt. In the command prompt, go to the project directory, 'debug' folder. Now, type 'sdcard' or 'sdcard.exe'. This will display the available options. This is described in this figure:<br />
<br />
<a href="http://2.bp.blogspot.com/_zqABT3suzXE/TP9lxlZSapI/AAAAAAAAAZU/TFNGtB0hkn0/s1600/3.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5548265168469912210" src="https://2.bp.blogspot.com/_zqABT3suzXE/TP9lxlZSapI/AAAAAAAAAZU/TFNGtB0hkn0/s400/3.JPG" style="cursor: pointer; display: block; height: 219px; margin: 0px auto 10px; text-align: center; width: 429px;" /></a>9. Using the command shown in the above figure, you can select 'read', 'write', 'delete' etc. options, as per the command format. After every command executed, it would display 'success!'. If any error, it would display an error message. Some of the file operations are shown here:<br />
<br />
<a href="http://2.bp.blogspot.com/_zqABT3suzXE/TP9ni0FRwYI/AAAAAAAAAZc/9Z_aSEBysYA/s1600/4.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5548267113737732482" src="https://2.bp.blogspot.com/_zqABT3suzXE/TP9ni0FRwYI/AAAAAAAAAZc/9Z_aSEBysYA/s400/4.JPG" style="cursor: pointer; display: block; height: 250px; margin: 0px auto 10px; text-align: center; width: 422px;" /></a><br />
10. Once you have performed some operations in last step by creating, deleting files, you need to remove the card and re-insert for checking out the files. (The re-inserting thing is not required if you use the DevCon utility as suggested by Henry). The files which are created will contain random data, as this code is mainly to understand FAT. What is important is that windows should not display that the file is corrupt. This figure shows the results of operations we did in the last step, by opening the card in windows after re-insert:<br />
<br />
<a href="http://2.bp.blogspot.com/_zqABT3suzXE/TP9n0259pnI/AAAAAAAAAZk/VuRdFXhuLgM/s1600/5.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5548267423733229170" src="https://2.bp.blogspot.com/_zqABT3suzXE/TP9n0259pnI/AAAAAAAAAZk/VuRdFXhuLgM/s400/5.JPG" style="cursor: pointer; display: block; height: 257px; margin: 0px auto 10px; text-align: center; width: 415px;" /></a><br />
11. Now, the next step is to see how to use the HxD Hex Editor to understand what we did in the previous steps: Install and open the HxD. From the top menu-line, under 'extras', select 'open disk', select the drive letter of the card and press OK, or select 'physical disks' & then 'removable disk1'. This will open the card memory area, starting with the first sector of the card. Here in the first sector, you can see how the boot sector or MBR (master boot record) of your card looks like.<br />
<br />
12. Using the 'find' menu, search for the text string, the name of any file stored in the card. This will take you to the FAT (File Allocation Table) area of the card. (you need to use 'search' option, as sometimes the FAT sector will be located far away and you'll be tired of scrolling down. Alternatively, using the boot-sector data, you can manually calculate the FAT's starting sector number and directly go there by entering the sector number in the box at upper right corner). Here you can see how files are arranged in FAT, by their names, starting cluster numbers etc. Following figure shows the occupied part of FAT and shows location of 'newfile.txt', which we created in step 9.<br />
<br />
<a href="http://4.bp.blogspot.com/_zqABT3suzXE/TP9s5vysnUI/AAAAAAAAAZs/QCh5DwvfK4A/s1600/6.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5548273005281189186" src="https://4.bp.blogspot.com/_zqABT3suzXE/TP9s5vysnUI/AAAAAAAAAZs/QCh5DwvfK4A/s400/6.JPG" style="cursor: pointer; display: block; height: 249px; margin: 0px auto 10px; text-align: center; width: 428px;" /></a><br />
This is really useful in understanding the effects of creation, deletion of files on FAT table & FSinfo sector, to gain a real insight of the FAT32. And this understanding helps a lot while debugging your code when you make the actual hardware.<br />
<br />
It also helps understanding the differences in file handling by the microcontroller FAT32 code and the windows, as you can check the card data in HxD after using either of them. It'll help in debugging by bridging in the troublesome differences.<br />
<br />
Here are the additional testing suggestions by Henry:<br />
------------------------------------------------------------------------<br />
<div>
In order to start debugging, you will need to enter command lines. You can either change the #if1 to #if0 in main(), or use the Visual C++ command argument input: In Visual C++, select the "Project", then "SDCard Properties", then select "Debugging", and then "Command Argunments", then enter the command. For example:" -w2 e: test1.txt". </div>
<div>
<br />
To trace the detail of the FAT32 system, you would go to the end of the getBootSectorData() function and select "Run to Cursor". Then you would record these two important sector numbers:<br />
<br /></div>
<div>
unusedSectors + reservedSectorCount = starting sector of the FAT table</div>
<div>
firstDataSector = starting sector of the data area</div>
<div>
<br />
Now you can open the HxD hex editor to see how these two sectors and how they are being changed by the program once you start stepping through the program. You can press F10 to single step, or F11 to step into a function, or right click on a line and set a breakpoint, then press F5 to run to the breakpoint. You need to press F5 in HxD hex editor to refresh the display in order to see any changes the program made to the SD card. </div>
<div>
<br />
Once you have master this procedure, you can try doing file transfer between Windows XP and the program, for example, writing a file in Windows XP and reading it back by the program etc. You can also use HxD hex editior to view how Windows XP changes the card when it create or delete files on the card.</div>
<div>
<br />
<br /></div>
Enjoy the testing, It's really a fun!!!CC Dharmanihttp://www.blogger.com/profile/13217855743473839524noreply@blogger.com303tag:blogger.com,1999:blog-8014888555955763990.post-63611218850963510872009-01-31T16:26:00.004+05:302021-10-03T03:05:34.681+05:30SD/SDHC Card Interfacing with ATmega8 /32 (FAT32 implementation)<a href="http://3.bp.blogspot.com/_zqABT3suzXE/SYQxS83ZYfI/AAAAAAAAAPk/GAVn6wavCGQ/s1600-h/SD_setup.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5297413263340429810" src="https://3.bp.blogspot.com/_zqABT3suzXE/SYQxS83ZYfI/AAAAAAAAAPk/GAVn6wavCGQ/s320/SD_setup.JPG" style="cursor: pointer; display: block; height: 262px; margin: 0px auto 10px; text-align: center; width: 433px;" /></a><br />
Hi friends,<br />
Here is my project on interfacing of SD Card (microSD). microSD cards are available very cheap nowadays, a great option for having a huge memory in any embedded system project. It is compatible with SPI bus, so the interfacing is easy. SD card adapters are also easily available in market, one can easily make a bread-board adapter by soldering few pins on it. Following figures show the SD card pin-out & the bread-board adapter design by soldering 7-pins of a breakout header on the microSD adapter (Click on images for larger view).<br />
<br />
<a href="http://3.bp.blogspot.com/_zqABT3suzXE/SYQyx7EZHAI/AAAAAAAAAPs/EcS3c3YhBTQ/s1600-h/SD_adapter1.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5297414894945639426" src="https://3.bp.blogspot.com/_zqABT3suzXE/SYQyx7EZHAI/AAAAAAAAAPs/EcS3c3YhBTQ/s200/SD_adapter1.JPG" style="cursor: pointer; float: left; height: 155px; margin: 0pt 10px 10px 0pt; width: 194px;" /></a><a href="http://1.bp.blogspot.com/_zqABT3suzXE/SYQzBqyMTJI/AAAAAAAAAP0/37qlijBjp1Y/s1600-h/SD_adapter2.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5297415165452242066" src="https://1.bp.blogspot.com/_zqABT3suzXE/SYQzBqyMTJI/AAAAAAAAAP0/37qlijBjp1Y/s200/SD_adapter2.JPG" style="cursor: pointer; float: left; height: 157px; margin: 0pt 10px 10px 0pt; width: 169px;" /></a><a href="http://3.bp.blogspot.com/_zqABT3suzXE/SYQzKx0xOKI/AAAAAAAAAP8/c9PvJ0xIrYw/s1600-h/SD_pinout.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5297415321960921250" src="https://3.bp.blogspot.com/_zqABT3suzXE/SYQzKx0xOKI/AAAAAAAAAP8/c9PvJ0xIrYw/s200/SD_pinout.JPG" style="cursor: pointer; float: left; height: 172px; margin: 0pt 10px 10px 0pt; width: 168px;" /></a><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
I had started this project with 1GB microSD card from SanDisk (later on tested with transcend cards also). The microcontroller is AVR ATmega8 or ATmega32 running at <span style="color: #cc0000;">8Mhz</span> internal clock. MAX232 is used to interface the circuit with PC for monitoring the data. A 3.3v supply is used for powering the mega8, microSD and max232 (though the specified supply for max232 is 5v, it works comfortably at 3.3v).7 pins of the microSD are used here, shown in the figure of pin-out.<br />
<br />
Schematic for ATmega8 is shown here (<span style="color: red;">updated on 10 May 2010</span>, SD series resistors are removed, as they were limiting the speed of SPI bus. 51k pullups are added on CMD/DAT lines. This gives better stability with different cards. Also, two 3.6v zeners are added to protect SD in case when the ISP programmer voltage levels are of 5v. these diodes are not required if your programmer has settings for 3.3v output)<br />
<span style="font-size: 85%;">(Note: VCC & GND pins of MAX232 are not shown in the schematic, but they must be connected in the actual hardware)</span><a href="http://2.bp.blogspot.com/_zqABT3suzXE/S-d-qSljX4I/AAAAAAAAAWA/_FbQEDRj32k/s1600/Sd_M8_Sch.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5469479537473707906" src="https://2.bp.blogspot.com/_zqABT3suzXE/S-d-qSljX4I/AAAAAAAAAWA/_FbQEDRj32k/s400/Sd_M8_Sch.JPG" style="cursor: pointer; display: block; height: 285px; margin: 0px auto 10px; text-align: center; width: 445px;" /></a><br />
Following is the schematic for ATmega32, without RTC (updated on <span style="color: red;">10 May 2010</span>):<br />
<br />
<a href="http://3.bp.blogspot.com/_zqABT3suzXE/S_EhXQS-NSI/AAAAAAAAAWQ/x5kRQ3OsCoU/s1600/SD_M32.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5472191705627112738" src="https://3.bp.blogspot.com/_zqABT3suzXE/S_EhXQS-NSI/AAAAAAAAAWQ/x5kRQ3OsCoU/s400/SD_M32.JPG" style="cursor: pointer; display: block; height: 359px; margin: 0px auto 10px; text-align: center; width: 415px;" /></a><span style="color: black;"><br />Following is the schematic for ATmega32, with RTC (added on </span><span style="color: red;">17 May 2010</span><span style="color: black;">; CS pin correction, PB4 instead of PB1, done in <span style="color: red;">Mar 2014</span>)</span>. Here two supply voltages are used, 3.3v for SD & 5v for remaining ICs.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-RofE5TLbFhA/UyfW68emLoI/AAAAAAAAAkA/k4PGjiNHZD4/s1600/SD_M32_RTC.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="281" src="https://4.bp.blogspot.com/-RofE5TLbFhA/UyfW68emLoI/AAAAAAAAAkA/k4PGjiNHZD4/s1600/SD_M32_RTC.png" width="400" /></a></div><p>
<br />
<br />
The aim of this project was to learn interfacing of SD card and to understand the data transfer in raw format as well as in FAT32 format. I started with raw data transfer, sending some data to any block of the microSD, reading a block of it, reading and writing multiple blocks, erasing multiple blocks. All this in raw format. I used RS232 for viewing the data read by microcontroller from SD card. The uc sends the data to HyperTerminal. Similarly, to write data to card, the data was fed thru HyperTerminal, by typing some text.<br />
<br />
Once raw data transfer achieved, I formatted the card with windowsXP (FAT32) and loaded it with some text files, directories and other files (all stored in root directory of the card). After that I wrote the FAT32 routines to read files, get file list (using HyperTerminal again), finding the total/free memory of card. All this data is sent to HyperTerminal by the uc.<br />
<br />
Following is the HyperTerminal window showing different options:<a href="http://3.bp.blogspot.com/_zqABT3suzXE/Sa1oOv3FtVI/AAAAAAAAARU/-A4enDBeY-g/s1600-h/main+menu.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5309014138314667346" src="https://3.bp.blogspot.com/_zqABT3suzXE/Sa1oOv3FtVI/AAAAAAAAARU/-A4enDBeY-g/s320/main+menu.JPG" style="cursor: pointer; float: left; height: 218px; margin: 0pt 10px 10px 0pt; width: 218px;" /></a><br />
Options 0 to 4 are low level functions dealing with raw data. If you use option 0, 1 or 3, you may have to reformat the card before using the FAT32 routines.<br />
0: Erases selected number of blocks strating from selected block<br />
1: Writes data to specified SD block address. Data to be entered in HyperTerminal using PC keyboard<br />
2: Readss data of specified SD block address. Data is displayed on HyperTerminal window<br />
3. Writes selected number of blocks strating from selected block<br />
4. Reads selected number of blocks strating from selected block<br />
<br />
Here, the multiple-block functions related to options 3 & 4 are disabled due to memory constraint as that time mega8 was used for testing and these functions are not required for FAT32 testing. While testing with mega32, options 3 & 4 can be enabled by removing a macro (#define FAT_TESTING_ONLY) defined in SD_routines.h.<br />
<br />
Options 5 to 9 are related to FAT32 . Only short file names are supported right now, 8byte name+3bytes extension. If you store a long name file in SD, it will be displayed by these routines in short name format only.<br />
For testing these options, format the card with FAT32 file system and store some directories and text files (because text files can be read & checked thru HyperTerminal).<br />
<br />
5: Displays list of available directories and files with size (in the root directory of the card)<br />
6: Reads a specified file and displays the file contents on HyperTerminal<br />
7: Create/Append file with specified name, enter text from HyperTerminal<br />
8: Deletes any existing file with specified name<br />
9: Displays total & free memory of the card (using FSinfo sector of the SD card)<br />
<br />
Following figures show the HyperTerminal window when options 5 & 9 are selected:<br />
<span style="color: #009900;">(</span><span style="color: #009900;">These figures show menu from Ver2.3 or earlier. Menu style is changed from Ver_2.4 onwards, which is shown in the update history</span><span style="color: #009900;">)</span><br />
<br />
<a href="http://2.bp.blogspot.com/_zqABT3suzXE/Sa1o-E76NnI/AAAAAAAAARk/llBKemYY9WI/s1600-h/file+list.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5309014951425881714" src="https://2.bp.blogspot.com/_zqABT3suzXE/Sa1o-E76NnI/AAAAAAAAARk/llBKemYY9WI/s320/file+list.JPG" style="cursor: pointer; float: left; height: 317px; margin: 0pt 10px 10px 0pt; width: 219px;" /></a><a href="http://3.bp.blogspot.com/_zqABT3suzXE/Sa1orywQ8hI/AAAAAAAAARc/VWDai3qGrE0/s1600-h/memory.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5309014637307556370" src="https://3.bp.blogspot.com/_zqABT3suzXE/Sa1orywQ8hI/AAAAAAAAARc/VWDai3qGrE0/s320/memory.JPG" style="cursor: pointer; float: left; height: 257px; margin: 0pt 10px 10px 0pt; width: 230px;" /></a><span style="font-weight: bold;">Note</span>: HyperTerminal is used here at 19200 baudrate, No parity, Flow Control 'none'.<br />
<br />
This project needs very few components and can be done easily at home. Try it out!<br />
<br />
<span style="font-weight: bold;"><span style="color: #000099; font-family: "verdana"; font-size: 100%;"><span style="color: black;"><u><br /></u></span></span></span>
<span style="font-weight: bold;"><span style="color: #000099; font-family: "verdana"; font-size: 100%;"><span style="color: black;"><u><br /></u></span></span></span>
<span style="font-weight: bold;"><span style="color: #000099; font-family: "verdana"; font-size: 100%;"><span style="color: black;"><u><br /></u></span></span></span>
<span style="font-weight: bold;"><span style="color: #000099; font-family: "verdana"; font-size: 100%;"><span style="color: black;"><u><br /></u></span></span></span>
<span style="font-weight: bold;"><span style="color: #000099; font-family: "verdana"; font-size: 100%;"><span style="color: black;"><u><br /></u></span></span></span>
<span style="font-weight: bold;"><span style="color: #000099; font-family: "verdana"; font-size: 100%;"><span style="color: black;"><u><br /></u></span></span></span>
<span style="font-weight: bold;"><span style="color: #000099; font-family: "verdana"; font-size: 100%;"><span style="color: black;"><u><br /></u></span></span></span>
<span style="font-weight: bold;"><span style="color: #000099; font-family: "verdana"; font-size: 100%;"><span style="color: black;"><u><br /></u></span></span></span>
<span style="font-weight: bold;"><span style="color: #000099; font-family: "verdana"; font-size: 100%;"><span style="color: black;"><u><br /></u></span></span></span><br />
<span style="font-weight: bold;"><span style="color: #000099; font-family: "verdana"; font-size: 100%;"><span style="color: black;"><u>Download the source code files from here</u></span>:</span></span>Download here the zipped source code files modified for mega32, written in winAVR-AVRStudio.<br />
<br />
<a href="https://drive.google.com/file/d/0B53C_HLwEgi-LUJPRGRYeFVSaHM/view?usp=sharing&resourcekey=0-Kq9Guj1yst3HirI8o5hvDg" style="color: #000099; font-weight: bold;">Version 2.4.1 (RTC added for Date/Time entries)</a><a href="http://sites.google.com/a/dharmanitech.com/sd-mega32-code-v2-0/Home/SD_GCC_V2.4_M32.zip?attredirects=0&d=1"> </a><span style="font-size: 85%;"><span style="color: red;">17 May 2010/24 Apr 2011</span></span><br />
<a href="https://drive.google.com/file/d/0B53C_HLwEgi-X1hMUlBEUjQ3bFU/view?usp=sharing&resourcekey=0-WFmJgMn4_kADJfPWracd6A" style="color: #000099; font-weight: bold;">Version 2.3 (SDHC support added)</a><span style="color: red; font-weight: bold;"> </span><span style="font-size: 85%;"><span style="color: red;"> 09 May 2010</span></span><br />
<a href="https://drive.google.com/file/d/0B53C_HLwEgi-NnZjalpIV280UlU/view?usp=sharing&resourcekey=0-WaRaTyVIR9qvS9mtVilkjA" style="color: #000099;"><span style="font-weight: bold;">Version 2.2 (No SDHC support)</span></a><span style="color: red;"> <span style="font-size: 85%;">13 Sep 2009<br /><br /><a href="https://drive.google.com/file/d/0B53C_HLwEgi-bF9FY3dZU3FlYVk/view?usp=sharing&resourcekey=0-vB5HBcY_VLqMsU_9zPHecw"><span style="font-size: 130%;"><span style="color: #000099;">Download EAGLE schematic file of Ver 2.4</span></span></a></span></span><span style="font-weight: bold;"><br /></span><span style="color: black; font-weight: bold;">Download/view source code fil</span><span style="color: black; font-weight: bold;">es V2.1 (for ATmega8)</span><span style="color: black;">:</span><br />
Following files are compiled using winAVR inside AVRStudio. This Version does not support SDHC cards. Also, append file feature is not available.<br />
1.<a href="https://docs.google.com/document/d/18g5-uvt75mOEwnBwiY_jnX0OChjnuXa3OtBztihy7yw/edit" style="font-weight: bold;"> SD_main.c</a><br />
2.<a href="https://docs.google.com/document/d/14M2dh1HMOWoM1fYxKaHZ4FA0ScJzKkWa108AVEOUQhQ/edit" style="font-weight: bold;"> SD_routines.c & SD_routines.h</a><br />
3.<a href="https://docs.google.com/document/d/1H1E11TbyQmhieVqbiPGrxl3pzJdJaCqLHhCVUMGMxBQ/edit" style="font-weight: bold;"> FAT32.c & FAT32.h</a> (Ver 2.1, last updated-<span style="color: red;">13 Sep 09</span>)<br />
4. <a href="https://docs.google.com/document/d/1758kN2EqKHl0Rco2oaetdHPnHi3qwjGbGiD2afPxsLQ/edit" style="font-weight: bold;">SPI_routines.c & SPI_routines.h</a><br />
5. <a href="https://docs.google.com/document/d/1758kN2EqKHl0Rco2oaetdHPnHi3qwjGbGiD2afPxsLQ/edit" style="font-weight: bold;">UART_routines.c & UART_routines.h</a><br />
6. <a href="https://docs.google.com/document/d/1X5NrZ8LERyfsYox0EDs6fjWeIth3PU0xhtfSo1GJMBo/edit" style="font-weight: bold;">Makefile</a><br />
7. <a href="https://docs.google.com/document/d/1Ng-LHb86xZ_oztv821WtR0qN4SyzfUX2m7mO0LmGUc8/edit" style="font-weight: bold;">HEX file</a><span style="font-weight: bold;"> </span>(<span style="color: black;">Ver 2.1, </span> last updated-<span style="color: red;">13 Sep 09</span>)<br />
<br />
Please put up a comment or mail me if you find a bug in the code. The updates are because of valuable suggestions & comments from the users of this code. Thanks a lot!!<br />
<br />
This library has been updated by ExploreEmbedded to support lpc2148, lpc1114, lpc1768 controllers (in addition to ATmega devices). Please visit this page for more details:<br />
<b><a href="https://www.exploreembedded.com/wiki/LPC1768:_SD_Card_Interface">https://www.exploreembedded.com/wiki/LPC1768:_SD_Card_Interface</a></b><br />
<br />
Buy from Farnell (Element14): <a href="http://in.element14.com/atmel" target="_blank"><b>ATmega32</b></a> (India), <b><a href="http://www.newark.com/atmel" target="_blank">ATmega32</a></b> (USA)<br />
<br />
<br />
<span style="font-weight: bold;">Related posts:</span><br /></p><ul style="text-align: left;"><li>
You can visit my post of <a href="https://www.dharmanitech.com/2018/07/uart-based-8-channel-data-logger-with.html" style="color: #3333ff;">microSD ATmega32 Data-Logger</a>, with LCD and temperature sensor, which uses modified FAT32 (or FatFs) library for automatically creating files without using hyper terminal.</li><li>
If you want to test FAT32 functions or learn more without making the microcontroller hardware, you can visit my post here: <a href="http://www.dharmanitech.com/2010/12/microsd-fat32-testing-using-visual-c.html" style="color: #3333ff;">microSD-FAT32 using Visual C++</a>)</li></ul><p>
<br />
<span style="font-weight: bold;">Update History</span>-----------------------------------------------------------------------------<span style="font-weight: bold;"><br />Version 2.4:</span><a href="http://1.bp.blogspot.com/_zqABT3suzXE/S_EkpImNChI/AAAAAAAAAWw/KIqx-DaOm6I/s1600/with+RTC.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5472195311332821522" src="https://1.bp.blogspot.com/_zqABT3suzXE/S_EkpImNChI/AAAAAAAAAWw/KIqx-DaOm6I/s320/with+RTC.JPG" style="cursor: pointer; float: right; height: 164px; margin: 0pt 0pt 10px 10px; width: 222px;" /></a><br />
- Real Time Clock circuit support is added for time & date entries in the files. Now the current date of file creation and file update will be entered in the FAT table (can be viewed by checking file 'properties' using a PC)<br />
(The RTC will also be useful in data-logging with time-stamp)<br />
- Three more options added in the Hyper Terminal menu for displaying or updating RTC date & time. New menu is shown in the above figure.<br />
<br />
Ver 2.4.1:<br />
- Same as 2.4, with a bug fix for RTC: 'twi_init' function added to define I2C clock freq. 100K@ 16MHz (50k@8MHz). This was taking default values earlier, which was as high as 500K@8MHz, not desirable<br />
<br />
(Note: Version 2.2, 2.3 & 2.4 are tested on ATmega32, but they can be adopted to any controller having RAM >= 1KB and Flash >= 16KB)<br />
<span style="color: #000099;">Current memory usage (Ver_2.4):</span> Flash: <span style="color: #cc0000;">12908 Bytes</span>; RAM: <span style="color: #cc0000;">700 Bytes (appx.)</span>;<br />
<br />
<span style="font-weight: bold;">Version 2.3:</span><br />
- Support for <span style="font-weight: bold;">SDHC</span> cards added (tested with SanDisk & Transcend microSD and microSDHC cards). The initialization sequence and command formats are modified.<br />
- A bug which was causing the program flow to go into infinite loop if the character number 512 in a sector was a CR (Carriage Return, '\r'), in the writeFile function. Thanks to <span style="color: #009900;">David</span> & <span style="color: #009900;">Piotr M.</span> who pointed it out in the comments.<br />
- Code is also tested successfully at 16MHz clock (8MHz SPI clock) with for SD/SDHC cards.<br />
<br />
Follwing are the Hyper Terminal windows showing card detection (One window shows baudrate as 38400, that was while testing for higher clock speeds, current code still uses 19200 baud and 8MHz internal clock of Mega32).<br />
<br />
<a href="http://3.bp.blogspot.com/_zqABT3suzXE/S-bMf18bkQI/AAAAAAAAAVY/fs5wjWrsP5g/s1600/high+capacity.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5469283644916601090" src="https://3.bp.blogspot.com/_zqABT3suzXE/S-bMf18bkQI/AAAAAAAAAVY/fs5wjWrsP5g/s320/high+capacity.JPG" style="cursor: pointer; float: left; height: 164px; margin: 0pt 10px 10px 0pt; width: 226px;" /></a><a href="http://2.bp.blogspot.com/_zqABT3suzXE/S-bMOMXxJRI/AAAAAAAAAVQ/UBaxZxTFih8/s1600/std+capacity.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5469283341699196178" src="https://2.bp.blogspot.com/_zqABT3suzXE/S-bMOMXxJRI/AAAAAAAAAVQ/UBaxZxTFih8/s320/std+capacity.JPG" style="cursor: pointer; float: left; height: 160px; margin: 0pt 10px 10px 0pt; width: 219px;" /></a><br />
<br />
<br />
<span style="font-weight: bold;"><br /></span>
<span style="font-weight: bold;"><br /></span><br />
<span style="font-weight: bold;"><br /></span><span style="font-weight: bold;">Version 2.2:</span><br />
- Append file feature added. 'createFile' function replaced with writeFile, which looks for the filename first, if the given file name doesn't exist then it creates new file and writes data, but if the file already exists, then it opens it and appends the entered data.<br />
- A bug removed which was giving error related to use of 'LONG'<br />
- <avr h=""><avr h="">The FAT32.c & .h files are updated on </avr></avr><span style="color: red;">13 Sep 09</span><avr h=""><avr h=""> </avr></avr><span style="color: red;"><span style="color: black;">to remove a bug which </span></span><avr h=""><avr h="">was limiting file size to 32MB (Thanks to </avr></avr><span class="gI" style="color: #009900;"><span class="go">Kun-Szabo Marton</span></span> who pointed it out)<br />
<br />
<span style="color: red; font-weight: bold;">Data transfer rate</span>: 1 raw data block (512 bytes) takes 4.15ms for reading or writing (123.37 KBytes/s) at current 4 MHz SPI clock rate. If you have flash more than 8k, you can declare the SPI_receive() and SPI_transmit() functions as 'inline' functions. This will increase the transfer rate to 140 KBytes/s. These transfer rates can be further increased by using a 16MHz crystal (8 MHz SPI clock). FAT32 file reading is done at 78 to 91 KBytes/sec.<br />
<br />
<span style="font-weight: bold;">Version 2.1</span>:<br />
- A bug removed which stopped creating new files after 32*8 files in the root directory<br />
- The root directory was unnecessarily getting expanded by one cluster whenever a file was created. Fixed in the new version<br />
- Also, the fixed cluster size of 8 sectors is removed, this version will support other cluster sizes as well<br />
<br />
<span style="font-weight: bold;">Version 2.0:</span><br />
- Support added for SD cards having first sector as MBR rather than the boot sector<br />
- createFile and deleteFile functions added<br />
- A bug fixed in reading files stord at far locations in memory also correction made to accept 8+3 char file name (by mistake, it was taking 7+3 earlier)<br />
- FSinfo sector used for storing total free cluster count &<br />
next free cluster number for faster file access<br />
- Instant freeMemory display (earlier it was taking more than 30secs) using FSinfo sector. FSinfo sector is updated now whenever a file is created or deleted<br />
- File memory size display in decimal, like windows (earlier it was in hex)<br />
- Raw SD functions multiple block read and write, which are not required for FAT32, are disabled using FAT32_TESTING_ONLY macro for getting extra space required by createFile & deleteFile changes (you can activate it if you have more than 8k flash) Right now flash is 99.9% full<br />
- Clock speed raised from 1Mhz to 8 MHz, new SPI speed (after SD initialization): 4MHz instead of 500K & baudrate: 19200 (for HyperTerminal) instead of 4800<br />
-------------------------------------------------------------------------------<br />
<span style="font-weight: bold;"><br /></span><avr h=""><avr h=""></avr></avr><avr h=""><avr h=""></avr></avr><avr h=""><avr h=""><span style="font-weight: bold;">References/ Further Reading:</span><br />1. <a href="http://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-923143f3456c/fatgen103.doc" target="_blank">Microsoft's FAT32 specification document</a><br />2. <a href="https://www.sdcard.org/downloads/pls/index.html">SD-Simplified Physical Layer Specifications</a><br />4. <a href="http://www.cs.ucr.edu/~amitra/sdcard/Additional/sdcard_appnote_foust.pdf" target="_blank">F. Foust's Application Note on SD</a><br />5. <a href="http://home.teleport.com/~brainy/fat32.htm" target="_blank">FAT32 Structure info, includes MBR details</a><br />6. <a href="http://www.pjrc.com/tech/8051/ide/fat32.html" target="_blank">Simple FAT32 Structure explanation</a></avr></avr><avr h=""><avr h=""> </avr></avr><br />
<avr h=""><avr h="">7. <a href="http://elm-chan.org/fsw/ff/00index_e.html" target="_blank">Chan's FAT library</a></avr></avr><br />
<avr h=""><avr h="">8. <a href="https://www.sdcard.org/" target="_blank">SD Association's Website for further info </a><br /><br />Regards,</avr></avr><br />
<avr h=""><avr h="">CC Dharmani<br />ccd@dharmanitech.com</avr></avr></p>CC Dharmanihttp://www.blogger.com/profile/13217855743473839524noreply@blogger.com723tag:blogger.com,1999:blog-8014888555955763990.post-29438652330037215492009-01-09T18:00:00.001+05:302021-09-26T15:45:17.019+05:30IR Remote Controlled Car (PWM motor control using ATmega8)<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<a href="http://2.bp.blogspot.com/_zqABT3suzXE/SXDd_hCBTjI/AAAAAAAAAPE/ximVrniDyCY/s1600-h/IR_car2.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5291973645428674098" src="https://2.bp.blogspot.com/_zqABT3suzXE/SXDd_hCBTjI/AAAAAAAAAPE/ximVrniDyCY/s320/IR_car2.JPG" style="cursor: pointer; display: block; height: 328px; margin: 0px auto 10px; text-align: center; width: 441px;" /></a><br />
<a href="http://2.bp.blogspot.com/_zqABT3suzXE/SXDdzV6--FI/AAAAAAAAAO8/_cfqsbTkiTo/s1600-h/IR_car1.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5291973436287940690" src="https://2.bp.blogspot.com/_zqABT3suzXE/SXDdzV6--FI/AAAAAAAAAO8/_cfqsbTkiTo/s320/IR_car1.JPG" style="cursor: pointer; display: block; height: 336px; margin: 0px auto 10px; text-align: center; width: 450px;" /></a><br />
Hi Friends,<br />
in my last post of <a href="http://www.dharmanitech.com/2008/11/small-dc-motor-control-by-pwm-method.html">Simple DC motor Control</a>, I've discussed controlling a small DC motor using the PWM method with MOSFET H-bridge. The circuit was build with microcontroller ATmega8.<br />
Here, I'm extending the same circuit to control the DC motor with IR remote control. The motor is fitted on a toy car wheels with gears, as shown in the figure above.<br />
<br />
Following is the schematic (Click on the image to enlarge it):<br />
<br />
<a href="http://4.bp.blogspot.com/_zqABT3suzXE/SWdGRxwryhI/AAAAAAAAAO0/hNE8QgDCee8/s1600-h/IR+controlled+car.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5289273558599191058" src="https://4.bp.blogspot.com/_zqABT3suzXE/SWdGRxwryhI/AAAAAAAAAO0/hNE8QgDCee8/s320/IR+controlled+car.JPG" style="display: block; height: 230px; margin: 0px auto 10px; text-align: center; width: 405px;" /></a>The circuit uses two PWM channels of ATmega8 for controlling the speed and direction (reverse, forward) of the car, based on the command received from the IR remote. Here, a Sony TV remote was used. The IR codes were received by using TSOP1738 IR detector from Vishay. (Thanks a lot to Michael Spiceland from <a href="http://tinkerish.com/blog/">tinkerish.com</a>, for helping me out with the code for IR signal decoding!).<br />
<br />
Following buttons on the remote are used for control:<br />
'1' : Start motor<br />
Volume+ : Increase speed<br />
Volume-: Reduce speed<br />
Channel+: Forward direction<br />
Channel-: Reverse Direction<br />
'0': Stop motor<br />
<br />
Check out the video (the LED blinks whenevr a key on the remote is pressed. The remote is not visible in the video as I was holding the camera and remote both!!)<br />
<br />
<iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='335' height='278' src='https://www.blogger.com/video.g?token=AD6v5dzV-x-oSpCJB1ygfkzaDdgiD-xjmSN3F7AwljGT2UJcjINzIOMrrUTOwhK-RKSKUscXgBr_-pi5HQfB97UnMQ' class='b-hbp-video b-uploaded' frameborder='0'></iframe><br />
<br />
The coding is done with ICCAVR compiler. It can be easily adapted to other compilers with minor changes. Complete code is given here:<br />
<br />
<a href="http://docs.google.com/Doc?id=ddmkwx3z_24dh6npfg2" style="color: #000099; font-weight: bold;">View Code on Google Docs</a><br />
<a href="https://drive.google.com/file/d/0B53C_HLwEgi-a25JVDFSanBYb1k/view?usp=sharing&resourcekey=0-GrcKPa0L1SDQJHQYKt_0sQ" style="color: #000099; font-weight: bold;">Download source code files (zip)</a><br />
<br />
<br />
<b>Updated Design (done sometime in 2010, added here in 2018):</b><br />
-------------------------------------------------------------------------------------------------------<br />
As brought out by many in comments, above design is not power efficient, as it uses n-type MOSFETS in upper and lower, both the sides of the H-bridge. So here is the modified design of a <b>Three-wheeled dual DC motor robot (with speed, direction and turning controls),</b> using the popular L293D motor driver IC, which is very easy to control and size and power efficient, providing two full-bridge circuits in one IC, each having 1A capacity to drive a DC motor. <br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-ZLbnQNEpVeY/WyU1vPxiBeI/AAAAAAAAA2I/9pdFq3et0fgASsg_LZ6FO8kajbRk88UAQCLcBGAs/s1600/full.JPG" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="768" data-original-width="877" height="560" src="https://1.bp.blogspot.com/-ZLbnQNEpVeY/WyU1vPxiBeI/AAAAAAAAA2I/9pdFq3et0fgASsg_LZ6FO8kajbRk88UAQCLcBGAs/s640/full.JPG" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-HmlJURAKfKs/WyU1u-Os-sI/AAAAAAAAA2E/iyilijXHnHQr5N8uQC-Ok5r6rj8aIpCDgCLcBGAs/s1600/front.JPG" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="704" data-original-width="1024" height="275" src="https://1.bp.blogspot.com/-HmlJURAKfKs/WyU1u-Os-sI/AAAAAAAAA2E/iyilijXHnHQr5N8uQC-Ok5r6rj8aIpCDgCLcBGAs/s400/front.JPG" width="400" /></a></div>
<br />
Following is the circuit schematic:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://3.bp.blogspot.com/-yPz2P-3KtqQ/WyU5Rvx8UAI/AAAAAAAAA20/gpZX7A5xZm43Rw7piGKtPIx8QRkMwWmUgCLcBGAs/s1600/robotics_project.JPG" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="714" data-original-width="1027" height="441" src="https://3.bp.blogspot.com/-yPz2P-3KtqQ/WyU5Rvx8UAI/AAAAAAAAA20/gpZX7A5xZm43Rw7piGKtPIx8QRkMwWmUgCLcBGAs/s640/robotics_project.JPG" width="640" /></a></div>
<br />
<br />
This one is ATmega32 based, IR remote controlled (using TSOP1738 IR detector) with two optical detectors (MOC7811) provision to detect the robot speed. Two detectors can be used to implement a control algorithm, like PID, if required (here only one detector is used, just to display the speed). A slotted wheel is used, mounted on the motor shaft, to work with the optical detector. The wheel slots pass through the detector, generating pulses while robot is moving. The pulses are counted for speed detection.<br />
It has a 16x2 LCD with 4-bit interface to display the speed and current status of the robot (based on the IR input received). It has a reset button and two user buttons. There is also hardware provision for RS232 driver on-board, for adding any further functionality, like adding user configuration in EEPROM via serial port, without changing the code.<br />
The design runs on a 9-12V DC supply. A commonly available 9V higher density battery can be used while running the robot. When powered NO, the circuit waits in ready state (with Green LED ON) till the button1 is pressed, after which it starts accepting the IR remote commands, and acts as per the commands (with Red LED ON). Following pictures show some of the functional states. <br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://4.bp.blogspot.com/-VCJR92yzrdY/WyU1vKX8nJI/AAAAAAAAA2M/xKTTEoHE1YsuZDJG8kSnxOPGAaLktut9ACLcBGAs/s1600/green.JPG" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="768" data-original-width="830" height="592" src="https://4.bp.blogspot.com/-VCJR92yzrdY/WyU1vKX8nJI/AAAAAAAAA2M/xKTTEoHE1YsuZDJG8kSnxOPGAaLktut9ACLcBGAs/s640/green.JPG" width="640" /></a></div>
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-HmP8Te5kRMc/WyU1v-S_mfI/AAAAAAAAA2Q/NGJYQnScl-44xLXlvwYSwBMVPC4lx3fugCLcBGAs/s1600/red.JPG" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="804" data-original-width="768" height="640" src="https://1.bp.blogspot.com/-HmP8Te5kRMc/WyU1v-S_mfI/AAAAAAAAA2Q/NGJYQnScl-44xLXlvwYSwBMVPC4lx3fugCLcBGAs/s640/red.JPG" width="609" /></a></div>
<br />
Here are the IR remote commands used for robot control:<br />
<br />
Remote Button (IR code) - Robo Action <br />
---------------------------------------- ---------------<br />
<ul>
<li>START/STOP (21) Start/Stop</li>
<li>VOLUME+ (18) Increase Speed</li>
<li>VOLUME- (19) Decrease Speed</li>
<li>UP (116) Go Forward <i>(and stop any turn already in progress)</i></li>
<li>Down (117) Go Backward <i>(and stop any turn already in progress)</i></li>
<li>LEFT (52) Turn Left<i> (pressing again makes turn sharper and sharper) </i></li>
<li>RIGHT (51) Turn Right <i>(pressing again makes turn sharper and sharper)</i></li>
<li>CENTER (101) Pivot Turn <i>(both motor wheels in opp. directions)</i></li>
</ul>
<br />
Following are the optical encoder slotted disc, optical encoder and the IR Remote receiver:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-CS8R9S_GUdg/WyVJnVGu13I/AAAAAAAAA3M/JeJpqPPCz8w2HxdnSBbuP_qHZK6sIiK9ACLcBGAs/s1600/Encoder_Disc.jpg" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="300" data-original-width="300" height="200" src="https://1.bp.blogspot.com/-CS8R9S_GUdg/WyVJnVGu13I/AAAAAAAAA3M/JeJpqPPCz8w2HxdnSBbuP_qHZK6sIiK9ACLcBGAs/s200/Encoder_Disc.jpg" width="200" /></a> <a href="https://4.bp.blogspot.com/-nE51gNbjWLY/WyVJnh7zSiI/AAAAAAAAA3U/H-fQyiiGZMUbsKRZng3NFP_QdFy9CdWdgCLcBGAs/s1600/moc7811.JPG" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="299" data-original-width="516" height="184" src="https://4.bp.blogspot.com/-nE51gNbjWLY/WyVJnh7zSiI/AAAAAAAAA3U/H-fQyiiGZMUbsKRZng3NFP_QdFy9CdWdgCLcBGAs/s320/moc7811.JPG" width="320" /></a></div>
<a href="https://2.bp.blogspot.com/-1ZXIo_QeXRs/WyVJnuG-O5I/AAAAAAAAA3Q/Wsp112YRbY0gUqPfD-k6UfyE92vMW4iLACLcBGAs/s1600/TSOP1738.JPG" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="336" data-original-width="329" height="200" src="https://2.bp.blogspot.com/-1ZXIo_QeXRs/WyVJnuG-O5I/AAAAAAAAA3Q/Wsp112YRbY0gUqPfD-k6UfyE92vMW4iLACLcBGAs/s200/TSOP1738.JPG" width="195" /></a><br />
<br />
<br />
<br />
<span style="color: blue;"> <span style="color: blue;"><a href="https://drive.google.com/file/d/0B53C_HLwEgi-NVZrZkZPazVnRTQ/view?usp=sharing&resourcekey=0-_9xGfoBkCMDZC9uAM86EnQ"><b>Download source-code files (zip)</b></a></span></span><br />
<br />
Datasheets & further info:<br />
<a href="http://pdf.datasheetcatalog.com/datasheets/208/301092_DS.pdf">TSOP1738 datasheet</a><br />
<a href="http://www.nex-robotics.com/products/sensors/position-encoder-moc7811.html">MOC7811</a><br />
<a href="http://www.nex-robotics.com/products/motors-and-accessories/encoder-disc-metal.html">Encoder Slotted Disc</a> <br />
<br />
<br />
<br />
<br />
<br />
Thanks & Regards,<br />
ccd@dharmanitech.com CC Dharmanihttp://www.blogger.com/profile/13217855743473839524noreply@blogger.com211tag:blogger.com,1999:blog-8014888555955763990.post-58433442763796622322008-11-30T18:39:00.004+05:302021-09-26T15:58:53.134+05:304x4 Matrix Key-board Interfacing with ATmega32<a href="http://3.bp.blogspot.com/_zqABT3suzXE/STKQ8yUTHkI/AAAAAAAAANs/ajOESHMhIXM/s1600-h/Matrix_Keypad.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5274437487577734722" src="https://3.bp.blogspot.com/_zqABT3suzXE/STKQ8yUTHkI/AAAAAAAAANs/ajOESHMhIXM/s320/Matrix_Keypad.JPG" style="cursor: pointer; display: block; height: 242px; margin: 0px auto 10px; text-align: center; width: 385px;" /></a><br />
Hi guys,<br />
Here is a project for beginners to interface a 16-key (4x4) keypad with ATmega32 using 8-pins i.e. one port of the microcontroller. This is useful particularly where we need more keys but don't want to spend more uC pins for interfacing.<br />
The 4x4 keypad is a standard one available in the market. I've used here one from my <a href="http://www.dharmanitech.com/2008/10/home-made-double-layer-atmega32-pcb-for.html">earlier project</a>. The LED shown in the schematic is just extra, which can be used anyway you like.<br />
Here, the mega32 reads the code of key pressed and sends relevant character to display on LCD 2nd line. The first line displays 'WELCOME' all the time.<br />
<br />
The figure below shows ISIS Proteus Simulation of this code:<br />
<br />
<a href="http://1.bp.blogspot.com/-PoHY3KM66fk/TzfexmT9WhI/AAAAAAAAAfc/Louz8kmTacE/s1600/matrixKB.JPG"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5708275996394609170" src="https://1.bp.blogspot.com/-PoHY3KM66fk/TzfexmT9WhI/AAAAAAAAAfc/Louz8kmTacE/s400/matrixKB.JPG" style="cursor: pointer; display: block; height: 244px; margin: 0px auto 10px; text-align: center; width: 400px;" /></a><br />
<span style="font-weight: bold;"><br /></span>
<span style="font-weight: bold;">Download</span><br />
------------------<br />
<a href="https://drive.google.com/file/d/0B53C_HLwEgi-UlBuNnVKSkdhUDg/view?usp=sharing&resourcekey=0-op0wnKalrkkE54LuXTy1ig" style="color: #000099;"><span style="font-weight: bold;">Source Code</span> (AVR-GCC, winAVR, AVRStudio format)</a><br />
<a href="https://drive.google.com/file/d/0B53C_HLwEgi-aFZhSnVlTnk5aTg/view?usp=sharing&resourcekey=0-Dk_DTFIuJQqIKT0nnSqjSw" style="font-weight: bold;">Proteus Simulation model</a><br />
<a href="https://drive.google.com/file/d/0B53C_HLwEgi-aVFSTWk2X001WkU/view?usp=sharing&resourcekey=0-ME0znWowgg4aFrC2WzSjvg" style="color: #000099;"><span style="font-weight: bold;">Source Code</span> (CodeVision AVR format)</a><br />
<a href="https://drive.google.com/file/d/0B53C_HLwEgi-TkR3ckRUY0liVjQ/view?usp=sharing&resourcekey=0-Jwcwta-ZkNA67ptSS6ibXQ" style="color: #000099;"><span style="font-weight: bold;">Source Code</span> with <span style="font-weight: bold;">4-bit LCD</span> Implementation (ICCAVR)</a><br />
<a href="https://docs.google.com/document/d/1N5zPY6zlsVSg3XIDc8PVQvtfmSuo08SF6XWzVFWLvDg/edit" style="color: #000099;"><span style="font-weight: bold;">Source Code</span> (ICCAVR) with <span style="font-weight: bold;">Schematic on Google Docs</span></a><br />
<br /> <br />
Thanks!CC Dharmanihttp://www.blogger.com/profile/13217855743473839524noreply@blogger.com66tag:blogger.com,1999:blog-8014888555955763990.post-90396208616722385792008-11-23T01:01:00.002+05:302021-09-26T16:12:38.550+05:30Simple PWM DC motor control using MOSFET H-Bridge with AVR ATmega8<a href="http://1.bp.blogspot.com/_zqABT3suzXE/SSheqD8W9UI/AAAAAAAAANE/Vky1CYC_CBc/s1600-h/motor+control+hardware.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5271567440543151426" src="https://1.bp.blogspot.com/_zqABT3suzXE/SSheqD8W9UI/AAAAAAAAANE/Vky1CYC_CBc/s320/motor+control+hardware.JPG" style="cursor: pointer; display: block; height: 294px; margin: 0px auto 10px; text-align: center; width: 361px;" /></a><br />
<br />
Hi friends,<br />
here is a very simple project of controlling a small DC-motor (taken from an old personal cassette player) with ATmega8. The ATmega8 is having three PWM channels, out of which two are used here. PWM waveforms are fed to MOSFET (RFD3055) H-bridge.<br />
Here, direction is controlled using a two-position toggle switch and speed of the motor is controlled by two push-buttons, one for increasing the speed and other for reducing.<br />
The schematic is geiven here (click on the image to enlarge):<br />
<br />
<a href="http://4.bp.blogspot.com/_zqABT3suzXE/SShhr5Lur9I/AAAAAAAAANU/ap-j59gZL6o/s1600-h/motor+control+sch.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5271570770549452754" src="https://4.bp.blogspot.com/_zqABT3suzXE/SShhr5Lur9I/AAAAAAAAANU/ap-j59gZL6o/s320/motor+control+sch.JPG" style="cursor: pointer; display: block; height: 239px; margin: 0px auto 10px; text-align: center; width: 397px;" /></a><br />
When switch SW1 is closed, OC1A channel is active which will feed the PWM signal to Q1 & Q4 MOSFETs. The OC1B pin will remain low keeping the Q3 & Q2 in OFF condition. When SW1 is toggled to open position, OC1A pin will become low, making Q1 & Q4 OFF and OC1B will feed the PWM signal to Q3 & Q2, resulting in the change in the direction of current flow hrough motor. Hence, motor rotation direction will change.<br />
The speed is controlled by Push-buttons S2 & S3. Pressing S2 will increase the speed in fixed steps. Similarly, pressing S3 will reduce the speed in fixed steps.<br />
<br />
The closer look to the motor and the circuit:<br />
<br />
<a href="http://4.bp.blogspot.com/_zqABT3suzXE/SShjUgtzkQI/AAAAAAAAANc/iq5YQhBmlss/s1600-h/motor.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5271572567867756802" src="https://4.bp.blogspot.com/_zqABT3suzXE/SShjUgtzkQI/AAAAAAAAANc/iq5YQhBmlss/s200/motor.JPG" style="cursor: pointer; float: left; height: 156px; margin: 0pt 10px 10px 0pt; width: 194px;" /></a><a href="http://4.bp.blogspot.com/_zqABT3suzXE/SShjhWRo50I/AAAAAAAAANk/DZRYCPQYsqM/s1600-h/circuit.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5271572788403562306" src="https://4.bp.blogspot.com/_zqABT3suzXE/SShjhWRo50I/AAAAAAAAANk/DZRYCPQYsqM/s200/circuit.JPG" style="cursor: pointer; float: left; height: 156px; margin: 0pt 10px 10px 0pt; width: 232px;" /></a><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
Here on the bread-board, I've used two push-buttons but the direction control switch is replaced by a small wire which was connected to ground or kept open for changing the direction (since I was not having the toggle switch in stock at the moment). The bread-board also includes 6-pin In-System Programming connector which is not shown in the schematic.<br />
<br />
(The InSystemProgramming (ISP) connector is shown in my earlier posts, hence omitted here!! But, if you are new to ISP, refer to my post <a href="http://www.dharmanitech.com/2008/09/diy-avr-programmers.html">DIY AVR Programmers</a> to make one yourself!!)<br />
<br />
The schematic and code for this PWM motor control can be downloaded from here:<br />
<br />
<a href="https://docs.google.com/document/d/1KpNirSCz1cSHlzAXn2dO6cXMncCWobdvFVQ3fYzqPDI/edit" style="color: #000099;"><span style="font-weight: bold;">Schematic & Code</span></a><span color="rgb(0 , 0 , 153)"> on Google Docs</span><br />
<a href="https://drive.google.com/file/d/0B53C_HLwEgi-S1VLeEd1TW5YZ0E/view?usp=sharing&resourcekey=0-13fvivxGn8r_XeUNT9uGrQ" style="color: #000099;"><span style="font-weight: bold;">Source code in CodeVision format (C file)</span></a><br />
<br />
<br />
Download datasheet: <a href="http://www.datasheetcatalog.org/datasheets/90/346683_DS.pdf">RFD3055</a><br />
<br />
Thanks!<br />
---------<br />
ccd@dharmanitech.comCC Dharmanihttp://www.blogger.com/profile/13217855743473839524noreply@blogger.com86tag:blogger.com,1999:blog-8014888555955763990.post-70210481927731879512008-10-20T22:23:00.001+05:302021-09-26T16:15:07.037+05:308-Channel ADC Project with ATmega32<a href="http://3.bp.blogspot.com/_zqABT3suzXE/SPy-OADwqkI/AAAAAAAAAMA/OflKt1cPtJo/s1600-h/ch0.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5259287612605114946" src="https://3.bp.blogspot.com/_zqABT3suzXE/SPy-OADwqkI/AAAAAAAAAMA/OflKt1cPtJo/s320/ch0.jpg" style="cursor: pointer; float: left; height: 102px; margin: 0pt 10px 10px 0pt; width: 222px;" /></a><a href="http://2.bp.blogspot.com/_zqABT3suzXE/SPy-U-SQgbI/AAAAAAAAAMI/oOnix-bAXT8/s1600-h/ch1.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5259287732388135346" src="https://2.bp.blogspot.com/_zqABT3suzXE/SPy-U-SQgbI/AAAAAAAAAMI/oOnix-bAXT8/s320/ch1.jpg" style="cursor: pointer; float: left; height: 103px; margin: 0pt 10px 10px 0pt; width: 215px;" /></a><br />
<div style="text-align: left;">
<br /></div>
<br />
<br />
<br />
<br />
<br />
<br />
Hi friends,<br />
here is a small project of Analog to Digital Converter using ATmega32 which is having on-chip 8-channel ADC.<br />
The circuit also consists of an intelligent 16x2 LCD for displaying the value of the voltage applied at each channel. There is also a push-button to scroll throgh the different channels. The schematic is as shown in the figure:<br />
<br />
<a href="http://4.bp.blogspot.com/_zqABT3suzXE/SPy971BeigI/AAAAAAAAAL4/ybW_9fxT4Jw/s1600-h/ADC+Testing.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" height="392" id="BLOGGER_PHOTO_ID_5259287300405103106" src="https://4.bp.blogspot.com/_zqABT3suzXE/SPy971BeigI/AAAAAAAAAL4/ybW_9fxT4Jw/s400/ADC+Testing.JPG" style="display: block; margin: 0px auto 10px; text-align: center;" width="400" /></a><br />
When powered on, the LCD displays"ADC Testing.." on the first line and the value of the voltage applied at the channel0 on the second line. When the push-button is pressed, the second line displays the value of channel1. Like-wise, all the channels can be checked one-by-one by pressing the push-button. The channel count will roll back to channel0 after going to channel7.<br />
<br />
The displays shown in the pictures on top show values at channel0 and channel1. Here a AA battery was connected to channel0 and the channel1 was connected with the +5v supply.<br />
A 9-pin connector is used for ADC, 8 ADC channel pins and 1 ground pin. (the values displayed on LCD will fluctuate for a channel if nothing is connected to that channel)<br />
<br />
The software is created in C using ImageCraft ICCAVR compiler.<br />
The Schematic and code for this project can be downloaded here:<br />
<br />
<span style="font-weight: bold;"> <a href="https://docs.google.com/document/d/1OJWzAhFUtnu9gI9b81OKRwy-ndzGO18SqYRdirlwhxg/edit">Download Schematic and Code</a></span><br />
<a href="https://docs.google.com/document/d/17tPiT3pLvBfsixhfiqpNSuESvIjAzDvv3_TBSJOP5tk/edit"><span style="font-weight: bold;">Download HEX file</span></a><br />
<br />
Thanks!!<br />
-----------<br />
ccd@dharmanitech.comCC Dharmanihttp://www.blogger.com/profile/13217855743473839524noreply@blogger.com34tag:blogger.com,1999:blog-8014888555955763990.post-35799031428723646572008-10-09T18:43:00.001+05:302018-07-01T20:54:23.295+05:30Home-made Double Layer ATmega32 PCB for RS232/RS422 Communication testing<a href="http://4.bp.blogspot.com/_zqABT3suzXE/SO4D8m7FqcI/AAAAAAAAALQ/9yb4TgmIDpE/s1600-h/pcb_ready.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" height="383" id="BLOGGER_PHOTO_ID_5255142154963364290" src="https://4.bp.blogspot.com/_zqABT3suzXE/SO4D8m7FqcI/AAAAAAAAALQ/9yb4TgmIDpE/s400/pcb_ready.JPG" style="float: left; height: 214px; margin: 0pt 10px 10px 0pt; width: 223px;" width="400" /></a><a href="http://3.bp.blogspot.com/_zqABT3suzXE/SO4ED8eLUbI/AAAAAAAAALY/lLKg459WWR8/s1600-h/pcb_working.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5255142281006764466" src="https://3.bp.blogspot.com/_zqABT3suzXE/SO4ED8eLUbI/AAAAAAAAALY/lLKg459WWR8/s320/pcb_working.JPG" style="cursor: pointer; float: left; height: 213px; margin: 0pt 10px 10px 0pt; width: 230px;" /></a><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
Hi guys,<br />
after making my single layer starter's kit <a href="http://www.dharmanitech.com/2008/08/make-yourself-atmega32-starters-kit.html">M32_Card</a>, I was looking for making a double layer M32 PCB at home. So, here is my attempt to make it. Well, it didn't turn out to be as difficult as I had thought it to be earlier. I had to dump one PCB before making this one as the top-layer routine was not solder-friendly!!<br />
<br />
I've made this one mainly for an application where RS232 & RS422 testing was required. It uses MAX232 & MAX488 ICs from for those serial communication. Selection between RS232 & RS422 is through jumpers. The board is using ATmega32 controller, just like my single layer pcb. It also has 4x4 matrix keyboard, an LCD interface, ADC connector, SPI connector (for In System Programming), a reset switch and an LED for beginner's programming. It operates with the standard 12v DC adapter.<br />
<br />
Here is the schematic (click on the image to enlarge):<br />
<br />
<a href="http://1.bp.blogspot.com/_zqABT3suzXE/SO4Gq9kRthI/AAAAAAAAALg/ZomAlPlnooQ/s1600-h/schematic.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" height="307" id="BLOGGER_PHOTO_ID_5255145150338938386" src="https://1.bp.blogspot.com/_zqABT3suzXE/SO4Gq9kRthI/AAAAAAAAALg/ZomAlPlnooQ/s400/schematic.JPG" style="display: block; margin: 0px auto 10px; text-align: center;" width="400" /></a><br />
There is a small mistake here in the schematic, the RX/TX pin connections in the RS232 connector are swapped, which I found while testing the PCB. So, I had to correct it by cutting those two tracks and placing jumpers. After the correction, the communication with PC was established. The schematic is similar to the M32_Card, accept that I've removed the RTC DS1307 and placed the MAX488. Also, the individual push buttons are replaced with the 16 key matrix key-board.<br />
Click here to get more info and for downloading code to <a href="http://www.dharmanitech.com/2008/11/4x4-matrix-key-board-interfacing-with.html">interface the 4x4 matrix keyboard</a> shown here<br />
<br />
The PCB etching is done with Ferric Chloride. In making the double layer PCB, as I don't have any PTH (printed through holes) facility, I've put small pieces of single core wire into the holes and soldered both sides. Check out the top and bottom layers here<br />
<br />
<a href="http://4.bp.blogspot.com/_zqABT3suzXE/SO4ILwTACJI/AAAAAAAAALo/9LiM8SbaWFM/s1600-h/top+layer.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5255146813224126610" src="https://4.bp.blogspot.com/_zqABT3suzXE/SO4ILwTACJI/AAAAAAAAALo/9LiM8SbaWFM/s320/top+layer.JPG" style="cursor: pointer; float: left; height: 205px; margin: 0pt 10px 10px 0pt; width: 218px;" /></a><a href="http://4.bp.blogspot.com/_zqABT3suzXE/SO4Ic39srDI/AAAAAAAAALw/7mJ_nb8z5us/s1600-h/bottom+layer.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5255147107340037170" src="https://4.bp.blogspot.com/_zqABT3suzXE/SO4Ic39srDI/AAAAAAAAALw/7mJ_nb8z5us/s320/bottom+layer.JPG" style="cursor: pointer; float: left; height: 203px; margin: 0pt 10px 10px 0pt; width: 233px;" /></a><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
If you have an application where the circuit can not be contained in a single layer, a home-made double layer PCB is worth a try!!<br />
<br />
Thanks!<br />
---------<br />
ccd@dharmanitech.comCC Dharmanihttp://www.blogger.com/profile/13217855743473839524noreply@blogger.com26tag:blogger.com,1999:blog-8014888555955763990.post-35524136383002689382008-10-03T18:49:00.002+05:302021-09-26T16:20:28.594+05:30Thermometer using DS1621 and Nokia 3310 LCD interfaced with ATmega8<a href="http://4.bp.blogspot.com/_zqABT3suzXE/SOYcz-aAjvI/AAAAAAAAAKw/I8ZdIwcbt_M/s1600-h/Thermometer.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5252917694625255154" src="https://4.bp.blogspot.com/_zqABT3suzXE/SOYcz-aAjvI/AAAAAAAAAKw/I8ZdIwcbt_M/s320/Thermometer.JPG" style="cursor: pointer; display: block; height: 293px; margin: 0px auto 10px; text-align: center; width: 441px;" /></a><br />
Hi friends,<br />
in my last post I had discussed <a href="http://www.dharmanitech.com/2008/09/nokia-3310-lcd-interfacing-with-atmega8.html">Nokia 3310 LCD interfacing with AVR ATmega8</a>. It's really fun to work with this LCD.<br />
<br />
Now, here I'm presenting one application with the same LCD: Designing a thermometer using DS1621 temperature sensor IC. DS1621 is 8-pin sensor from Maxim, with temp range of -55 to +125 degree C, which can be interfaced with microcontroller over two-wire serial i2c bus. It has operating voltage range from 2.7 to 5.5v. I'm operating it here at 3.3v, same as the one driving the LCD and ATmega8. DS1621 doesn't require any external components to measure temperature. It has got continuous or one-shot temperature reading capability to save power.<br />
Check out the schematic:<br />
<br />
<a href="http://2.bp.blogspot.com/_zqABT3suzXE/SOYflGhdBbI/AAAAAAAAAK4/mtbjy7myWeg/s1600-h/thermo_sch.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" height="459" id="BLOGGER_PHOTO_ID_5252920737640809906" src="https://2.bp.blogspot.com/_zqABT3suzXE/SOYflGhdBbI/AAAAAAAAAK4/mtbjy7myWeg/s640/thermo_sch.JPG" style="display: block; margin: 0px auto 10px; text-align: center;" width="640" /></a><br />
Here is the Proteus ISIS simulation result:<br />
<br />
<a href="http://4.bp.blogspot.com/-06mcbbhqo08/TzfFpR35eNI/AAAAAAAAAes/x5Ct8H_0wzo/s1600/3310%2Bthermo.JPG"><img alt="" border="0" height="343" id="BLOGGER_PHOTO_ID_5708248365678557394" src="https://4.bp.blogspot.com/-06mcbbhqo08/TzfFpR35eNI/AAAAAAAAAes/x5Ct8H_0wzo/s400/3310%2Bthermo.JPG" style="display: block; margin: 0px auto 10px; text-align: center;" width="400" /></a><br />
<br />
I'm using here LM317 for getting 3.3v supply, any 3.3v rgulator can be used to replace it. The LED is only for checking the health of the circuit incase nothing comes up on display. The circuit is programmed to update temperature appx. every second.<br />
<br />
<a href="http://1.bp.blogspot.com/_zqABT3suzXE/SOYhRV8_mgI/AAAAAAAAALA/rw8OjpMAmZk/s1600-h/thermo_screen.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5252922597208726018" src="https://1.bp.blogspot.com/_zqABT3suzXE/SOYhRV8_mgI/AAAAAAAAALA/rw8OjpMAmZk/s320/thermo_screen.JPG" style="cursor: pointer; float: left; height: 186px; margin: 0pt 10px 10px 0pt; width: 218px;" /></a>I've taken help of LFG application for generating different sizes of fonts for the LCD, thanks o the author M.Ebrahimy. The application can be downloaded from here:<br />
<a href="http://www.elvand.com/en/Download.asp">LCD Font Generator</a><br />
<br />
I've created library functions for DS1621 interface with AVR using ICCAVR compiler. This functions can be used with i2c base routines discussed in my earlier posts. You can download the project source code here.<br />
<br />
<br />
<br />
<span style="font-weight: bold;"><br /></span>
<span style="font-weight: bold;"><br /></span>
<span style="font-weight: bold;">Download</span><br />
------------------<br />
<a href="https://docs.google.com/document/d/1A8-xGxPvF9YSJoOUEPR-dABXGD--Kmh2SEiWv6M0OSg/edit"><span style="font-weight: bold;">HEX file</span></a><br />
<a href="https://drive.google.com/file/d/0B53C_HLwEgi-U1AwSFh4QXBoaGs/view?usp=sharing&resourcekey=0-P2Yg8KPuAnKvfukCTl1o3g" style="font-weight: bold;">Source code</a> <span color="rgb(0 , 0 , 153)">(including the 3310 & DS1621 Libraries)</span><br />
<a href="https://drive.google.com/file/d/0B53C_HLwEgi-Tjc0QkdMamUxcmc/view?usp=sharing&resourcekey=0-eJbpvkBKmoJDwpBdCkE0rg" style="font-weight: bold;">Proteus Simulation Model</a><br />
<br />
<br />
(Do you wanna use this HEX file but don't want my name on the display?? Well, just learn how to play with hex file from <a href="http://www.keil.com/support/docs/1584.htm">intel HEX-file tutorial</a>, find ascii characters of my name in the hex file and replace them with yours!!)<br />
<br />
Download Datasheets:<br />
1. <a href="http://pdfserv.maxim-ic.com/en/ds/DS1621.pdf">DS1621</a><br />
2. <a href="http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-2486-8-bit-AVR-microcontroller-ATmega8_L_datasheet.pdf">ATmega8</a><br />
<br />
Thanks!!<br />
---------<br />
Contact: ccd@dharmanitech.comCC Dharmanihttp://www.blogger.com/profile/13217855743473839524noreply@blogger.com76tag:blogger.com,1999:blog-8014888555955763990.post-52249898575868913082008-09-22T00:47:00.001+05:302021-09-26T16:24:25.544+05:30NOKIA 3310 LCD interfacing with ATmega8<a href="http://2.bp.blogspot.com/_zqABT3suzXE/SNevCf2bHAI/AAAAAAAAAJg/IA94AT-DB3w/s1600-h/setup.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5248856348167969794" src="https://2.bp.blogspot.com/_zqABT3suzXE/SNevCf2bHAI/AAAAAAAAAJg/IA94AT-DB3w/s320/setup.jpg" style="cursor: pointer; display: block; height: 350px; margin: 0px auto 10px; text-align: center; width: 426px;" /></a><a href="http://4.bp.blogspot.com/_zqABT3suzXE/SNex_dIBunI/AAAAAAAAAJw/DD-JUromt-E/s1600-h/lcd+back-2.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5248859594431773298" src="https://4.bp.blogspot.com/_zqABT3suzXE/SNex_dIBunI/AAAAAAAAAJw/DD-JUromt-E/s320/lcd+back-2.JPG" style="cursor: pointer; display: block; height: 191px; margin: 0px auto 10px; text-align: center; width: 433px;" /></a><br />
Hi friends,<br />
<div>
using graphic LCD in a project gives itreally a good look and flexibility of displaying different characters and shapes. But, the graphic LCDs are quite costly. </div>
<div>
The NOKIA 3310 LCD provides a really low-cost solution to add a small graphic display into your project and also good for learning purpose. The LCD is SPI bus compatible, saving many pins for other uses. It operates at 3.3v.<br />
<br />
Here is a small circuit for interfacing the 3310 LCD with AVR microcontroller ATmega8. The schematic includes LCD connection with SPI port of ATmega8 with other connections required by LCD. The 3.3v is generated using adjustable voltage regulator LM317 (I was not having any 3.3v regulator at the moment). An LED is also connected with microcontroller just for making sure that the controller is working, particularly when you don't see anything on the display!<br />
<br />
Here is the schematic and the pin details of the LCD:<br />
<br />
<a href="http://2.bp.blogspot.com/_zqABT3suzXE/SVy-AeDWE9I/AAAAAAAAAOc/H5jpo4xaCEc/s1600-h/schematic.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" height="460" id="BLOGGER_PHOTO_ID_5286308977902490578" src="https://2.bp.blogspot.com/_zqABT3suzXE/SVy-AeDWE9I/AAAAAAAAAOc/H5jpo4xaCEc/s640/schematic.JPG" style="display: block; margin: 0px auto 10px; text-align: center;" width="640" /></a><br />
<a href="http://3.bp.blogspot.com/_zqABT3suzXE/SNeu4LOFkqI/AAAAAAAAAJY/AV2PgnYkv7s/s1600-h/screens.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5248856170831385250" src="https://3.bp.blogspot.com/_zqABT3suzXE/SNeu4LOFkqI/AAAAAAAAAJY/AV2PgnYkv7s/s320/screens.JPG" style="cursor: pointer; display: block; height: 196px; margin: 0px auto 10px; text-align: center; width: 418px;" /></a></div>
<div>
</div>
<div>
</div>
<br />
The connector of LCD is 'touch' type. So, I made a small connecor PCB with tracks touching to the pins of LCD. The pcb was pasted at backside of LCD using cello tapes as shown in the back-view image<br />
.<a href="http://4.bp.blogspot.com/_zqABT3suzXE/SNe0UjYUMbI/AAAAAAAAAKA/uoFwXYBugGo/s1600-h/lcd+back+n+pcbs.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5248862155911213490" src="https://4.bp.blogspot.com/_zqABT3suzXE/SNe0UjYUMbI/AAAAAAAAAKA/uoFwXYBugGo/s320/lcd+back+n+pcbs.JPG" style="cursor: pointer; display: block; height: 248px; margin: 0px auto 10px; text-align: center; width: 447px;" /></a><br />
<div>
</div>
<div>
</div>
<div>
</div>
<div>
<div>
</div>
</div>
<a href="http://1.bp.blogspot.com/_zqABT3suzXE/SNajqOcIq2I/AAAAAAAAAIo/M9vF5xC2XAM/s1600-h/BackView.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"></a><br />
<div>
</div>
<div>
<div>
</div>
</div>
<div>
<div>
</div>
</div>
<div>
<div>
</div>
</div>
<br />
Here is a testing with Proteus ISIS Simulation:<br />
<br />
<a href="http://4.bp.blogspot.com/-vjlCQQQYNNI/TzfLDSkVIoI/AAAAAAAAAe4/fXUI2TfVrVU/s1600/3310%2BLCD%2BCV.JPG"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5708254310099657346" src="https://4.bp.blogspot.com/-vjlCQQQYNNI/TzfLDSkVIoI/AAAAAAAAAe4/fXUI2TfVrVU/s400/3310%2BLCD%2BCV.JPG" style="cursor: pointer; display: block; height: 319px; margin: 0px auto 10px; text-align: center; width: 400px;" /></a><br />
The program routines are written in C with ICCAVR compiler. I've created a library for this display. The low-cost, easy availability has made me relly like this display.<br />
I'm going to use it for <br />
<div>
</div>
doing other stuffs, too!<br />
<br />
<span style="font-weight: bold;">Download</span><br />
<span style="font-weight: bold;">----------------</span><br />
<a href="https://drive.google.com/file/d/0B53C_HLwEgi-ZU51MWZFdEdTVjQ/view?usp=sharing&resourcekey=0-Xe3UGnv7pcxkQ_zw-Iklyg" style="font-weight: bold;">3310 Library (ICCAVR)</a><br />
<a href="https://drive.google.com/file/d/0B53C_HLwEgi-cDgyM2Jzb0tldUU/view?usp=sharing&resourcekey=0-aACOsB2MWgHajzAyFpUWNQ" style="font-weight: bold;">3310 Library (AVR-GCC, winAVR, AVRStudio)</a><br />
<a href="https://drive.google.com/file/d/0B53C_HLwEgi-S29hS1F0R2dnQWs/view?usp=sharing&resourcekey=0-qJSOG6sL4MV4y6oCO0nzrA" style="font-weight: bold;">3310 project (CodeVision AVR)</a><br />
<a href="https://drive.google.com/file/d/0B53C_HLwEgi-eWY5dTVxN0d4azA/view?usp=sharing&resourcekey=0-mOZvLFRvk9gUZefJAMTDgw" style="font-weight: bold;">Proteus Simulation Model</a> (Simulation was done with CodeVision AVR Hex file)<br />
<br />
<br />
Check out my thermometer project with this display:<br />
<a href="http://www.dharmanitech.com/2008/10/thermometer-design-using-ds1621.html">Thermometer with Nokia3310</a><br />
<br />
Download datasheets:<br />
1. <a href="http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-2486-8-bit-AVR-microcontroller-ATmega8_L_datasheet.pdf">ATmega8</a><br />
2. <a href="http://eia.udg.edu/~forest/PCD8544_1.pdf">PCD8544 - nokia 3310 display controller</a><br />
<br />
Thanks!!<br />
--------<br />
ccd@dharmanitech.com<br />
<div>
</div>
CC Dharmanihttp://www.blogger.com/profile/13217855743473839524noreply@blogger.com278tag:blogger.com,1999:blog-8014888555955763990.post-40709663629401162462008-09-14T03:39:00.001+05:302021-09-26T16:25:51.346+05:30Using M32_Card for Data Acquisition with on-board 8 channnel ADC<a href="http://1.bp.blogspot.com/_zqABT3suzXE/SMw7qdDl2lI/AAAAAAAAAHg/Ja1blCRGTvQ/s1600-h/ccd1.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5245633266520021586" src="https://1.bp.blogspot.com/_zqABT3suzXE/SMw7qdDl2lI/AAAAAAAAAHg/Ja1blCRGTvQ/s200/ccd1.JPG" style="cursor: pointer; float: left; height: 250px; margin: 0pt 10px 10px 0pt; width: 123px;" /></a><a href="http://1.bp.blogspot.com/_zqABT3suzXE/SMw_o3ibcqI/AAAAAAAAAHo/bInRE2nKMBE/s1600-h/M32_1.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5245637637315457698" src="https://1.bp.blogspot.com/_zqABT3suzXE/SMw_o3ibcqI/AAAAAAAAAHo/bInRE2nKMBE/s200/M32_1.jpg" style="cursor: pointer; float: left; height: 236px; margin: 0pt 10px 10px 0pt; width: 322px;" /></a><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
Hi friends,<br />
I'm showing here one more application of the home-made M32_Card discussed in my earlier post. The microcontroller of the card is having 8-channel, 10 bit resolution ADC which can be used for analog data acquisition. Using the hyper terminal for the selection of menu, ADC can be selected to display value of the analog voltage applied to each channel (at the 9-pin header pin; 8 ADC channels & 1 GND).<br />
The microcontroller reads the voltage at each channel and sends the data to PC via RS232 cable. At reciving end (PC), the incoming data can be converted into excel format to store the values at regular time intervals.<br />
As shown in the screen-shot of the hyper terminal, I had connected here the 5v Vcc to Channel 0 and an Li cell to channel 7.<br />
The M32 can also send a time impression along with the channel data using the on-board RTC DS1307 to record the voltage variation with time.<br />
<br />
The project source code files can be downloaded from here:<br />
<a href="https://drive.google.com/file/d/0B53C_HLwEgi-NTJPaUY4d3VMQnc/view?usp=sharing&resourcekey=0-QQ_nRlH5u6-NGRFVGbFJCg" style="color: #000099; font-weight: bold;">Download Source Code</a><br />
<br />
--------<br />
ccd@dharmanitech.comCC Dharmanihttp://www.blogger.com/profile/13217855743473839524noreply@blogger.com30tag:blogger.com,1999:blog-8014888555955763990.post-10145962005188792152008-09-03T16:00:00.000+05:302010-12-18T21:40:11.904+05:30DIY AVR ProgrammersHi guys,<br />for those who are trying to make AVR kit at home, an AVR programmer which can be simple to make will be really useful, as it'll avoid buying the programmer!! Here I'm giving a few webpage links on how to make a programmers yourself.<br /><br />- Here is a simple AVR serial programmer, works with PC serial port, easy to make:<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_zqABT3suzXE/SL5uU2cmN8I/AAAAAAAAAG4/nEoQifzu27A/s1600-h/at_prog_photo_complete.jpg"><img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 177px; height: 131px;" src="http://2.bp.blogspot.com/_zqABT3suzXE/SL5uU2cmN8I/AAAAAAAAAG4/nEoQifzu27A/s200/at_prog_photo_complete.jpg" alt="" id="BLOGGER_PHOTO_ID_5241748320797734850" border="0" /></a><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_zqABT3suzXE/SL5wPme6iGI/AAAAAAAAAHA/zb65eUz8NCU/s1600-h/atprog.gif"><img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 257px; height: 131px;" src="http://1.bp.blogspot.com/_zqABT3suzXE/SL5wPme6iGI/AAAAAAAAAHA/zb65eUz8NCU/s200/atprog.gif" alt="" id="BLOGGER_PHOTO_ID_5241750429636397154" border="0" /></a><br /><br /><br /><br /><br /><br /><br /><br /><br />For complete info check out the webpage:<br /><a href="http://extremeelectronics.co.in/avr-tutorials/part-iii-making-programmer-and-target/">AVR Serial programmer from Extremeelectronics.co.in</a><br /><br />- For using the serial programmer discussed above, a driver software is required to be installed in your pc. Download it from here:<br /><a href="http://www.lancos.com/prog.html">PonyProg : AVR serial programmer</a><br /><br />- <a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_zqABT3suzXE/SL50L1zYw2I/AAAAAAAAAHI/9ZbQ3g_4T-k/s1600-h/USB-AVR-PROG.jpg"><img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 238px; height: 175px;" src="http://4.bp.blogspot.com/_zqABT3suzXE/SL50L1zYw2I/AAAAAAAAAHI/9ZbQ3g_4T-k/s200/USB-AVR-PROG.jpg" alt="" id="BLOGGER_PHOTO_ID_5241754763075830626" border="0" /></a>If you are using a laptop which doesn't have serial port then you can buy a low-cost AVR USB programmer shown in the figure. Visit this webpage for buying it:<br /><div style="text-align: left;"><a href="http://shop.extremeelectronics.co.in/product_info.php?cPath=21&products_id=28">AVR USB Programmer</a><br /></div><br /><br /><br /><br /><br />Here is one more option for buying a cheap USB programmer for AVR at around $15 cost:<br /><a href="http://www.micro4you.com/store/usbasp-avr-usb-isp/prod_52.html">AVR USB Programmer lite</a><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_zqABT3suzXE/SduQIcmpkpI/AAAAAAAAASk/W61KhZxaoYY/s1600-h/usbasp.jpg"><img style="margin: 0pt 0pt 10px 10px; float: right; cursor: pointer; width: 186px; height: 154px;" src="http://4.bp.blogspot.com/_zqABT3suzXE/SduQIcmpkpI/AAAAAAAAASk/W61KhZxaoYY/s320/usbasp.jpg" alt="" id="BLOGGER_PHOTO_ID_5322005859460027026" border="0" /></a><br />And if you want to make an USB programmer yourself, check out here an easy to make AVR USB programmer:<img src="file:///C:/DOCUME%7E1/CCDHAR%7E1/LOCALS%7E1/Temp/moz-screenshot-1.jpg" alt="" /><img src="file:///C:/DOCUME%7E1/CCDHAR%7E1/LOCALS%7E1/Temp/moz-screenshot-2.jpg" alt="" /><br /><a style="color: rgb(0, 0, 153);" href="http://www.fischl.de/usbasp/">DIY AVR USB Programmer</a><br /><br />- Atmel has given a detailed document on design of In-System Programmer for AVR. It inclludes the schematic of the programmer. Download this pdf document from here:<br /><a href="http://www.atmel.com/dyn/resources/prod_documents/DOC0943.PDF"> In-System Programmer for AVR, from Atmel</a><br /><br />- For those who like pc parallel port better, here is a page containing data on how to make a parallel port AVR programmer along with the download for the pc:<br /><a href="http://www.speedy-bl.com/avr-prog-e.htm">Parallel port programmer for AVR</a><br /><br />- Here is another parallel port programmer from AVRdude:<br /><a href="http://www.bsdhome.com/avrdude/">AVRdude parallel port programmer</a><br /><br />- One more parallel port programmer using AT90S1200 microcontroller, with schematic and the .asm file. (Note: it need a pre-programmed AT90S1200 IC). Check out more on the webpage:<a href="http://electrons.psychogenic.com/modules/arms/art/5/AVRInSystemProgrammer.php"><br />Psychogenic PPI AVR Programmer</a><br /><br />- Apart from these, some more free designs are there, you'll find them by googling!! And if you want to buy, there are plenty of them available!!!<br /><br />Hope this info is useful for your project work..<br />Thanks!CC Dharmanihttp://www.blogger.com/profile/13217855743473839524noreply@blogger.com74tag:blogger.com,1999:blog-8014888555955763990.post-27566182628223258692008-08-30T15:31:00.001+05:302021-09-26T16:28:08.739+05:30Make-Yourself ATmega32 Starter's Kit with LCD, I2C, SPI, RTC, ADC interfaces<a href="http://2.bp.blogspot.com/_zqABT3suzXE/SLkoW52P28I/AAAAAAAAAFM/8CfkpPRVmPU/s1600-h/DSC00172.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5240264015372868546" src="https://2.bp.blogspot.com/_zqABT3suzXE/SLkoW52P28I/AAAAAAAAAFM/8CfkpPRVmPU/s320/DSC00172.jpg" style="cursor: pointer; float: left; height: 191px; margin: 0pt 10px 10px 0pt; width: 211px;" /></a><a href="http://3.bp.blogspot.com/_zqABT3suzXE/SLknJpd5pjI/AAAAAAAAAFE/dFL604AKQ0A/s1600-h/DSC00168.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5240262688125855282" src="https://3.bp.blogspot.com/_zqABT3suzXE/SLknJpd5pjI/AAAAAAAAAFE/dFL604AKQ0A/s320/DSC00168.jpg" style="cursor: pointer; float: left; height: 194px; margin: 0pt 10px 10px 0pt; width: 227px;" /></a><br />
<br />
<div style="text-align: left;">
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
Hi friends,<br />
here is my home-made kit of ATmega32 microcontroller interfacing. The ATmega32 controller is rich with features like onboard 32kB in-System programmable flash, 1 KB EEPROM, 2KB SRAM, 10bit ADC (8 channel), SPI bus inteface, TWI (compatible with I2C bus) interface, an USART, analog comparator, etc. That's why I've selected it to load my kit with all those features.<br />
<br />
This M32 card is having an LCD inteface with contrast adjustment, an RS232 port for connecting with PC, a connector for 8 analog voltage inputs to measure by ADC, a Real Time Clock IC DS1307 from maxim with battery back-up, four general purpose keys, two keys for generating interrupts and an LED.<br />
The circuit can be powered by an easily available 12v DC adapter. The voltage regulator IC 7805 used to convert the input into regulated 5v supply.<br />
<br />
See below the kit in powered on condition and the schematic (click to enlarge the images)<br />
<br />
<a href="http://1.bp.blogspot.com/_zqABT3suzXE/SLksklsXEFI/AAAAAAAAAFc/RdUU7gmLKYQ/s1600-h/DSC00176.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5240268648527368274" src="https://1.bp.blogspot.com/_zqABT3suzXE/SLksklsXEFI/AAAAAAAAAFc/RdUU7gmLKYQ/s320/DSC00176.jpg" style="cursor: pointer; float: left; height: 175px; margin: 0pt 10px 10px 0pt; width: 205px;" /></a><a href="http://2.bp.blogspot.com/_zqABT3suzXE/SLp8dnL3NwI/AAAAAAAAAGM/4wGUNgnMLp0/s1600-h/M32_Schematic.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5240637964575782658" src="https://2.bp.blogspot.com/_zqABT3suzXE/SLp8dnL3NwI/AAAAAAAAAGM/4wGUNgnMLp0/s320/M32_Schematic.JPG" style="cursor: pointer; float: left; height: 173px; margin: 0pt 10px 10px 0pt; width: 241px;" /></a><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
The PCB is completely home-made, using the etching technique with the Ferric Chloride chemical. If you want to know how to make a PCB yourself from your layout, visit following webpage, it's really helpful:<br />
<br />
<a href="http://electrons.psychogenic.com/modules/arms/art/10/pcb_howto.php">http://electrons.psychogenic.com/modules/arms/art/10/pcb_howto.php</a><br />
<br />
The schematic and layout of the M32_card shown here are prepared using EAGLE. It's a single layer board for making the home-preparation easy. Check out the bottom layer and the layouts in the pics below:<br />
<br />
<a href="http://4.bp.blogspot.com/_zqABT3suzXE/SLp9AsMprQI/AAAAAAAAAGU/nOVrj71vCWg/s1600-h/M32_sch.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5240638567216688386" src="https://4.bp.blogspot.com/_zqABT3suzXE/SLp9AsMprQI/AAAAAAAAAGU/nOVrj71vCWg/s320/M32_sch.JPG" style="cursor: pointer; float: left; height: 173px; margin: 0pt 10px 10px 0pt; width: 223px;" /></a><a href="http://1.bp.blogspot.com/_zqABT3suzXE/SLp9nP2keYI/AAAAAAAAAGc/0my8qnwjBqM/s1600-h/M32_pcb.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5240639229622778242" src="https://1.bp.blogspot.com/_zqABT3suzXE/SLp9nP2keYI/AAAAAAAAAGc/0my8qnwjBqM/s320/M32_pcb.JPG" style="cursor: pointer; float: left; height: 172px; margin: 0pt 10px 10px 0pt; width: 217px;" /></a><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
The software for the ATmega32 controller is written using imageCraft AVR compiler. The software contains code for LCD interface, use of RTC and communication with PC with RS232 port. Using the Hyper terminal in windows, the functionality of the kit can be checked, as I've mentioned in my previous post of RTC_EEPROM interface with ATmega128.<br />
Sown below are the pics of RTC circuit in test and related screen shot of the hyper terminal while interacting with the M32_Card<br />
<br />
<a href="http://4.bp.blogspot.com/_zqABT3suzXE/SLzaeXXckyI/AAAAAAAAAGo/9DpEV3GVRew/s1600-h/RTC_display.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5241304281555702562" src="https://4.bp.blogspot.com/_zqABT3suzXE/SLzaeXXckyI/AAAAAAAAAGo/9DpEV3GVRew/s200/RTC_display.jpg" style="cursor: pointer; float: left; height: 265px; margin: 0pt 10px 10px 0pt; width: 200px;" /></a><a href="http://3.bp.blogspot.com/_zqABT3suzXE/SL9u4fMEKYI/AAAAAAAAAHQ/fOLW1pvJ2HA/s1600-h/M32_screenShot.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5242030408006379906" src="https://3.bp.blogspot.com/_zqABT3suzXE/SL9u4fMEKYI/AAAAAAAAAHQ/fOLW1pvJ2HA/s200/M32_screenShot.JPG" style="cursor: pointer; float: left; height: 260px; margin: 0pt 10px 10px 0pt; width: 141px;" /></a><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
Here is Proteus ISIS Simulation:<br />
<br />
<a href="http://1.bp.blogspot.com/-NOlvBnYF3zY/Tzfaeo-dkyI/AAAAAAAAAfQ/6FSwEZnji9o/s1600/M32_card.JPG"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5708271272645727010" src="https://1.bp.blogspot.com/-NOlvBnYF3zY/Tzfaeo-dkyI/AAAAAAAAAfQ/6FSwEZnji9o/s400/M32_card.JPG" style="cursor: pointer; display: block; height: 202px; margin: 0px auto 10px; text-align: center; width: 400px;" /></a><br />
<br />
The complete source code files including new addition of ADC (check out <a href="http://www.dharmanitech.com/2008/09/using-m32card-for-data-acquisition-with.html">Here</a>) can be downloaded below.<br />
<br />
<br />
<span style="font-weight: bold;">Download</span><br />
----------------<br />
<a href="https://drive.google.com/file/d/0B53C_HLwEgi-NTJPaUY4d3VMQnc/view?usp=sharing&resourcekey=0-QQ_nRlH5u6-NGRFVGbFJCg" style="font-weight: bold;">Source code</a><br />
<a href="https://drive.google.com/file/d/0B53C_HLwEgi-cUxOaERTajhWUUE/view?usp=sharing&resourcekey=0-fvH0IubdxMamhq6jPGvWTw"><span style="font-weight: bold;">PCB files </span>(in PDF & EAGLE formats)</a><a href="https://drive.google.com/file/d/0B53C_HLwEgi-WUNlMnpNVDZyejQ/view?usp=sharing&resourcekey=0-9LCl15LWv4XhI6LivN79_Q"><span id="formatbar_Buttons" style="display: block;"><span id="formatbar_CreateLink" onmousedown="CheckFormatting(event);FormatbarButton('richeditorframe', this, 8);ButtonMouseDown(this);" onmouseout="ButtonHoverOff(this);" onmouseover="ButtonHoverOn(this);" onmouseup="" style="display: block;" title="Link"><img alt="Link" border="0" class="gl_link" src="https://www.blogger.com/img/blank.gif" /></span></span><span style="font-weight: bold;">Proteus Simulation Model</span></a><br />
<br />
<br /></div>
<div style="text-align: left;">
Datasheets:</div>
<div style="text-align: left;">
<a href="http://ww1.microchip.com/downloads/en/DeviceDoc/doc2503.pdf">ATmega32</a> <a href="https://datasheets.maximintegrated.com/en/ds/DS1307.pdf">DS1307</a> <a href="http://pdf.datasheetcatalog.com/datasheet/maxim/MAX220-MAX249.pdf">MAX232</a></div>
<div style="text-align: left;">
<br />
<br />
--------<br />
ccd@dharmanitech.com</div>
CC Dharmanihttp://www.blogger.com/profile/13217855743473839524noreply@blogger.com224tag:blogger.com,1999:blog-8014888555955763990.post-56180751437578833082008-08-15T03:27:00.001+05:302021-09-26T16:30:00.257+05:30Interfacing RTC & serial EEPROM using i2c bus, with ATmega128 uC<a href="http://4.bp.blogspot.com/_zqABT3suzXE/STggK8W6eCI/AAAAAAAAAN0/3WQF7JEff-4/s1600-h/RTC_EEPROM_Sch.jpeg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" height="349" id="BLOGGER_PHOTO_ID_5276002335837550626" src="https://4.bp.blogspot.com/_zqABT3suzXE/STggK8W6eCI/AAAAAAAAAN0/3WQF7JEff-4/s400/RTC_EEPROM_Sch.jpeg" style="float: left; margin: 0pt 10px 10px 0pt;" width="400" /></a><a href="http://3.bp.blogspot.com/_zqABT3suzXE/STggStWeQPI/AAAAAAAAAN8/OUAfUj3mqxg/s1600-h/RTC_EEPROM_Hyp.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" height="320" id="BLOGGER_PHOTO_ID_5276002469248123122" src="https://3.bp.blogspot.com/_zqABT3suzXE/STggStWeQPI/AAAAAAAAAN8/OUAfUj3mqxg/s320/RTC_EEPROM_Hyp.JPG" style="float: left; margin: 0pt 10px 10px 0pt;" width="144" /></a><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
Hi friends,<br />
here is my experiment with i2c bus for interfacing serial EEPROM (24C256) and RTC (DS1307) using AVR microcontroller ATmega128. The circuit is also provided with an RS232 port for connecting with PC to send commands for reading/writing EEPROM or setting date/time in RTC (Click on images to enlarge them).<br />
<br />
Communication with PC is done through Hyper Terminal. A screen shot of the message sent to PC by microcontroller immediately after power ON is shown in the figure at the left, where the user is asked to enter choice from the menu options related to EEPROM and RTC. User can store data in EEPROM, or set RTC date and time by entering them using PC keyboard.<br />
Hyper Terminal is used with 19200 Baud, No parity, No hardware flow control settings.<br />
<br />
When the circuit is powered on, a welcome message is displayed on the Hyper Terminal window and a menu with 9 options (0-8) is displayed (refer to the figure). The options are explained here:<br />
<br />
0: Erase EEPROM (fills eeprom with 0xff bytes)<br />
1: Write EEPROM (starts writing eeprom starting with 0x0000 address)<br />
2: Read EEPROM (reads eeprom starting with 0x0000 address)<br />
3: Write eeprom page (writes one page of eeprom at specified page number)<br />
4: Read eeprom page (Reads one page of eeprom at specified page number)<br />
5: Display RTC Date (Displays current date from RTC)<br />
6: Display RTC time (Displays current time from RTC)<br />
7: Update RTC Date (Setting new date in RTC)<br />
8: Update RTC time (Setting new time in RTC)<br />
<br />
The option is selected from PC keyboard. While writing to eeprom or RTC the data is entered using PC keyboard as specified by the program.<br />
<br />
The software routines include DS1307 library, 24C256 library & I2C library along with the main function.<br />
<br />
The code is written in C using winAVR (inside AVRStudio). The complete project folder can be downloaded here in zip format (<span color="rgb(255 , 0 , 0)">updated on 25-April-2009, <span color="rgb(51 , 51 , 51)">earlier it was in ICCAVR</span></span> format):<br />
<br />
Here is running simulation on Proteus ISIS (click on image to enlarge it):<br />
<br />
<a href="http://2.bp.blogspot.com/-G56TEZ_Pfcs/TzfQPraOFWI/AAAAAAAAAfE/tZHDplascwE/s1600/RTC_EEPROM.JPG"><img alt="" border="0" height="355" id="BLOGGER_PHOTO_ID_5708260020484707682" src="https://2.bp.blogspot.com/-G56TEZ_Pfcs/TzfQPraOFWI/AAAAAAAAAfE/tZHDplascwE/s640/RTC_EEPROM.JPG" style="display: block; margin: 0px auto 10px; text-align: center;" width="640" /></a><br />
<span style="font-weight: bold;">Downloads</span><br />
------------------<span style="text-decoration: underline;"><span style="font-weight: bold;"><br /></span></span><a href="https://drive.google.com/file/d/1T9aj-x8rFutdRf-e5FOjXA_RVRjWagWU/view?usp=sharing" style="font-weight: bold;">Complete Source code </a>(winAVR, AVRStudio-4 format)<br />
<a href="https://drive.google.com/file/d/0B53C_HLwEgi-NjM3enZQM0N6bXM/view?usp=sharing&resourcekey=0-LDbayAtVywoviJaYLgu8rQ" style="font-weight: bold;">Proteus Simulation Model</a><br />
<br />
<br />
<div>
Datasheets:<br />
<a href="http://ww1.microchip.com/downloads/en/DeviceDoc/doc2467.pdf">ATmega128</a>, <a href="http://pdf.datasheetcatalog.com/datasheet/maxim/MAX220-MAX249.pdf">DS1307</a>, <a href="http://pdf.datasheetcatalog.com/datasheet/fairchild/FM24C256.pdf">FM24C256</a>, <a href="http://www.datasheetcatalog.org/datasheet/texasinstruments/max232.pdf">MAX232</a></div>
<div>
<br />
Thanks!<br />
<br />
(<span color="rgb(255 , 0 , 0)">last updated on 25-April-2009</span>)<br />
---------<br />
ccd@dharmanitech.com</div>
CC Dharmanihttp://www.blogger.com/profile/13217855743473839524noreply@blogger.com115tag:blogger.com,1999:blog-8014888555955763990.post-66511138324079321232008-08-06T22:38:00.000+05:302008-09-03T19:00:25.470+05:30opamp Precision Rectifier<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_zqABT3suzXE/SJnmZ7V7wQI/AAAAAAAAADQ/YcbIBrDxDMs/s1600-h/precRect.JPG"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://2.bp.blogspot.com/_zqABT3suzXE/SJnmZ7V7wQI/AAAAAAAAADQ/YcbIBrDxDMs/s320/precRect.JPG" alt="" id="BLOGGER_PHOTO_ID_5231465775268348162" border="0" /></a>Hi friends,<br />this is a simple opamp precision rectifier. Very useful in rectifying or making bipolar signals unipolar, specially in small signals where we cannot afford to have that 0.7v drop across the normal diode bridge rectifier.<br />The circuit shown here gives rectified output going only in the negative direction, as my application required it that way. But if you want rectified positive output, just reverse the direction of both the diodes and you'll get it!CC Dharmanihttp://www.blogger.com/profile/13217855743473839524noreply@blogger.com56tag:blogger.com,1999:blog-8014888555955763990.post-4957260901457999762008-07-27T21:38:00.000+05:302010-12-18T21:42:15.824+05:30USART-to-USB converter using FT232BM chip<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp1.blogger.com/_zqABT3suzXE/SIyenbCSo3I/AAAAAAAAADI/8YL_41gwmRY/s1600-h/FT232BM.JPG"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://bp1.blogger.com/_zqABT3suzXE/SIyenbCSo3I/AAAAAAAAADI/8YL_41gwmRY/s320/FT232BM.JPG" alt="" id="BLOGGER_PHOTO_ID_5227727667579757426" border="0" /></a>Hi guys,<br /> here is an easy an popular way to start using USB in your designs without going into learning the complicated USB protocol. This circuit converts normal USART signals from any microcontroller into USB compatible signals which can be directly connected to the PC. If u r designing a circuit and u need pc interface, then this is the best way, use USB, as the RS232 ports are disappearing from PCs and laptops very fast.<br /><br /> This circuit is as suggested by FTDI's datasheet for the device FT232BM. It also includes an EEPROM to input your device name which will appear in PC when u connect your circuit to PC. The Tx and Rx LED indication is also provided.<br /><br /> Drivers for this IC are available free on FTDI's website mentioned below. The drivers create virtual serial comm ports, hence keep the USB protocol completely in background. U can program yr controller just like u r designing it for RS232 communication!!<br /><br /><span style="font-weight: bold;">New!</span> (21 May 2010)<br /><br />FTDI has released a RS232 to USB converter in DB9 connector package, an easiest way to migrate from RS232 to USB without any change in your PCB, you can have the footprint of DB9 female connector but place this module instead and you are USB ready!! Really cool!!!<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_zqABT3suzXE/S_YcLCGyeRI/AAAAAAAAAXA/mhnCF1WASes/s1600/rs232-usb.JPG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 400px; height: 141px;" src="http://3.bp.blogspot.com/_zqABT3suzXE/S_YcLCGyeRI/AAAAAAAAAXA/mhnCF1WASes/s400/rs232-usb.JPG" alt="" id="BLOGGER_PHOTO_ID_5473593372984899858" border="0" /></a><br />More info: http://www.ftdichip.comCC Dharmanihttp://www.blogger.com/profile/13217855743473839524noreply@blogger.com25tag:blogger.com,1999:blog-8014888555955763990.post-47429692764808368922008-07-26T22:59:00.000+05:302010-11-01T11:30:52.658+05:30Ring Detector for Caller ID Unit<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp2.blogger.com/_zqABT3suzXE/SIti_-Ve9qI/AAAAAAAAADA/2r7r0xNyh4w/s1600-h/ring+detector.JPG"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 458px; height: 150px;" src="http://bp2.blogger.com/_zqABT3suzXE/SIti_-Ve9qI/AAAAAAAAADA/2r7r0xNyh4w/s320/ring+detector.JPG" alt="" id="BLOGGER_PHOTO_ID_5227380643697981090" border="0" /></a>Hi Friends,<br /> this is an addition to the <a href="http://www.dharmanitech.com/2008/07/hi-friends-one-more-circuit-dtmf.html">caller ID circuit</a> of my previous post. For deciding whether call is received call or missed call, u need to monitor the ringing signal along with the off-hook detector signal, which is discussed in the last post. If the off-hook detector signal goes low (i.e. receiver lifted) before the ringing signal stops, then the call is labeled as received call, otherwise it is a missed call.<br /> This small circuit converts the ringing signal (sine wave 90vrms) into 5v dc pulses which can be directly fed to microcontroller pin. The circuit outputs a pulse for each ring. The delay between two pulses is to be monitered and if it exceeds 4 sec, then ring is dead, hence, the call is missed call.!<br /> Try it out..CC Dharmanihttp://www.blogger.com/profile/13217855743473839524noreply@blogger.com32tag:blogger.com,1999:blog-8014888555955763990.post-46979971963911899652008-07-25T18:41:00.000+05:302010-12-18T21:37:29.707+05:30Design Caller ID using DTMF decoder MT8870<a href="http://bp2.blogger.com/_zqABT3suzXE/SInTNjOZPrI/AAAAAAAAACw/lwI65X2uaeE/s1600-h/DTMF+Decoder.JPG"><img id="BLOGGER_PHOTO_ID_5226941072287547058" style="margin: 0px auto 10px; display: block; text-align: center; width: 368px; height: 234px;" alt="" src="http://bp2.blogger.com/_zqABT3suzXE/SInTNjOZPrI/AAAAAAAAACw/lwI65X2uaeE/s320/DTMF+Decoder.JPG" border="0" /></a><br />Hi friends,<br /><div>one more circuit: DTMF decoder interface for designing Caller ID Unit. It's very simple circuit using DTMF decoder MT8870 (or CM8870). As shown in the circuit, u'll receive an interrupt ( if NAND output is connected to INT of the microcontroller) whenever u receive a call or make a call and then u can use yr program to read the digits coming out of pin 11 to 14 of the MT8870. I designed the circuit with additional features like seperating received calls, missed calls, dialled numbers along with telephone directory.<br /><br /></div><div>Download datasheet:</div><div> <a href="http://www.datasheet4u.com/download.php?id=268108">MT8870</a></div><div> <a href="http://www.datasheetcatalog.org/datasheet/calmicro/CM8870.pdf">CM8870</a></div><div><br /></div><div>To determine whether number is dialled or received, u need to know whether receiver is on-hook or off-hook. following simple circuit will give u that indication:<br /><br /></div><div></div><div><a href="http://bp0.blogger.com/_zqABT3suzXE/SInTEjuvfiI/AAAAAAAAACo/bzLs7NdhK28/s1600-h/off-hook+detector.JPG"><img id="BLOGGER_PHOTO_ID_5226940917804400162" style="margin: 0px auto 10px; display: block; text-align: center; width: 372px; height: 277px;" alt="" src="http://bp0.blogger.com/_zqABT3suzXE/SInTEjuvfiI/AAAAAAAAACo/bzLs7NdhK28/s320/off-hook+detector.JPG" border="0" /></a><br />I had used microcontroller 8951 with16x2 LCD and Dallas nvRAM for storing numbers and names. The code is in assembly language. It's really easy to make this one with lot of variations. </div><div><br />Check out my next post on <a href="http://www.dharmanitech.com/2008/07/ring-detector-for-caller-id-unit.html">telephone ring detector</a> to check whether the call is received call or missed call.<br /><br />----------<br />ccd@dharmanitech.com<br /></div>CC Dharmanihttp://www.blogger.com/profile/13217855743473839524noreply@blogger.com79tag:blogger.com,1999:blog-8014888555955763990.post-56172558687292091882008-07-17T23:58:00.000+05:302010-12-18T21:45:45.715+05:30Rate or Position measurement using Solid State Gyroscope<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_zqABT3suzXE/TQzeAfpOmWI/AAAAAAAAAZ0/TohtCnnb1ZY/s1600/gyro_pcb_lcd.JPG"><img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 400px; height: 213px;" src="http://2.bp.blogspot.com/_zqABT3suzXE/TQzeAfpOmWI/AAAAAAAAAZ0/TohtCnnb1ZY/s400/gyro_pcb_lcd.JPG" alt="" id="BLOGGER_PHOTO_ID_5552056540716767586" border="0" /></a><br />updated:14/08/08<br /><br /><div>Hi friends,<br />here is a circuit to measure rate of a rotating object using solid state gyro ADXRS150 (used here is DIP sized evaluation version). this circuit gives output of -10v to +10v for rate upto 80 deg/sec in both the directions (i.e. -80 to +80 deg/sec). A direction o/p logic signal is also there to feed to microcontroller. Temperature of gyroscope also can be measured with onchip ADC of the microcontroller like ATmega32 (describd in previos post), which can be used for temperature compensation of the gyro o/p.<br /><br />find the detailed datasheet of ADXRS150 here:<br /><a href="http://www.analog.com/static/imported-files/data_sheets/ADXRS150.pdf">ADXRS150 Datasheet</a><br /><span class="a"><br /></span></div>CC Dharmanihttp://www.blogger.com/profile/13217855743473839524noreply@blogger.com41tag:blogger.com,1999:blog-8014888555955763990.post-23118380662476206532008-07-13T23:25:00.001+05:302021-09-26T16:33:26.979+05:30interfacing ATmega32<p><a href="http://bp0.blogger.com/_zqABT3suzXE/SHpDv3RxzvI/AAAAAAAAACA/Pu0inwu5Tg4/s1600-h/ATmega32_interface.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5222561207460941554" src="http://bp0.blogger.com/_zqABT3suzXE/SHpDv3RxzvI/AAAAAAAAACA/Pu0inwu5Tg4/s320/ATmega32_interface.JPG" style="cursor: pointer; display: block; margin: 0px auto 10px; text-align: center;" /></a> </p><p>Hi techies!! </p><p>This is one more of my circuits, interfacing ATmega32 with an LCD and a DAC. it also includes two general purpose push-buttons and In System Programming connector. The controller is operating with 14.7456 MHz frequency crystal, convenient for gene</p><p>rating standard baud rates (for RS422 communication which I used in my actual project, not shown here).
The Atmel AVR controller ATmega32 is a very powerful chip with 1 MIPS/MHz throughput and contains a lots of on-chip peripherals like UART, SPI, 32bits I/O, TWI(I2C compatible), versatile timer/counters and lot more..
the LCD and DAC driver functions are written in C(using imageCraft compiler)
</p><p><a href="https://docs.google.com/document/d/1R27daPXfEjw-XVDlKwpdlgMlJWxCQuCfgjD56ddaEDo/edit" style="font-weight: bold;">Download schematic & code for LCD interfacing</a> </p><p>Enjoy!</p>CC Dharmanihttp://www.blogger.com/profile/13217855743473839524noreply@blogger.com18tag:blogger.com,1999:blog-8014888555955763990.post-20719355746633489502008-07-12T17:05:00.000+05:302008-07-12T17:14:32.981+05:30<span style="font-weight: bold;">Hi</span> all the<span style="color: rgb(0, 0, 153);"> <span style="font-weight: bold;">techy</span></span> guys!!! welcome to this blog!<br />I love designing things with microcontroller,<br />so here I m, to share the my ideas with you guys and to know your ideas!!<br /><span style="font-style: italic; color: rgb(255, 0, 0);">Start Blogging!!!</span>CC Dharmanihttp://www.blogger.com/profile/13217855743473839524noreply@blogger.com19