I have been trying to get modbus TCP to work on a teknic clearcore to control a VSD on a CNC.
I uploaded the example modbus tcp sketch from the arduino Modbus library and if I set the board to any standard arduino board it compiles fine but if I set it to the teknic board it wont compile. with the below error
I am trying to use the ethernet port to run tcp/ip because I need the other com ports for other coms. I Have managed to open a connection with the drive over ethernet but I get problems when I try to introduce the ArduinoModbus library.
Can anyone point me in the right direction?
Heres the example code
/*
Ethernet Modbus TCP Client Toggle
This sketch toggles the coil of a Modbus TCP server connected
on and off every second.
Circuit:
- Any Arduino MKR Board
- MKR ETH Shield
created 16 July 2018
by Sandeep Mistry
*/
#include <SPI.h>
#include <Ethernet.h>
#include <ArduinoRS485.h> // ArduinoModbus depends on the ArduinoRS485 library
#include <ArduinoModbus.h>
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177);
EthernetClient ethClient;
ModbusTCPClient modbusTCPClient(ethClient);
IPAddress server(192, 168, 1, 10); // update with the IP Address of your Modbus server
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
// Check for Ethernet hardware present
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
while (true) {
delay(1); // do nothing, no point running without Ethernet hardware
}
}
if (Ethernet.linkStatus() == LinkOFF) {
Serial.println("Ethernet cable is not connected.");
}
}
void loop() {
if (!modbusTCPClient.connected()) {
// client not connected, start the Modbus TCP client
Serial.println("Attempting to connect to Modbus TCP server");
if (!modbusTCPClient.begin(server, 502)) {
Serial.println("Modbus TCP Client failed to connect!");
} else {
Serial.println("Modbus TCP Client connected");
}
} else {
// client connected
// write the value of 0x01, to the coil at address 0x00
if (!modbusTCPClient.coilWrite(0x00, 0x01)) {
Serial.print("Failed to write coil! ");
Serial.println(modbusTCPClient.lastError());
}
// wait for 1 second
delay(1000);
// write the value of 0x00, to the coil at address 0x00
if (!modbusTCPClient.coilWrite(0x00, 0x00)) {
Serial.print("Failed to write coil! ");
Serial.println(modbusTCPClient.lastError());
}
// wait for 1 second
delay(1000);
}
}
and this is the error I get
Arduino: 1.8.19 (Windows Store 1.8.57.0) (Windows 10), Board: "Teknic ClearCore"
Arduino Sketches\libraries\ArduinoRS485\src\RS485.cpp:189:18: error: 'SERIAL_PORT_HARDWARE' was not declared in this scope
RS485Class RS485(SERIAL_PORT_HARDWARE, RS485_DEFAULT_TX_PIN, RS485_DEFAULT_DE_PIN, RS485_DEFAULT_RE_PIN);
^~~~~~~~~~~~~~~~~~~~
Arduino Sketches\libraries\ArduinoRS485\src\RS485.cpp:189:18: note: suggested alternative: 'SERIAL_PARITY_MARK'
RS485Class RS485(SERIAL_PORT_HARDWARE, RS485_DEFAULT_TX_PIN, RS485_DEFAULT_DE_PIN, RS485_DEFAULT_RE_PIN);
^~~~~~~~~~~~~~~~~~~~
SERIAL_PARITY_MARK
In file included from: Arduino Sketches\libraries\ArduinoRS485\src\RS485.cpp:20:0:
Arduino Sketches\libraries\ArduinoRS485\src\RS485.h:35:30: error: 'A6' was not declared in this scope
#define RS485_DEFAULT_DE_PIN A6
^
Arduino Sketches\libraries\ArduinoRS485\src\RS485.cpp:189:62: note: in expansion of macro 'RS485_DEFAULT_DE_PIN'
RS485Class RS485(SERIAL_PORT_HARDWARE, RS485_DEFAULT_TX_PIN, RS485_DEFAULT_DE_PIN, RS485_DEFAULT_RE_PIN);
^~~~~~~~~~~~~~~~~~~~
Arduino Sketches\libraries\ArduinoRS485\src\RS485.h:35:30: note: suggested alternative: 'Ac'
#define RS485_DEFAULT_DE_PIN A6
^
Arduino Sketches\libraries\ArduinoRS485\src\RS485.cpp:189:62: note: in expansion of macro 'RS485_DEFAULT_DE_PIN'
RS485Class RS485(SERIAL_PORT_HARDWARE, RS485_DEFAULT_TX_PIN, RS485_DEFAULT_DE_PIN, RS485_DEFAULT_RE_PIN);
^~~~~~~~~~~~~~~~~~~~
Arduino Sketches\libraries\ArduinoRS485\src\RS485.h:36:30: error: 'A5' was not declared in this scope
#define RS485_DEFAULT_RE_PIN A5
^
Arduino Sketches\libraries\ArduinoRS485\src\RS485.cpp:189:84: note: in expansion of macro 'RS485_DEFAULT_RE_PIN'
RS485Class RS485(SERIAL_PORT_HARDWARE, RS485_DEFAULT_TX_PIN, RS485_DEFAULT_DE_PIN, RS485_DEFAULT_RE_PIN);
^~~~~~~~~~~~~~~~~~~~
Arduino Sketches\libraries\ArduinoRS485\src\RS485.h:36:30: note: suggested alternative: 'Ac'
#define RS485_DEFAULT_RE_PIN A5
^
Arduino Sketches\libraries\ArduinoRS485\src\RS485.cpp:189:84: note: in expansion of macro 'RS485_DEFAULT_RE_PIN'
RS485Class RS485(SERIAL_PORT_HARDWARE, RS485_DEFAULT_TX_PIN, RS485_DEFAULT_DE_PIN, RS485_DEFAULT_RE_PIN);
^~~~~~~~~~~~~~~~~~~~
And this is this is the sketch that successfully opened a connection with the drive (well the serial monitor said it was successful anyway)
#include <Ethernet.h>
byte mac[] = { 0x24, 0x15, 0x10, 0xb0, 0x0a, 0xd9 };
byte ip[] = { 192, 168, 33, 110 };
byte server[] = { 192, 168, 33, 10 };
int tcp_port = 80;
EthernetClient client;
void setup()
{
Ethernet.begin(mac, ip);
Serial.begin(9600);
delay(1000);
Serial.println("Connecting...");
if (client.connect(server, tcp_port)) { // Connection to VSD
Serial.println("Connected to VSD");
client.println();
} else {
Serial.println("connection failed");
}
}
void loop()
{
if (client.available()) {
if(Serial.available()){
char s = Serial.read();
client.write(s); // Send what is reed on serial monitor
char c = client.read();
Serial.print(c); // Print on serial monitor the data from server
}
}
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
for(;;)
;
}
}