Difference between revisions of "Lesson 1--Microduino "LED and a Breadboard""

From Microduino Wiki
Jump to: navigation, search
(Created page with "{| style="width: 800px;" |- | ==Objective== Using Microduino to control a LED. Actually you can learn to how to use the Micrduino's I/O port. This is a basic skill you should ...")
 
 
(21 intermediate revisions by 6 users not shown)
Line 1: Line 1:
 +
{{Language|第一课--LED灯闪烁实验(面包板的使用)}}
 
{| style="width: 800px;"
 
{| style="width: 800px;"
 
|-
 
|-
 
|
 
|
 
==Objective==
 
==Objective==
Using Microduino to control a LED. Actually you can learn to how to use the Micrduino's I/O port. This is a basic skill you should master and for further study.
+
This lesson will teach you how to use Microduino to control a LED. Once you are familiar with Microduino's I/O ports, you will have developed solid fundamentals for future projects.
  
 
==Equipment==
 
==Equipment==
 
*'''[[Microduino-Core]]'''
 
*'''[[Microduino-Core]]'''
Microduino-Core is a 8-bit microcontroller development board based on Atmel ATmega328P, ATmega168PA series, and is an open source, compatible with Arduino UNO controller module.
+
Microduino-Core is an 8-bit microcontroller development board based on Atmel ATmega328P, ATmega168PA series. It is open source and compatible with the Arduino UNO.
 
 
Detailed information, please refer to http://wiki.microduino.net/index.php?title=Microduino-Core
 
  
 
*'''[[Microduino-FT232R]]'''
 
*'''[[Microduino-FT232R]]'''
Download program module, connect with Microduino-Core or Microduino-Core+ directly and communicate with PC. It uses MicUSB  as the download port. And it has the same size with a dollar coin. Download line with most smart phones usb data cable is the same, convenient and practical
+
This module is used to upload your program into the core. You can stack it directly onto the Microduino-Core or Microduino-Core+ and communicate with your PC. Similar to many smartphones, it uses a MicroUSB as the download/upload port.
  
Detailed information, please refer to http://wiki.microduino.net/index.php?title=Microduino-FT232R
+
*Other hardware equipment:
 +
**1x Box of breadboard jumper wires 
 +
**1x Breadboard
 +
**8x LEDs (Light-Emitting Diodes)
 +
**1x 220ohm resistor 
 +
**1x USB Data cable
  
*Other hardware equipment
+
[[File:lesson1Main.jpg|350px|center|thumb]]
**Breadboard Jumper            one box 
+
[[File:lesson1All.jpg|350px|center|thumb]]
**Breadboard                one piece
 
**LED Light-emitting diodes    one
 
**220ohm resistor       one 
 
**USB Data cable              one
 
  
 
===Breadboard===
 
===Breadboard===
In the vertical direction,5 points connected together and 25 points connected together in a horizontal direction. Some bread has 50 points connected together, so make sure connection format before you use it, in order to avoid generating erroneous results. The next two rows of points 50 have more usage, one row as GDN, the other row as VCC. Please refer to the following picture.
+
In the breadboard provided in the picture, for the two long strips in the middle,every 5 points are connected vertically. For the four strips running along the outer board, every 25 points are connected horizontally.  For the outer two strips, one row is usually connected to GND and the other to VCC.
 +
<br><br>
 +
Note: In some breadboards, all 50 points are connected together in the outer strips. The breadboard provided in the Microduino Basic Tutorial Kit has 30 points all connected together in the outer two strips. Be aware of the connection format when working on projects.
  
[[File:面包板使用.jpg|600px|center|thumb]]
+
[[File:breadboard.jpg|600px|center|thumb]]
  
 
===Resistor and LED===
 
===Resistor and LED===
Limiting resistor is used to prevent LED burned. Usually red and green LED voltage is 1.8 ~ 2.4V, blue and white is 2.8 ~ 4.2V, 3mmLED rated current is 1 ~ 10mA, 5mmLED rated current is 5 ~ 25mA, and 10mmLED rated current is 25 ~ 100mA. According to R = U / I to the calculated resistance. Usually hundreds of ohm should be ok.
+
Resistors prevent your LED from being damaged by limiting the voltage supplied. Max voltage for red and green LEDs is 1.8 ~ 2.4V, blue and white is 2.8 ~ 4.2V. 3mmLED rated current is 1 ~ 10mA, 5mmLED rated current is 5 ~ 25mA, and 10mmLED rated current is 25 ~ 100mA. You can use Resistance = Voltage / Current to calculate the resistance required. 200-400 ohms of resistance is usually adequate.
 +
 
 +
'''How to Judge the Positive/Negative Ends of a LED Light'''
 +
 
 +
*Method One: Take a look inside the LED light. The pin with a bigger bracket is negative and the one with a smaller bracket is positive.
 +
*Method Two: For a new LED light, you can tell from the length of the pins. The longer pin is positive and and the shorter pin is negative.
 +
 
 +
'''Test a LED Light via a Multimeter'''
 +
 
 +
When using an analog multimeter to test a diode, you must choose the "Rxl0k" slot since the voltage of the battery inside the multimeter is only 1.5V when the multimeter is under the "R×lk" slot, lower than the voltage drop of a 3V LED light. In that case, it is impossible to test LED lights no matter what connection method you adopt. While the analog multimeter is under the "R×l0k" slot, you can test the LED light for the voltage of the battery is about 9V(or 15V), higher than the voltage drop.
 +
 
 +
Since the black probe of the analog multimeter shows positive and the red probe shows negative, you need to connect the black probe to the positive of the LED light and the red probe to the negative. If the LED lights up, then it works.
  
==Experimental schematic==
+
Different from the analog multimeter, the digital multimeter shows contrary electrode. Adopting the right connection method, you will know the LED is working when it lights up.
There are two connection methods, one is that led cathode connects to GND, anode connects to Microduino digital I/O port 13, which is the high light led. The other method ist that led cathode connected Microduino digital I/O port 13, anode connects to VCC, so that low-level light led.
 
  
 +
==Experiment Schematic==
 +
There are two connection methods:
  
[[File:原理图.jpg|600px|center|thumb]]
+
*Method One: Connect the positive end (anode) to Microduino digital I/O port 13 and the negative end (cathode) to GND. This creates a high level connection.
 +
*Method Two: Connect the anode to Microduino digital I/O port 13 and the cathode to VCC. This creates a low level connection.
 +
 
 +
[[File:schematic.jpg|600px|center|thumb]]
 +
 
 +
[[File:lesson1Setup.jpg|600px|center|thumb]]
  
 
==Program==
 
==Program==
*采用delay()函数:
+
*Using delay() function:
  
 
<source lang="cpp">
 
<source lang="cpp">
int led = 13;//定义引脚
+
int led = 13;// Define the PIN
 
void setup() {                 
 
void setup() {                 
   pinMode(led, OUTPUT);  //定义microduino数字13脚为输出    
+
   pinMode(led, OUTPUT);  // Define the I/O port 13 as output    
 
}
 
}
 
void loop() {
 
void loop() {
digitalWrite(led, HIGH); //数据13口输出高,若接法是高电平点亮则点亮,反之则熄灭
+
digitalWrite(led, HIGH); //Set I/O port 13 output as High.In high level connection: LED will turn on; low level connection: LED will turn off
delay(1000);              // 延时1s
+
delay(1000);              // delay 1s
digitalWrite(led, LOW); //数据13口输出低,若接法是高电平点亮则熄灭,反之则点亮 
+
digitalWrite(led, LOW); //Set I/O port 13 output as Low.In high level connection: LED will turn off; low level connection: LED will turn on
delay(1000);              // 延时1s
+
delay(1000);              // delay 1s
 
}
 
}
 
</source>
 
</source>
  
*采用milles():返回自Microduino板开始运行当前程序的毫秒数
+
*Using function millis():Returns the number of milliseconds from when the program started running.
 +
 
 
<source lang="cpp">
 
<source lang="cpp">
 
int ledPin=13;
 
int ledPin=13;
Line 78: Line 98:
 
</source>
 
</source>
  
采用millis()比delay()函数效果更好,占用资源少,对系统拖延较少。
+
Although the code looks more complicated when using millis(), it is more efficient than the delay() function since it uses less resources and causes fewer delays on the system. It may not be of concern for now and you are free to use delay(), but when projects get large, using delay() may cause unintended lag.
 +
 
 +
==How To Download The Program==
 +
*Choose the board type in "tools". The "Microduino-Core(ATmega328P@16M,5V)" is used in this experiment. There are two types of 328 boards, so you need identify which type of board you are using. You can check the 0 resistor's connection method to identify.
  
==程序下载方法==
+
[[File:boardtype.jpg|600px|center|thumb]]
*选择控制板型号,本次实验使用的是Microduino-Core(ATmega328P@16M,5V)。在工具下的板卡中进行选择。328有两种,如何判断自己的板卡是哪种,可通过0电阻的接法来判断。
+
*Choose COM port in "tools". The serial port is different for everyone's computer. It is usually ports 3-5. The COM port is in "properties"->"device manager" in your computer. You also can double-click "Advanced" to change the COM port by port settings.
[[File:板卡判断.jpg|600px|center|thumb]]
+
*Compile and then download program
*选择COM端口,每个人电脑上匹配的串口都不一样,选好就可以。COM端口可在电脑属性中的设备管理器里面有个COM端口,也可以双击通过端口设置的高级来改变COM端口。
+
[[File:compile.jpg|600px|center|thumb]]
*编译下载
 
[[File:编译图.jpg|600px|center|thumb]]
 
  
[[File:下载界面.jpg|600px|center|thumb]]
+
[[File:download.jpg|600px|center|thumb]]
  
==结果==
+
==Result==
程序下载后,可看到led每隔1s闪烁一次。
+
After the download, you can see the LED flash once every second!
  
==视频==
+
[[File:lesson1OK.jpg|600px|center|thumb]]
  
 +
==Video==
 +
http://v.youku.com/v_show/id_XNzEwMDA0NzA4.html
 
|}
 
|}

