Skip to content

Commit

Permalink
Adds ESP8266 support c/o jacobrosental and jnsbyr
Browse files Browse the repository at this point in the history
bare minimum esp support

missing paren

pin functions based on board depended defaults

to support different ESP8266 boad layouts, use board depended constants
from "...\esp8266\hardware\esp8266\2.1.0\variants\...\pins_arduino.h"

analog pin mapping fixed

requires Arduino core for ESP8266 V2.2

VERSION_BLINK_PIN and PIN_SERIAL1_TX removed

most remaining absolte pin numbers/counts replaced by defines/constants from pins_arduino.h

config optimizations

- Firmata 2.5.1 or higher required
- esp8266/Adruino needs to fix macros digitalPinHasPWM and
digitalPinToInterrupt
- no wifio board support

fixed macro IS_PIN_INTERRUPT

new define DEFAULT_PWM_RESOLUTION

- default to 8-bit for all architectures and board
- ESP8266 default is 10-bit

examples updated to use define DEFAULT_PWM_RESOLUTION

WiFiStream variant integration

wifi updates

- Consolidate WiFi stream classes into single class
- Remove unused WiFi stream classes
- Fix ESP8266 serial output (needed flush)
- Fix ESP8266 connection status issue
- Automatically include WiFi lib for MKR1000 and ESP8266
- Simplify config error checking
- Update instructions in wifiConfig.h
- Do not ignore MKR1000 pins
  • Loading branch information
jacobrosenthal authored and soundanalogous committed Apr 11, 2016
1 parent e5582d0 commit 51e3c7d
Show file tree
Hide file tree
Showing 12 changed files with 223 additions and 321 deletions.
25 changes: 25 additions & 0 deletions Boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,28 @@ writePort(port, value, bitmask): Write an 8 bit port.
#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
#define PIN_TO_SERVO(p) ((p) - 2)

// ESP8266
// note: boot mode GPIOs 0, 2 and 15 can be used as outputs, GPIOs 6-11 are in use for flash IO
#elif defined(ESP8266)
#define TOTAL_ANALOG_PINS NUM_ANALOG_INPUTS
#define TOTAL_PINS A0 + NUM_ANALOG_INPUTS
#define PIN_SERIAL_RX 3
#define PIN_SERIAL_TX 1
#define IS_PIN_DIGITAL(p) (((p) >= 0 && (p) <= 5) || ((p) >= 12 && (p) < A0))
#define IS_PIN_ANALOG(p) ((p) >= A0 && (p) < A0 + NUM_ANALOG_INPUTS)
#define IS_PIN_PWM(p) digitalPinHasPWM(p)
#define IS_PIN_SERVO(p) (IS_PIN_DIGITAL(p) && (p) < MAX_SERVOS)
#define IS_PIN_I2C(p) ((p) == SDA || (p) == SCL)
#define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
#define IS_PIN_INTERRUPT(p) (digitalPinToInterrupt(p) > NOT_AN_INTERRUPT)
#define IS_PIN_SERIAL(p) ((p) == PIN_SERIAL_RX || (p) == PIN_SERIAL_TX)
#define PIN_TO_DIGITAL(p) (p)
#define PIN_TO_ANALOG(p) ((p) - A0)
#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
#define PIN_TO_SERVO(p) (p)
#define DEFAULT_PWM_RESOLUTION 10


// anything else
#else
#error "Please edit Boards.h with a hardware abstraction for this board"
Expand All @@ -695,6 +717,9 @@ writePort(port, value, bitmask): Write an 8 bit port.
#define IS_PIN_SERIAL(p) 0
#endif

#ifndef DEFAULT_PWM_RESOLUTION
#define DEFAULT_PWM_RESOLUTION 8
#endif

/*==============================================================================
* readPort() - Read an 8 bit port
Expand Down
2 changes: 1 addition & 1 deletion examples/StandardFirmata/StandardFirmata.ino
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ void sysexCallback(byte command, byte argc, byte *argv)
}
if (IS_PIN_PWM(pin)) {
Firmata.write(PIN_MODE_PWM);
Firmata.write(8); // 8 = 8-bit resolution
Firmata.write(DEFAULT_PWM_RESOLUTION);
}
if (IS_PIN_DIGITAL(pin)) {
Firmata.write(PIN_MODE_SERVO);
Expand Down
2 changes: 1 addition & 1 deletion examples/StandardFirmataChipKIT/StandardFirmataChipKIT.ino
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ void sysexCallback(byte command, byte argc, byte *argv)
}
if (IS_PIN_PWM(pin)) {
Firmata.write(PIN_MODE_PWM);
Firmata.write(8); // 8 = 8-bit resolution
Firmata.write(DEFAULT_PWM_RESOLUTION);
}
if (IS_PIN_DIGITAL(pin)) {
Firmata.write(PIN_MODE_SERVO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ void sysexCallback(byte command, byte argc, byte *argv)
}
if (IS_PIN_PWM(pin)) {
Firmata.write(PIN_MODE_PWM);
Firmata.write(8); // 8 = 8-bit resolution
Firmata.write(DEFAULT_PWM_RESOLUTION);
}
if (IS_PIN_DIGITAL(pin)) {
Firmata.write(PIN_MODE_SERVO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ void sysexCallback(byte command, byte argc, byte *argv)
}
if (IS_PIN_PWM(pin)) {
Firmata.write(PIN_MODE_PWM);
Firmata.write(8); // 8 = 8-bit resolution
Firmata.write(DEFAULT_PWM_RESOLUTION);
}
if (IS_PIN_DIGITAL(pin)) {
Firmata.write(PIN_MODE_SERVO);
Expand Down
2 changes: 1 addition & 1 deletion examples/StandardFirmataPlus/StandardFirmataPlus.ino
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ void sysexCallback(byte command, byte argc, byte *argv)
}
if (IS_PIN_PWM(pin)) {
Firmata.write(PIN_MODE_PWM);
Firmata.write(8); // 8 = 8-bit resolution
Firmata.write(DEFAULT_PWM_RESOLUTION);
}
if (IS_PIN_DIGITAL(pin)) {
Firmata.write(PIN_MODE_SERVO);
Expand Down
41 changes: 28 additions & 13 deletions examples/StandardFirmataWiFi/StandardFirmataWiFi.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
Copyright (C) 2009 Shigeru Kobayashi. All rights reserved.
Copyright (C) 2009-2016 Jeff Hoefs. All rights reserved.
Copyright (C) 2015-2016 Jesse Frush. All rights reserved.
Copyright (C) 2016 Jens B. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand All @@ -21,7 +22,7 @@
See file LICENSE.txt for further informations on licensing terms.
Last updated by Jeff Hoefs: January 10th, 2016
Last updated by Jeff Hoefs: April 10th, 2016
*/

