310 views|1 replies

9

Posts

1

Resources
The OP
 

【Follow me Season 2 Episode 2】+ Getting Started Tasks: Setting up the Environment, Blink, and Serial Port Printing Output [Copy link]

  This post was last edited by cqutmianma on 2024-9-30 00:43

1. Environment Construction

First, download Arduino IDE https://www.arduino.cc from the official website according to your computer's operating system and install it. Then open Arduino IDE and connect the Arduino UNO R4 development board to the computer via a type-c cable. At this time, you need to select the development board version model connected to the serial port on the IDE as shown in Figure 1 below. The corresponding software package will pop up in the lower right corner automatically, as shown in Figure 2 below. Click and wait for the installation to complete.

Figure 1. Select the Arduino UNO R4 development board to connect

Figure 2. Waiting for the software package to be installed

2. Run Blink

Click File, Create a New Project, and then Save. The first thing we need to achieve is lighting, yes, hahahaha, a qualified embedded engineer must be able to light various lights.

Open the schematic diagram of Arduino UNO R4, as shown in Figure 3 below, you can see that the pin of the LED is P102.

Figure 3. LED pin control diagram

From the schematic diagram, we can see that directly controlling the high and low of P102 can achieve the flipping of the DL4 light. According to the pin diagram of Arduino UNO R4, Figure 4, we can know that P102 is D13 of the development board.

Figure 4. Development board pin diagram

So we can directly control D13 in the code. The specific code is as follows, which mainly flips the level once every 500ms. Before each flip, we read the level first, and then take the inverted level to flip.

void setup() {
  // put your setup code here, to run once:
  pinMode(13, OUTPUT); /* 设置13引脚为输出模式 */
  digitalWrite(13, HIGH); /* 默认输出为高*/
}

void loop() {
  // put your main code here, to run repeatedly:
  delay(500); 
  digitalWrite(13, !digitalRead(13));  /* 每500ms进行一次LED灯的翻转*/
}

3. Serial port output

The official documentation tells us that D0 and D1 are used for USB serial port input and output. So we don't need to configure the IO of serial port 0, we can just use it directly.

First, initialize the baud rate to 115200, and then output the serial port data every 500ms directly in the loop function. The specific code is as follows:



/*串口初始化函数*/
void uart_init(uint32_t baud)
{
   Serial.begin(baud);  
}

void setup() {
  // put your setup code here, to run once:
  pinMode(13, OUTPUT); /* 设置13引脚为输出模式 */
  digitalWrite(13, HIGH); /* 默认输出为高*/
  uart_init(115200);      /* 串口初始化 */
}

void loop() {
  // put your main code here, to run repeatedly:
  delay(500); 
  digitalWrite(13, !digitalRead(13));  /* 每500ms进行一次LED灯的翻转*/
  Serial.println("Hello EEWorld !");
}

Then open the serial port monitor and set the baud rate to 115200. You can see that the serial port monitor outputs a frame of serial port data every 500ms.

4. Display videos and source code files


followme_unor4.ino

504 Bytes, downloads: 0

LED翻转+串口输出

This post is from DigiKey Technology Zone

Latest reply

The result is still OK, indicating that the environment is successfully built   Details Published on 2024-9-26 07:32
 
 

6570

Posts

0

Resources
2
 

The result is still OK, indicating that the environment is successfully built

This post is from DigiKey Technology Zone
 
 
 

Guess Your Favourite
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews

Room 1530, Zhongguancun MOOC Times Building, Block B, 18 Zhongguancun Street, Haidian District, Beijing 100190, China Tel:(010)82350740 Postcode:100190

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list