Hi,
I need to use a teensy 4.0 as a Modbus Server(Slave) to send and receive integer and bit values to a touchscreen HMI or a PLC for process diagnostics and control. I am using the ArduinoModbus library and wanted tried using the code mentioned in the following page by @PaulStoffregen :
https://forum.pjrc.com/threads/37018-Modbus-RTU/page2
After compiling and downloading the code, and connecting an oscilloscope to various Teensy pins, I can see some modbus like data on Pin 1 of the Teensy 4.0 (standby state is high at 3v3). I can also see Pins 19 and 20 both go from 0V to 3V3 for the duration of the time that Pin 1 is sending data. I am also hoping that I can use the Server commands in place of the Client commands to use the Teensy as a Slave (code attached is for Teensy as a Master if I am reading it correctly),
I am assuming that the code will work with transmitting the required data but before I can test it with ModScan or an actual HMI or PLC, I need to wire up a test system.
Please help me with how I should wire this system. (Teensy 4.0 - maybe some level converter to step up 3v3 to 5v - connection to Data+ and Data- terminals on the HMI).
Are the Teensy Pins configured as under:
Pin 0 (Rx) - RO
Pin 1 (Tx) - DI
Pin 19 and 20 - DE and RE?
If so, what components should I use to convert the 4 wire signals to a 2 wire RS485 communication that can be connected to a standard HMI or PLC
Thanks!
I need to use a teensy 4.0 as a Modbus Server(Slave) to send and receive integer and bit values to a touchscreen HMI or a PLC for process diagnostics and control. I am using the ArduinoModbus library and wanted tried using the code mentioned in the following page by @PaulStoffregen :
https://forum.pjrc.com/threads/37018-Modbus-RTU/page2
Code:
#include <ArduinoRS485.h>
#include <ArduinoModbus.h>
bool clientStarted = 0;
void setup() {
clientStarted = ModbusRTUClient.begin(57600);
while (!clientStarted) {
Serial.println("Client Error");
}
}
void loop() {
ModbusRTUClient.beginTransmission(15, HOLDING_REGISTERS, 0x100, 6);
ModbusRTUClient.write(100);
ModbusRTUClient.write(101);
ModbusRTUClient.write(102);
ModbusRTUClient.write(103);
ModbusRTUClient.write(104);
ModbusRTUClient.write(105);
if (!ModbusRTUClient.endTransmission()) {
Serial.println ("failed! ");
Serial.println (ModbusRTUClient.lastError());
}
else{
Serial.println("Success");
}
}
After compiling and downloading the code, and connecting an oscilloscope to various Teensy pins, I can see some modbus like data on Pin 1 of the Teensy 4.0 (standby state is high at 3v3). I can also see Pins 19 and 20 both go from 0V to 3V3 for the duration of the time that Pin 1 is sending data. I am also hoping that I can use the Server commands in place of the Client commands to use the Teensy as a Slave (code attached is for Teensy as a Master if I am reading it correctly),
I am assuming that the code will work with transmitting the required data but before I can test it with ModScan or an actual HMI or PLC, I need to wire up a test system.
Please help me with how I should wire this system. (Teensy 4.0 - maybe some level converter to step up 3v3 to 5v - connection to Data+ and Data- terminals on the HMI).
Are the Teensy Pins configured as under:
Pin 0 (Rx) - RO
Pin 1 (Tx) - DI
Pin 19 and 20 - DE and RE?
If so, what components should I use to convert the 4 wire signals to a 2 wire RS485 communication that can be connected to a standard HMI or PLC
Thanks!