Hello,
For a current project i want to make a TCP server, but i got a problem connecting it to my network.
A while ago i tested my software on a arduino mega2560 with the ethernetshield(2nd version), this worked flawless as it connected to my network and i could reach it and read its registers.
A few weeks later my custom PCB arrived, i uploaded the bootloader with my sketch(same software) but i did not connect to my network.
So i went to test my software again to be sure on my arduino, but it also did not connect to my network.
I cant get it working again, i tested a few things:
-tested 2 arduino mega
-arduino uno
-tested 2 shields
-tested 2 ethernet cable
-created a little network with a router with only my pc and arduino on it
The code i am using will be in the attachments.
The IP-adress is free on the network and cant reach it tough CMD and my modbus TCP test woftware, also the MAC-adress is the same in the software as the hardware.
Does anyone know what the problem is or what i should be checking?
Kind Regards,
#include <Ethernet.h>
#include <ArduinoModbus.h>
unsigned long HoldingResult, InputResult;
int holding, holding1;
int ledpin = 11;
int ledpin1 = 9;
int inpin = A0;
int val = 0;
int Coils = 2-4;
int Input;
EthernetServer EthServer(502);
ModbusTCPServer modbusTCPServer;
void setup() {
pinMode(ledpin, OUTPUT);
pinMode(ledpin1, OUTPUT);
pinMode(inpin, INPUT);
pinMode(29, OUTPUT);
// byte mac[] = { 0xA8, 0x61, 0x0A, 0xAE, 0x8A, 0x08 };
byte ip[] = { 192, 168, 1, 150 };
byte subnet[] = { 255, 255, 255, 0 };
Ethernet.begin(ip, subnet);
EthServer.begin();
modbusTCPServer.begin();
HoldingResult = modbusTCPServer.configureHoldingRegisters(0, 5);
InputResult = modbusTCPServer.configureInputRegisters(0, 100);
//Coils = modbusTCPServer.configureCoils(0x00, 3);
}
void loop() {
EthernetClient client = EthServer.available();
if (client.connected()) {
modbusTCPServer.accept(client);
modbusTCPServer.poll();
}
holding = modbusTCPServer.holdingRegisterRead(0);
holding1 = modbusTCPServer.holdingRegisterRead(1);
{
if (holding)
{
digitalWrite(ledpin, HIGH);
}
else
{
digitalWrite(ledpin, LOW);
}
{
}
}
/*
{
if (holding1)
{
digitalWrite(ledpin1, HIGH);
}
else
{
digitalWrite(ledpin1, LOW);
}
{
lcd.setCursor(3, 0);
lcd.print(holding1);
}
} */
val = digitalRead(inpin);
{
if (val)
{
int inputRegisterWrite(2, 2);
}
else
{
int inputRegisterWrite(2,2);
}
}
digitalWrite(29, HIGH);
delay(200);
digitalWrite(29, LOW);
delay(200);
}