[Arduino Experiment Notes] Robotic Arm (1) Control the onboard LED lights to flicker


foreword

I bought an Arduino board a long time ago, but I have been eating ashes until now. Recently, I spent time studying and found that this board is a must-have entry board for Xiaobai ( the bottom layer is highly packaged and rich in information ). Of course, although Arduino is simple, this does not affect its powerful functions. I believe that in the process of learning, you can reap the joy of creation.

I am used to recording the experiments I have done, and each chapter will introduce a kind of hardware and related functions . Combining multiple chapters is one article , and at the end of each article, a comprehensive small project will be done . It will use the knowledge learned in the previous chapters.

This is the first article , our goal is to make a robotic arm ! It's cool! So, without further ado, let's get started!

Reference 1 in this series


Introduction to Arduino

Arduino does not specifically refer to a single- chip microcomputer or a development environment , but actually refers to the entire ecosystem from software to hardware .

Arduino is developed based on Arduino IDE , the bottom layer is C language and C++ , and the hardware and code are open source . It has the characteristics of rich ecology and cross-platform .

insert image description here


Arduino development board

insert image description here
Common development boards for Arduino include Arduino UNO , Arduino Nano , Arduino Mega 2560 , etc. This article uses the Arduino UNO R3 model development board, the important parameters are as follows:

  • Chip : ATmega328P microcontroller based on Atmel
  • Crystal oscillator : 16MHz
  • Digital IO : 0 - 13 , output digital signal. The pin output level voltage is 5V , and the maximum output current is 40mA .
    • PWM: 3, 5, 6, 9, 10, 11 with~
    • Serial port: 0, 1
  • Analog IO: A0 - A5 , with 10-bit analog-to-analog conversion channel , which is also an advantage of Arduino , with its own ADC .
  • Power supply : 3.3V/5V output, the maximum output current is 150mA
  • Power supply : 12V DC port power supply is recommended
  • Download : Burning program
    • USB : download interface.
    • ICSP : download interface.

Arduino IDE

Write programs in C language , and at the same time have the object-oriented thinking of C++ . Since the Arduino IDE has rich library functions and many packaged modules, it is very easy to get started. The IDE interface is as follows:
insert image description here
the interface is very simple, with one-click compilation and upload in the upper left corner , and a serial port debugging tool in the upper right corner .

Here is the official website link of Arduino IDE . The installation of Arduino IDE is not the focus of this article, so I won't repeat it here.


Configure the development board and ports

Open the Arduino IDE , and then open Tools - Development Boards - Arduino AVR Boards - Arduino Uno .

Before setting the port , connect the development board with a USB data cable and connect it to the computer . Open Tools - Ports - COMx in turn . x is the port number .


hardware introduction

LED introduction

For a detailed introduction to LED , please refer to another blog "51 MCU LED" . Because the Arduino board has a controllable LED light (silk-printed L), so this article does not need to connect an external LED to directly control it logically.


schematic diagram

Find the silkscreen on the Arduino development board as LLFor the LEDof L ,by default, the anode is connected to pin 13 of the digital IO, and the cathode is grounded (of course, the board passes through a current-limiting resistor). That is to say,We only need to control the level of pin 13 to control the LED on and off.


Software Implementation

Programs in Arduino IDE can be written in C/C++ .


Introduction to library functions

First, the functions in the three core libraries are introduced . Move to the official function manual for details .

  • Pin output input initialization
    void pinMode(uint8_t pin, uint8_t mode)
    • pin : pin number
    • mode : pin mode
      • Output: OUTPUT
      • Input: INOUT
      • Input pull-up: INPUT_PULLUP
  • digital pin write
    void digitalWrite(uint8_t pin, uint8_t val)
    • pin : pin number
    • val : level high or low
      • Low level: LOW
      • High level: HIGH
  • delay function
    void delay(unsigned long ms)
    • ms : delay in milliseconds

code

// 2022.11.12
// Author:Qiu

#define LED_L 13    // 引脚号
#define SPEED 1000  // 控制闪烁间隔1000ms

// 参数初始化,仅执行一次
void setup() {
    
    
  // 初始化数字引脚13作为输出
  pinMode(LED_L, OUTPUT);
}

// 主循环
void loop() {
    
    
  digitalWrite(LED_L, HIGH);  // 向13引脚写入高电平
  delay(SPEED);               // 等待
  digitalWrite(LED_L, LOW);   // 向13引脚写入低电平
  delay(SPEED);               // 等待
}

After the compilation is successful, upload it to the board. The experimental phenomenon is that the LED light flickers at a frequency of 1Hz.

Of course, the same implementation can be found in the examples that come with Arduino , the path is:Documentation - Examples - Basics - Blink. I suggest that you can implement it yourself first . After all, we will involve more complex applications later, and examples alone cannot meet our needs.


Goal of the next article

We hope to control LED lights in a more advanced way , for example, add aphysical switch. See you next time!


Summarize

Through this chapter, you have learned how to control the digital IO port to output high and low levels , and completed the LED blinking experiment with the help of the delay function .This is so important that it will be the indicator light in our future robotic arms . Please don't take this small first step lightly!


  1. Station B: Tai Chi Maker ↩︎

Guess you like

Origin blog.csdn.net/m0_46500149/article/details/127819935