Skip to content

Commit bc52a7a

Browse files
authored
Merge pull request #1326 from arduino/karlsoderby/esp32-i2c-spi-fix
[Nano ESP32] I2C & SPI clarifications
2 parents 3e83dd3 + 64205a6 commit bc52a7a

File tree

1 file changed

+37
-1
lines changed
  • content/hardware/03.nano/boards/nano-esp32/tutorials/cheat-sheet

1 file changed

+37
-1
lines changed

content/hardware/03.nano/boards/nano-esp32/tutorials/cheat-sheet/cheat-sheet.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ analogWrite(pin,value);
253253

254254
![I2C Pins](assets/nano-esp32-i2c.png)
255255

256-
The default pins used for I2C on the Nano ESP32 are the following:
256+
The default pins used for the **main I2C bus** on the Nano ESP32 are the following:
257257

258258
| Pin | Function | Description |
259259
| --- | -------- | -------------------- |
@@ -281,6 +281,19 @@ Wire.write(val); //send a value
281281
Wire.endTransmission(); //stop transmit
282282
```
283283

284+
### Second I2C Bus
285+
286+
The Nano ESP32 has a second I2C bus, accessed via `Wire1`. To use it, you will need to set two free pins for SDA & SCL.
287+
288+
For example:
289+
290+
```arduino
291+
//initializes second I2C bus on pins D4,D5
292+
Wire1.begin(D4, D5); //sda, scl
293+
```
294+
295+
***`Wire` and `Wire1` can be used simultaneously, a great feature when working with devices that may share the same addresses.***
296+
284297
## SPI
285298

286299
![SPI Pins](assets/nano-esp32-spi.png)
@@ -320,6 +333,29 @@ void loop() {
320333
}
321334
```
322335

336+
### Second SPI Port (HSPI)
337+
338+
The Nano ESP32 has a second SPI port (HSPI). To use it, we need to create an object using `SPIClass`, and initialize communication on a specific set of pins.
339+
340+
***The HSPI port's default pins are: `GPIO14` (SCK), `GPIO12` (CIPO), `GPIO13` (COPI), `GPIO15` (CS). As some of these pins are not accessible on the Nano ESP32, you will need to configure them manually. See the definitions at the top of the code example below.***
341+
342+
```arduino
343+
//define SPI2 pins manually
344+
//you can also choose any other free pins
345+
#define SPI2_SCK D2
346+
#define SPI2_CIPO D3
347+
#define SPI2_COPI D4
348+
#define SPI2_CS D5
349+
350+
//create SPI2 object
351+
SPIClass SPI2(HSPI);
352+
353+
void setup() {
354+
//initialize SPI communication
355+
SPI2.begin(SPI2_SCK, SPI2_CIPO, SPI2_COPI, SPI2_CS);
356+
}
357+
```
358+
323359
## USB Serial & UART
324360

325361
The Nano ESP32 board features 2 separate hardware serial ports.

0 commit comments

Comments
 (0)