Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 39 additions & 40 deletions docs/arduino/Blink.rst
Original file line number Diff line number Diff line change
@@ -1,59 +1,58 @@
Lập trình GPIO với ESP32 bằng Arduino IDE.
--------------------------------------------
-------------------------------------------

Giới thiệu.
============

* Trong ESP32 có tất cả 34 chân GPIO:
* GPIO 00 - GPIO 19
* GPIO 21 - GPIO 23
* GPIO 25 - GPIO 27
* GPIO 32 - GPIO 39
**Lưu ý**
* ``Không bao gồm`` các chân ``20, 24, 28, 29, 30 và 31``.
* Các chân ``GPIO 34 - GPIO39`` chỉ thiết lập ở chế độ ``INPUT``.
* Các chân ``GPIO 06 - GPIO 11`` thường được dùng để giao tiếp với thẻ nhớ ngoài thông qua giao thức SPI nên hạn chế sử dụng để thiết lập IO.
* Dưới đây là ví dụ đơn giản về thiết lập IO bằng Arduino để nhấp nháy LED cho ESP32 sử dụng board ESP32-Wifi-Uno.
===========

* Trong ESP32 có tất cả 34 chân GPIO:
* GPIO 00 - GPIO 19
* GPIO 21 - GPIO 23
* GPIO 25 - GPIO 27
* GPIO 32 - GPIO 39
* Lưu ý:
* ``Không bao gồm`` các chân ``20, 24, 28, 29, 30 và 31``.
* Các chân ``GPIO 34 - GPIO39`` chỉ thiết lập ở chế độ ``INPUT``.
* Các chân ``GPIO 06 - GPIO 11`` thường được dùng để giao tiếp với thẻ nhớ ngoài thông qua giao thức SPI nên hạn chế sử dụng để thiết lập IO.
* Dưới đây là ví dụ đơn giản về thiết lập IO bằng Arduino để nhấp nháy LED cho ESP32 sử dụng board ESP32-Wifi-Uno.

Chuẩn bị.
=========

+------------------------+----------------------------------------------------------+
| **Phần cứng** | **Link** |
+========================+==========================================================+
| Board ESP32-Wifi-UNO | https://github.com/esp32vn/esp32-iot-uno |
+------------------------+----------------------------------------------------------+
+--------------------+----------------------------------------------------------+
| **Tên board mạch** | **Link** |
+====================+==========================================================+
| Board IoT Wifi Uno | https://github.com/esp32vn/esp32-iot-uno |
+--------------------+----------------------------------------------------------+

Kết nối.
========

* Trên board ESP32-Wifi-Uno có đèn D3 nối với chân số GPIO23 và nút nhấn nối với chân GPIO18.
* Trên board ESP32-Wifi-Uno có đèn D3 nối với chân số GPIO23 và nút nhấn nối với chân GPIO18.

Chưong trình.
Chương trình.
=============
Chạy chương trình Arduino IDE lên và copy toàn bộ code dưới đây vào và save với lại với một tên bất kì.

.. code:: cpp

int LED = 23;
int inPin = 18;
int val = 0;

void setup(){
pinMode(LED, OUTPUT);
pinMode(inPin, INPUT_PULLUP);
}

void loop(){
while(digitalRead(inPin)==val)
{
delay(200);
digitalWrite(LED, LOW);
val = digitalRead(inPin);
delay(200);
digitalWrite(LED, HIGH);
}
}
int LED = 23;
int inPin = 18;
int val = 0;

void setup(){
pinMode(LED, OUTPUT);
pinMode(inPin, INPUT_PULLUP);
}

void loop(){
while(digitalRead(inPin)==val){
delay(200);
digitalWrite(LED, LOW);
val = digitalRead(inPin);
delay(200);
digitalWrite(LED, HIGH);
}
}

**Lưu ý**
* Khi chân được thiết lập ``INPUT`` không nối với gì thì mặc định khi trả về sẽ là mức ``HIGH``.
Expand All @@ -62,7 +61,7 @@ Chạy chương trình Arduino IDE lên và copy toàn bộ code dưới đây v
Nạp chương trình.
=================

