Skip to content

Commit 985e34c

Browse files
Merge branch 'jnsbyr-esp' into esp
2 parents c1bafb7 + 7ecba4e commit 985e34c

File tree

14 files changed

+225
-626
lines changed

14 files changed

+225
-626
lines changed

Boards.h

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -665,22 +665,26 @@ writePort(port, value, bitmask): Write an 8 bit port.
665665
#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
666666
#define PIN_TO_SERVO(p) ((p) - 2)
667667

668-
// ESP8266 generic
668+
// ESP8266
669+
// note: boot mode GPIOs 0, 2 and 15 can be used as outputs, GPIOs 6-11 are in use for flash IO
669670
#elif defined(ESP8266)
670-
#define TOTAL_ANALOG_PINS 0
671-
#define TOTAL_PINS 17
672-
#define VERSION_BLINK_PIN 4
673-
// #define IS_PIN_DIGITAL(p) ((p) == 0 || (p) == 1 || (p) == 2 || (p) == 3 || (p) == 4 || (p) == 5 || (p) == 12 || (p) == 13 || (p) == 14 || (p) == 15 || (p) == 16) //for wifi dont protect serial pins because these things only have 2 pins otherwise
674-
#define IS_PIN_DIGITAL(p) ((p) == 0 || (p) == 2 || (p) == 4 || (p) == 5 || (p) == 12 || (p) == 13 || (p) == 14 || (p) == 15 || (p) == 16)
675-
#define IS_PIN_ANALOG(p) (false)
676-
#define IS_PIN_PWM(p) (false)
677-
#define IS_PIN_SERVO(p) ((p) >= 0 && (p) < MAX_SERVOS)
678-
#define IS_PIN_I2C(p) (false)
679-
#define IS_PIN_SPI(p) (false)
671+
#define TOTAL_ANALOG_PINS NUM_ANALOG_INPUTS
672+
#define TOTAL_PINS A0 + NUM_ANALOG_INPUTS
673+
#define PIN_SERIAL_RX 3
674+
#define PIN_SERIAL_TX 1
675+
#define IS_PIN_DIGITAL(p) (((p) >= 0 && (p) <= 5) || ((p) >= 12 && (p) < A0))
676+
#define IS_PIN_ANALOG(p) ((p) >= A0 && (p) < A0 + NUM_ANALOG_INPUTS)
677+
#define IS_PIN_PWM(p) digitalPinHasPWM(p)
678+
#define IS_PIN_SERVO(p) (IS_PIN_DIGITAL(p) && (p) < MAX_SERVOS)
679+
#define IS_PIN_I2C(p) ((p) == SDA || (p) == SCL)
680+
#define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
681+
#define IS_PIN_INTERRUPT(p) (digitalPinToInterrupt(p) > NOT_AN_INTERRUPT)
682+
#define IS_PIN_SERIAL(p) ((p) == PIN_SERIAL_RX || (p) == PIN_SERIAL_TX)
680683
#define PIN_TO_DIGITAL(p) (p)
681-
#define PIN_TO_ANALOG(p) ((p) - 17)
684+
#define PIN_TO_ANALOG(p) ((p) - A0)
682685
#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
683-
#define PIN_TO_SERVO(p) p
686+
#define PIN_TO_SERVO(p) (p)
687+
#define DEFAULT_PWM_RESOLUTION 10
684688

685689

686690
// anything else
@@ -697,6 +701,9 @@ writePort(port, value, bitmask): Write an 8 bit port.
697701
#define IS_PIN_SERIAL(p) 0
698702
#endif
699703

704+
#ifndef DEFAULT_PWM_RESOLUTION
705+
#define DEFAULT_PWM_RESOLUTION 8
706+
#endif
700707

