出了一款国产芯片LGT8F328P,价格只要五块多,可以代替连连涨价的ATMEGA328P。
LGT8F328P使用的编译器和ATMEGA328P相同,但是库不同,只需要添加库文件即可使用。
先介绍arduino IDE中添加方法:
首选项--添加开发板管理器网址并确定:
https://raw.githubusercontent.com/dbuezas/lgt8fx/master/package_lgt8fx_index.json
--到开发板管理器--搜索lgt--安装
Arduino CLI 添加方法:
Arduino CLI主要用于scratch3.0软件中,或者其他不适应IDE的平台,我把配置过的CLI文件打包在我的下载资源里,包括arduino系列、esp32、esp8266、LGT8fxBoards等常用开发板都添加了,可以直接下载后使用。
这个是官方的CLI介绍
Arduino CLIArduino Command Line Interfacehttps://arduino.github.io/arduino-cli/0.20/
下面的教程参考MacOS下使用Arduino命令行工具进行嵌入式开发——Arduino CLI使用教程 - 知乎
我把原来的ESP32换成了 LGT8F328P。
LGT8F328P的GitHub地址
https://github.com/dbuezas/lgt8fxhttps://github.com/dbuezas/lgt8fx
0 安装
当然,你得先安装Arduino IDE,具体过程这里就不赘述了。
然后执行以下命令安装Arduino CLI:
$ brew update
$ brew install arduino-cli
如果无法使用brew安装,可以参考其他方法:
1 基本使用
1.1 在你开始之前 Before you start
arduino-cli
是一个命令的容器,每个命令都有自己专门的帮助文本,可以像这样用help
命令显示。
$ arduino-cli help core
Arduino Core operations.
Usage:
arduino-cli core [command]
Examples:
./arduino-cli core update-index
Available Commands:
download Downloads one or more cores and corresponding tool dependencies.
install Installs one or more cores and corresponding tool dependencies.
list Shows the list of installed platforms.
search Search for a core in Boards Manager.
uninstall Uninstalls one or more cores and corresponding tool dependencies if no more used.
update-index Updates the index of cores.
upgrade Upgrades one or all installed platforms to the latest version.
Flags:
-h, --help help for core
Global Flags:
--additional-urls strings Additional URLs for Boards Manager.
--config-file string The custom config file (if not specified the default will be used).
--format string The output format, can be [text|json]. (default "text")
--log-file string Path to the file where logs will be written.
--log-format string The output format for the logs, can be [text|json].
--log-level string Messages with this level and above will be logged.
-v, --verbose Print the logs on the standard output.
Use "arduino-cli core [command] --help" for more information about a command.
1.2 创建一个配置文件 Create a configuration file
严格来说,Arduino CLI不需要一个配置文件来工作,因为命令行界面提供了任何可能的功能。然而,有一个配置文件可以让你在发布命令时少打很多字,可以用如下的命令创建:
$ arduino-cli config init
Config file written to: /Users/reus/Library/Arduino15/arduino-cli.yaml
如果你检查arduino-cli.yaml
的内容,你会发现可用的选项及其各自的默认值。更多信息,请看配置文档。
1.3 创建一个新的sketch Create a new sketch
要在当前目录下创建一个名为MyFirstSketch
的新项目,运行以下命令:
$ arduino-cli sketch new MyFirstSketch
Sketch created in: [path/to/your/current/dir]/MyFirstSketch
一个sketch是一个包含源文件和库等资源的文件夹;new
命令为你创建一个名为MyFirstSketch.ino
的.ino文件,里面是空的模板代码:
$ cat ./MyFirstSketch/MyFirstSketch.ino
void setup() {
}
void loop() {
}
1.4 将开发板连接到电脑 Connect the board to your PC
新安装后要做的第一件事是通过运行以下命令更新本地可用平台和库的cache:
$ arduino-cli core update-index
Updating index: package_index.json downloaded
Updating index: package_index.json.sig downloaded
使用USB线将板子连接到电脑后,你可以通过执行以下命令检查它是否被识别:
$ arduino-cli board list
1.5 为你的板子安装内核 Install the core for your board
我们要安装的是lgt8fx,故执行以下命令:
$ arduino-cli core install LGT8fxBoards:lgt8fx
Error during install: Platform 'LGT8fxBoards:lgt8fx' not found: platform LGT8fxBoards:lgt8fx has no available releases
这里出现了问题,因为我们没有添加第三方内核。比如我们需要lgt8fx的内核,那么就对配置文件的board_manager作如下修改,文件一般在cli安装目录下:
board_manager:
additional_urls:
- https://raw.githubusercontent.com/dbuezas/lgt8fx/master/package_lgt8fx_index.json
然后更新cache:
$ arduino-cli core update-index
Updating index: package_index.json downloaded
Updating index: package_index.json.sig downloaded
Updating index: package_lgt8fx_index.json downloaded
$ arduino-cli core search lgt8fx
重新安装内核:
$ arduino-cli core install LGT8fxBoards:lgt8fx
执行以下命令验证一下:
$ arduino-cli core list
1.6 编译和烧写 Compile and upload the sketch
$ arduino-cli compile --fqbn LGT8fxBoards:avr:328