Skip to content

Commit 5d9f72e

Browse files
Added nano esp 32
1 parent e579f79 commit 5d9f72e

File tree

1 file changed

+137
-3
lines changed
  • content/micropython/03.micropython/04.board-examples/nano-esp32

1 file changed

+137
-3
lines changed
Lines changed: 137 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,138 @@
11
---
2-
title: Nano ESP32
3-
description: Learn how to use specific features on the Nano ESP32 using MicroPython
4-
---
2+
title: Nano ESP32
3+
description: Learn how to use specific features on the Nano ESP32 using MicroPython
4+
---
5+
6+
![Nano ESP32](./assets/nano-esp32.png)
7+
8+
In this guide, you will find information specific to the [Nano ESP32 board](https://store.arduino.cc/products/nano-esp32), such as supported serial protocols, built-in sensors, and how to access the wireless features.
9+
10+
For installation instructions, please visit the link below:
11+
- [Installing MicroPython](https://labs.arduino.cc/en/labs/micropython-installer)
12+
13+
## Pinout
14+
15+
The pinout for the Nano ESP32 can be found in the image below.
16+
17+
![Nano ESP32 Pinout](./assets/nano-esp32-pinout.png)
18+
19+
***For more details on this product, visit the [hardware product page](/hardware/nano-esp32/).***
20+
21+
## Board-Specific Features
22+
23+
The Nano ESP32 has several board-specific features that we can access through MicroPython:
24+
25+
- **RGB LED**: A built-in RGB LED that can be controlled by setting `r`, `g`, and `b` values.
26+
- **Touch Pins**: Capacitive touch sensors available on multiple pins.
27+
- **ESP-NOW**: A wireless communication protocol developed by Espressif that enables low-power, peer-to-peer communication without the need for a Wi-Fi router. ESP-NOW is particularly useful for creating mesh networks or communicating with other ESP32 devices with low latency and minimal setup.
28+
29+
30+
## Wireless Connectivity
31+
32+
The Nano ESP32 has a radio module that supports **Wi-Fi®** and **Bluetooth®**. To find examples, please visit the links below:
33+
34+
- **[MicroPython - Bluetooth® documentation]()**
35+
- **[MicroPython - Wi-Fi® documentation]()**
36+
37+
38+
### ESP-NOW
39+
40+
ESP-NOW is a powerful feature of the ESP32 that allows devices to communicate directly with each other using a simple, lightweight protocol. This is useful for applications where quick data transfer is needed between devices, such as in sensor networks or remote control systems.
41+
42+
**Example:**
43+
Here's a basic outline of how you can set up ESP-NOW communication between two ESP32 boards using MicroPython:
44+
45+
```python
46+
import espnow
47+
import network
48+
49+
# Initialize the Wi-Fi interface in station mode
50+
wifi = network.WLAN(network.STA_IF)
51+
wifi.active(True)
52+
53+
# Initialize ESP-NOW
54+
esp_now = espnow.ESPNow()
55+
esp_now.init()
56+
57+
# Add a peer device (MAC address needed)
58+
peer_mac = b'\x24\x0A\xC4\x12\x34\x56' # Replace with the MAC address of the peer
59+
esp_now.add_peer(peer_mac)
60+
61+
# Send a message
62+
esp_now.send(peer_mac, b'Hello, ESP-NOW!')
63+
64+
# Receive messages
65+
def on_recv_msg(mac, msg):
66+
print("Received message from:", mac, "Message:", msg)
67+
68+
esp_now.on_recv(on_recv_msg)
69+
```
70+
71+
> **Note**: ESP-NOW requires you to know the MAC address of the peer device in advance and does not require a Wi-Fi router or internet connection.
72+
73+
74+
## Communication Protocols
75+
76+
The Nano ESP32 supports **I2C**, **UART**, and **SPI** for communication with external devices. Here are examples of how to use them in MicroPython.
77+
78+
### I2C
79+
80+
The I2C bus on the Nano ESP32 is available on pins **A4 (SDA)** and **A5 (SCL)**. Here is how to set it up:
81+
82+
```python
83+
from machine import Pin, I2C
84+
85+
# Initialize I2C with SCL on A5 and SDA on A4
86+
i2c = I2C(0, scl=Pin(5), sda=Pin(4))
87+
devices = i2c.scan()
88+
89+
print("I2C devices found:", devices)
90+
```
91+
92+
***Read more about I2C in [this article]().***
93+
94+
### UART
95+
96+
The Nano ESP32 can communicate using UART, available on specific pins. Here’s how to set it up:
97+
98+
```python
99+
from machine import UART
100+
101+
# Initialize UART on pins 16 (TX) and 17 (RX)
102+
uart = UART(1, baudrate=9600, tx=16, rx=17)
103+
104+
# Send and receive data
105+
uart.write("Hello from Nano ESP32!")
106+
data = uart.read()
107+
print("Received:", data)
108+
```
109+
110+
***Read more about UART in [this article]().***
111+
112+
### SPI
113+
114+
SPI communication is also supported on the Nano ESP32, which is useful for high-speed data transfer with peripherals:
115+
116+
```python
117+
from machine import Pin, SPI
118+
119+
# Initialize SPI with SCK on pin 18, MOSI on pin 23, and MISO on pin 19
120+
spi = SPI(1, baudrate=1000000, polarity=0, phase=0, sck=Pin(18), mosi=Pin(23), miso=Pin(19))
121+
122+
print("SPI initialized")
123+
```
124+
125+
***Read more about SPI in [this article]().***
126+
127+
## Additional Features
128+
129+
The Nano ESP32 includes other features that can be explored:
130+
131+
- **Analog Pins**: Use `ADC` to read analog values from sensors.
132+
- **PWM**: Use `PWM` for pulse-width modulation to control motors or LEDs.
133+
134+
## Summary
135+
136+
The Nano ESP32 is a powerful microcontroller that supports a variety of features for embedded programming with MicroPython. From controlling the built-in RGB LED to using capacitive touch sensors and establishing wireless connections, this guide covers the essentials to get started.
137+
138+
For more advanced projects and examples, visit the [Arduino Docs - MicroPython](https://docs.arduino.cc/micropython/).

0 commit comments

Comments
 (0)