Showing posts with label blinking. Show all posts
Showing posts with label blinking. Show all posts

Friday, January 09, 2015

Arduino 101 - Blinking LED using Arduino

This tutorial is for the beginners who have just bought a arduino and want to start using it. Just like while learning programming we start with a simple program of Hello World!, in embedded systems we start by blinking an led. Before we start i want to give a brief introduction of how a arduino program or sketch looks like? For writing and uploading sketch to arduino you will need arduino IDE which can be downloaded from here

Arduino Sketch:

Every arduino program also called as sketch has 2 parts:
  1. Initialization Part : Where we define things and initialize any arduino peripheral like Serial or USB Connection and Input / Output Port.
  2. Infinite Loop : After initialization is complete there is a infinite loop in which arduino runs till it is not reset or switched off.
If things are not clear, after you will see the code below, i hope everything will be clear.

Code for Blinking Led: 


Some Explanation of Code: 

The two parts discussed above are implemented in code as setup() function and loop() function. In arduino led is connected to pin number 13 so we name a variable ledPin for our convenience.

The setup() block runs only once and initializes all the peripherals and assignments. Then the pinMode(pinNumber, direction) function assigns the mode of pin, (in our case pin number 13 or ledPin) as OUTPUT, because we want to output high or low voltage level so that our led lights up. If you are reading the voltage level of the pin then you have to choose the  direction as INPUT.

Now, the loop() function block, this block runs continuously till the reset or power off of the board. In this block there are two functions digitalWrite(pinNumber, Value) and delay(milliseconds). digitalWrite(pinNumber, Value) writes value (either LOW or HIGH) to the pinNumber and delay(milliseconds) is used to give accurate time delays between any two sequence of instruction.

Now upload this code using Arduino IDE to Arduino Board and you will see the led light blinking at an interval of 1sec.




Thursday, July 17, 2014

Blink Led Project in CCS 5 with TivaWare C library for Tiva-C Launchpad Microcontrollers

TivaWare Library:
TivaWare Peripheral Driver Library is an extensive C library for accessing the peripherals on Tiva C launchpad microcontrolller. This library makes it easy to use the device peripherals without knowing a lot about the internal registers. So, it is helpful as you don't need to look at the datasheet and bit banging for programming a simple application like blinking an led.
TivaWare Library can be downloaded from here: http://www.ti.com/tool/sw-tm4c 

Complete TivaWare Library includes:

  • Royalty free libraries(Peripheral, USB, Graphics , Sensor)
  • Kit and peripheral specific code
  • Release note and other documentation
Documentation for TivaWare Library could be downloaded from here: http://www.ti.com/lit/pdf/spmu298

Code Composer Studio is and Integrated development environment that supports Texas Instruments Microcontrolllers and Processors. CCS could e downloaded freely from here: http://www.ti.com/tool/ccstudio

How to build and debug a new project in CCS with TivaWare C library:
  1. Open Code Composer Studio. 
  2. Click on the New -> CCS Project.

  3. Give a Project Name, Select Family -> ARM, Variant -> Tiva TM4C123GH6PM, Connection -> Stellaris ICDI then click on Finish.

Now for Adding the TivaWare Library in your newly created project 
  1. Right Click on your Project and then goto Properties. A properties window will open like the shown below
  1.  
  2. Then goto Build -> ARM Compiler -> Include Options in the list Add dir to #include search path click on Add.

  3. A Add directory path dialog box will open. Click on File System , Browse to TivaWare installed location (by default it go to C:\ti\TivaWare_C_Series_version_no.) Click on Ok and then again OK.

  4. Now go to ARM Linker option, then File Search Path. Click on Add -> File System and then search for driverlib.lib in your installedLibraryPath\driverlib\ccs\debug\driverlib.lib , then Click on OK.

     
  5. If you don't do this linker step the you will get a linking error.

Compiling and Debugging the Code:

  • In this tutorial i will be compiling a simple blinking code given below. For Compiling and Debugging your Code. Right Click on Project then Click on Build Project.

     
  • After compiling and building has been finished . Click on Run -> Debug to start debugging of your program. Tiva C lets you debug your code while running it on real hardware so that you can know whats going on inside.



Debugger on Tiva C Launchpad is very helpful in finding small bugs as we can see full registers value and memory location. And Here is my Blinking LED on Tiva C Launchpad.


Thank you , comments to improve this article will be appreciated.