0_Arduino-ESP32_环境搭建ubuntu,LED闪烁,按钮控制LED

3,549 阅读1分钟

1_环境搭建ubuntu


安装arduino IDE

sudo snap install arduino

如果想卸载arduino IDE

sudo snap remove arduino

安装必要工具

sudo apt-get install git wget flex bison gperf python3 python3-pip python3-setuptools cmake ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0-0
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 1
sudo update-alternatives --config python

国内pip源

pip3 config set global.index-url http://mirrors.aliyun.com/pypi/simple/

pip3 config set global.trusted-host mirrors.aliyun.com

如果遇到串口访问权限问题

sudo usermod -a -G dialout $USER
pip3 install pyserial
sudo reboot

下载 arduino-esp32和json和esptool

https://github.com/espressif/arduino-esp32

下载必要工具链

https://github.com/espressif/crosstool-NG
https://github.com/igrr/mkspiffs
https://github.com/earlephilhower/esp-quick-toolchain

如何确认下载什么工具和什么版本,请查看json里面内容

放在对应目录

~/snap/arduino/61/.arduino15

屏幕截图.png

~/snap/arduino/61/.arduino15/staging/packages

屏幕截图.png

填写开发板地址

https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json

2022-03-04 17-17-38屏幕截图.png

本地安装

2022-03-04 17-19-13屏幕截图.png

开发板型号espressif esp32 dev module

2_LED闪烁


#include<Arduino.h>
#define LED 5

void setup() {
  // put your setup code here, to run once:
  pinMode(LED, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(LED,HIGH); //高电平
  delay(1000); //等待1000毫秒
  digitalWrite(LED, LOW); //低电平
  delay(1000); //等待1000毫秒
}

3_按钮控制LED


#include<Arduino.h>
#define LED 5
#define botton 0  

void setup() {
  // put your setup code here, to run once:
  pinMode(LED, OUTPUT);
  pinMode(botton,INPUT_PULLUP); //内部上拉
}

void loop() {
  // put your main code here, to run repeatedly:
  if(digitalRead(botton)){    
    digitalWrite(LED,HIGH); //高电平
    
  }else{
    digitalWrite(LED,LOW); //低电平
  
  }  
  
}