Introduction to Arduino Learning

Source: Internet
Author: User

Always heard that many do IoT, smart Home controller using the Arduino, studied brother there got an Arduino development board, a afternoon study, feel this suitable for children play:)

Talk less, sum up, it is easy to use later. I mainly refer to the Baidu Library of a 60+ page of "Arduino from scratch" and some technical forums such as Geek Workshop bar.

As a result of the previous study of a number of development boards, here are mainly to explore their similarities and differences, transplant problems.

The individual is summed up in three parts:

First, the Arduino IDE environment to build

Due to the inability to access the official website to download, the 1.6.11-free installation version is selected here, and is a Chinese environment, very convenient

(2) Installation of the drive

This old version of the CH340 is generally not recognized on the computer, through the Device Manager select Manual installation, select the Arduino installation path in the Drivers folder can be

(3) How to compile

As the development Board mainly through the serial port to download the program, so you need to choose the Development Board model and serial port

After that, click the Compile button, upload button to implement the program's error detection and download.

Second, the basic Grammar of learning

(1) We will find that the Arduino main program consists of two parts: Setup () and loop ()

Setup () can only be initialized once, mainly placing some initialization functions such as port configuration, etc.

Loop () So the statement will be repeated execution needs to be careful.

(2) Variable type, global/local variables, mathematical operators, relational operators, logical operators, bitwise operations

Three major control structures, arrays, function learning

(3) Learning of some arduino built-in functions

such as the serial port configuration print display, the input and output of ports and the value of the PWM value modification

About this part, oneself will learn the function to write a small program, each small programming different knowledge point of study, everybody can learn from it. Attached to the back.

Third, take Ardunio as the core controller, complete a series of expansion functions.

As the author has only a piece of development board, there is no redundant bread and other accessories, so this part can not be verified, but summed it up again.

(1) The function of the Development Board pin should be observed first according to the schematic diagram.

For example, in 0-13-pin: 13-pin connected to the LED, 0/1-pin to achieve the RX/TX function, the 3/5/6/9/10/11/12/13 port output voltage value variable, you can realize the PWM function.

In A0-a5, the function of ad analog input can be realized by dividing the 0-5v voltage into 0-1023 parts and using successive approximation to realize sampling

Digital power supply, analog power supply and so on.

Fixed keys, or those ports can be input function, and then extended to the pull-up resistor-type key design circuit

(2) Design of the function

Display class: Digital tube Digital display, LCD1602 display, OLED display, 8*8 dot matrix display ...

Key class: External independent keys, matrix keys, etc.

Sound Control Category: Buzzer, infrared detection, etc.

Timing Interrupt class: Clock count, pulse count, interrupt detection, ad sampling, etc.

Output Control class: Stepper motor, rudder control, led brightness change, DC motor, etc.

Communication class: SPI communication, UART Communication, infrared communication, external network port communication

Data storage class: Encoder decoder module, SD module, etc.

....

Attached code:

/******************** function: Display serial printing information * Wang Maochun * Knowledge points: Understanding, Getting Started, using serial port baud rate setting function, serial printing function *********************/voidSetup () {//Put your setup code here, to run once:Serial.begin (9600);}voidLoop () {//put your main code here, to run repeatedly:Serial.println ("Wanghello"); Delay ( +);}/******************** function: 13-pin blinking light, time interval 1000ms* Wang Maochun * Knowledge points: Pin output configuration, high and low level configuration *********************/voidSetup () {//Put your setup code here, to run once:Pinmode ( -, OUTPUT);//set the 13 pin to output}voidLoop () {//put your main code here, to run repeatedly:Digitalwrite ( -, high);// //the 13-pin high-levelDelay +); Digitalwrite ( -, low);// //the 13-pin low levelDelay +);}/******************** function: 13-pin blinking lamp, time interval change: 1000-5000ms* Wang Maochun * Knowledge points: Pin output configuration, high and low level configuration * global variable usage, if-else statement usage, operator + =, + +, etc. *****************/intLedpin = -;//use global variable to indicate pin isintDelaytime = +;//Delay 100msvoidSetup () {//Put your setup code here, to run once:Pinmode (Ledpin,output);//set the 13 pin to output}voidLoop () {//put your main code here, to run repeatedly:Digitalwrite (Ledpin,high);// //the 13-pin high-leveldelay (delaytime); Digitalwrite (Ledpin,low); // //the 13-pin low leveldelay (delaytime); Delaytime+= -; if(Delaytime = = the) {Delaytime= +;//Recovery Benchmark   }}/******************** function: Global array value Printing * Wang Maochun * Knowledge Point: Initialization of global Array learning * Use of a while loop *********************/intarr[Ten]={1,2,3,4,5,6,7,8,9};//Global Array Declaration and initializationintCount=0;//define the counter variable and initialize it to 0voidSetup () {//Put your setup code here, to run once:Serial.begin (9600);}voidLoop () {//put your main code here, to run repeatedly:   while(Count <Ten) {serial.println (Arr[count]); Count++; }}/******************** function: Global array value Printing * Wang Maochun * Knowledge Point: Initialization of global Array learning * For loop use. Note that the program has an error: * Due to the counter count initialization placed in the For loop, plus loop The impact of the program has been circulating, easy to crash *********************/intarr[Ten]={1,2,3,4,5,6,7,8,9};//Global Array Declaration and initializationvoidSetup () {//Put your setup code here, to run once:Serial.begin (9600);}voidLoop () {//put your main code here, to run repeatedly:   for(intCount=0; count <Ten; count++) {serial.println (Arr[count]); }}/******************** function: Call of the max function * Wang Maochun * Knowledge Point: Use of custom Functions (no declaration required) * Consider the formal parameter consistency problem, considering that this experiment does not need to loop, the code is placed in the setup ******************** */voidSetup () {//Put your setup code here, to run once:Serial.begin (9600); intA=Ten, b= -; intValue=MaxValue (A, b); Serial.println (value);}voidLoop () {//put your main code here, to run repeatedly: }intMaxValue (intXinty) {  returnx > y?x:y;}

Today to learn so much, and we hope to communicate a lot, the recommended blog is:

Http://www.cnblogs.com/rayray/category/457863.html

http://www.cnblogs.com/shuqingstudy/

Introduction to Arduino Learning

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.