20
20
21
21
See file LICENSE.txt for further informations on licensing terms.
22
22
23
- Last updated by Jeff Hoefs: January 10th , 2016
23
+ Last updated by Jeff Hoefs: June 18th , 2016
24
24
*/
25
25
26
26
/*
27
27
README
28
28
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
31
31
StandardFirmataEthernet and the Firmata client application.
32
32
33
33
To use StandardFirmataEthernet you will need to have one of the following
58
58
#include < Firmata.h>
59
59
60
60
/*
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.
64
64
*/
65
65
// #define SERIAL_DEBUG
66
66
#include " utility/firmataDebug.h"
69
69
#include " ethernetConfig.h"
70
70
#include " utility/EthernetClientStream.h"
71
71
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
+
72
83
#define I2C_WRITE B00000000
73
84
#define I2C_READ B00001000
74
85
#define I2C_READ_CONTINUOUSLY B00010000
88
99
* GLOBAL VARIABLES
89
100
*============================================================================*/
90
101
91
- /* network */
92
102
#if defined remote_ip && !defined remote_host
93
103
#ifdef local_ip
94
104
EthernetClientStream stream (client, local_ip, remote_ip, NULL , remote_port);
@@ -304,7 +314,8 @@ void setPinModeCallback(byte pin, int mode)
304
314
}
305
315
}
306
316
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 );
308
319
}
309
320
if (IS_PIN_DIGITAL (pin)) {
310
321
if (mode == INPUT || mode == PIN_MODE_PULLUP) {
@@ -801,10 +812,36 @@ void systemResetCallback()
801
812
isResetting = false ;
802
813
}
803
814
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 ()
805
822
{
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
807
830
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
+ {
808
845
#ifdef YUN_ETHERNET
809
846
Bridge.begin ();
810
847
#else
@@ -816,9 +853,11 @@ void setup()
816
853
#endif
817
854
818
855
DEBUG_PRINTLN (" connecting..." );
856
+ }
819
857
858
+ void initFirmata ()
859
+ {
820
860
Firmata.setFirmwareVersion (FIRMATA_FIRMWARE_MAJOR_VERSION, FIRMATA_FIRMWARE_MINOR_VERSION);
821
-
822
861
Firmata.attach (ANALOG_MESSAGE, analogWriteCallback);
823
862
Firmata.attach (DIGITAL_MESSAGE, digitalWriteCallback);
824
863
Firmata.attach (REPORT_ANALOG, reportAnalogCallback);
@@ -828,36 +867,22 @@ void setup()
828
867
Firmata.attach (START_SYSEX, sysexCallback);
829
868
Firmata.attach (SYSTEM_RESET, systemResetCallback);
830
869
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 ();
855
871
856
872
// start up Network Firmata:
857
873
Firmata.begin (stream);
858
874
systemResetCallback (); // reset to default config
859
875
}
860
876
877
+ void setup ()
878
+ {
879
+ DEBUG_BEGIN (9600 );
880
+
881
+ initTransport ();
882
+
883
+ initFirmata ();
884
+ }
885
+
861
886
/* ==============================================================================
862
887
* LOOP()
863
888
*============================================================================*/
0 commit comments