
Originally Posted by
joepasquariello
If you look at the card that came with your Teensy 4.0, you'll see that hardware serial 1 (RX1, TX1) are on pins 0 and 1. You'll want to connect those two pins to the A and B pins of your TTL/485 converter.
This advice might not be quite right. You do need to use pin 0 (RX1) and pin 1 (TX1). But don't connect them to A & B on the MAX485 chip. The A & B pins are the RS485 signals which you connect to whatever modbus device(s) you wish to use.
When you use ArduinoModbus, it will require another library called ArduinoRS485. Get it here:
https://github.com/arduino-libraries/ArduinoRS485
I believe these are the default connections ArduinoRS485 expects:
MAX485 DI - Teensy pin 1 (TX)
MAX485 DE - Teensy pin 20 (A6)
MAX485 RE - Teensy pin 19 (A5)
MAX485 RO - Teensy pin 0 (RX) - but beware 5V, see next message
The specific pins ArduinoRS485 uses are controlled in 2 places. First is RS485.h starting at line 25.
https://github.com/arduino-libraries...rc/RS485.h#L25
These lines control which pins it will use for DE & RE.
Code:
#ifdef __AVR__
#define RS485_DEFAULT_DE_PIN 2
#define RS485_DEFAULT_RE_PIN -1
#else
#define RS485_DEFAULT_DE_PIN A6
#define RS485_DEFAULT_RE_PIN A5
#endif
If you want to use different pins, I believe you can just edit RS485.h and change these to any digital pin. I believe setting RS485_DEFAULT_RE_PIN to -1 means it will only use DE. In that case, you could connect both DE and RE to that single pin on Teensy.
Which serial pins ArduinoRS485 uses is a little more complicated. That is controlled by the last line in RS485.cpp.
https://github.com/arduino-libraries...RS485.cpp#L189
This is the code:
Code:
RS485Class RS485(SERIAL_PORT_HARDWARE, RS485_DEFAULT_TX_PIN, RS485_DEFAULT_DE_PIN, RS485_DEFAULT_RE_PIN);
The special name "SERIAL_PORT_HARDWARE" is actually defined in the core library, in pins_arduino.h.
https://github.com/PaulStoffregen/co...arduino.h#L184
For Teensy, it is always this:
Code:
#define SERIAL_PORT_HARDWARE Serial1
If you wanted to use a different pins, you could just edit that last line in RS485.h. For example, if you wanted to use Serial4 (pins 16 & 17) and pin 18 for both DE+RE, I'm pretty sure you could just edit RS485.cpp like this:
Code:
RS485Class RS485(Serial4, 17, 18, -1);
But to use ArduinoModbus and ArduinoRS485 as-is, these would be the pins to connect between Teensy and MAX485.
MAX485 DI - Teensy pin 1 (TX)
MAX485 DE - Teensy pin 20 (A6)
MAX485 RE - Teensy pin 19 (A5)
MAX485 RO - Teensy pin 0 (RX) - but beware 5V, see next message
The MAX485 A & B pins are the actual RS-485 signals which you would connect to the Modbus RTU device you wish to use.