Wednesday 16 October 2013

Arduino Starter Kit - First two chapter



Today I explain you what you can expect from the first two chapter of the manual:
01 GET TO KNOW YOUR TOOLS an introduction to the concepts you'll need to use this kit
02 SPACESHIP INTERFACE design to control panel for your startship
01 GET TO KNOW YOUR TOOLS
The first chapter actually is not a proper Arduino project, instead in this chapter the authors try to introduce the world of electronic at those who not know nothing (or almost) about it.
So they introduce the concept of Series/Parallel and the Ohm's Law for calculate the current of you circuit.


This project divide it self in 4 little, microscopic, project: In the first, as you can see in the schema above, you will simply connect put in series a LED and a 220Ω (ohm) resistor. Arduino board in this case is used only as power source.


The second improve the first, adding a pushbutton between LED and resistor.
Here you can see the magic: The LED do not light until you press the button! And when you release the button the LED turn it off again! Magic, it's magic for sure...

In this rare picture you can see me do the MAGIC.





The third project explain how work two button in series, when you press only one the led do not turn on, when istead you press both button the led, like magic, turn it on. Magically magic.




The fourth, and the last of the first chapter, demonstrate how work two button in parallel. When you press either of two button the led turn it on. Enlightening.
The chapter end with an explanation of the Ohm's Law (V = A*Ω).

02 SPACESHIP INTERFACE
Ok now we know the basic of electronic, why do not try to do something more complex?
In the beginning here they give us an, IMHO, important tip: Since pin 0 and 1 are used for communicating with the computer it is best to start with pin 2.




The Code: the full code for reprogramming our board is already included inside the IDE under "Examples->10.Starter Kit-> p02_SpaceShipInterface" , but I think that writing the code by yourself is really really better considered the fact that you buy this kit for learning how to program and use Arduino.
First of all: Every Arduino program has two main function: setup() and loop(). These function need to be declared.
The setup() run once, when the Arduino is first powered on.
A function named pinMode() is needed for configure the digital pins.
Syntax: pinMode(pinNumber,IOType)
Where pinNumber is the number of the pin which you need to configure, these number are printed on the board; IOType is the type of Input/Output you want give to the pin, the accepted value are INPUT and OUTPUT , both written upper case. Be carefull : Arduino code is case sensitive.

The loop(), instead, runs continuosly after setup() has completed.
To check the voltage level use function digitalRead()
Syntax:digitalRead(pinToRead)
where pinToRead is the number of the pin as explained before.
To sent a value to the output-pin use function digitalWrite()
Syntax: digitalWrite(pin,voltLev)
pin is the number of the output-pin, voltLev can be only HIGH or LOW , which mean 1 or 0.
Another function introducted in this chapter is the delay(), which let you stop the arduino from executing anything for the period of time indicate.
Syntax: delay(mmSec)
Where mmSec is the number of millisecond you want wait.

In the original code they simply put an if/else block and when you press the button the last two led turn on once then turn off again. I think can be more nice adding an for loop block into the else block, and do more cicle of on/off to the led.

The result of this last project is the photo at the top of this post.

Ok, next post in the next days.
If you want know how I draw the schematics, I use EAGLE software with Adafruit library for arduino.

end of transmission...
Ygy Freezone


No comments:

Post a Comment