Skip to content

Commit

Permalink
add pre-defined board selectors BOARD_SELECT_*
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Toth committed Oct 31, 2020
1 parent dee270c commit 8aeda24
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Default settings are for Adafruit HUZZAH32 board.

In esp32_mediumone_bridge.ino ```#define CLIENT_SERIAL``` controls which serial port is used for the UART AT command input/output. Only TX & RX lines are used with no hardware flow control lines. Since this app is based on the Arduino programming model, it will typically be ```Serial```, ```Serial1``` or ```Serial2```. Usually ```Serial``` refers to the primary USB serial port on the ESP32 board which may or may not be the one you want to use for AT commands. See the source code for details about UART TX/RX pin mappings for Serialx on certain target boards. For Adafruit HUZZAH32 CLIENT_SERIAL is Serial1, REMAP_UART_PINS is 0, and Serial1 TX & RX are on the board's Feather connector.

A set of pre-defined board selections are available in the source code based on #defines that begin with ```BOARD_SELECT_```. Each defined board selects an appropriate serial port configuration for that particular board, with variants for swapped TX and RX pins. To select a particular board configuration, set that #define to 1 and set all the rest to 0. The ```BOARD_SELECT_CUSTOM``` selector allows you to define custom settings.

### Programming the ESP32 Board

For ESP32 boards that have a USB serial port, connect the ESP32 board to your computer using a USB cable, then compile and upload the program to the board.
Expand Down
64 changes: 56 additions & 8 deletions esp32_mediumone_bridge.ino
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,73 @@
*/

#define IDENT "MediumOne ESP32 Bridge"
#define VERSION "0.8.2"
#define VERSION "0.8.3"

#include <WiFiClientSecure.h> // https://github.com/espressif/arduino-esp32/tree/master/libraries/WiFiClientSecure
#define MQTT_MAX_PACKET_SIZE 1024
#include <PubSubClient.h>
#include <ArduinoJson.h>

/* Board select */
#define BOARD_SELECT_HUZZAH32 0
#define BOARD_SELECT_HUZZAH32_SWAPPED 1
#define BOARD_SELECT_ESP32_DEVKITC 0
#define BOARD_SELECT_ESP32_DEVKITC_SWAPPED 0
#define BOARD_SELECT_MIKRO_WIFI_BLE_CLICK 0
#define BOARD_SELECT_CUSTOM 0

