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
Conversation
Wi-Fi transport only for now. Tested on Sparkfun ESP32 Thing board.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
This should really be fixed in the esp32 arduino library. analogRead
should be able to accept the analog pin number or the digital pin number.
@@ -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 comment
The 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.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
the esp32 library redefines INPUT
, OUTPUT
and ANALOG
@@ -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 comment
The 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.
@@ -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) |
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.
@@ -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 comment
The 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 analogWrite
is added to the esp32 library.
Closing this, as ESP32 support has now been merged (with help of this PR as well). Works for me with both USB and Wifi connection. Thanks to https://github.com/espressif/arduino-esp32 the ESP32 can be programmed and used like an Arduino. |
Wi-Fi transport only for now.
Tested on Sparkfun ESP32 Thing board.
This is sorta working when the board is configured as a TCP server (default) or client. However establishing a connection currently requires some patience. I suspect there may be issues in the ESP32 WiFi library because board locks up while trying to establish a connection with the AP more than half the time. It could also be a power issue. I've found the connection to be much more stable when using a USB power supply vs using my laptop usb port, but even with a power supply I still have to hit reset on the board a few times. I suspect a power supply > 500 mA is required (something in the 1000 to 2000 mA range is probably best).
Currently the procedure is restart the board, wait a couple of seconds then start the Firmata client application. It may take several seconds for the Firmata client to connect. Also, if reading analog pins, there are very noticeable lags. I suspect a more robust buffering scheme is necessary for Firmata to support boards like this.
I have no immediate plans to enable using ESP32 boards with Firmata using a Serial/USB transport or a BLE transport.
Firmata client examples interfacing with the ESP32 via a TCP client or server connection can be found here (using firmata.js).
This branch will not be merged until WiFi connectivity and buffering is improved (could use help on figuring out an approach for the later), so checkout the esp-thing branch in the mean time.