Difference between revisions of "Maple Lesson 01 - Blinking LED"

From Microduino Wiki
Jump to: navigation, search
(Created page with "{| style="width: 800px;" |- | == Objective == Using Microduino-CoreSTM32 to control the on-board LED. Actually you can learn to how to use the Micrduino-CoreSTM32's I/O port. ...")
 
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
 +
{{Language|第一课--LED灯闪烁实验}}
 
{| style="width: 800px;"
 
{| style="width: 800px;"
 
|-
 
|-
 
|
 
|
== Objective ==
+
==Objective==
Using Microduino-CoreSTM32 to control the on-board LED. Actually you can learn to how to use the Micrduino-CoreSTM32's I/O port. This is a basic skill you should master and for further study.
+
Use the Microduino-CoreSTM32 to control a LED light, and use the Maple IDE to program for the Microduino-CoreSTM32, just like programming in the Arduino IDE.
  
== Prerequisites ==
+
==Equipment==
 +
*[[ Microduino-CoreSTM32]]
 +
Microduino-CoreSTM32 is an ARM development board using STM32F103CBT6 chip. It use special Upin7 interface, the size is similar with a coin and fully compatible other Microduino modules.
 +
 
 +
*Other hardware equipment
 +
**Breadboard Jumper one box
 +
**Breadboard one piece
 +
**LED Light-emitting diodes one
 +
**220ohm resistor one
 +
**USB Data cable one
  
*'''[[Setting Up Maple IDE for Microduino-CoreSTM32]]]'''
 
  
== Equipment ==
+
==Experiment schematic==
*'''[[Microduino-CoreSTM32]]'''
 
Microduino-CoreSTM32 is a 32-bit ARM Cortex-M3 development board, based on STMicroelectronics' STM32F103CBT6.
 
  
*Other hardware equipment
+
*There are two connection methods:
**USB Data cable                  1(one) piece
+
**LED cathode connects the GND of Microduino-CoreSTM32, and anode connects to Microduino digital I/O port 13, which is the high-level light led.
 +
**LED cathode connects Microduino-CoreSTM32 digital I/O port 13, anode connects to VCC, so that low-level light led.
 +
[[File: STM32-lesson1Setup.jpg|600px|center|thumb]]
  
== Program ==
+
This experiment will use the first method, you can try another method.
*Using delay() function:
 
  
 +
==Program==
 
<source lang="cpp">
 
<source lang="cpp">
int led = 13;// Define the PIN
+
int led = 13;             //Define the LED control pin
 
void setup() {                 
 
void setup() {                 
   pinMode(led, OUTPUT);  // Define the I/O port 13 as output   
+
   pinMode(led, OUTPUT);  //Define the pin as output   
 
}
 
}
 
void loop() {
 
void loop() {
digitalWrite(led, HIGH); //I/O port 13 output High. If the connection is high lighted,the LED will light, otherwise extinguished
+
digitalWrite(led, HIGH);   //Output higt voltage
delay(1000);               // delay 1s
+
delay(1000);             // Delay 1s
digitalWrite(led, LOW); //I/O port 13 output Low.If the connection is high lighted,the LED off, otherwise light.
+
digitalWrite(led, LOW);   //Output low voltage
delay(1000);               // delay 1s
+
delay(1000);           // Delay 1s
 
}
 
}
 
</source>
 
</source>
  
*Using function millis():Return the number of milliseconds from start running Microduino program to now.
+
Let's analyze the program:
 +
*Firstly define a control pin, we used the pin 13, you can can change it to (0 ~ 21) accroding to your requirement.
 +
'''Note: 0 ~ 13 mapping to D0 ~ D13 and 14 ~ 21 mapping to A0 ~ A7 on board. For example, if you want to use A0 to control the LED, need change the “int led = 13;” to “int led = 14;”'''
 +
*setup() function is the initralization function, and only is executed one time.
 +
*loop() function is a loop function which will run the inside program in loop. In this example, output the high voltage in pin, then output low voltage after 1s, then dalay 1s again befort stop. Then repeat this procedure, so you can see the LED blinks.
 +
*pinMode(pin,mode) function defines the state of PIN as outpur or input.
 +
*digitalWrite(pin,HIGH) function controls the output, high or low.
 +
*delay(ms) function use to delay, the unit is ms.
 +
 
 
<source lang="cpp">
 
<source lang="cpp">
int ledPin=13;
+
int led=13;
#define TIME 1000
+
void setup() {
long time1=0,time2=0;
+
    // Set up the built-in LED pin as an output:
void setup()
+
    pinMode(led, OUTPUT);
{
 
  pinMode(ledPin,OUTPUT);
 
}
 
void loop()
 
{
 
if(millis()<time2+TIME)
 
{
 
digitalWrite(ledPin,HIGH);
 
time1=millis();
 
}
 
else
 
{
 
digitalWrite(ledPin,LOW);
 
if(millis()>time1+TIME)
 
time2=millis();
 
 
}
 
}
 +
 +
void loop() {
 +
    togglePin(led);          // Turn the LED from off to on, or on to off
 +
    delay(1000);          // Wait for 1 second (1000 milliseconds)
 
}
 
}
 
</source>
 
</source>
  
Using function millis () is better than the delay () function, less resource and fewer delays on the system.
+
Grammatical information:
 
+
togglePin(led):Swith the specific pin's output value. If the pin is high voltage, then set it to low voltage, otherwise set it to high.
==Download program method==
 
*Choose the board type in "tools", the "Microduino-CoreSTM32 to Flash" if you want to run the program after reset the board, or "Microduino-CoreSTM32 to RAM" if you just want to test it for one time.
 
 
 
*Compile downloads
 
[[File:compile.jpg|600px|center|thumb]]
 
 
 
[[File:download.jpg|600px|center|thumb]]
 
 
 
==Result==
 
After the download, you can see LED flashes once every 1s.
 
 
 
==Video==
 
  
 +
==Debug==
 +
*Connect the module accordign the shcematic.
 +
[[File: STM32-lesson1yuanli.jpg|600px|center|thumb]]
 +
*Open the Maple IDE, copy the program to editor, then choose the board type (Microduino-CoreSTM32 to Flash). Click the download button or shortcut key (Ctrl+U) to download program.
 +
*After download, you can see the LED blinking every 1s. You also can change to other parameter to try.
 
|}
 
|}