Kết nối ``ESP32 IoT Wifi Uno`` với máy tính và thực hiện theo `hướng dẫn tại đây. <https://esp32.vn/hardware/connection.html#cau-hinh-ket-noi>`_
Kết nối ``ESP32 IoT Wifi Uno`` với máy tính và thực hiện theo `hướng dẫn tại đây. <https://esp32.vn/hardware/connection.html#cau-hinh-ket-noi>`_

Kết luận.
=========
Expand Down
158 changes: 158 additions & 0 deletions docs/idf/blink-idf.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
Lập trình chớp tắt LED với ESP32 bằng ESP-IDF
---------------------------------------------

Giới thiệu.
===========

* Trong ESP32 có tất cả 34 chân GPIO:
* GPIO 00 - GPIO 19
* GPIO 21 - GPIO 23
* GPIO 25 - GPIO 27
* GPIO 32 - GPIO 39

* Lưu ý:
* ``Không bao gồm`` các chân ``20, 24, 28, 29, 30 và 31``.
* Các chân ``GPIO34 - GPIO39`` chỉ thiết lập ở chế độ ``INPUT`` và không có chức năng pullup hoặc pulldown cho phần mềm.
* Các chân ``GPIO06 - GPIO11`` thường được dùng để giao tiếp với thẻ nhớ ngoài thông qua giao thức SPI nên hạn chế sử dụng để thiết lập IO.

* Dưới đây là ví dụ đơn giản nhấp nháy LED sử dụng board ESP32-Wifi-Uno.

Chuẩn bị.
=========

+--------------------+----------------------------------------------------------+
| **Tên board mạch** | **Link** |
+====================+==========================================================+
| Board IoT Wifi Uno | https://github.com/esp32vn/esp32-iot-uno |
+--------------------+----------------------------------------------------------+

Kết nối.
========

* Trên board ESP32-Wifi-Uno đã có đèn D3 nối với chân GPIO23.

Demo
====
.. youtube:: https://www.youtube.com/watch?v=E0ZU68mlbj4

Hướng dẫn
=========

Tải dự án mẫu:
**************
.. code:: bash

git clone https://github.com/espressif/esp-idf.git

Include
*******
.. code:: cpp

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"

* ``driver/gpio.h``: Bao gồm cấu hình đầu vào và đầu ra với mục đích cơ bản.

Define
******
.. code:: cpp

#define BLINK_GPIO 23

* Định nghĩa ``BLINK_GPIO`` là ``GPIO23``.

GPIO
****
.. code:: cpp

gpio_pad_select_gpio (uint8_t gpio_num);

* Chọn pad làm chức năng GPIO từ IOMUX.

.. code:: cpp

gpio_set_direction (gpio_num_t gpio_num, gpio_mode_t mode);

* Định hướng GPIO, chẳng hạn như output only, input only, output and input.
* Có 2 đối số được truyền vào hàm:
* ``gpio_num_t gpio_num``: Lựa chon PIN
* ``GPIO_NUM_0`` ... ``GPIO_NUM_39`` hoặc ``0`` ... ``39``.
* ``gpio_mode_t mode`` : Lựa chọn Mode
* ``GPIO_MODE_INPUT``: input only
* ``GPIO_MODE_OUTPUT``: output only mode
* ``GPIO_MODE_OUTPUT_OD``: output only with open-drain mode
* ``GPIO_MODE_INPUT_OUTPUT_OD``: output and input with open-drain mode
* ``GPIO_MODE_INPUT_OUTPUT``: output and input mode

.. code:: cpp

gpio_set_level (gpio_num_t gpio_num, uint32_t level);
* Thiết lập mức (LOW hoặc HIGH) cho GPIO.
* Có 2 đối số được truyền vào hàm:
* ``gpio_num_t gpio_num``: Lựa chon PIN
* ``GPIO_NUM_0`` ... ``GPIO_NUM_39`` hoặc ``0`` ... ``39``.
* ``uint32_t level`` : Lựa chọn mức logic
* ``0``: Mức thấp
* ``1``: Mức cao

Make file:
**********
.. code:: bash

PROJECT_NAME := myProject
include $(IDF_PATH)/make/project.mk

* ``PROJECT_NAME := myProject`` : Tạo ra một mã nhị phân với tên này tức là - myProject.bin, myProject.elf.

Lập trình
=========
Bây giờ, bạn có thể xem code hoàn chỉnh.

