New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial pass at ESP32 support #71
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
Copyright (C) 2013 Norbert Truchsess. All rights reserved. | ||
Copyright (C) 2014 Nicolas Panel. All rights reserved. | ||
Copyright (C) 2015-2016 Jesse Frush. All rights reserved. | ||
Copyright (C) 2009-2016 Jeff Hoefs. All rights reserved. | ||
Copyright (C) 2009-2017 Jeff Hoefs. All rights reserved. | ||
Copyright (C) 2016 Jens B. All rights reserved. | ||
|
||
This library is free software; you can redistribute it and/or | ||
|
@@ -24,7 +24,7 @@ | |
|
||
See file LICENSE.txt for further informations on licensing terms. | ||
|
||
Last updated by Jeff Hoefs: August 14th, 2016 | ||
Last updated by Jeff Hoefs: May 28th, 2017 | ||
*/ | ||
|
||
/* | ||
|
@@ -43,6 +43,7 @@ | |
- ESP8266 WiFi board compatible with ESP8266 Arduino core | ||
- Arduino WiFi Shield 101 | ||
- Arduino WiFi Shield (or clone) | ||
- ESP32 board compatible with ESP32 Arduino core | ||
|
||
Follow the instructions in the wifiConfig.h file (wifiConfig.h tab in Arduino IDE) to | ||
configure your particular hardware. | ||
|
@@ -53,6 +54,7 @@ | |
https://github.com/arduino-libraries/WiFi101) | ||
- ESP8266 requires the Arduino ESP8266 core v2.1.0 or higher which can be obtained here: | ||
https://github.com/esp8266/Arduino | ||
- ESP32 requires the Arduino ESP32 core: https://github.com/espressif/arduino-esp32 | ||
|
||
In order to use the WiFi Shield 101 with Firmata you will need a board with at least 35k of Flash | ||
memory. This means you cannot use the WiFi Shield 101 with an Arduino Uno or any other | ||
|
@@ -85,7 +87,7 @@ | |
* connection that may help in the event of connection issues. If defined, some boards may not begin | ||
* executing this sketch until the Serial console is opened. | ||
*/ | ||
//#define SERIAL_DEBUG | ||
#define SERIAL_DEBUG | ||
#include "utility/firmataDebug.h" | ||
|
||
#define MAX_CONN_ATTEMPTS 20 // [500 ms] -> 10 s | ||
|
@@ -100,8 +102,8 @@ | |
*============================================================================*/ | ||
|
||
// STEP 1 [REQUIRED] | ||
// Uncomment / comment the appropriate set of includes for your hardware (OPTION A, B or C) | ||
// Arduino MKR1000 or ESP8266 are enabled by default if compiling for either of those boards. | ||
// Uncomment / comment the appropriate set of includes for your hardware (OPTION A, B, C, or D). | ||
// Arduino MKR1000, ESP8266 and ESP32 boards are enabled by default if compiling for any of those boards. | ||
|
||
/* | ||
* OPTION A: Configure for Arduino MKR1000 or Arduino WiFi Shield 101 | ||
|
@@ -186,6 +188,30 @@ | |
#endif | ||
#endif | ||
|
||
/* | ||
* OPTION D: Configure for ESP32 | ||
* | ||
* This will configure ConfigurableFirmataWiFi to use the ESP32 WiFi library for boards | ||
* with an ESP32 chip. It is compatible with 802.11 B/G/N networks. | ||
* | ||
* The appropriate libraries are included automatically when compiling for the ESP32 so | ||
* continue on to STEP 2. | ||
* | ||
* IMPORTANT: You must have the esp32 board support installed. To easily install this board see | ||
* the instructions here: https://github.com/espressif/arduino-esp32#installation-instructions. | ||
*/ | ||
#ifdef ESP32 | ||
#define ESP32_WIFI | ||
#include <WiFi.h> | ||
#include "utility/WiFiClientStream.h" | ||
#include "utility/WiFiServerStream.h" | ||
#ifdef WIFI_LIB_INCLUDED | ||
#define MULTIPLE_WIFI_LIB_INCLUDES | ||
#else | ||
#define WIFI_LIB_INCLUDED | ||
#endif | ||
#endif | ||
|
||
|
||
// STEP 2 [OPTIONAL for all boards and shields] | ||
// By default the board/shield is configured as a TCP server. | ||
|
@@ -282,7 +308,7 @@ char wep_key[] = "your_wep_key"; | |
#error "you must define a wifi security type in wifiConfig.h." | ||
#endif //WIFI_* security define check | ||
|
||
#if (defined(ESP8266_WIFI) && !(defined(WIFI_NO_SECURITY) || (defined(WIFI_WPA_SECURITY)))) | ||
#if ((defined(ESP8266_WIFI) || defined(ESP32_WIFI)) && !(defined(WIFI_NO_SECURITY) || (defined(WIFI_WPA_SECURITY)))) | ||
#error "you must choose between WIFI_NO_SECURITY and WIFI_WPA_SECURITY" | ||
#endif | ||
|
||
|
@@ -317,6 +343,9 @@ char wep_key[] = "your_wep_key"; | |
#elif defined(ESP8266_WIFI) && defined(SERIAL_DEBUG) | ||
#define IS_IGNORE_PIN(p) ((p) == 1) | ||
|
||
#elif defined(ESP32_WIFI) && defined(SERIAL_DEBUG) | ||
#define IS_IGNORE_PIN(p) ((p) == 1 || (p) == 3) | ||
|
||
#endif | ||
|
||
/*============================================================================== | ||
|
@@ -339,12 +368,18 @@ DigitalOutputFirmata digitalOutput; | |
#include <AnalogInputFirmata.h> | ||
AnalogInputFirmata analogInput; | ||
|
||
// analogWrite not supported for ESP32 boards | ||
#ifndef ESP32 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I hate to have to do this... will probably not merge this branch until |
||
#include <AnalogOutputFirmata.h> | ||
AnalogOutputFirmata analogOutput; | ||
#endif | ||
|
||
// servo not supported for ESP32 boards | ||
#ifndef ESP32 | ||
#include <Servo.h> | ||
#include <ServoFirmata.h> | ||
ServoFirmata servo; | ||
#endif | ||
// ServoFirmata depends on AnalogOutputFirmata | ||
#if defined ServoFirmata_h && ! defined AnalogOutputFirmata_h | ||
#error AnalogOutputFirmata must be included to use ServoFirmata | ||
|
@@ -514,6 +549,8 @@ void initTransport() | |
DEBUG_PRINTLN( "using the legacy WiFi library." ); | ||
#elif defined(ESP8266_WIFI) | ||
DEBUG_PRINTLN( "using the ESP8266 WiFi library." ); | ||
#elif defined(ESP32_WIFI) | ||
DEBUG_PRINTLN( "using the ESP32 WiFi library." ); | ||
//else should never happen here as error-checking in wifiConfig.h will catch this | ||
#endif //defined(WIFI_101) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,7 +52,8 @@ void AnalogInputFirmata::reportAnalog(byte analogPin, int value) | |
// Send pin value immediately. This is helpful when connected via | ||
// ethernet, wi-fi or bluetooth so pin states can be known upon | ||
// reconnecting. | ||
Firmata.sendAnalog(analogPin, analogRead(analogPin)); | ||
// Firmata.sendAnalog(analogPin, analogRead(analogPin)); | ||
Firmata.sendAnalog(analogPin, analogRead(analogInputToDigitalPin(analogPin))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should really be fixed in the esp32 arduino library. |
||
} | ||
} | ||
} | ||
|
@@ -79,7 +80,11 @@ void AnalogInputFirmata::handleCapability(byte pin) | |
{ | ||
if (IS_PIN_ANALOG(pin)) { | ||
Firmata.write(PIN_MODE_ANALOG); | ||
#ifdef DEFAULT_ADC_RESOLUTION | ||
Firmata.write(DEFAULT_ADC_RESOLUTION); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be added for all of the StandardFirmata variants in the firmata/arduino repo as well. |
||
#elif | ||
Firmata.write(10); // 10 = 10-bit resolution | ||
#endif | ||
} | ||
} | ||
|
||
|
@@ -102,7 +107,8 @@ void AnalogInputFirmata::report() | |
if (IS_PIN_ANALOG(pin) && Firmata.getPinMode(pin) == PIN_MODE_ANALOG) { | ||
analogPin = PIN_TO_ANALOG(pin); | ||
if (analogInputsToReport & (1 << analogPin)) { | ||
Firmata.sendAnalog(analogPin, analogRead(analogPin)); | ||
// Firmata.sendAnalog(analogPin, analogRead(analogPin)); | ||
Firmata.sendAnalog(analogPin, analogRead(analogInputToDigitalPin(analogPin))); | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,11 @@ | |
#include "AnalogFirmata.h" | ||
#include "AnalogOutputFirmata.h" | ||
|
||
// Hack to compile for ESP32 boards until arduino-esp32 supports analogWrite | ||
#ifdef ESP32 | ||
void analogWrite(byte pin, int value); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Necessary because Arduino compiles all cpp files whether or not they are included. |
||
#endif | ||
|
||
AnalogOutputFirmata::AnalogOutputFirmata() | ||
{ | ||
Firmata.attach(ANALOG_MESSAGE, analogWriteCallback); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,8 +100,8 @@ | |
#define SYSEX_SAMPLING_INTERVAL 0x7A // same as SAMPLING_INTERVAL | ||
|
||
// pin modes | ||
//#define INPUT 0x00 // defined in Arduino.h | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the esp32 library redefines |
||
//#define OUTPUT 0x01 // defined in Arduino.h | ||
#define PIN_MODE_INPUT 0x00 // pin connfigured for digital input | ||
#define PIN_MODE_OUTPUT 0x01 // pin configured for digital output | ||
#define PIN_MODE_ANALOG 0x02 // analog pin in analogInput mode | ||
#define PIN_MODE_PWM 0x03 // digital pin in PWM output mode | ||
#define PIN_MODE_SERVO 0x04 // digital pin in Servo output mode | ||
|
@@ -115,7 +115,9 @@ | |
#define PIN_MODE_IGNORE 0x7F // pin configured to be ignored by digitalWrite and capabilityResponse | ||
#define TOTAL_PIN_MODES 13 | ||
// DEPRECATED as of Firmata v2.5 | ||
#define ANALOG 0x02 // same as PIN_MODE_ANALOG | ||
// #undef ANALOG | ||
// #define ANALOG 0x02 // same as PIN_MODE_ANALOG | ||
#undef PWM | ||
#define PWM 0x03 // same as PIN_MODE_PWM | ||
#define SERVO 0x04 // same as PIN_MODE_SERVO | ||
#define SHIFT 0x05 // same as PIN_MODE_SHIFT | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have not been able to determine if this is absolutely necessary for the ESP32 since the connection is so flaky.