701708
/*==============================================================================
702709
* readPort() - Read an 8 bit port

examples/StandardFirmata/StandardFirmata.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ void sysexCallback(byte command, byte argc, byte *argv)
615615
}
616616
if (IS_PIN_PWM(pin)) {
617617
Firmata.write(PIN_MODE_PWM);
618-
Firmata.write(8); // 8 = 8-bit resolution
618+
Firmata.write(DEFAULT_PWM_RESOLUTION);
619619
}
620620
if (IS_PIN_DIGITAL(pin)) {
621621
Firmata.write(PIN_MODE_SERVO);

examples/StandardFirmataChipKIT/StandardFirmataChipKIT.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ void sysexCallback(byte command, byte argc, byte *argv)
616616
}
617617
if (IS_PIN_PWM(pin)) {
618618
Firmata.write(PIN_MODE_PWM);
619-
Firmata.write(8); // 8 = 8-bit resolution
619+
Firmata.write(DEFAULT_PWM_RESOLUTION);
620620
}
621621
if (IS_PIN_DIGITAL(pin)) {
622622
Firmata.write(PIN_MODE_SERVO);

examples/StandardFirmataEthernet/StandardFirmataEthernet.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ void sysexCallback(byte command, byte argc, byte *argv)
672672
}
673673
if (IS_PIN_PWM(pin)) {
674674
Firmata.write(PIN_MODE_PWM);
675-
Firmata.write(8); // 8 = 8-bit resolution
675+
Firmata.write(DEFAULT_PWM_RESOLUTION);
676676
}
677677
if (IS_PIN_DIGITAL(pin)) {
678678
Firmata.write(PIN_MODE_SERVO);

examples/StandardFirmataEthernetPlus/StandardFirmataEthernetPlus.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ void sysexCallback(byte command, byte argc, byte *argv)
680680
}
681681
if (IS_PIN_PWM(pin)) {
682682
Firmata.write(PIN_MODE_PWM);
683-
Firmata.write(8); // 8 = 8-bit resolution
683+
Firmata.write(DEFAULT_PWM_RESOLUTION);
684684
}
685685
if (IS_PIN_DIGITAL(pin)) {
686686
Firmata.write(PIN_MODE_SERVO);

examples/StandardFirmataPlus/StandardFirmataPlus.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ void sysexCallback(byte command, byte argc, byte *argv)
635635
}
636636
if (IS_PIN_PWM(pin)) {
637637
Firmata.write(PIN_MODE_PWM);
638-
Firmata.write(8); // 8 = 8-bit resolution
638+
Firmata.write(DEFAULT_PWM_RESOLUTION);
639639
}
640640
if (IS_PIN_DIGITAL(pin)) {
641641
Firmata.write(PIN_MODE_SERVO);

examples/StandardFirmataWiFi/StandardFirmataWiFi.ino

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
Copyright (C) 2009 Shigeru Kobayashi. All rights reserved.
1414
Copyright (C) 2009-2016 Jeff Hoefs. All rights reserved.
1515
Copyright (C) 2015-2016 Jesse Frush. All rights reserved.
16+
Copyright (C) 2016 Jens B. All rights reserved.
1617
1718
This library is free software; you can redistribute it and/or
1819
modify it under the terms of the GNU Lesser General Public
@@ -21,7 +22,7 @@
2122
2223
See file LICENSE.txt for further informations on licensing terms.
2324
24-
Last updated by Jeff Hoefs: January 10th, 2016
25+
Last updated by Jeff Hoefs: April 10th, 2016
2526
*/
2627

