0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

esp-idf の使い方

Last updated at Posted at 2023-01-28

Ubuntu 24.10 で使いました。
デバイスは、M5Stack Core2 を使いました。

インストール

詳しい説明はこちら
Standard Toolchain Setup for Linux and macOS

必要なライブラリーのインストール

sudo apt-get install git wget flex bison gperf python3 python3-venv cmake ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0-0

ソースのダウンロード

mkdir -p ~/esp
cd ~/esp
git clone --recursive https://github.com/espressif/esp-idf.git

コンパイル

cd ~/esp/esp-idf
./install.sh esp32
. ./export.sh

バージョンの確認

$ idf.py --version
ESP-IDF v5.5-dev-1655-gc5865270b5

サンプルプロジェクトの作成

cd ~/esp
cp -r esp-idf/examples/get-started/hello_world .

main/hello_world_main.c を改造します。

hello_world_main.c
(省略)
void app_main(void)
{
    printf("Hello world!\n");
    printf("Good Morning!\n");
    printf("Good Afternoon!\n");
    printf("こんにちは\n");

    /* Print chip information */
(省略)

コンパイル

idf.py build

デバイスにアップロード

idf.py -p /dev/ttyUSB0 flash

実行結果

$ cu -l /dev/ttyUSB0 -s 115200
Connected.


I (289) app_start: Starting scheduler on CPU0
I (294) app_start: Starting scheduler on CPU1
I (294) main_task: Started on CPU0
I (304) main_task: Calling app_main()
Hello world!
Good Morning!
Good Afternoon!
こんにちは
This is esp32 chip with 2 CPU core(s), WiFi/BT/BLE, silicon revision v3.0, 2MB external flash
Minimum free heap size: 301900 bytes
Restarting in 10 seconds...
Restarting in 9 seconds...

ソースを更に改造

プログラム

main/hello_world_main.c
// -----------------------------------------------------------------------
/*
	main/hello_world_main.c

					Jan/28/2023
*/
// -----------------------------------------------------------------------
#include <stdio.h>
#include <unistd.h>

#define	VERSION	"2023-1-28 PM 20:35"
// -----------------------------------------------------------------------
void loop()
{
	int icount = 0;

	while(1)
	{
	printf("icount = %d\n",icount);
	printf("*** loop *** %s ***\n",VERSION);
	printf("Hello world!\n");
	printf("Good Morning!\n");
	printf("Good Afternoon!\n");
	printf("こんにちは\n");
	printf("\n");
	sleep(5);

	icount++;
	}
}

// -----------------------------------------------------------------------
void app_main(void)
{
	sleep(3);
	printf("*** 開始 *** %s ***\n",VERSION);
	sleep(3);

	loop();
}

// -----------------------------------------------------------------------

実行結果

$ cu -l /dev/ttyUSB0 -s 115200
Connected.
*** 開始 *** 2023-1-28 PM 20:35 ***
icount = 0
*** loop *** 2023-1-28 PM 20:35 ***
Hello world!
Good Morning!
Good Afternoon!
こんにちは

icount = 1
*** loop *** 2023-1-28 PM 20:35 ***
Hello world!
Good Morning!
Good Afternoon!
こんにちは

icount = 2
*** loop *** 2023-1-28 PM 20:35 ***
Hello world!
Good Morning!
Good Afternoon!
こんにちは

関連情報

esp-idf で c++ を使う
esp-idf: ssid のスキャン
esp-idf: http_request の使い方
esp-idf: https_request の使い方

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?