Latest revision as of 07:16, 12 September 2016

Language: English  • 中文

Objective

This lesson will teach you how to use Microduino to control a LED. Once you are familiar with Microduino's I/O ports, you will have developed solid fundamentals for future projects.

Equipment

Microduino-Core is an 8-bit microcontroller development board based on Atmel ATmega328P, ATmega168PA series. It is open source and compatible with the Arduino UNO.

This module is used to upload your program into the core. You can stack it directly onto the Microduino-Core or Microduino-Core+ and communicate with your PC. Similar to many smartphones, it uses a MicroUSB as the download/upload port.

  • Other hardware equipment:
    • 1x Box of breadboard jumper wires
    • 1x Breadboard
    • 8x LEDs (Light-Emitting Diodes)
    • 1x 220ohm resistor
    • 1x USB Data cable
Lesson1Main.jpg
Lesson1All.jpg

Breadboard

In the breadboard provided in the picture, for the two long strips in the middle,every 5 points are connected vertically. For the four strips running along the outer board, every 25 points are connected horizontally. For the outer two strips, one row is usually connected to GND and the other to VCC.

Note: In some breadboards, all 50 points are connected together in the outer strips. The breadboard provided in the Microduino Basic Tutorial Kit has 30 points all connected together in the outer two strips. Be aware of the connection format when working on projects.

