code not working - Printable Version +- Smart Home Automation Forum (https://www.kincony.com/forum) +-- Forum: Technical Support (https://www.kincony.com/forum/forumdisplay.php?fid=20) +--- Forum: KC868-A16 (https://www.kincony.com/forum/forumdisplay.php?fid=25) +--- Thread: code not working (/showthread.php?tid=2891) |
code not working - soccer - 05-08-2023 Could someone tell what is wrong in the code? it's not working with a hmi delta dop-107EV, I don't know what could be an error in the code. #include <WiFi.h> #include <ETH.h> #include <ModbusIP_ESP8266.h> #include <SPI.h> #include <Ethernet.h> #include <PCF8574.h> //////////////////////////////////////////////////////////////////// #define ETH_ADDR 0 #define ETH_POWER_PIN -1 #define ETH_MDC_PIN 23 #define ETH_MDIO_PIN 18 #define ETH_TYPE ETH_PHY_LAN8720 #define ETH_CLK_MODE ETH_CLOCK_GPIO17_OUT const int port = 502; //////////////////////////////////////////////////////////////////// TwoWire I2Cone = TwoWire(0); //TwoWire I2Ctwo = TwoWire(1); // Set i2c address PCF8574 pcf8574_I1(&I2Cone, 0x21, 4, 5); PCF8574 pcf8574_I2(&I2Cone, 0x22, 4, 5); PCF8574 pcf8574_R1(&I2Cone, 0x24, 4, 5); PCF8574 pcf8574_R2(&I2Cone, 0x25, 4, 5); //////////////////////////////////////////////////////////////////// const int LED_COIL = 100; const int ledPin = pcf8574_R1.pinMode (P1); //GPIO0 const int TEST_HREG = 100; //////////////////////////////////////////////////////////////////// IPAddress staticIP(192, 168, 0, 40); IPAddress gateway(192, 168, 0, 1); IPAddress subnet(255, 255, 255, 0); IPAddress dns(192, 168, 0, 1); //////////////////////////////////////////////////////////////////// ModbusIP mb; ETH mb; void setup() { Serial.begin(115200); ETH.begin(ETH_ADDR, ETH_POWER_PIN, ETH_MDC_PIN, ETH_MDIO_PIN, ETH_TYPE, ETH_CLK_MODE); Serial.begin(115200); if (WiFi.config(staticIP, gateway, subnet, dns, dns) == false) { Serial.println("Configuration failed."); } //////////////////////////////////////////////////////////////////// // put your setup code here, to run once: pcf8574_R1.pinMode(P0, OUTPUT); pcf8574_R1.pinMode(P1, OUTPUT); pcf8574_R1.pinMode(P2, OUTPUT); pcf8574_I1.pinMode(P0, INPUT); pcf8574_I1.pinMode(P1, INPUT); pcf8574_I1.pinMode(P2, INPUT); //////////////////////////////////////////////////////////////////// modbus.server(port); mb.addCoil(LED_COIL); } void loop() { // put your main code here, to run repeatedly: mb.task(); //Attach ledPin to LED_COIL register digitalWrite(ledPin, mb.Coil(LED_COIL)); delay(10); } RE: code not working - admin - 05-09-2023 which board you are using? which communication port you are using? should have details of question. RE: code not working - soccer - 05-09-2023 I'm using the kc868-A16 board, I'm using the ethernet port for communication, through modbus tcp/ip, so it's not working, and I don't know why. would the code be incorrect? RE: code not working - admin - 05-10-2023 it's not easy to say. you can test with two step: 1. ethernet whether work well. 2. modbus protocol whether work well. |