Electron - Modbus-485 Library

Hello. I am looking for a Modbus Master library to use with the Electron and a max485 breakout chip to read data from a modbus slave device. I am currently using SimpleModbusMaster on an Arduino and it has been working fine however I am not experienced enough to port the library for the Electron.

I have looked through previous posts on this topic but was unable to get any of the code working. Does anyone have a working example sketch for getting a master to read the holding registers from a slave?

Any help is appreciated. Thank you.

@pdoyle, the library seems very straight forward to port since it uses a serial port. I can have it ported for you this weekend unless you want to give it a shot. :wink:

That would be awesome. I tried to do it myself but kept getting errors trying to compile it…

@peekay123, @pdoyle,

I’ve made a pull request to @peekay123’s MODBUS library that modifies it a bit and provides an example for MODBUS master. I can confirm this works (well) with the TI SN65HVD70, and I think it will work OK with your max485 breakout board if you specify master (0), serial port, and your TXEN/RXEN pins.

If @peekay agrees to merge it in, I think this would fit your need. Would be awesome to keep any modbus development in one place!

2 Likes

@pdoyle, spent the weekend recovering from my trip to Maker Faire. I’ll have the ported library for you tonight.

@hwestbrook, thanks for the PR! Before I merge it, it would be good to put inline comments on how to use the library with the max485 as you stated above. Perhaps @pdoyle can then test it to confirm it works. :grinning:

@pdoyle, I’m still working on the port. The arduino code only uses Serial whereas the Photon and Electron have two or more serial ports available. In the meantime, I’ve merged @hwestbrook’s PR so you can try that as well. Stay tuned!

Wow thanks for the help! I was able to load the master example into the build site and have the basics up and running. Since I was using the breakout board I just had a single CTS pin but couldn’t get it to work by just initializing TXEN. I had to initialize it with both TXEN and RXEN and tied both into the CTS pin.

The only issue I have encountered is that I can’t seem to get the ‘read input registers’ function to store any data. See below for a log…

Edit:
Nevermind, found the issue… There wasn’t a get_FC3() call for the input registers…

1 Like

Hi all,

this might sound like an extremely newbie question, but can someone post a sample schematic for connecting the SN65HVD70 to the photon?

thanks!

Hooman