Breadboard.jpg

Resistor and LED

Resistors prevent your LED from being damaged by limiting the voltage supplied. Max voltage for red and green LEDs is 1.8 ~ 2.4V, blue and white is 2.8 ~ 4.2V. 3mmLED rated current is 1 ~ 10mA, 5mmLED rated current is 5 ~ 25mA, and 10mmLED rated current is 25 ~ 100mA. You can use Resistance = Voltage / Current to calculate the resistance required. 200-400 ohms of resistance is usually adequate.

How to Judge the Positive/Negative Ends of a LED Light

  • Method One: Take a look inside the LED light. The pin with a bigger bracket is negative and the one with a smaller bracket is positive.
  • Method Two: For a new LED light, you can tell from the length of the pins. The longer pin is positive and and the shorter pin is negative.

Test a LED Light via a Multimeter

When using an analog multimeter to test a diode, you must choose the "Rxl0k" slot since the voltage of the battery inside the multimeter is only 1.5V when the multimeter is under the "R×lk" slot, lower than the voltage drop of a 3V LED light. In that case, it is impossible to test LED lights no matter what connection method you adopt. While the analog multimeter is under the "R×l0k" slot, you can test the LED light for the voltage of the battery is about 9V(or 15V), higher than the voltage drop.

Since the black probe of the analog multimeter shows positive and the red probe shows negative, you need to connect the black probe to the positive of the LED light and the red probe to the negative. If the LED lights up, then it works.

Different from the analog multimeter, the digital multimeter shows contrary electrode. Adopting the right connection method, you will know the LED is working when it lights up.

Experiment Schematic

There are two connection methods:

  • Method One: Connect the positive end (anode) to Microduino digital I/O port 13 and the negative end (cathode) to GND. This creates a high level connection.
  • Method Two: Connect the anode to Microduino digital I/O port 13 and the cathode to VCC. This creates a low level connection.
Schematic.jpg
Lesson1Setup.jpg

Program

  • Using delay() function:
int led = 13;// Define the PIN
void setup() {                
  pinMode(led, OUTPUT);  // Define the I/O port 13 as output   
}
void loop() {
digitalWrite(led, HIGH); //Set I/O port 13 output as High.In high level connection: LED will turn on; low level connection: LED will turn off
delay(1000);               // delay 1s
digitalWrite(led, LOW); //Set I/O port 13 output as Low.In high level connection: LED will turn off; low level connection: LED will turn on
delay(1000);               // delay 1s
}
  • Using function millis():Returns the number of milliseconds from when the program started running.
int ledPin=13;
#define TIME 1000 
long time1=0,time2=0;
void setup()
{
  pinMode(ledPin,OUTPUT);
}
void loop()
{
if(millis()<time2+TIME)
{
digitalWrite(ledPin,HIGH);
time1=millis();
}
else 
{
digitalWrite(ledPin,LOW);
if(millis()>time1+TIME)
time2=millis();
}
}

Although the code looks more complicated when using millis(), it is more efficient than the delay() function since it uses less resources and causes fewer delays on the system. It may not be of concern for now and you are free to use delay(), but when projects get large, using delay() may cause unintended lag.

How To Download The Program

  • Choose the board type in "tools". The "Microduino-Core(ATmega328P@16M,5V)" is used in this experiment. There are two types of 328 boards, so you need identify which type of board you are using. You can check the 0 resistor's connection method to identify.
Boardtype.jpg
  • Choose COM port in "tools". The serial port is different for everyone's computer. It is usually ports 3-5. The COM port is in "properties"->"device manager" in your computer. You also can double-click "Advanced" to change the COM port by port settings.
  • Compile and then download program
Compile.jpg
Download.jpg

Result

After the download, you can see the LED flash once every second!

Lesson1OK.jpg

Video

http://v.youku.com/v_show/id_XNzEwMDA0NzA4.html