.. code:: cpp

/* Blink Example
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"

#define BLINK_GPIO 23

void blink_task(void *pvParameter)
{
/* Configure the IOMUX register for pad BLINK_GPIO (some pads are
muxed to GPIO on reset already, but some default to other
functions and need to be switched to GPIO. Consult the
Technical Reference for a list of pads and their default
functions.)
*/
gpio_pad_select_gpio(BLINK_GPIO);
/* Set the GPIO as a push/pull output */
gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
while(1) {
/* Blink off (output low) */
gpio_set_level(BLINK_GPIO, 0);
vTaskDelay(1000 / portTICK_PERIOD_MS);
/* Blink on (output high) */
gpio_set_level(BLINK_GPIO, 1);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}

void app_main()
{
xTaskCreate(&blink_task, "blink_task", 512, NULL, 5, NULL);
}

Lưu ý
=====
* Hướng dẫn cài đặt `ESP-IDF <https://esp-idf.readthedocs.io/en/latest/index.html>`_
* Nạp và Debug chương trình `xem tại đây <https://esp-idf.readthedocs.io/en/latest/index.html>`_
* Tài nguyên hệ thống xem `tại đây <https://github.com/espressif/esp-idf>`_
31 changes: 16 additions & 15 deletions docs/idf/hello-world.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,40 @@ Espressif Internet Development Framework (ESP-IDF) sử dụng FreeRTOS để t
Chương trình Hello world sau mỗi 10 giây in ra một chuỗi "Hello world" và hiển thị trên terminal máy tính xuất từ cổng UART của ESP32.

Demo
==================
====
.. youtube:: https://www.youtube.com/watch?v=SxPDVPu8tug

Chuẩn bị
========
+--------------------+----------------------------------------------------------+
| **Tên board mạch** | **Link** a |
+====================+==========================================================+
| Board IoT Wifi Uno | https://github.com/esp32vn/esp32-iot-uno |
+--------------------+----------------------------------------------------------+
+--------------------+----------------------------------------------------------+
| **Tên board mạch** | **Link** |
+====================+==========================================================+
| Board IoT Wifi Uno | https://github.com/esp32vn/esp32-iot-uno |
+--------------------+----------------------------------------------------------+

Hướng dẫn
==================
=========

Tải dự án mẫu:
**************
.. code:: bash

git clone https://github.com/espressif/esp-idf.git

Include thư viện
*****************
****************
.. code:: cpp

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"

* ``stdio.h``: Cung cấp cốt lõi của những khả năng nhập trong C. Tập tin này bao gồm họ hàm printf.
* ``freertos/FreeRTOS.h``: Thư viện này bao gồm các thiết lập cấu hình yêu cầu để chạy freeRTOS trên ESP32.
* ``freertos/task.h``: Cung cấp chức năng đa nhiệm. (Chúng tôi sẽ làm đa nhiệm ở các ví dụ sau)
* ``esp_system.h``: Bao gồm cấu hình các thiết bị ngoại vi trong hệ thống ESP. Chức năng của nó như là hệ thống khởi tạo.

Tải dự án mẫu:
**************
.. code:: bash

git clone https://github.com/espressif/esp-idf.git

Một dự án trông như thế này:

.. code:: bash
Expand Down Expand Up @@ -76,7 +77,7 @@ Hướng dẫn sửa và tạo make file:
PROJECT_NAME := myProject
include $(IDF_PATH)/make/project.mk

* PROJECT_NAME := myProject : Tạo ra một mã nhị phân với tên này tức là - myProject.bin, myProject.elf.
* ``PROJECT_NAME := myProject`` : Tạo ra một mã nhị phân với tên này tức là - myProject.bin, myProject.elf.

Hướng dẫn config, nạp và debug chương trình:
********************************************
Expand Down
4 changes: 2 additions & 2 deletions docs/idf/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ ESP32 IDF
*********

.. toctree::
:maxdepth: 2
:maxdepth: 3

Cài đặt <install>
Hello World <hello-world>

Blink <blink-idf>
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Mạch nguyên lý

.. toctree::
:caption: ESP32 IDF
:maxdepth: 2
:maxdepth: 3

ESP-IDF cơ bản <idf/index>
Thẻ nhớ <idf/sdcard>
Expand Down