Tuesday, September 17, 2019

Referencing the PINs on the ESPDuino on the Arduino IDE

I bought the ESPDuino a while back to tinkle with, and finally got down to actually using it. It's a pretty nice piece of hardware considering the fact that you get an ESP8266 processor on an UNO R3 form factor for a USD7 - USD10 (RM20 - RM40) price point. You can purchase the the dev board from their website: -

http://www.smartarduino.com/view.php?id=94894 ;

or from Shopee / Lazada.


Although the company claims it's a drop-in replacement for the UNO with Wi-Fi, there are already 2 obvious differences. The first being a 3.3V device (ESP8266) and the second, the pins. It's the pins I'll be talking about here.

The ESPDuino from http://www.doit.am/


The Arduino UNO from http://www.arduino.cc/


The PINs : UNO vs ESPDuino

We'll kind of kick off with an example. Pin 13 on the UNO physically maps to a "NC" (no connection) on the ESPDuino and Pin 2 on the UNO physically maps to D0 on the ESPDuino.

So, if you had an existing UNO project that goes like ...

#define pinLED 13

you'll end up having to move your DuPont Wire to MOSI/D13 on the ESPDuino.

The ESPDuino comes with a set of #defines for their pinout. You can find them in a file named "pins_arduino.h". The location of the file is in

"C:\Users\<User>\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\<version>\variants\ESPDuino"

for Linux, that would be

"/home/<User>/.arduino15/packages/esp8266/hardware/esp8266/<version>/variants/ESPDuino"

N.B. : the location of the folder can be obtained from the boards.txt file.

From the pins_arduino.h file for ESPDuino, we have the following pins ...

#define PIN_WIRE_SDA (4)
#define PIN_WIRE_SCL (5)

static const uint8_t SDA = PIN_WIRE_SDA;
static const uint8_t SCL = PIN_WIRE_SCL;

// All digital pins are PWM capable
static const uint8_t D0   = 0;
static const uint8_t D1   = 1; //TX0
static const uint8_t D2   = 2;
static const uint8_t D3   = 3; //RX0
static const uint8_t D4   = 4;
static const uint8_t D5   = 5;
static const uint8_t D12   = 12; // MISO
static const uint8_t D13   = 13; // MOSI
static const uint8_t D14   = 14; // SCK
static const uint8_t D15   = 15; // SS(SDA)
static const uint8_t D16   = 16; // LED_BUILTIN
static const uint8_t RX0   = 3;
static const uint8_t TX0   = 1;

#define LED_BUILTIN 16

#include "../generic/common.h"

So it looks like you can't port your UNO project verbatim over to the ESPDuino.

You'll have to rewrite your code ...

#define pinLED D13

and that's the best way to go, since the labels match exactly the pins on the ESPDuino board.


References
How to Determine Which pins_arduino.h File is Used? - StackExchange
Communication Between the Arduino UNO and ESPDuino - Arduino Forums
ESPDuino Pinout - ESP8266 Community