1111 Copyright (C) 2006-2008 Hans-Christoph Steiner. All rights reserved.
1212 Copyright (C) 2010-2011 Paul Stoffregen. All rights reserved.
1313 Copyright (C) 2009 Shigeru Kobayashi. All rights reserved.
14- Copyright (C) 2009-2015 Jeff Hoefs. All rights reserved.
14+ Copyright (C) 2009-2016 Jeff Hoefs. All rights reserved.
1515
1616 This library is free software; you can redistribute it and/or
1717 modify it under the terms of the GNU Lesser General Public
2020
2121 See file LICENSE.txt for further informations on licensing terms.
2222
23- Last updated by Jeff Hoefs: December 26th, 2015
23+ Last updated by Jeff Hoefs: January 9th, 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
31+ StandardFirmataEthernet and the Firmata client application.
32+
2933 To use StandardFirmataEthernet you will need to have one of the following
3034 boards or shields:
3135
3236 - Arduino Ethernet shield (or clone)
3337 - Arduino Ethernet board (or clone)
3438 - Arduino Yun
3539
36- Follow the instructions in the NETWORK CONFIGURATION section below to
40+ Follow the instructions in the ethernetConfig.h file (ethernetConfig.h tab in Arduino IDE) to
3741 configure your particular hardware.
3842
3943 NOTE: If you are using an Arduino Ethernet shield you cannot use the following pins on
4347 - Arduino Mega: (D4, D10, D50, D51, D52, D53)
4448 - Arduino Leonardo: (D4, D10)
4549 - Arduino Due: (D4, D10)
50+ - Arduino Zero: (D4, D10)
4651
4752 If you are using an ArduinoEthernet board, the following pins cannot be used (same as Uno):
4853 - D4, D10, D11, D12, D13
5257#include < Wire.h>
5358#include < Firmata.h>
5459
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.
64+ */
5565// #define SERIAL_DEBUG
5666#include " utility/firmataDebug.h"
5767
68+ // follow the instructions in ethernetConfig.h to configure your particular hardware
69+ #include " ethernetConfig.h"
70+ #include " utility/EthernetClientStream.h"
71+
5872#define I2C_WRITE B00000000
5973#define I2C_READ B00001000
6074#define I2C_READ_CONTINUOUSLY B00010000
7084// the minimum interval for sampling analog input
7185#define MINIMUM_SAMPLING_INTERVAL 1
7286
73-
74- /* ==============================================================================
75- * NETWORK CONFIGURATION
76- *
77- * You must configure your particular hardware. Follow the steps below.
78- *============================================================================*/
79-
80- // STEP 1 [REQUIRED]
81- // Uncomment / comment the appropriate set of includes for your hardware (OPTION A or B)
82- // Option A is enabled by default.
83-
84- /*
85- * OPTION A: Configure for Arduino Ethernet board or shield
86- *
87- * To configure StandardFirmataEthernet to use the original WIZ5100-based
88- * ethernet shield or Arduino Ethernet uncomment the includes of 'SPI.h' and 'Ethernet.h':
89- */
90-
91- #include < SPI.h>
92- #include < Ethernet.h>
93-
94- /*
95- * OPTION B: Configure for Arduin Yun
96- *
97- * To execute StandardFirmataEthernet on Yun uncomment Bridge.h and YunClient.h.
98- * Do not include Ethernet.h or SPI.h above in this case.
99- * On Yun there's no need to configure local_ip and mac in the sketch
100- * as this is configured on the linux-side of Yun.
101- */
102-
103- // #include <Bridge.h>
104- // #include <YunClient.h>
105-
106-
107- // STEP 2 [REQUIRED for all boards and shields]
108- // replace with IP of the server you want to connect to, comment out if using 'remote_host'
109- #define remote_ip IPAddress (10 , 0 , 0 , 3 )
110- // *** REMOTE HOST IS NOT YET WORKING ***
111- // replace with hostname of server you want to connect to, comment out if using 'remote_ip'
112- // #define remote_host "server.local"
113-
114- // STEP 3 [REQUIRED unless using Arduin Yun]
115- // Replace with the port that your server is listening on
116- #define remote_port 3030
117-
118- // STEP 4 [REQUIRED unless using Arduino Yun OR if not using DHCP]
119- // Replace with your board or ethernet shield's IP address
120- // Comment out if you want to use DHCP
121- #define local_ip IPAddress (10 , 0 , 0 , 15 )
122-
123- // STEP 5 [REQUIRED unless using Arduino Yun]
124- // replace with ethernet shield mac. Must be unique for your network
125- const byte mac[] = {0x90 , 0xA2 , 0xDA , 0x00 , 0x53 , 0xE5 };
126-
127- // Since Arduino 1.6.6 ethernet_h is not recognized, even when Ethernet.h is included so this
128- // always throws the error. Commenting out until the issue introduced in Arduino 1.6.6 is resolved.
129- // #if !defined ethernet_h && !defined _YUN_CLIENT_H_
130- // #error "you must uncomment the includes for your board configuration. See OPTIONS A and B in the NETWORK CONFIGURATION SECTION"
131- // #endif
132-
133- #if defined remote_ip && defined remote_host
134- #error "cannot define both remote_ip and remote_host at the same time!"
135- #endif
136-
137-
13887/* ==============================================================================
13988 * GLOBAL VARIABLES
14089 *============================================================================*/
14190
14291/* network */
143-
144- #include " utility/EthernetClientStream.h"
145-
146- #ifdef _YUN_CLIENT_H_
147- YunClient client;
148- #else
149- EthernetClient client;
150- #endif
151-
15292#if defined remote_ip && !defined remote_host
15393#ifdef local_ip
15494EthernetClientStream stream (client, local_ip, remote_ip, NULL , remote_port);
@@ -845,7 +785,7 @@ void setup()
845785{
846786 DEBUG_BEGIN (9600 );
847787
848- #ifdef _YUN_CLIENT_H_
788+ #ifdef YUN_ETHERNET
849789 Bridge.begin ();
850790#else
851791#ifdef local_ip
@@ -868,27 +808,26 @@ void setup()
868808 Firmata.attach (START_SYSEX, sysexCallback);
869809 Firmata.attach (SYSTEM_RESET, systemResetCallback);
870810
811+ #ifdef WIZ5100_ETHERNET
871812 // StandardFirmataEthernet communicates with Ethernet shields over SPI. Therefore all
872813 // SPI pins must be set to IGNORE. Otherwise Firmata would break SPI communication.
873814 // add Pin 10 and configure pin 53 as output if using a MEGA with an Ethernet shield.
874815
875- // ignore SPI and pin 4 that is SS for SD-Card on Ethernet-shield
876816 for (byte i = 0 ; i < TOTAL_PINS; i++) {
877- if (IS_PIN_SPI (i)
878- || 4 == i // SD-Card on Ethernet-shield uses pin 4 for SS
879- || 10 == i // Ethernet-shield uses pin 10 for SS
880- #if defined(__AVR_ATmega32U4__)
817+ if (IS_IGNORE_ETHERNET_SHIELD (i)
818+ #if defined(__AVR_ATmega32U4__)
881819 || 24 == i // On Leonardo, pin 24 maps to D4 and pin 28 maps to D10
882820 || 28 == i
883- #endif
821+ #endif
884822 ) {
885823 pinConfig[i] = PIN_MODE_IGNORE;
886824 }
887825 }
888826
889- // Arduino Ethernet, Arduino EthernetShield and Arduino Yun all have SD SS wired to D4
827+ // Arduino Ethernet and Arduino EthernetShield have SD SS wired to D4
890828 pinMode (PIN_TO_DIGITAL (4 ), OUTPUT); // switch off SD card bypassing Firmata
891829 digitalWrite (PIN_TO_DIGITAL (4 ), HIGH); // SS is active low;
830+ #endif // WIZ5100_ETHERNET
892831
893832#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
894833 pinMode (PIN_TO_DIGITAL (53 ), OUTPUT); // configure hardware SS as output on MEGA
@@ -937,9 +876,9 @@ void loop()
937876 }
938877 }
939878
940- #if !defined local_ip && !defined _YUN_CLIENT_H_
941- if (Ethernet. maintain ())
942- {
879+ #if !defined local_ip && !defined YUN_ETHERNET
880+ // only necessary when using DHCP, ensures local IP is updated appropriately if it changes
881+ if (Ethernet. maintain ()) {
943882 stream.maintain (Ethernet.localIP ());
944883 }
945884#endif
0 commit comments