#if defined(BOARD_SELECT_HUZZAH32) && BOARD_SELECT_HUZZAH32 == 1
/* Adafruit HUZZAH32 with default TX/RX pins */
#define CONSOLE_SERIAL Serial /* console serial port for info & debug messages */
#define CLIENT_SERIAL Serial1 /* client serial port for incoming AT commands */
#define REMAP_UART_PINS 0 /* 0=use default TX/RX pin mappings, 1=remap to alternate pins */
#define HAS_LED_BUILTIN 1 /* 0=board does not have LED_BUILT_IN, 1=has LED_BUILTIN */
#elif defined(BOARD_SELECT_HUZZAH32_SWAPPED) && BOARD_SELECT_HUZZAH32_SWAPPED == 1
/* Adafruit HUZZAH32 with swapped TX/RX pins */
#define CONSOLE_SERIAL Serial /* console serial port for info & debug messages */
#define CLIENT_SERIAL Serial1 /* client serial port for incoming AT commands */
#define REMAP_UART_PINS 1 /* 0=use default TX/RX pin mappings, 1=remap to alternate pins */
#define CLIENT_SERIAL_RX_GPIO 17 /* GPIO17 = chip pin 28 (IO17) = JP1-2 on HUZZAH32 */
#define CLIENT_SERIAL_TX_GPIO 16 /* GPIO16 = chip pin 27 (IO16) = JP1-3 on HUZZAH32 */
#define HAS_LED_BUILTIN 1 /* 0=board does not have LED_BUILT_IN, 1=has LED_BUILTIN */
#elif defined(BOARD_SELECT_ESP32_DEVKITC) && BOARD_SELECT_ESP32_DEVKITC == 1
/* ESP32 DevKitC with default TX/RX pins */
#define CONSOLE_SERIAL Serial /* console serial port for info & debug messages */
#define CLIENT_SERIAL Serial2 /* client serial port for incoming AT commands */
#define REMAP_UART_PINS 0 /* 0=use default TX/RX pin mappings, 1=remap to alternate pins */
#define HAS_LED_BUILTIN 1 /* 0=board does not have LED_BUILT_IN, 1=has LED_BUILTIN */
#elif defined(BOARD_SELECT_ESP32_DEVKITC_SWAPPED) && BOARD_SELECT_ESP32_DEVKITC_SWAPPED == 1
/* ESP32 DevKitC with swapped TX/RX pins */
#define CONSOLE_SERIAL Serial /* console serial port for info & debug messages */
#define CLIENT_SERIAL Serial2 /* client serial port for incoming AT commands */
#define REMAP_UART_PINS 1 /* 0=use default TX/RX pin mappings, 1=remap to alternate pins */
#define CLIENT_SERIAL_RX_GPIO 4 /* GPIO4 = chip pin 26 = IO4 = J3-13 on DevKitC */
#define CLIENT_SERIAL_TX_GPIO 2 /* GPIO2 = chip pin 24 = IO2 = J3-15 on DevKitC */
#define HAS_LED_BUILTIN 1 /* 0=board does not have LED_BUILT_IN, 1=has LED_BUILTIN */
#elif defined(BOARD_SELECT_MIKRO_WIFI_BLE_CLICK) && BOARD_SELECT_MIKRO_WIFI_BLE_CLICK
/* Mikro Wi-Fi BLE Click */
#define CONSOLE_SERIAL Serial /* console serial port for info & debug messages */
#define CLIENT_SERIAL Serial2 /* client serial port for incoming AT commands */
#define REMAP_UART_PINS 0 /* 0=use default TX/RX pin mappings, 1=remap to alternate pins */
#define HAS_LED_BUILTIN 1 /* 0=board does not have LED_BUILT_IN, 1=has LED_BUILTIN */
#elif defined(BOARD_SELECT_CUSTOM) && BOARD_SELECT_CUSTOM == 1
/* Custom board definition */
#define CONSOLE_SERIAL Serial /* console serial port for info & debug messages */
#define CLIENT_SERIAL Serial1 /* client serial port for incoming AT commands */
#define REMAP_UART_PINS 0 /* 0=use default TX/RX pin mappings, 1=remap to alternate pins */
#define HAS_LED_BUILTIN 0 /* 0=board does not have LED_BUILT_IN, 1=has LED_BUILTIN */
#else
/* Default settings if no pre-defined board selected */
#define CONSOLE_SERIAL Serial /* console serial port for info & debug messages */
#define CLIENT_SERIAL Serial1 /* client serial port for incoming AT commands */
#define REMAP_UART_PINS 0 /* 0=use default TX/RX pin mappings, 1=remap to alternate pins */
#define HAS_LED_BUILTIN 0 /* 0=board does not have LED_BUILT_IN, 1=has LED_BUILTIN */
#endif

/* Defaults on Adafruit HUZZAH32 ESP32 Feather:
* Serial RX & TX are mapped to USB-to-Serial converter.
* Serial1 RX is mapped to GPIO16 = chip pin 27 (IO16) = JP3-3 (RX),
* Serial1 TX is mapped to GPIO17 = chip pin 28 (IO17) = JP3-2 (TX).
* Serial1 RX is mapped to GPIO16 = chip pin 27 (IO16) = JP1-3 (RX),
* Serial1 TX is mapped to GPIO17 = chip pin 28 (IO17) = JP1-2 (TX).
* For HUZZAH32 use CONSOLE_SERIAL=Serial, CLIENT_SERIAL=Serial1, REMAP_UART_PINS=0, and HAS_LED_BUILTIN=1.
* Defaults on ESP32 DevKitC:
* Serial RX & TX are mapped to USB-to-Serial converter
Expand All @@ -48,11 +100,7 @@
* For Mikro WiFi BLE Click use CONSOLE_SERIAL=Serial, CLIENT_SERIAL=Serial2, REMAP_UART_PINS=0,
* and HAS_LED_BUILTIN=0.
*/
#if defined(REMAP_UART_PINS) && REMAP_UART_PINS == 1
/* Optional serial RX & TX port pin remapping used with CLIENT_SERIAL. */
#define CLIENT_SERIAL_RX_GPIO 4 /* GPIO4 = chip pin 26 = IO4 = J3-13 on DevKitC */
#define CLIENT_SERIAL_TX_GPIO 2 /* GPIO2 = chip pin 24 = IO2 = J3-15 on DevKitC */
#endif

/* Serial data rates */
#define CONSOLE_SERIAL_BAUD 115200
#define CLIENT_SERIAL_BAUD 115200
Expand Down

0 comments on commit 8aeda24

Please sign in to comment.