Photon and Modbus 485 RTU - Connections & interface requirements

Hi all

I wish to read some modbus coils from my laptop using a modbus slave simulator, and a Photon running the ported modbusmaster library.
I have tried to determine as much info from current threads and keep arriving at the same point… however there are several indications that people have had some successes.

A physical interface is required between photon and 232/485 serial converter at laptop and/or interface inbetween…

What interface (if any) would I use, and How do I connect RX / TX pins to photon?
The modbus master library suggests “D7 is the pin used to control the TX enable pin of RS485 driver” - what does this mean?

EG: One suggestion is to use this:

I also found this breakout: which may be more suitable to bypass MOXA completely.

How does (if at all) this relate / utilise the RX / TX pins on the photon?

Can someone please shed some much needed light on this / recommend drawing for connection would be absolutely appreciated.

unfortunately its in chinese…look ant the bottom one for master…

see figure 4 here…termination and bias resistors for network are needed terms are typically 120ohm bias about 600

1 Like

@1bit thanks for sharing.

Still hoping to know how this physically connects to Photon (to what specific pins / using what interface etc… using either this interface or perhaps either of the two that I mention in my query above.

There are a handful of cleaver people that clearly have had success with this which is promising

If you’re just trying to talk to a PC running a simulator - vs a real MODBUS-RTU device - then you can just do this with an FTDI USB-serial cable like this:

You’d connect the TX on the cable (orange, as I remember) to the RX on the photon, the RX on the cable (yellow) to the TX on the photon, and GND on the cable (black) to ground on the photon.

You don’t need to worry about TX enable for this application. RS485 (which is what MODBUS-RTU uses) is a multidrop protocol, so each node on the network will by default just listen - only one device can transmit at a time, and that’s what the TX enable pin does. Given that you are running point to point with a bidirectional serial, you don’t need this.

1 Like

@adamg @peekay123 @beck

Hi guys
Just after some help on this topic with respect to detailing more about connections and requirements? Example - Using modbus slave simulator on laptop via MOXA USB - 232/485 adaptor to talk to photon with current ported ModbusMaster lib

What interface (if any) would I use / How to connect RX / TX pins to photon? Forgive me but the info above and on several other threads details various experiences, some suggestion to use something like this:

It seems that you guys have had some successes already…
For now though I’m just wanting to simply read a coil from my slave simulator over 485.

Any help greatly appreciated!!

@BIBZY84, the Sparkfun board should work. Some information on how to hook things up are in the library comments:

USARTSerial MBSerial = Serial1;		 ///< Pointer to Serial1 class object
uint8_t MBTXEnablePin = D7;		 ///< GPIO pin used for toggling RS485 Driver IC's TX Enable pin, default is D7

From this we know that Serial1 is used (RX/TX pins) and we know that pin D7 is used for controlling the RS485 transceiver direction. The schematics for the Sparkfun board are poorly drawn (missing RTS pin indication on JP9). With minor adjustments it should show:

JP9 is the 5-pin un-numbered connector on the board. From the schematics, the connections from the board to the Photon should be:

RS485 Board     Photon
 1 (Vcc)         Vin
 2 (RX-i)        TX
 3 (TX-o)        RX
 4 (RTS)         D7
 5 (GND)         GND

Notice that the RTS line has a resistor and LED and pin D7 of the Photon also has a resistor and LED connected to it. If things don’t seem to work due to the voltage drops caused by the resistors/LEDs, you should change pin D7 to another digital pin on the Photon. The code in the library example that specifies this pin is in setup()

node.enableTXpin(D7);  // If this is not working, specify a different can and make sure you
                       // change the wiring to match

Hope that helps! :wink:



I have been successful using an inexpensive MAX485 chip as found on such sites as banggood or Ebay.

The MAX485 RD/DI pins should be connected to the Photon RX/TX pins. I am also using the RE/DE pins connected to D6 for transmission control. Your USB-RS485 cable connected to your computer should work well with some simulation software, I usually prefer Modbus Poll or Qmodbus.

One thing to note is that sometimes RS485 networks require pull up resistors on the transmit positive and pull down resistors on the transmit negative. Depending on your network, you may need this.

Let me know how it goes

Well If you can get there (RTU on the tx/rx pins) we can run a TCP stack on this…

that would be wonderful…only a library port for the RTU lib…now where did put those??? I’ll be runing TCP with a GREEN breather…

Actually MODBUS ASCII would be a whole lot less taxing on the particle…

AnywayI did hook up the grid connect and get it up wit the rest of my application. I now have a HARDWIRED MODBUS TCP port on a photon. Like this

GC xport to photon
pin1 to gnd photon
pin2 to 3.3 photon
pin3 to rst photon
pin4 to rx photon
pin5 to tx photon
pin 6 to D4 photon ((CTS)
pin7 to D3 photon (DCD)
pin8 to D2 photon (RTS)

I built

this test bed yesterday and loaded it…it runs my sequence code scheduler and these peripherals just fine…with a blue light breathing…

Particle Electron WIFI “bidiot”
This afternoon i did…
List of peripherals:
Sparkun 7 Segment i2c 4 digit display I2C Address 0x
AVIA HX711 PGA onewire A1,A0
Digole I2C displaytouch I2c Slave address 0x027
Thermistor TC A3 pin
Matek WS1228B Lightstack/Buzzer D6 pin
ABS4988i2cN I2C triple stepper slave I2C address 0x08
with slidewire feedback/ModbusRTU
GridConnect XPORT-MBTCP Modbus TCP to Modbus Ascii converter TX/RX

Adafruit ADS1115 16bitx4ch ADC i2c slave addr TBD
MCP4728 quad DAC i2c slave Address TBD

I got my electron yesterday (2 day delivery)

I need it for another serial port for another 485 network to my analyzers that this unit communicates with…

Cheers! Now off to play with the Teensy and the Electron…and SPI knitting project…JFL

@BIBZY84, since your question here looks pretty similar to your other thread and double posting isn’t appreciated, I’ll split this off (from this thread RS-485 modbus library) into your own thread (here).

Guys, apologies for the delay response.
Thank you so much for the collective help and info with this.
@hfiennes spot on mate - I had USB / UART module already and had successes over rs232 with modsim and using rx / tx without TX en.
@peekay123 - thank you kindly for the heads up and detailed explanation mate - still awaiting for my board to arrive (ex USA I believe) and will be definitely using your info to press forward! Yes definitely helps!.
@adamg - Cheers mate, yes will let you know how I get on asap. Was not familiar with Qmodbus until you recommend it however now using it and impressed :slight_smile:
@1bit - this module very much interests me… Well done on your benching - once I’m satisfied with 485 I would love to visit tcp also!
@ScruffR No problem sorry mate! :smile:

After a bit of bone saw work mostly data type issues. I did get the Xport configured and the RTU slave library to compile…I did fix the 38400 baud rate and the format to 8N1. with this slave library

and it didn’t barf up a lung…when I flashed it…so I’ll try for a master on the particle…