2728
/*
@@ -36,7 +37,7 @@
3637
- Arduino WiFi Shield (or clone)
3738
- Arduino WiFi Shield 101
3839
- Arduino MKR1000 board (built-in WiFi 101)
39-
- Adafruit HUZZAH CC3000 WiFi Shield (support coming soon)
40+
- ESP8266 WiFi board compatible with ESP8266 Arduino core
4041
4142
Follow the instructions in the wifiConfig.h file (wifiConfig.h tab in Arduino IDE) to
4243
configure your particular hardware.
@@ -45,6 +46,8 @@
4546
- WiFi Shield 101 requires version 0.7.0 or higher of the WiFi101 library (available in Arduino
4647
1.6.8 or higher, or update the library via the Arduino Library Manager or clone from source:
4748
https://github.com/arduino-libraries/WiFi101)
49+
- ESP8266 requires the Arduino ESP8266 core which can be obtained here:
50+
https://github.com/esp8266/Arduino
4851
4952
In order to use the WiFi Shield 101 with Firmata you will need a board with at least
5053
35k of Flash memory. This means you cannot use the WiFi Shield 101 with an Arduino Uno
@@ -74,11 +77,6 @@
7477
#include <Wire.h>
7578
#include <Firmata.h>
7679

77-
// I dont understand either
78-
void disableI2CPins();
79-
void enableI2CPins();
80-
void reportAnalogCallback(byte analogPin, int value);
81-
8280
/*
8381
* Uncomment the #define SERIAL_DEBUG line below to receive serial output messages relating to your
8482
* connection that may help in the event of connection issues. If defined, some boards may not begin
@@ -125,6 +123,12 @@ SerialFirmata serialFeature;
125123
#ifdef STATIC_IP_ADDRESS
126124
IPAddress local_ip(STATIC_IP_ADDRESS);
127125
#endif
126+
#ifdef SUBNET_MASK
127+
IPAddress subnet(SUBNET_MASK);
128+
#endif
129+
#ifdef GATEWAY_IP_ADDRESS
130+
IPAddress gateway(GATEWAY_IP_ADDRESS);
131+
#endif
128132

129133
int wifiConnectionAttemptCounter = 0;
130134
int wifiStatus = WL_IDLE_STATUS;
@@ -692,7 +696,7 @@ void sysexCallback(byte command, byte argc, byte *argv)
692696
}
693697
if (IS_PIN_PWM(pin)) {
694698
Firmata.write(PIN_MODE_PWM);
695-
Firmata.write(8); // 8 = 8-bit resolution
699+
Firmata.write(DEFAULT_PWM_RESOLUTION);
696700
}
697701
if (IS_PIN_DIGITAL(pin)) {
698702
Firmata.write(PIN_MODE_SERVO);
@@ -822,37 +826,37 @@ void systemResetCallback()
822826
}
823827

824828
void printWifiStatus() {
825-
#if defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101)
829+
#if defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101) || defined(ESP8266_WIFI)
826830
if ( WiFi.status() != WL_CONNECTED )
827831
{
828832
DEBUG_PRINT( "WiFi connection failed. Status value: " );
829833
DEBUG_PRINTLN( WiFi.status() );
830834
}
831835
else
832-
#endif //defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101)
836+
#endif //defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101) || defined(ESP8266_WIFI)
833837
{
834838
// print the SSID of the network you're attached to:
835839
DEBUG_PRINT( "SSID: " );
836840

837-
#if defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101)
841+
#if defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101) || defined(ESP8266_WIFI)
838842
DEBUG_PRINTLN( WiFi.SSID() );
839-
#endif //defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101)
843+
#endif //defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101) || defined(ESP8266_WIFI)
840844

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

844-
#if defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101)
848+
#if defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101) || defined(ESP8266_WIFI)
845849
IPAddress ip = WiFi.localIP();
846850
DEBUG_PRINTLN( ip );
847-
#endif //defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101)
851+
#endif //defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101) || defined(ESP8266_WIFI)
848852

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

852-
#if defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101)
856+
#if defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101) || defined(ESP8266_WIFI)
853857
long rssi = WiFi.RSSI();
854858
DEBUG_PRINT( rssi );
855-
#endif //defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101)
859+
#endif //defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101) || defined(ESP8266_WIFI)
856860

857861
DEBUG_PRINTLN( " dBm" );
858862
}
@@ -873,6 +877,8 @@ void setup()
873877
DEBUG_PRINTLN( "using the WiFi 101 library." );
874878
#elif defined(ARDUINO_WIFI_SHIELD)
875879
DEBUG_PRINTLN( "using the legacy WiFi library." );
880+
#elif defined(ESP8266_WIFI)
881+
DEBUG_PRINTLN( "using the ESP8266 WiFi library." );
876882
#elif defined(HUZZAH_WIFI)
877883
DEBUG_PRINTLN( "using the HUZZAH WiFi library." );
878884
//else should never happen here as error-checking in wifiConfig.h will catch this
@@ -884,9 +890,13 @@ void setup()
884890
#ifdef STATIC_IP_ADDRESS
885891
DEBUG_PRINT( "Using static IP: " );
886892
DEBUG_PRINTLN( local_ip );
887-
//you can also provide a static IP in the begin() functions, but this simplifies
888-
//ifdef logic in this sketch due to support for all different encryption types.
893+
#ifdef ESP8266_WIFI
894+
stream.config( local_ip , gateway, subnet );
895+
#else
896+
// you can also provide a static IP in the begin() functions, but this simplifies
897+
// ifdef logic in this sketch due to support for all different encryption types.
889898
stream.config( local_ip );
899+
#endif
890900
#else
891901
DEBUG_PRINTLN( "IP will be requested from DHCP ..." );
892902
#endif
@@ -952,7 +962,8 @@ void setup()
952962
|| 28 == i
953963
#endif //defined(__AVR_ATmega32U4__)
954964
) {
955-
#elif defined (WIFI_101)
965+
// don't ignore pins when using Wi-Fi 101 library with the MKR1000
966+
#elif defined (WIFI_101) && !defined(ARDUINO_SAMD_MKR1000)
956967
if (IS_IGNORE_WIFI101_SHIELD(i)) {
957968
#elif defined (HUZZAH_WIFI)
958969
// TODO

0 commit comments

Comments
 (0)