diff --git a/Modules/ESP32 Rate/RC_ESP32/Begin.ino b/Modules/ESP32 Rate/RC_ESP32/Begin.ino index 9ad30ca8..bb8adc00 100644 --- a/Modules/ESP32 Rate/RC_ESP32/Begin.ino +++ b/Modules/ESP32 Rate/RC_ESP32/Begin.ino @@ -68,46 +68,43 @@ void DoSetup() } // ethernet - if (MDL.EthernetEnabled) + Serial.println("Starting Ethernet ..."); + MDL.IP3 = MDL.ID + 50; + IPAddress LocalIP(MDL.IP0, MDL.IP1, MDL.IP2, MDL.IP3); + static uint8_t LocalMac[] = { 0x0A,0x0B,0x42,0x0C,0x0D,MDL.IP3 }; + + Ethernet.init(W5500_SS); // SS pin + Ethernet.begin(LocalMac, 0); + Ethernet.setLocalIP(LocalIP); + IPAddress Mask(255, 255, 255, 0); + Ethernet.setSubnetMask(Mask); + IPAddress Gateway(MDL.IP0, MDL.IP1, MDL.IP2, 1); + Ethernet.setGatewayIP(Gateway); + + delay(1500); + ChipFound = (Ethernet.hardwareStatus() != EthernetNoHardware); + if (ChipFound) { - Serial.println("Starting Ethernet ..."); - MDL.IP3 = MDL.ID + 50; - IPAddress LocalIP(MDL.IP0, MDL.IP1, MDL.IP2, MDL.IP3); - static uint8_t LocalMac[] = { 0x0A,0x0B,0x42,0x0C,0x0D,MDL.IP3 }; - - Ethernet.init(W5500_SS); // SS pin - Ethernet.begin(LocalMac, 0); - Ethernet.setLocalIP(LocalIP); - IPAddress Mask(255, 255, 255, 0); - Ethernet.setSubnetMask(Mask); - IPAddress Gateway(MDL.IP0, MDL.IP1, MDL.IP2, 1); - Ethernet.setGatewayIP(Gateway); - - delay(1500); - ChipFound = (Ethernet.hardwareStatus() != EthernetNoHardware); - if (ChipFound) + if (Ethernet.linkStatus() == LinkON) { - if (Ethernet.linkStatus() == LinkON) - { - Serial.println("Ethernet connected."); - } - else - { - Serial.println("Ethernet not connected."); - } - Serial.print("IP Address: "); - Serial.println(Ethernet.localIP()); + Serial.println("Ethernet connected."); } else { - Serial.println("Ethernet hardware not found."); + Serial.println("Ethernet not connected."); } + Serial.print("IP Address: "); + Serial.println(Ethernet.localIP()); + } + else + { + Serial.println("Ethernet hardware not found."); + } - Ethernet_DestinationIP = IPAddress(MDL.IP0, MDL.IP1, MDL.IP2, 255); // update from saved data + Ethernet_DestinationIP = IPAddress(MDL.IP0, MDL.IP1, MDL.IP2, 255); // update from saved data - // UDP - UDP_Ethernet.begin(ListeningPort); - } + // UDP + UDP_Ethernet.begin(ListeningPort); // sensors for (int i = 0; i < MDL.SensorCount; i++) @@ -429,7 +426,6 @@ void LoadDefaults() MDL.WifiModeUseStation = false; MDL.Is3Wire = true; MDL.ADS1115Enabled = false; - MDL.EthernetEnabled = false; MDL.InvertFlow = false; MDL.InvertRelay = false; } @@ -469,7 +465,7 @@ bool ValidData() } if (!Result) break; } - debug3 = Result; + if (Result) { for (int i = 0; i < MDL.SensorCount; i++) @@ -512,7 +508,7 @@ bool ValidData() if (!Result) break; } } - debug4 = Result; + if (Result && MDL.RelayControl == 1) { // check GPIOs for relays diff --git a/Modules/ESP32 Rate/RC_ESP32/RC_ESP32.ino b/Modules/ESP32 Rate/RC_ESP32/RC_ESP32.ino index 0fa1b837..cf75b2fd 100644 --- a/Modules/ESP32 Rate/RC_ESP32/RC_ESP32.ino +++ b/Modules/ESP32 Rate/RC_ESP32/RC_ESP32.ino @@ -17,8 +17,8 @@ #include // rate control with ESP32 board: DOIT ESP32 DEVKIT V1 -# define InoDescription "RC_ESP32 : 02-Dec-2024" -const uint16_t InoID = 2124; // change to send defaults to eeprom, ddmmy, no leading 0 +# define InoDescription "RC_ESP32 : 03-Dec-2024" +const uint16_t InoID = 3124; // change to send defaults to eeprom, ddmmy, no leading 0 const uint8_t InoType = 4; // 0 - Teensy AutoSteer, 1 - Teensy Rate, 2 - Nano Rate, 3 - Nano SwitchBox, 4 - ESP Rate const uint8_t Processor = 0; // 0 - ESP32-Wroom-32U @@ -59,7 +59,6 @@ struct ModuleConfig bool Is3Wire = true; // False - DRV8870 provides powered on/off with Output1/Output2, True - DRV8870 provides on/off with Output2 only, Output1 is off uint8_t PressurePin = 15; // NC - no pressure pin bool ADS1115Enabled = false; - bool EthernetEnabled = false; }; ModuleConfig MDL; @@ -317,7 +316,8 @@ void Blink() //Serial.print(" Micros: "); //Serial.print(MaxLoopTime); - + debug1 = Sensor[0].FlowPin; + debug2 = Sensor[0].MeterCal; //Serial.print(", "); Serial.print(debug1); diff --git a/Modules/ESP32 Rate/RC_ESP32/Rate.ino b/Modules/ESP32 Rate/RC_ESP32/Rate.ino index 610bf34d..3c58d724 100644 --- a/Modules/ESP32 Rate/RC_ESP32/Rate.ino +++ b/Modules/ESP32 Rate/RC_ESP32/Rate.ino @@ -62,6 +62,7 @@ void GetUPM() { if (PulseCount[i] && Sensor[i].MeterCal > 0) { + debug3++; LastPulse[i] = millis(); noInterrupts(); diff --git a/Modules/ESP32 Rate/RC_ESP32/Relays.ino b/Modules/ESP32 Rate/RC_ESP32/Relays.ino index 5029df20..6fe8f3cb 100644 --- a/Modules/ESP32 Rate/RC_ESP32/Relays.ino +++ b/Modules/ESP32 Rate/RC_ESP32/Relays.ino @@ -30,7 +30,7 @@ void CheckRelays() if (Button[i + 8]) bitSet(NewHi, i); } } - } + } else if ((millis() - Sensor[0].CommTime < 4000) || (millis() - Sensor[1].CommTime < 4000)) { NewLo = RelayLo; @@ -131,42 +131,23 @@ void CheckRelays() uint8_t mcpOutA = 0; // Output for port A uint8_t mcpOutB = 0; // Output for port B - if (MDL.Is3Wire) - { - // Only Out2 is used on the DRV8870. Each DRV8870 controls 1 valve. - // Calculate output for port A - mcpOutA = (bitRead(RelayLo, 0) ? 2 : 0) | - (bitRead(RelayLo, 1) ? 8 : 0) | - (bitRead(RelayLo, 2) ? 32 : 0) | - (bitRead(RelayLo, 3) ? 128 : 0); + // Calculate output for port A, DRV sections 9-16 + mcpOutA = (bitRead(RelayLo, 4) ? 2 : 1) | + (bitRead(RelayLo, 5) ? 8 : 4) | + (bitRead(RelayLo, 6) ? 32 : 16) | + (bitRead(RelayLo, 7) ? 128 : 64); - // Calculate output for port B - mcpOutB = (bitRead(RelayLo, 4) ? 2 : 0) | - (bitRead(RelayLo, 5) ? 8 : 0) | - (bitRead(RelayLo, 6) ? 32 : 0) | - (bitRead(RelayLo, 7) ? 128 : 0); - } - else - { - // Calculate output for port A - mcpOutA = (bitRead(RelayLo, 0) ? 2 : 1) | - (bitRead(RelayLo, 1) ? 8 : 4) | - (bitRead(RelayLo, 2) ? 32 : 16) | - (bitRead(RelayLo, 3) ? 128 : 64); + // Calculate output for port B, DRV sections 1-8 + mcpOutB = (bitRead(RelayLo, 0) ? 2 : 1) | + (bitRead(RelayLo, 1) ? 8 : 4) | + (bitRead(RelayLo, 2) ? 32 : 16) | + (bitRead(RelayLo, 3) ? 128 : 64); - // Calculate output for port B - mcpOutB = (bitRead(RelayLo, 4) ? 2 : 1) | - (bitRead(RelayLo, 5) ? 8 : 4) | - (bitRead(RelayLo, 6) ? 32 : 16) | - (bitRead(RelayLo, 7) ? 128 : 64); - } if (MDL.InvertRelay) { mcpOutA = ~mcpOutA; mcpOutB = ~mcpOutB; } - debug1 = RelayLo; - debug2 = mcpOutA; // Send both outputs in a single transmission Wire.beginTransmission(MCP23017address); @@ -222,7 +203,7 @@ void CheckRelays() // Iterate through all 8 channels and write data using auto-increment for (int i = 0; i < 8; i++) { - if (NewLo & (1 << i)) + if (NewLo & (1 << i)) { // Turn on channel: ON = 0, OFF = 4096 Wire.write(0); // ON_L diff --git a/Modules/ESP32 Rate/RC_ESP32/UDPComm.ino b/Modules/ESP32 Rate/RC_ESP32/UDPComm.ino index 9d394b8f..cf3c460d 100644 --- a/Modules/ESP32 Rate/RC_ESP32/UDPComm.ino +++ b/Modules/ESP32 Rate/RC_ESP32/UDPComm.ino @@ -379,7 +379,6 @@ void ParseData(byte Data[], uint16_t len) // bit 3 - work pin is momentary // bit 4 - Is3Wire valve // bit 5 - ADS1115 enabled - // bit 6 - Ethernet enabled //5 relay control type 0 - no relays, 1 - GPIOs, 2 - PCA9555 8 relays, 3 - PCA9555 16 relays, 4 - MCP23017 // , 5 - PCA9685, 6 - PCF8574 //6 wifi module serial port @@ -410,7 +409,6 @@ void ParseData(byte Data[], uint16_t len) MDL.WorkPinIsMomentary = ((tmp & 8) == 8); MDL.Is3Wire = ((tmp & 16) == 16); MDL.ADS1115Enabled = ((tmp & 32) == 32); - MDL.EthernetEnabled = ((tmp & 64) == 64); MDL.RelayControl = Data[5]; Sensor[0].FlowPin = Data[7];