/*
Expand All @@ -36,7 +37,7 @@
- Arduino WiFi Shield (or clone)
- Arduino WiFi Shield 101
- Arduino MKR1000 board (built-in WiFi 101)
- Adafruit HUZZAH CC3000 WiFi Shield (support coming soon)
- ESP8266 WiFi board compatible with ESP8266 Arduino core
Follow the instructions in the wifiConfig.h file (wifiConfig.h tab in Arduino IDE) to
configure your particular hardware.
Expand All @@ -45,6 +46,8 @@
- WiFi Shield 101 requires version 0.7.0 or higher of the WiFi101 library (available in Arduino
1.6.8 or higher, or update the library via the Arduino Library Manager or clone from source:
https://github.com/arduino-libraries/WiFi101)
- ESP8266 requires the Arduino ESP8266 core which can be obtained here:
https://github.com/esp8266/Arduino
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
Expand Down Expand Up @@ -120,6 +123,12 @@ SerialFirmata serialFeature;
#ifdef STATIC_IP_ADDRESS
IPAddress local_ip(STATIC_IP_ADDRESS);
#endif
#ifdef SUBNET_MASK
IPAddress subnet(SUBNET_MASK);
#endif
#ifdef GATEWAY_IP_ADDRESS
IPAddress gateway(GATEWAY_IP_ADDRESS);
#endif

int wifiConnectionAttemptCounter = 0;
int wifiStatus = WL_IDLE_STATUS;
Expand Down Expand Up @@ -687,7 +696,7 @@ void sysexCallback(byte command, byte argc, byte *argv)
}
if (IS_PIN_PWM(pin)) {
Firmata.write(PIN_MODE_PWM);
Firmata.write(8); // 8 = 8-bit resolution
Firmata.write(DEFAULT_PWM_RESOLUTION);
}
if (IS_PIN_DIGITAL(pin)) {
Firmata.write(PIN_MODE_SERVO);
Expand Down Expand Up @@ -817,37 +826,37 @@ void systemResetCallback()
}

void printWifiStatus() {
#if defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101)
#if defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101) || defined(ESP8266_WIFI)
if ( WiFi.status() != WL_CONNECTED )
{
DEBUG_PRINT( "WiFi connection failed. Status value: " );
DEBUG_PRINTLN( WiFi.status() );
}
else
#endif //defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101)
#endif //defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101) || defined(ESP8266_WIFI)
{
// print the SSID of the network you're attached to:
DEBUG_PRINT( "SSID: " );

#if defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101)
#if defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101) || defined(ESP8266_WIFI)
DEBUG_PRINTLN( WiFi.SSID() );
#endif //defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101)
#endif //defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101) || defined(ESP8266_WIFI)

// print your WiFi shield's IP address:
DEBUG_PRINT( "IP Address: " );

#if defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101)
#if defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101) || defined(ESP8266_WIFI)
IPAddress ip = WiFi.localIP();
DEBUG_PRINTLN( ip );
#endif //defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101)
#endif //defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101) || defined(ESP8266_WIFI)

// print the received signal strength:
DEBUG_PRINT( "signal strength (RSSI): " );

#if defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101)
#if defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101) || defined(ESP8266_WIFI)
long rssi = WiFi.RSSI();
DEBUG_PRINT( rssi );
#endif //defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101)
#endif //defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101) || defined(ESP8266_WIFI)

DEBUG_PRINTLN( " dBm" );
}
Expand All @@ -868,6 +877,8 @@ void setup()
DEBUG_PRINTLN( "using the WiFi 101 library." );
#elif defined(ARDUINO_WIFI_SHIELD)
DEBUG_PRINTLN( "using the legacy WiFi library." );
#elif defined(ESP8266_WIFI)
DEBUG_PRINTLN( "using the ESP8266 WiFi library." );
#elif defined(HUZZAH_WIFI)
DEBUG_PRINTLN( "using the HUZZAH WiFi library." );
//else should never happen here as error-checking in wifiConfig.h will catch this
Expand All @@ -879,9 +890,13 @@ void setup()
#ifdef STATIC_IP_ADDRESS
DEBUG_PRINT( "Using static IP: " );
DEBUG_PRINTLN( local_ip );
//you can also provide a static IP in the begin() functions, but this simplifies
//ifdef logic in this sketch due to support for all different encryption types.
#ifdef ESP8266_WIFI
stream.config( local_ip , gateway, subnet );
#else
// you can also provide a static IP in the begin() functions, but this simplifies
// ifdef logic in this sketch due to support for all different encryption types.
stream.config( local_ip );
#endif
#else
DEBUG_PRINTLN( "IP will be requested from DHCP ..." );
#endif
Expand Down
Loading

0 comments on commit 51e3c7d

Please sign in to comment.