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?
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
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.
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:
@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:
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
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.
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)
@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 @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!
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…