diff --git a/Modules/Nano/RCnano/CheckShield.ino b/Modules/Nano/RCnano/CheckShield.ino index 97fa6de9e..432210510 100644 --- a/Modules/Nano/RCnano/CheckShield.ino +++ b/Modules/Nano/RCnano/CheckShield.ino @@ -1,4 +1,4 @@ - +#if SupportEthernet == 1 // uses SPI.h // use 'if(ShieldFound())' before 'ether.begin(sizeof Ethernet::buffer, LocalMac, selectPin);' to prevent hang @@ -65,4 +65,4 @@ static byte readOp(byte op, byte address) { disableChip(); return result; } - +#endif diff --git a/Modules/Nano/RCnano/RCnano.ino b/Modules/Nano/RCnano/RCnano.ino index 04760ac85..186005af0 100644 --- a/Modules/Nano/RCnano/RCnano.ino +++ b/Modules/Nano/RCnano/RCnano.ino @@ -1,18 +1,8 @@ -#include -#include -#include -#include #include #include -#include -#include -#include -#include - -#include -#include - +# define SupportEthernet 1 // Requires Ethercard library +# define SupportMCP23017 1 // Requires Adafruit MCP23008 and MCP23017 libraries # define InoDescription "RCnano : 25-Jun-2023" const uint16_t InoID = 25063; // change to send defaults to eeprom, ddmmy, no leading 0 int16_t StoredID; // Defaults ID stored in eeprom @@ -26,7 +16,7 @@ struct ModuleConfig uint8_t IPpart3 = 1; // IP address, 3rd octet uint8_t RelayOnSignal = 0; // value that turns on relays uint8_t FlowOnDirection = 0; // sets on value for flow valve or sets motor direction - uint8_t UseMCP23017 = 1; // 0 use Nano pins for relays, 1 use MCP23017 for relays + uint8_t UseMCP23017 = SupportMCP23017 == 1 ? 1 : 0; // 0 use Nano pins for relays, 1 use MCP23017 for relays uint8_t Relays[16]; }; @@ -61,6 +51,9 @@ struct SensorConfig SensorConfig Sensor[2]; +#if SupportEthernet == 1 +#include +#include // If using the ENC28J60 ethernet shield these pins // are used by it and unavailable for relays: // 7,8,10,11,12,13. It also pulls pin D2 high. @@ -82,6 +75,17 @@ unsigned int DestinationPort = 29999; // Rate Controller listening port byte Ethernet::buffer[300]; // udp send and receive buffer bool ENCfound; static byte selectPin = 10; +#endif + +#if SupportMCP23017 == 1 +#include +#include +#include +#include +#include +#include +#include +#include Adafruit_MCP23X17 mcp; @@ -108,6 +112,8 @@ Adafruit_MCP23X17 mcp; #define Relay15 1 #define Relay16 0 +#endif + const uint16_t LOOP_TIME = 50; //in msec = 20hz uint32_t LoopLast = LOOP_TIME; @@ -215,16 +221,15 @@ void setup() if (MDL.SensorCount < 1) MDL.SensorCount = 1; if (MDL.SensorCount > 2) MDL.SensorCount = 2; +#if UseMCP23017 == 1 if (MDL.UseMCP23017) - { Serial.println("Using MCP23017 for relays."); - } else - { +#endif Serial.println("Using Nano pins for relays."); - } Wire.begin(); +#if SupportMCP23017 == 1 if (MDL.UseMCP23017) { // I/O expander on default address 0x20 @@ -273,6 +278,7 @@ void setup() } } else +#endif { // Nano pins for (int i = 0; i < 16; i++) @@ -293,6 +299,7 @@ void setup() attachInterrupt(digitalPinToInterrupt(Sensor[0].FlowPin), ISR0, FALLING); attachInterrupt(digitalPinToInterrupt(Sensor[1].FlowPin), ISR1, FALLING); +#if SupportEthernet == 1 Serial.println(""); Serial.println("Starting Ethernet ..."); @@ -331,6 +338,7 @@ void setup() Serial.println(""); Serial.println("Ethernet controller not found."); } +#endif Serial.println(""); Serial.println("Finished Setup."); @@ -372,15 +380,18 @@ void loop() { SendLast = millis(); SendSerial(); +#if SupportEthernet == 1 SendUDPwired(); +#endif } +#if SupportEthernet == 1 if (ENCfound) { //this must be called for ethercard functions to work. ether.packetLoop(ether.packetReceive()); } - +#endif ReceiveSerial(); } diff --git a/Modules/Nano/RCnano/Relays.ino b/Modules/Nano/RCnano/Relays.ino index e29d059c5..35cc3834d 100644 --- a/Modules/Nano/RCnano/Relays.ino +++ b/Modules/Nano/RCnano/Relays.ino @@ -44,6 +44,7 @@ void CheckRelays() NewLo |= PowerRelayLo; NewHi |= PowerRelayHi; +#if UseMCP23017 == 1 if (MDL.UseMCP23017 == 1) { if (IOexpanderFound) @@ -68,7 +69,7 @@ void CheckRelays() } } else - { +#endif // use Nano pins for (int j = 0; j < 2; j++) { @@ -81,5 +82,4 @@ void CheckRelays() } } } - } } diff --git a/Modules/Nano/RCnano/UDPwiredComm.ino b/Modules/Nano/RCnano/UDPwiredComm.ino index c0ca2939d..0f17335c1 100644 --- a/Modules/Nano/RCnano/UDPwiredComm.ino +++ b/Modules/Nano/RCnano/UDPwiredComm.ino @@ -1,4 +1,4 @@ - +#if SupportEthernet == 1 byte UDPpacket[30]; uint16_t UDPpgn; @@ -407,3 +407,4 @@ void ReceiveAGIO(uint16_t dest_port, uint8_t src_ip[IP_LEN], uint16_t src_port, } } +#endif \ No newline at end of file