Skip to content

Commit

Permalink
update ESP32 code for PCF8574
Browse files Browse the repository at this point in the history
  • Loading branch information
SK21 committed Feb 16, 2024
1 parent d39e9ab commit 2aff10d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
Binary file modified Modules/ESP32 Rate/RC_ESP32.ino.bin
Binary file not shown.
4 changes: 2 additions & 2 deletions Modules/ESP32 Rate/RC_ESP32/Begin.ino
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void DoSetup()
IPAddress LocalIP(MDL.IP0, MDL.IP1, MDL.IP2, MDL.IP3);
static uint8_t LocalMac[] = { 0x0A,0x0B,0x42,0x0C,0x0D,MDL.IP3 };

Ethernet.init(5); // SS pin
Ethernet.init(W5500_SS); // SS pin
Ethernet.begin(LocalMac, 0);
Ethernet.setLocalIP(LocalIP);
IPAddress Mask(255, 255, 255, 0);
Expand Down Expand Up @@ -266,7 +266,7 @@ void DoSetup()
while (!PCA9685_found)
{
Serial.print(".");
Wire.beginTransmission(DriverAddress);
Wire.beginTransmission(PCAaddress);
PCA9685_found = (Wire.endTransmission() == 0);
ErrorCount++;
delay(500);
Expand Down
18 changes: 13 additions & 5 deletions Modules/ESP32 Rate/RC_ESP32/RC_ESP32.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <Adafruit_MCP23X17.h>
#include <Adafruit_MCP23XXX.h>

#include <pcf8574.h>

#include <Adafruit_BusIO_Register.h>
#include <Adafruit_I2CDevice.h>
#include <Adafruit_I2CRegister.h>
Expand All @@ -27,8 +29,8 @@
#include <ESP2SOTA.h> // https://github.com/pangodream/ESP2SOTA

// rate control with ESP32 board: DOIT ESP32 DEVKIT V1
# define InoDescription "RC_ESP32 : 14-Feb-2024"
const uint16_t InoID = 14024; // change to send defaults to eeprom, ddmmy, no leading 0
# define InoDescription "RC_ESP32 : 16-Feb-2024"
const uint16_t InoID = 16024; // 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

Expand All @@ -39,8 +41,10 @@ const uint8_t Processor = 0; // 0 - ESP32-Wroom-32U

// servo driver
#define OutputEnablePin 27
#define DriverAddress 0x55
#define PCAaddress 0x55

#define PCFaddress 0x20
#define W5500_SS 5 // W5500 SPI SS
#define NC 0xFF // Pin not connected

struct ModuleConfig
Expand All @@ -53,7 +57,8 @@ struct ModuleConfig
uint8_t IP1 = 168;
uint8_t IP2 = 5;
uint8_t IP3 = 60;
uint8_t RelayControl = 6; // 0 - no relays, 1 - GPIOs, 2 - PCA9555 8 relays, 3 - PCA9555 16 relays, 4 - MCP23017, 5 - PCA9685 single , 6 - PCA9685 paired
uint8_t RelayControl = 6; // 0 - no relays, 1 - GPIOs, 2 - PCA9555 8 relays, 3 - PCA9555 16 relays, 4 - MCP23017
//, 5 - PCA9685 single , 6 - PCA9685 paired, 7 - PCF8574
uint8_t RelayPins[16] = { 8,9,10,11,12,25,26,27,NC,NC,NC,NC,NC,NC,NC,NC }; // pin numbers when GPIOs are used for relay control (1), default RC11
char Name[ModStringLengths] = "RateModule";
char Password[ModStringLengths] = "111222333";
Expand Down Expand Up @@ -130,10 +135,13 @@ uint32_t SendLast = SendTime;
bool MasterOn = false;
bool AutoOn = true;

PCF8574 PCF;
bool PCF_found = false;

PCA9555 PCA;
bool PCA9555PW_found = false;

Adafruit_PWMServoDriver PWMServoDriver = Adafruit_PWMServoDriver(DriverAddress);
Adafruit_PWMServoDriver PWMServoDriver = Adafruit_PWMServoDriver(PCAaddress);
bool PCA9685_found = false;

Adafruit_MCP23X17 MCP;
Expand Down
4 changes: 2 additions & 2 deletions Modules/ESP32 Rate/RC_ESP32/RC_ESP32.vcxproj

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion Modules/ESP32 Rate/RC_ESP32/Relays.ino
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,18 @@ void CheckRelays()
RelayStatus[i] = BitState;
}
}
break;
}
break;

case 7:
// PCF8574
if (PCF_found)
{
for (int i = 0; i < 8; i++)
{
if (bitRead(NewLo, i)) PCF.write(i, MDL.RelayOnSignal); else PCF.write(i, !MDL.RelayOnSignal);
}
}
break;
}
}

0 comments on commit 2aff10d

Please sign in to comment.