22
22
23
23
See file LICENSE.txt for further informations on licensing terms.
24
24
25
- Last updated by Jeff Hoefs: April 17th , 2016
25
+ Last updated by Jeff Hoefs: April 24th , 2016
26
26
*/
27
27
28
28
/*
36
36
37
37
- Arduino WiFi Shield (or clone)
38
38
- Arduino WiFi Shield 101
39
- - Arduino MKR1000 board (built-in WiFi 101)
39
+ - Arduino MKR1000 board
40
40
- ESP8266 WiFi board compatible with ESP8266 Arduino core
41
41
42
42
Follow the instructions in the wifiConfig.h file (wifiConfig.h tab in Arduino IDE) to
46
46
- WiFi Shield 101 requires version 0.7.0 or higher of the WiFi101 library (available in Arduino
47
47
1.6.8 or higher, or update the library via the Arduino Library Manager or clone from source:
48
48
https://github.com/arduino-libraries/WiFi101)
49
- - ESP8266 requires the Arduino ESP8266 core which can be obtained here:
49
+ - ESP8266 requires the Arduino ESP8266 core v2.1.0 or higher which can be obtained here:
50
50
https://github.com/esp8266/Arduino
51
51
52
52
In order to use the WiFi Shield 101 with Firmata you will need a board with at least 35k of Flash
@@ -308,7 +308,7 @@ void checkDigitalInputs(void)
308
308
}
309
309
310
310
// -----------------------------------------------------------------------------
311
- // function forward declarations
311
+ // function forward declarations for xtensa compiler (ESP8266)
312
312
void enableI2CPins ();
313
313
void disableI2CPins ();
314
314
void reportAnalogCallback (byte analogPin, int value);
@@ -832,9 +832,9 @@ void systemResetCallback()
832
832
833
833
/*
834
834
* Called when a TCP connection is either connected or disconnected.
835
- * TODO - figure out why the callback is not being called when using ESP8266 as a TCP server and
836
- * why only connect is called when using ESP8266 as a TCP client. In both cases the actual
837
- * connection is working but not reported via the callback.
835
+ * TODO:
836
+ * - report connected or reconnected state to host (to be added to protocol)
837
+ * - report current state to host (to be added to protocol)
838
838
*/
839
839
void hostConnectionCallback (byte state)
840
840
{
@@ -883,43 +883,30 @@ void printWifiStatus() {
883
883
* Additional pins may also need to be ignored depending on the particular board or
884
884
* shield in use.
885
885
*/
886
- void ignoreWiFiPins ()
886
+ void ignorePins ()
887
887
{
888
+ #ifdef IS_IGNORE_PIN
888
889
for (byte i = 0 ; i < TOTAL_PINS; i++) {
889
- #if defined(ARDUINO_WIFI_SHIELD)
890
- if (IS_IGNORE_WIFI_SHIELD (i)
891
- #if defined(__AVR_ATmega32U4__)
892
- || 24 == i // On Leonardo, pin 24 maps to D4 and pin 28 maps to D10
893
- || 28 == i
894
- #endif // defined(__AVR_ATmega32U4__)
895
- ) {
896
- // don't ignore pins when using Wi-Fi 101 library with the MKR1000
897
- #elif defined (WIFI_101) && !defined(ARDUINO_SAMD_MKR1000)
898
- if (IS_IGNORE_WIFI101_SHIELD (i)) {
899
- #elif defined (HUZZAH_WIFI)
900
- // TODO
901
- if (false ) {
902
- #else
903
- if (false ) {
904
- #endif
890
+ if (IS_IGNORE_PIN (i)) {
905
891
Firmata.setPinMode (i, PIN_MODE_IGNORE);
906
892
}
907
893
}
894
+ #endif
908
895
909
896
// Set up controls for the Arduino WiFi Shield SS for the SD Card
910
897
#ifdef ARDUINO_WIFI_SHIELD
911
- // Arduino WiFi, Arduino WiFi Shield and Arduino Yun all have SD SS wired to D4
898
+ // Arduino WiFi Shield has SD SS wired to D4
912
899
pinMode (PIN_TO_DIGITAL (4 ), OUTPUT); // switch off SD card bypassing Firmata
913
900
digitalWrite (PIN_TO_DIGITAL (4 ), HIGH); // SS is active low;
914
901
915
902
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
916
903
pinMode (PIN_TO_DIGITAL (53 ), OUTPUT); // configure hardware SS as output on MEGA
917
- #endif // defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
904
+ #endif // defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
918
905
919
- #endif // ARDUINO_WIFI_SHIELD
906
+ #endif // ARDUINO_WIFI_SHIELD
920
907
}
921
908
922
- void initWiFi ()
909
+ void initTransport ()
923
910
{
924
911
// This statement will clarify how a connection is being made
925
912
DEBUG_PRINT ( " StandardFirmataWiFi will attempt a WiFi connection " );
@@ -967,11 +954,7 @@ void initWiFi()
967
954
#endif // defined(WIFI_WEP_SECURITY)
968
955
DEBUG_PRINTLN ( " WiFi setup done" );
969
956
970
- // Wait for connection to access point to be established. This is necessary for ESP8266
971
- // or we won't have a connection state once printWiFiStatus() is called and the state
972
- // will be reported as disconnected. We don't want to wait until the TCP connection is
973
- // established before calling printWiFiStatus() because printing the IP address upon
974
- // connection with the access point is useful when using DHCP
957
+ // Wait for connection to access point to be established.
975
958
while (WiFi.status () != WL_CONNECTED && ++connectionAttempts <= MAX_CONN_ATTEMPTS) {
976
959
delay (500 );
977
960
DEBUG_PRINT (" ." );
@@ -991,7 +974,7 @@ void initFirmata()
991
974
Firmata.attach (START_SYSEX, sysexCallback);
992
975
Firmata.attach (SYSTEM_RESET, systemResetCallback);
993
976
994
- ignoreWiFiPins ();
977
+ ignorePins ();
995
978
996
979
// Initialize Firmata to use the WiFi stream object as the transport.
997
980
Firmata.begin (stream);
@@ -1002,7 +985,7 @@ void setup()
1002
985
{
1003
986
DEBUG_BEGIN (9600 );
1004
987
1005
- initWiFi ();
988
+ initTransport ();
1006
989
1007
990
initFirmata ();
1008
991
}
0 commit comments