-
Notifications
You must be signed in to change notification settings - Fork 516
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
pin functions based on board depended defaults #278
Conversation
to support different ESP8266 boad layouts, use board depended constants from "...\esp8266\hardware\esp8266\2.1.0\variants\...\pins_arduino.h"
requires Arduino core for ESP8266 V2.2
#define IS_PIN_SPI(p) (false) | ||
#define TOTAL_ANALOG_PINS 1 | ||
#define TOTAL_PINS 18 // 11 digital + 1 analog + 6 inaccessible | ||
#define VERSION_BLINK_PIN LED_BUILTIN |
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.
Remove VERSION_BLINK_PIN
. The version blink sequence takes too long and excluding this define will exclude the version blink sequence - saving up to 2.5 seconds or more of startup time (since each Firmata version increment adds additional time to the sequence).
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.
will be removed with next commit
Note that with current release V2.1 of esp8266/Arduino you need #if !defined(ARDUINO_ARCH_ESP8266)
Firmata.sendAnalog(analogPin, analogRead(analogPin));
#else
Firmata.sendAnalog(analogPin, analogRead(A0));
#endif to make the analog input work. I opened an issue (esp8266/Arduino#1766) to make the define unnecessary. |
#define PIN_SERIAL_TX 1 | ||
#define PIN_SERIAL1_TX 2 | ||
#define IS_PIN_DIGITAL(p) (((p) >= 0 && (p) <= 5) || ((p) >= 12 && (p) <= 16)) | ||
#define IS_PIN_ANALOG(p) ((p) == A0) |
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.
What about the wifio?
static const uint8_t A0 = 14;
static const uint8_t A1 = 15;
static const uint8_t A2 = 16;
static const uint8_t A3 = 17;
static const uint8_t A4 = 18;
static const uint8_t A5 = 19;
static const uint8_t A6 = 20;
static const uint8_t A7 = 21;
?
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.
Please tell me where these constants are needed for. A0 = 17 is already in use in the esp8266/Arduino project for the one and only analog input pin.
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.
OK, found it myself. For this board probably a separate definition is needed in Board.h and that may not be enough to make it work.
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.
👍
As much as I hate to add yet another StandardFirmata variant (mostly because it sucks to maintain them all), we may need to add StandardFirmataESP and include espConfig.h (much in the same way I've included a config for Ethernet, WiFi and BLE). That way the user can uncomment a define that will configure the sketch properly for their particular board. |
Or it could all be handled in wifiConfig.h (in StandardFirmataWiFi) - provide different configurations and the user selects one by uncommenting an appropriate define. |
I see now the wifiConfig.h route is what Jacob had started so lets continue down that route. Also need to figure out a better way to manage this as it's starting to get out of hand. In wifiConfig you can manage configurations per specific ESP board. |
One thing that would make this much easier is if each variant in esp8266/Arduino had a unique define - then we could sort these out easily in Boards.h. |
For my tests I didn't need to go so far as the changes you refer to. I based my tests on StandardFirmataEthernetPlus, changed Ethernet into WiFi, added a few lines to setup WiFi and added a few defines to exclude the Arduino board special pin configurations. Having a unique identifier for the different boards would help. Maybe the project is open to such an enhancement. |
One way to have a different unique identifier is to have a unique sketch name for each board and inspect that name view the firmware query (which returns the filename) |
I looked over the
|
Looks good to me, but I would explicitly exclude the pins 6 to 11. They are used for the flash IO on most of the boards and accessing them by accident will probably crash the application. Using the higher number of the total pins constant from pins_arduino.h for an ifdef one could try to make a special config for wifio. |
Untested, but this may cover all boards:
|
Don't know why but I had trouble with the line |
Because of esp8266/Arduino#1766 |
I don't see how that would be an issue since wifio A0 is mapped to pin 14 as it should be for that board: https://github.com/esp8266/Arduino/blob/master/variants/wifio/pins_arduino.h#L41.
|
I did not say that it's not possible but that the esp project V2.1 assumes that analogRead is called with the absolute pin number. Even A0 is currently only working by calling analogRead(17) but PIN_TO_ANALOG would call analogRead(0) instead. |
The broken pin mapping in esp8266 is definitely a blocker. Hopefully they resolve that soon. |
Guys, you may ignore wifio variant — it's a board which was never released. We keep the code in repository because it shows how to implement "virtual" IO with an AVR slave. Noone is actually using it. I'll fix analogRead(0) asap. |
@igrr thanks for the details :) |
…ts from pins_arduino.h
|
lets try to get the
It should compile in 2.5.1 or higher. I removed the dependency on |
Agreed, Upgraded to Firmata 2.5.2 and now I can do without |
#define TOTAL_ANALOG_PINS 1 | ||
#define TOTAL_PINS 18 // 11 digital + 1 analog + 6 inaccessible | ||
#define TOTAL_ANALOG_PINS NUM_ANALOG_INPUTS | ||
#define TOTAL_PINS (NUM_DIGITAL_PINS > A0 + NUM_ANALOG_INPUTS ? NUM_DIGITAL_PINS : A0 + NUM_ANALOG_INPUTS) |
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 conditional isn't needed anymore, should just be A0 + NUM_ANALOG_INPUTS
.
- Firmata 2.5.1 or higher required - esp8266/Adruino needs to fix macros digitalPinHasPWM and digitalPinToInterrupt - no wifio board support
Added a request to fix the macros |
The |
Just found something else not considered so far: the ESP8266 project default PWM resolution is 10 bits, not 8, but Firmata always claims 8 bit PWM resolution, even with AVR hardware that can do better (Due, Zero), relying on API defaults. Using |
I drafted a proposal to add analog configuration a couple of years ago: firmata/protocol#8 I also opened a PR for this long ago but ran into MCU architecture issues that I was not able to resolve: #174 Open to picking this back up if I can find the time. |
#174 adds interesting configuration options but they go much further than necessary for basic operations. A capability query should not return the wrong properties. Even if a platform does not support changing PWM resolution, it should report the build-in resolution and on more powerful platforms the default resolution. A simple but ugly way to do it is if (IS_PIN_PWM(pin)) {
Firmata.write(PIN_MODE_PWM);
#if defined(ARDUINO_ARCH_ESP8266)
Firmata.write(10); // 10 = 10-bit resolution, see Arduino.h PWMRANGE
#else
Firmata.write(8); // 8 = 8-bit resolution
#endif
} but a new property like if (IS_PIN_PWM(pin)) {
Firmata.write(PIN_MODE_PWM);
Firmata.write(DEFAULT_PWM_RESOLUTION); // resolution in bits
} |
I think the second approach is a good short-term solution. Some Arduino variants already report the default pwm resolution (for example), but it's probably irregular enough to justify adding it to Boards.h. Can you add |
#define IS_PIN_SPI(p) (false) | ||
#define TOTAL_ANALOG_PINS NUM_ANALOG_INPUTS | ||
#define TOTAL_PINS A0 + NUM_ANALOG_INPUTS | ||
#define PIN_SERIAL_RX 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.
Do pins 3 and 1 appear to be common for RX and TX across all ESP8266 board variants?
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.
Serial has some special properties with the ESP8266. I don't think they can be completely described in a Boards.h approach (e.g. similar to the PWM resolution you can change the serial pin assignment and there is a Serial1 but you typically can't use the RX pin). The details are described here.
All boards seem to have Serial in common and the default mapping for Serial is always pins 1 and 3.
- default to 8-bit for all architectures and board - ESP8266 default is 10-bit
to support different ESP8266 boad layouts, use board depended constants
from "...\esp8266\hardware\esp8266\2.1.0\variants...\pins_arduino.h"
DOUT, DIN, I2C and SERIAL0 have been tested and are working with a HUZZA board