2020
2121 See file LICENSE.txt for further informations on licensing terms.
2222
23- Last updated by Jeff Hoefs: January 10th , 2016
23+ Last updated by Jeff Hoefs: June 18th , 2016
2424*/
2525
2626/*
2727 README
2828
29- StandardFirmataEthernet is a client implementation. You will need a Firmata client library with
30- a network transport that can act as a server in order to establish a connection between
29+ StandardFirmataEthernet is a TCP client implementation. You will need a Firmata client library
30+ with a network transport that can act as a TCP server in order to establish a connection between
3131 StandardFirmataEthernet and the Firmata client application.
3232
3333 To use StandardFirmataEthernet you will need to have one of the following
5858#include < Firmata.h>
5959
6060/*
61- * Uncomment the #define SERIAL_DEBUG line below to receive serial output messages relating to your connection
62- * that may help in the event of connection issues. If defined, some boards may not begin executing this sketch
63- * until the Serial console is opened.
61+ * Uncomment the #define SERIAL_DEBUG line below to receive serial output messages relating to your
62+ * connection that may help in the event of connection issues. If defined, some boards may not begin
63+ * executing this sketch until the Serial console is opened.
6464 */
6565// #define SERIAL_DEBUG
6666#include " utility/firmataDebug.h"
6969#include " ethernetConfig.h"
7070#include " utility/EthernetClientStream.h"
7171
72+ /*
73+ * Uncomment the following include to enable interfacing with Serial devices via hardware or
74+ * software serial.
75+ *
76+ * DO NOT uncomment if you are running StandardFirmataEthernet on an Arduino Leonardo,
77+ * Arduino Micro or other ATMega32u4-based board or you will not have enough Flash and RAM
78+ * remaining to reliably run Firmata. Arduino Yun is okay because it doesn't import the Ethernet
79+ * libraries.
80+ */
81+ // #include "utility/SerialFirmata.h"
82+
7283#define I2C_WRITE B00000000
7384#define I2C_READ B00001000
7485#define I2C_READ_CONTINUOUSLY B00010000
8899 * GLOBAL VARIABLES
89100 *============================================================================*/
90101
91- /* network */
92102#if defined remote_ip && !defined remote_host
93103#ifdef local_ip
94104EthernetClientStream stream (client, local_ip, remote_ip, NULL , remote_port);
@@ -304,7 +314,8 @@ void setPinModeCallback(byte pin, int mode)
304314 }
305315 }
306316 if (IS_PIN_ANALOG (pin)) {
307- reportAnalogCallback (PIN_TO_ANALOG (pin), mode == PIN_MODE_ANALOG ? 1 : 0 ); // turn on/off reporting
317+ // turn on/off reporting
318+ reportAnalogCallback (PIN_TO_ANALOG (pin), mode == PIN_MODE_ANALOG ? 1 : 0 );
308319 }
309320 if (IS_PIN_DIGITAL (pin)) {
310321 if (mode == INPUT || mode == PIN_MODE_PULLUP) {
@@ -801,10 +812,36 @@ void systemResetCallback()
801812 isResetting = false ;
802813}
803814
804- void setup ()
815+ /*
816+ * StandardFirmataEthernet communicates with Ethernet shields over SPI. Therefore all
817+ * SPI pins must be set to IGNORE. Otherwise Firmata would break SPI communication.
818+ * Additional pins may also need to be ignored depending on the particular board or
819+ * shield in use.
820+ */
821+ void ignorePins ()
805822{
806- DEBUG_BEGIN (9600 );
823+ #ifdef IS_IGNORE_PIN
824+ for (byte i = 0 ; i < TOTAL_PINS; i++) {
825+ if (IS_IGNORE_PIN (i)) {
826+ Firmata.setPinMode (i, PIN_MODE_IGNORE);
827+ }
828+ }
829+ #endif
807830
831+ #ifdef WIZ5100_ETHERNET
832+ // Arduino Ethernet and Arduino EthernetShield have SD SS wired to D4
833+ pinMode (PIN_TO_DIGITAL (4 ), OUTPUT); // switch off SD card bypassing Firmata
834+ digitalWrite (PIN_TO_DIGITAL (4 ), HIGH); // SS is active low;
835+
836+ #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
837+ pinMode (PIN_TO_DIGITAL (53 ), OUTPUT); // configure hardware SS as output on MEGA
838+ #endif
839+
840+ #endif // WIZ5100_ETHERNET
841+ }
842+
843+ void initTransport ()
844+ {
808845#ifdef YUN_ETHERNET
809846 Bridge.begin ();
810847#else
@@ -816,9 +853,11 @@ void setup()
816853#endif
817854
818855 DEBUG_PRINTLN (" connecting..." );
856+ }
819857
858+ void initFirmata ()
859+ {
820860 Firmata.setFirmwareVersion (FIRMATA_FIRMWARE_MAJOR_VERSION, FIRMATA_FIRMWARE_MINOR_VERSION);
821-
822861 Firmata.attach (ANALOG_MESSAGE, analogWriteCallback);
823862 Firmata.attach (DIGITAL_MESSAGE, digitalWriteCallback);
824863 Firmata.attach (REPORT_ANALOG, reportAnalogCallback);
@@ -828,36 +867,22 @@ void setup()
828867 Firmata.attach (START_SYSEX, sysexCallback);
829868 Firmata.attach (SYSTEM_RESET, systemResetCallback);
830869
831- #ifdef WIZ5100_ETHERNET
832- // StandardFirmataEthernet communicates with Ethernet shields over SPI. Therefore all
833- // SPI pins must be set to IGNORE. Otherwise Firmata would break SPI communication.
834- // add Pin 10 and configure pin 53 as output if using a MEGA with an Ethernet shield.
835-
836- for (byte i = 0 ; i < TOTAL_PINS; i++) {
837- if (IS_IGNORE_ETHERNET_SHIELD (i)
838- #if defined(__AVR_ATmega32U4__)
839- || 24 == i // On Leonardo, pin 24 maps to D4 and pin 28 maps to D10
840- || 28 == i
841- #endif
842- ) {
843- Firmata.setPinMode (i, PIN_MODE_IGNORE);
844- }
845- }
846-
847- // Arduino Ethernet and Arduino EthernetShield have SD SS wired to D4
848- pinMode (PIN_TO_DIGITAL (4 ), OUTPUT); // switch off SD card bypassing Firmata
849- digitalWrite (PIN_TO_DIGITAL (4 ), HIGH); // SS is active low;
850- #endif // WIZ5100_ETHERNET
851-
852- #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
853- pinMode (PIN_TO_DIGITAL (53 ), OUTPUT); // configure hardware SS as output on MEGA
854- #endif
870+ ignorePins ();
855871
856872 // start up Network Firmata:
857873 Firmata.begin (stream);
858874 systemResetCallback (); // reset to default config
859875}
860876
877+ void setup ()
878+ {
879+ DEBUG_BEGIN (9600 );
880+
881+ initTransport ();
882+
883+ initFirmata ();
884+ }
885+
861886/* ==============================================================================
862887 * LOOP()
863888 *============================================================================*/
0 commit comments