CloudX Hello-World with an LED Blink CloudX
Learning about the microcontroller could at times prove a bit difficult to start with. And some of the available learning tools sometimes do not help the situation either, they simply end up adding to some avoidable complication(s). Meanwhile, a microcontroller is an IC (integrated Circuit) chip with an on-board core processor, specially designed to have support devices like ROM memory, RAM memory, I/O ports and serial communication all integrated into it.
Thus, with this level of integration, an external interfacing of those devices no longer becomes a necessity to get awesome projects done with it.
LED blinking happens to be the simplest and most basic project with a microcontroller to see the effect of a physical output. It aids in readily understanding the basic working concept of the controllers in practical environment. Moreover, it is generally used as a kind of stepping stone example for the beginners in their microcontroller development. The LEDs are simple electronic display units.
In this LED blinking project, we will be learning how to make use of the microcontroller's I/O (input-output) ports with the aid of a very flexible and easy-to-use learning tool called the CloudX.
Here, we will be connecting up a very simple circuit using a solderless breadboard and also using a very few lines of code to control a single LED on and off repeatedly.
List Of Materials Needed
(You can readily get the project full kit via this link.)
- (i) CloudX Microcontroller and Softcard
- (ii) An LED
- (iii) A Resistor (any value from 100Ω – 1kΩ)
Step 1: Hints and Brief Overview
LEDs are a type of diode which can pass current in only direction. They emit light (ie. glow) when they are powered up; hence the name Light Emitting Diode ─LED.
- Just like any other diode, the two terminals (ie. the anode and the cathode) must be properly connected, otherwise it might lead to an instant damage.
- There is always a limitation as to the maximum amount of current every LED can safely handle, beyond which the LED burns out. Thus, a current limiting resistor has to be connected in series with it.
Identifying the right polarity of the LED is just straight forward:
the cathode (-) lead is typically the shorter one of the two; or the one located at the flat side of the LED.
Generally, knowing the specified maximum current handling of a given LED, we can always sort out the right resistor just as depicted below:
The resistor is basically used to limit current flow in a circuit. Colour bands are usually used to code the resistance value of a typical through-hole resistor. Below chart guides you through with the resistance decoding.
The resistor in use here in this project is 330Ω ±5%; having the colour code of Orange Orange Brown Gold.
Step 2: Build The Circuit
As illustrated in the schematic diagram above, the LED connects up to the microcontroller board via a (current limiting) 330Ω resistor through to p1 of the digital I/O ports.
(Or alternatively, you could make use of an on-board LED attached to p1 of the same digital I/O ports for this blink-LED project).
Power can be sourced to the board either via the USB Softcard; or via connecting an external power supply (between 7 – 12 VDC) to the VIN pin of the microcontroller board.
Step 3: Build The Source Code
The simple CloudX code goes as thus:
Let’s try to further explore the code in more detail. As could be seen, it is written in plain C Language.
The double slash // is a precursor to a comment. Comments are meant to just allow the reader readily understands what a certain part of the code is intended to; and hence not part of the actual program the CloudX executes.
The set-up section of the CloudX code typically takes care of all the necessary and prior configurations needed of the microcontroller. It is, as one of its primary jobs, to carry out the needed settings and initializations vis-à-vis the other component units it's interfacing to in a given project.
In other words, this section is to get it (the microcontroller) properly prepared, setting the stage for its finally ‘hit the ground running’ at transition into the loop section.
The loop section of the code could also be alternatively implemented in two other ways:
At this juncture, it's worthy of note to know that the main operation of a code is actually executed in the loop section of a typical program. Once the program runs into the section, it simply remains there for the rest of its life span; (of course, not until there is a sort of power-off or a reset)!
Step 4: Compile The Code
The code will have to be converted from its High Level Language (i.e. human readable) format to that which the microcontroller hardware can easily relate to, called the Machine Language (Hex format), in order for the code to be finally executed. The process is known as Compiling.
For further details on how to compile the code into an executable (hex) file, you can refer to this link.
Step 5: Burn (Load) In The Hex Code File
The already compiled executable code (i.e. hexadecimal encoding) is now to be loaded into the CloudX board via the CloudX softcard. On clicking the loader button on the menu bar of CloudX IDE, a configurable environment pops up for a few settings to be effected preparatory to the code burning.
For further details on how to burn in the code to the microcontroller, you can refer to this link.
Step 6: Power Up The Project
Now everything is set, it is now left for us to bring the project circuit alive. Once the circuit is powered on, the LED should blink accordingly as depicted below.
Now that we have learnt how to blink a simple LED, adequately equipped by this skill, we are ready to a bit advance further by adding an extra feature to the project. Hence, moving on to the next lesson, we will be learning how to manually blink the LED by toggling a button (tactile) switch.
Copy the Code
#define LED 1 //anytime the compiler sees the text LED,
//it replaces it with a numeral 1.
pinMode(LED, OUTPUT); //sets up digital I/O pin 1 (LED) as an OUTPUT pin
digitalWrite(LED, ON); //turns on LED
delayMs(1000); //keeps LED on for 1000 milliseconds (one second)
digitalWrite(LED, OFF); //turns off LED
delayMs(1000); //keeps LED off for one second