Latest revision as of 06:16, 17 August 2014

Language: English  • 中文

Objective

Use the Microduino-CoreSTM32 to control a LED light, and use the Maple IDE to program for the Microduino-CoreSTM32, just like programming in the Arduino IDE.

Equipment

Microduino-CoreSTM32 is an ARM development board using STM32F103CBT6 chip. It use special Upin7 interface, the size is similar with a coin and fully compatible other Microduino modules.

  • Other hardware equipment
    • Breadboard Jumper one box
    • Breadboard one piece
    • LED Light-emitting diodes one
    • 220ohm resistor one
    • USB Data cable one


Experiment schematic

  • There are two connection methods:
    • LED cathode connects the GND of Microduino-CoreSTM32, and anode connects to Microduino digital I/O port 13, which is the high-level light led.
    • LED cathode connects Microduino-CoreSTM32 digital I/O port 13, anode connects to VCC, so that low-level light led.

This experiment will use the first method, you can try another method.

Program

int led = 13;              //Define the LED control pin
void setup() {                
  pinMode(led, OUTPUT);  //Define the pin as output   
}
void loop() {
digitalWrite(led, HIGH);    //Output higt voltage
delay(1000);             // Delay 1s
digitalWrite(led, LOW);    //Output low voltage
delay(1000);            // Delay 1s
}

Let's analyze the program:

  • Firstly define a control pin, we used the pin 13, you can can change it to (0 ~ 21) accroding to your requirement.

Note: 0 ~ 13 mapping to D0 ~ D13 and 14 ~ 21 mapping to A0 ~ A7 on board. For example, if you want to use A0 to control the LED, need change the “int led = 13;” to “int led = 14;”

  • setup() function is the initralization function, and only is executed one time.
  • loop() function is a loop function which will run the inside program in loop. In this example, output the high voltage in pin, then output low voltage after 1s, then dalay 1s again befort stop. Then repeat this procedure, so you can see the LED blinks.
  • pinMode(pin,mode) function defines the state of PIN as outpur or input.
  • digitalWrite(pin,HIGH) function controls the output, high or low.
  • delay(ms) function use to delay, the unit is ms.
int led=13;
void setup() {
    // Set up the built-in LED pin as an output:
    pinMode(led, OUTPUT);
}

void loop() {
    togglePin(led);          // Turn the LED from off to on, or on to off
    delay(1000);          // Wait for 1 second (1000 milliseconds)
}

Grammatical information: togglePin(led):Swith the specific pin's output value. If the pin is high voltage, then set it to low voltage, otherwise set it to high.

Debug

  • Connect the module accordign the shcematic.
  • Open the Maple IDE, copy the program to editor, then choose the board type (Microduino-CoreSTM32 to Flash). Click the download button or shortcut key (Ctrl+U) to download program.
  • After download, you can see the LED blinking every 1s. You also can change to other parameter to try.