You're very kind, Tab Maryland! I just hope I'm not going to overload my Arduinite subscribers and followers with information. I'll try and restrain my enthusiasm. Don't forget to "follow" on the blog though! Thanks for posting.
Cool, reminds me of my old days when I ran Land-line teletype over in Vietnam, we dealt with a sort of ancient version of this using tube sets that amplified the signals after they had been processed by the crypto gear, I also did some time in the Brigade Headquarters Switchboard room as an operator for a few months, this was where I was exposed to the phantom and phantom simplex circuits using the earth as one side of a land line phone circuit it was really amazing, we could go from the Cam Rahn Bay to Saigon and to Phu Bi using just the earth for one side of the circuit. Basically one wire communications. Of course we did use special gear that got it done, I still recall the glow from the tubes in those boxes....
Single line transmission was how the first telegraphs were sent, Jerry, using the actual ground as, er, ground. Unfortunately, for the Wild West users, the ground in the USA sometimes became so dry that the transmissions stopped. There are anecdotes of telegraph operators pouring jugs of water around the earth peg to try and get a connection. Eventually, technology caught up and two-wire comms became the norm and no more wet earth pegs were required! I'm not recalling this from memory, I hasten to add, it's just something I have learned about!
Once used some RS232 - RS485 converters for a fussy customer. Distance was a bit close to 10m, so customer insisted. He also insisted on some "fancy" ones at about £50 each! He was paying, so he was correct ;)
If the customer has a reason for specifying higher quality components, so be it! They must have a reason (and not just that the bloke down the pub said so).
Hi Ralph. I see you managed to find your MAX485 modules. '-) You can have up to 32 standard 12 Kohm modules (including the master) on a RS485 bus. If, however, you use the MAX487 chip you can increase this to 128. I'm soaking up Nick Gammon's wise words and will adapt his protocol to my needs. Many thanks for the video.
ALWAYS USE GREAT CAUTION WHEN MAKING DIRECT COPPER CONNECTIONS OF ANY KIND TO OUTBUILDINGS!! This is a HUGE subject to try to cover briefly in a comment. Suffice to say the following. 1. MASSIVE inductive spikes (10's thousands of volts) can appear on the outdoor connections that can blow your circuitry (literally) to smithereens. Research for example opto and galvanic isolation of RS485 lines. 2. Protect your circuits and youselves as much as possible by fitting suitable lightning arrestors and transorbs (tranzorbs, TVS diodes) with suitable fuses in series - Google for more info. 3. Even when any outside mains power supply has been properly and professionally installed with maybe individual bonded earth in addition to any SWA earth cable back to the consumer unit, NEVER, NEVER, NEVER assume that there is ZERO voltage between ground potential in the outbuilding and ground potential in the house!! It MIGHT spike to several thousand volts difference during an overhead lightning storm!! It's why it's not such a good idea necessarily to have an outside supply from an MCB covered by an RCD feeding other internal circuits as well. Use a separate supply feed altogether from the main isolator or use an RCBO connected BEFORE the main RCDs. Otherwise you may find spurious whole or half house power trips happening all the time. Hope this doesn't confuse people too much but please research on line as it is important for YOUR life and safety as well as to protect your gear.
Thanks for that safety update, Bob, much appreciated, as many treat anything at mains potential and higher as no more than a 9-volt battery. And as you say, ground on any circuit is not necessary zero volts.
Used RS485 for my original home grown home control system, about 9 years ago. Had the same problem with the output buffer. RS485 worked well for a few devices but found CAN bus a lot easer and more reliable for multiple devices. The MCP2515 CAN bus Module are a bit more expensive but still less than a £1 each (from AliExpress) and go up to 1Mb/s and use the same number of com wires. If you use a micro controller with built in CAN bus (e.g. ESP32) you can just use a SN65HVD230 CAN bus buffer about the same cost but requires fewer pins.
So another comms protocol for me to investigate then, Nick! Although I think my car uses a CANBUS to route all the signals around, which is how it knows the offside parking bulb is blown. I'll take a look at the device you mention, at that price it seems worth looking at in some detail. Thanks for the heads up, good to hear from you.
Yes as you probably know Can bus was originally developed for vehicles by Bosch back in 1983. Great Videos btw Some good starting points I found. Just in case you or anyone else are interested in investigate. Using the MCP2515 CAN BUS Module Board with Arduino www.14core.com/wiring-the-mcp2515-controller-area-network-can-bus-diagnostics/ This site was useful in getting CAN working with an ESP-32 www.iotsharing.com/2017/09/how-to-use-arduino-esp32-can-interface.html Im also using a PiCAN hat on a Raspberry Pi skpang.co.uk/catalog/pican2-canbus-board-for-raspberry-pi-23-p-1475.html Think it would be possible to use the MCP2515 CAN BUS Module Board though. It uses the same chipset as the PiCAN. The PiCAN was just more convenient. Been using CAN on my Raspberry Pi to communicate with several Arduino nodes on my home control system for several years and has proved very reliable using four core telephone cable for 12v power and signal.
Excellent links there, NIck, thanks for that, I (and perhaps others too) will explore. I'm amazed you can use standard telephone wire for both power and signal; as far as I know, they are not even twisted pairs just wire so I will be interested in that, for sure.
Not sure if standard phone cable has twisted pairs but the cable I used has. It’s a lot better to use, in the home, than ethernet cable as it’s thiner and more flexible. This makes it easer to install without looking too messy. So far my run of cabe is about 30m using 500Mb/s it has been very reliable. Ideal for sending short control messages to and from multiple low cost devices. Which is what it was designed for I guess.
Hi Ralph I do think RS485 deserves to be revisited to scratch a little deeper below the surface. You had a defective module first time round so you were unable to create a multidrop network. Additionally, you never overcame the buffered delay in printed characters.
I'm struggling to recall the details, Brian, but wasn't the delay just the fact that one unit was receiving the data and the other was sending the NEXT request at which point the first request was then echoed back to the first unit? Hence the (one character) delay? We could have overcome it, I believe, by asking for the response before sending another character. If this all barking up the wrong tree let me know and I'll deeper into it.
Hi Ralph I recall you were unable to properly set up a multi-drop network as one of your RS485 modules decided to have a benny (no pun intended). Wasn't the character held in the buffer and not sent out until it had received another? Or something like that.
If using twisted pair you have to ensure you pair the twists up, and you should use a drain wire, as you mention grounding the shield on one side, this is a drain.
Just like my shiny new CAT-6 ethernet cable going to my soon-to-be-constructed workshop, that has an exposed drain at one end for (extra) earthing. Good point, tablatronix, thanks for posting.
Hi Ralph, I maybe missed it somewhere in the video but it is probably worth mentioning that RS485 requires 120ohm terminating resistors at each end of the line, i cant imagine they are built in to the RS485 modules as this would then prevent you from having anymore than 2 in the network so this would likely need to be added manually. nice video though, thanks for sharing :)
Ah, yes, you have to be careful here, DazzleK93. I did mention that you don't need to add resistors because they are all built into the module (see schematic here: yourduino.com/sunshop//index.php?l=product_detail&p=323 ) BUT you are very right in pointing out that the more you connect the lower this resistance will be. I'm guessing the manufacturer of the module does this so you can start using the module right away with no faffing about. But... If you connect more than one (and this applies to I2C modules too that have 10K pull-up resistors on the CLK and DATA lines) you should really REMOVE the extra ones. So, in this case, R5, R6 and R7 should be removed on all but one of the modules. Very well spotted, and thanks for bringing this up as it would surely cause issues if half a dozen were all connected up on the same lines. Thanks for the post and your kind words too!
The only reason: cost. As always, things are built down to a price. Now if Sparkfun had designed these they would have had jumpers, a built-in LED display of some kind, and an onboard 4K EEPROM, just for fun. And then they would have cost £10 each! Sorry, am I being too cynical here? As it happens, your post has highlighted this issue so removal of said surface-mounted resistors should be easy.
If you want to optimally use these modules in a multi-drop configuration you'll need to remove R5, R6 & R7 from the MAX485 board at all the intermediate stations and R5 and R6 at one of the end stations.
I use SN75176B for RS485 communication. I have not faced the issue as mentioned by Gammon. But I have a different issue -- after transmission, once I enable reception, sometime, the 1st byte of reception is the last byte that was transmitted. I have used some software work around, but a simple fixed delay after transmission did not solve the issue. Somehow, either the delay sometime appears inadequate while some other time, the delay becomes too much and I loose the 1st valid RX byte.
So is the 2nd byte you receive actually the first byte from the sender unit? Do you get the last byte successfully? I had a similar issue but it was all about the FIFO or buffering. In other words, it was my misunderstanding of the protocol and my software than an actual error.
@@RalphBacon Yes could be the reason. In such case, I usually bypass the SW layer and directly access the HW register. But my code is running on ESP8266-NodeMCU and I am not familar with background. Hence, I have to be happy with using serial functions provided in Arduino like code.
I just remembered why I have a pile of these modules at home, RS485 is used for DMX lighting control, so you can use these modules along with an Arduino (or any similar) to control DMX stage/disco lights. Now I mention it sounds like a cross over to Big Clive channel :D (sure you don't mind me mentioning his channel here) I had a sketch working on a few lights as a proof of concept and meant to do something proper with it for a simple control without needing full computer, dmx dongles and software for some static looks and some basic effects.
Who Clive? New boy, is he, Matt? 😜 In my days as a DJ (yes, really) I hankered after a DMX controller. Even though my lights could have been connected up together, the controllers and cables and so on made it prohibitively expensive, back in the '90s. I think I might have been able to concoct something to control those lights with an Arduino and an RS485 module, had the Arduino been invented back then. Even worse, I did one stint in a huge nightclub and they let me use all their equipment, including DMX controlled lighting. There's something special seeing laser lights move in perfect synchronisation before doing their own thing! Ah yes, memories of Robin S, Show Me Love... Thanks for the memories, Matt.
I'm using SoftwareSerial library to keep things simple. Unless you can make each slave accept an ID, using digitalWrite and then ensure you only send data to that Slave ID (eg for a response), I don't know if the way I did this would work. There is undoubtedly an RS485 (or MODBUS) library available these days that works on the Arduino family and which you can assign an ID to a Slave (or read it, if previously set). Best I can suggest, sorry I can't be of more help.
@@RalphBacon Thank you so much, your tutorial help me a lot, though i wanted to understand more about master and multiple slave. Once again thank you so much.
Thank you Sir for another great video!!! Question: what is the relation between baud rate and admissible transmission distance? Half baudrate means double distance or is it more complicated? Here's an idea for some future video: PCA9615 that converts I2C to a differential line. Looks quite nice for long distance communications with sensors and there's surprisingly little amount of info online. Best regards
It's not quite that mathematical, Alex. The lower baud rate ensures less risk of corruption over longer distances. The only way to know whether your baud rate works is to try it. But what works today may not work tomorrow when the microwave next door (or a hairdryer) is switched on! Regarding the PCA9615, that deice does indeed look intriguing. I wonder if it could be coupled with a TCA9548A I2C multiplexer, that would be interesting too?
Hello, I have a question: is this a 485 communication. Is it possible with a "D1 MINI WEMOS Pro 4M 16M" using "Tasmota" e.g. B. to control a "JUNTEK DPM8624 60V24A Programmable DC DC Digital Adjustable Step Down Voltage Power Supply Buck Converter 485 Communication"?
Hmm.. are we talking about THIS device: s.click.aliexpress.com/e/_DE0lb5h That device is controlled via a standard USB-to-Serial (TTL) adapter, just like the ones we use in an Arduino environment. Nothing is mentioned about using RS485, although the protocol might be used as part of that Serial comms... but seems unlikely. Let me know if it is another device.
@@RalphBacon OK. I saw somewhere that you can use "TTL to RS485 Module UART Port Converter Module EIG88" to control the device. watch?v=yOcoux9IbzM&t=218s
Hi, great video, I have a question, is it possible to connect multiple slaves (rs485 output sensors) to MAX 485 (to A- B), and read slave values from Arduino, Thanks in advance
The LTC1480 is certainly advertised as a 3v3 part but can take up to 7v. I suspect that is why Nick's using the full, Arduino-friendly 5v supply thus avoiding any level shifting requirements.
The module from BangGood and from AliExpress for less than a Dollar is a MAX458 chip, the data sheet lists that as 5v. Searching Maxim, the matrix for 3v3 to5v does not list the MAX485 chip. I gave you a thumbs up for a great video and your contributions to the community. My needs are for the EXP32/8266 chips that are 3v3. Interestingly there two sides to the RS485. the external connection side can take a very large swing of voltages as the chip is looking for differential signals on the two lines as the means of detecting data and not any actual voltage. The receiver side has a very large voltage range the LTC1480 is -7 to 12V. The MAX485 is slightly more. That allows a 3v3 ESP8266 device to connect to a PLC or automobile based network that is running at 12 volts. In a side note, I personally try to buy the mainstream parts. I assume there is a flood of them and that brings the lower costs and keeps the chip in production. I suspect that one of the main supply outlets will start with 3v3 and 5v tolerant parts and make us all happy. Thanks again for your educational videos !
Great project Ralph, Can you help me fixing issue. My master somehow not receiving anything back. It only sending. Not sure if slave is even getting message.
Make sure your TX/RX pair go to RX/TX. Put lots of Serial.print() statements in the code so you can see what, if anything, is happening. Debugging is all part of learning C++ (as I have just spent most of the day tracking down a bug, very laborious, lots of display statements, I know how time-consuming and tedious it can be - but it must be done. Don't give up, you know the sketch works, it can only be your modules and/or the wiring.
@@RalphBacon Yes trying same, would it be possible for you to share exact wiring picture, so it might help me debug if i am missing anything from video. Also i am using 2 nano, for which i used Tx & Rx pin and changed code to use 0,1 pin.
@@RalphBacon Finally i am getting on both Serial monitor, thanks it took me long to fix it. But i still have issue, the data is always reverse ? mark, i did looked at baud rate and its 9600 on both Serial monitor and program. Any idea what could be i am doing wrong here?
Thx for the good video! i tried it out immediately but unfortunately only got This: Received:? in the Responders Serial Monitor. Did i wire something incorrectly? pls help
So you got a question mark as the received data? Hmm, sounds like corruption or transmission speed incorrect or mismatched. When I get stuck like this I just liberally sprinkle my code with Serial.print statements so I can trace the data from one module to another, and see exactly where it got changed. Try that first, Dominik.
I think you will get an email back when a new post is sent, Bob. I'll experiment on one of my old email addresses and see what happens. Thanks for your kind words and keep tuned!
Let's not forget _poorer_ version! I'm not sure whether to be flattered or offended at the comparison (although I have some sympathy with Pierce and his say-it-like-I-see-it manner). Let's hope I'm not as abrasive as him, though! Thanks for the kind words, Rube, and thanks for posting.
A very good point there, JH. I must admit I imagined in my mind that everyone buries their cables but I guess they could equally string them on poles like telephone wires. Now I know you can get ADSL surge protectors so maybe you can get some other form of surge protection for standard "data" wiring, I just don't know but it's certainly something that should be considered. Thanks for the post.
If you have long overhead cable runs it may be possible to include a degree of protection (up to about 15kV) by using opto-isolated transceivers like the LTM2881. Obviously nothing can protect completely against a direct lightning strike. Ouch!
I've half understood the question but you need to rephrase it. Are you looking to operate a relay using RS485 comms, a pair of Arduinos and a touch screen (HMI) made by Delta?
As i promised before, here is the code for using struct with RS485. Same usage of pins as your sketches Ralph. But i added 3 led's to each bord to show sending, recieving and errors. www.digihz.com/ArduinoCode/RS485SenderStructV3.zip www.digihz.com/ArduinoCode/RS485ResponderStructV3.zip Picture of my sender / responder. www.digihz.com/ArduinoCode/Sender_Responder.jpg I will supply a new version soon where the sender sends some configuration struct data to the responder, and the responder sends back sensor values. Sometimes you want to send some configuration values to a slave from a master and once that slave recieves the configuration , then the slave starts to continiously send sensor data back to the master.
@@RalphBacon so you tried the sketches with leds connected? Or did you just have time to look at the code Ralph? Led' s are more informative i think and fun to look at to. Yes, documentation is allways important, not only for others, but for yourself to when you look at a code 5 years later :)
I just looked at the code, Hans. But I could see what you were doing. An old Dev Mgr of mine said that we were commenting our code for the next programmer who had to maintain that codebase - who would probably be yourself in 6 months time!!! See, we all think alike.
@@RalphBacon ok Ralph. But I think that you should try it in real life... (could be good code for your Bluetooth to to use Easytransfer). But mayby by tomorrow I have the other example finished about sending configuration data from "sender" and "responder" sending back sensor data.
Great info Ralph! And i had a problem with one of my RS485 modules. I could not get it to work at all at first. But...After checking the RS485 module i noticed that the chip on the module was not soldered correctly at all (1 side of the chip had all 4 legs not even making contact with the circuit board!) After replacing the module with another one, everything worked out fine. SO!!!! Check your modules if you are not getting it to work, Ralphs code IS working. I tested with 50 meters of new telephone cable (still unwrapped from package with 4 leads (using 2 of them) and it worked like a charm, but as Ralph and Nick Gammon states....use a common ground wire to to make the transfer more reliable). I am playing around with EasyTransfer by Bill Porter www.billporter.info/2011/05/30/easytransfer-arduino-library/ Github:github.com/madsci1016/Arduino-EasyTransfer to be able to send and recieve structs, and will post an update here later with the code.
I made a new version , same hardware connection as before, only the code is different. www.digihz.com/ArduinoCode/RS485SenderStructV4.zip www.digihz.com/ArduinoCode/RS485ResponderStructV4.zip Picture of my sender / responder. www.digihz.com/ArduinoCode/Sender_Responder.jpg This version (V4) is for sending and recieving in different intervals depending on if the sender and responder are connected or not. Added some error handler function to clean up the code a bit. This example simulate the use of up to 7 pir sensors connected to the responder. (You don't really connect them :) ) INFO:Use the led's, disconnect the sender or responder or the RS485 data line and see what happens, that will make you understand everything i think.
That looks very neat, Hans. And from I can see in the photo, you've used the same coloured wires for each module, good consistency! You'll be wanting a video on LoRa next! Oh, wait! What's just arrived in my mailbox...
LoRa = LOng RAnge radio, a bit like Bluetooth/nRF24L01/433 Serial Transmitters but can have a HUGE range. The record is about 200 Km. OK, in normal use several Km. Keep tuned for a future video on this, you might find it interesting and possibly even useful!
@@RalphBacon Of course I will look at it. Wireless solutions are fun and neat, but I prefer wired connections for reability more. Have a nice weekend Ralph.
@@RalphBacon It has been two decades since I heard someone talking about it but it still has its uses [I nearly puke at yet another BlueTooth boombox folks insist on using an use tech in ignorance ).
The wires from a RS485 device can be long and rambling too, though, so I guess I got caught up in my subject matter. All my videos end up at the 30 minute length, so I hope I don't ramble too much in the others.
love you man.. wanna give you hug right now.. been battling rs485 for over a week now and getting nowhere.. this opened up the opportunity for me to go to the next phase in my home automation system im building. go to this link. www.dropbox.com/s/3renihvj2xt1y7h/20191007_031146.mp4?dl=0 want to have remote arduino nanos around the house detecting motion and writing a numeric code back to main controller with 8 ch dimmer board. codes will specify which rooms detect motion and which havent... if (motion_livingroom == High) write 10001 across rs485 to dimmer control panel. if (motion_kitchen == high) write 20001 ...ect..ect need help with if statements to write certain codes for certain conditions...
OK, hug duly accepted (hey, I'm British, we don't go in much for actual physical contact) but the sentiment is nice. Regarding help with your project I recommend the Arduino forum which has many experts literally just waiting to help you if you clearly specify what you are stuck on and what you have done so far to get over the hurdles. forum.arduino.cc/
Thanks to you and Gammon, I got my RS485s working. The absence of that delay that Gammon found out was the culprit of the failed communication.
Excellent news! So glad you got it working. With Bacon AND Gammon how can you go wrong!?
What could possibly be better than more Ralph Bacon. Huzzah!
You're very kind, Tab Maryland! I just hope I'm not going to overload my Arduinite subscribers and followers with information. I'll try and restrain my enthusiasm. Don't forget to "follow" on the blog though! Thanks for posting.
Cool, reminds me of my old days when I ran Land-line teletype over in Vietnam, we dealt with a sort of ancient version of this using tube sets that amplified the signals after they had been processed by the crypto gear, I also did some time in the Brigade Headquarters Switchboard room as an operator for a few months, this was where I was exposed to the phantom and phantom simplex circuits using the earth as one side of a land line phone circuit it was really amazing, we could go from the Cam Rahn Bay to Saigon and to Phu Bi using just the earth for one side of the circuit. Basically one wire communications. Of course we did use special gear that got it done, I still recall the glow from the tubes in those boxes....
Single line transmission was how the first telegraphs were sent, Jerry, using the actual ground as, er, ground. Unfortunately, for the Wild West users, the ground in the USA sometimes became so dry that the transmissions stopped. There are anecdotes of telegraph operators pouring jugs of water around the earth peg to try and get a connection. Eventually, technology caught up and two-wire comms became the norm and no more wet earth pegs were required! I'm not recalling this from memory, I hasten to add, it's just something I have learned about!
Excellent tutorial on RS485. I am justing a project that will be using RS485 and your video was a big help. Thanks so much..
Glad it helped, David!
Once used some RS232 - RS485 converters for a fussy customer. Distance was a bit close to 10m, so customer insisted. He also insisted on some "fancy" ones at about £50 each! He was paying, so he was correct ;)
If the customer has a reason for specifying higher quality components, so be it! They must have a reason (and not just that the bloke down the pub said so).
Hi Ralph. I see you managed to find your MAX485 modules. '-) You can have up to 32 standard 12 Kohm modules (including the master) on a RS485 bus. If, however, you use the MAX487 chip you can increase this to 128. I'm soaking up Nick Gammon's wise words and will adapt his protocol to my needs. Many thanks for the video.
Yes, Nick Gammon (no relationship, but there should be) has a great website and goes into great detail, Brian. Good luck with your project.
ALWAYS USE GREAT CAUTION WHEN MAKING DIRECT COPPER CONNECTIONS OF ANY KIND TO OUTBUILDINGS!!
This is a HUGE subject to try to cover briefly in a comment. Suffice to say the following.
1. MASSIVE inductive spikes (10's thousands of volts) can appear on the outdoor connections that can blow your circuitry (literally) to smithereens. Research for example opto and galvanic isolation of RS485 lines.
2. Protect your circuits and youselves as much as possible by fitting suitable lightning arrestors and transorbs (tranzorbs, TVS diodes) with suitable fuses in series - Google for more info.
3. Even when any outside mains power supply has been properly and professionally installed with maybe individual bonded earth in addition to any SWA earth cable back to the consumer unit, NEVER, NEVER, NEVER assume that there is ZERO voltage between ground potential in the outbuilding and ground potential in the house!! It MIGHT spike to several thousand volts difference during an overhead lightning storm!!
It's why it's not such a good idea necessarily to have an outside supply from an MCB covered by an RCD feeding other internal circuits as well. Use a separate supply feed altogether from the main isolator or use an RCBO connected BEFORE the main RCDs. Otherwise you may find spurious whole or half house power trips happening all the time.
Hope this doesn't confuse people too much but please research on line as it is important for YOUR life and safety as well as to protect your gear.
Thanks for that safety update, Bob, much appreciated, as many treat anything at mains potential and higher as no more than a 9-volt battery. And as you say, ground on any circuit is not necessary zero volts.
Used RS485 for my original home grown home control system, about 9 years ago. Had the same problem with the output buffer.
RS485 worked well for a few devices but found CAN bus a lot easer and more reliable for multiple devices. The MCP2515 CAN bus Module are a bit more expensive but still less than a £1 each (from AliExpress) and go up to 1Mb/s and use the same number of com wires.
If you use a micro controller with built in CAN bus (e.g. ESP32) you can just use a SN65HVD230 CAN bus buffer about the same cost but requires fewer pins.
So another comms protocol for me to investigate then, Nick! Although I think my car uses a CANBUS to route all the signals around, which is how it knows the offside parking bulb is blown. I'll take a look at the device you mention, at that price it seems worth looking at in some detail. Thanks for the heads up, good to hear from you.
Yes as you probably know Can bus was originally developed for vehicles by Bosch back in 1983. Great Videos btw
Some good starting points I found. Just in case you or anyone else are interested in investigate.
Using the MCP2515 CAN BUS Module Board with Arduino
www.14core.com/wiring-the-mcp2515-controller-area-network-can-bus-diagnostics/
This site was useful in getting CAN working with an ESP-32
www.iotsharing.com/2017/09/how-to-use-arduino-esp32-can-interface.html
Im also using a PiCAN hat on a Raspberry Pi
skpang.co.uk/catalog/pican2-canbus-board-for-raspberry-pi-23-p-1475.html
Think it would be possible to use the MCP2515 CAN BUS Module Board though. It uses the same chipset as the PiCAN. The PiCAN was just more convenient.
Been using CAN on my Raspberry Pi to communicate with several Arduino nodes on my home control system for several years and has proved very reliable using four core telephone cable for 12v power and signal.
Excellent links there, NIck, thanks for that, I (and perhaps others too) will explore. I'm amazed you can use standard telephone wire for both power and signal; as far as I know, they are not even twisted pairs just wire so I will be interested in that, for sure.
Not sure if standard phone cable has twisted pairs but the cable I used has. It’s a lot better to use, in the home, than ethernet cable as it’s thiner and more flexible. This makes it easer to install without looking too messy.
So far my run of cabe is about 30m using 500Mb/s it has been very reliable. Ideal for sending short control messages to and from multiple low cost devices. Which is what it was designed for I guess.
I will check my telephone cable - perhaps they are twisted by default! Thanks for this, keep tuned!
Hi Ralph I do think RS485 deserves to be revisited to scratch a little deeper below the surface. You had a defective module first time round so you were unable to create a multidrop network. Additionally, you never overcame the buffered delay in printed characters.
I'm struggling to recall the details, Brian, but wasn't the delay just the fact that one unit was receiving the data and the other was sending the NEXT request at which point the first request was then echoed back to the first unit? Hence the (one character) delay? We could have overcome it, I believe, by asking for the response before sending another character. If this all barking up the wrong tree let me know and I'll deeper into it.
Hi Ralph I recall you were unable to properly set up a multi-drop network as one of your RS485 modules decided to have a benny (no pun intended). Wasn't the character held in the buffer and not sent out until it had received another? Or something like that.
If using twisted pair you have to ensure you pair the twists up, and you should use a drain wire, as you mention grounding the shield on one side, this is a drain.
Just like my shiny new CAT-6 ethernet cable going to my soon-to-be-constructed workshop, that has an exposed drain at one end for (extra) earthing. Good point, tablatronix, thanks for posting.
Hi Ralph, I maybe missed it somewhere in the video but it is probably worth mentioning that RS485 requires 120ohm terminating resistors at each end of the line, i cant imagine they are built in to the RS485 modules as this would then prevent you from having anymore than 2 in the network so this would likely need to be added manually. nice video though, thanks for sharing :)
Ah, yes, you have to be careful here, DazzleK93. I did mention that you don't need to add resistors because they are all built into the module (see schematic here: yourduino.com/sunshop//index.php?l=product_detail&p=323 ) BUT you are very right in pointing out that the more you connect the lower this resistance will be. I'm guessing the manufacturer of the module does this so you can start using the module right away with no faffing about. But...
If you connect more than one (and this applies to I2C modules too that have 10K pull-up resistors on the CLK and DATA lines) you should really REMOVE the extra ones. So, in this case, R5, R6 and R7 should be removed on all but one of the modules.
Very well spotted, and thanks for bringing this up as it would surely cause issues if half a dozen were all connected up on the same lines. Thanks for the post and your kind words too!
I am surprised they did not make the EOL resistors a jumper to make it more multi drop useful.
The only reason: cost. As always, things are built down to a price. Now if Sparkfun had designed these they would have had jumpers, a built-in LED display of some kind, and an onboard 4K EEPROM, just for fun. And then they would have cost £10 each! Sorry, am I being too cynical here? As it happens, your post has highlighted this issue so removal of said surface-mounted resistors should be easy.
If you want to optimally use these modules in a multi-drop configuration you'll need to remove R5, R6 & R7 from the MAX485 board at all the intermediate stations and R5 and R6 at one of the end stations.
Thanks for sharing 😀👍
Interesting to see your blog, nice done 👍
Thanks for that, Asger Vestbjerg, glad you liked my blog, nice to hear from you.
Thanks ! As always very detailed and informative...greatly appreciated.
Thanks for your post, Mr ASP, good to hear from you.
I use SN75176B for RS485 communication. I have not faced the issue as mentioned by Gammon. But I have a different issue -- after transmission, once I enable reception, sometime, the 1st byte of reception is the last byte that was transmitted. I have used some software work around, but a simple fixed delay after transmission did not solve the issue. Somehow, either the delay sometime appears inadequate while some other time, the delay becomes too much and I loose the 1st valid RX byte.
So is the 2nd byte you receive actually the first byte from the sender unit? Do you get the last byte successfully?
I had a similar issue but it was all about the FIFO or buffering. In other words, it was my misunderstanding of the protocol and my software than an actual error.
@@RalphBacon Yes could be the reason. In such case, I usually bypass the SW layer and directly access the HW register. But my code is running on ESP8266-NodeMCU and I am not familar with background. Hence, I have to be happy with using serial functions provided in Arduino like code.
I just remembered why I have a pile of these modules at home, RS485 is used for DMX lighting control, so you can use these modules along with an Arduino (or any similar) to control DMX stage/disco lights.
Now I mention it sounds like a cross over to Big Clive channel :D (sure you don't mind me mentioning his channel here)
I had a sketch working on a few lights as a proof of concept and meant to do something proper with it for a simple control without needing full computer, dmx dongles and software for some static looks and some basic effects.
Who Clive? New boy, is he, Matt? 😜
In my days as a DJ (yes, really) I hankered after a DMX controller. Even though my lights could have been connected up together, the controllers and cables and so on made it prohibitively expensive, back in the '90s. I think I might have been able to concoct something to control those lights with an Arduino and an RS485 module, had the Arduino been invented back then. Even worse, I did one stint in a huge nightclub and they let me use all their equipment, including DMX controlled lighting. There's something special seeing laser lights move in perfect synchronisation before doing their own thing! Ah yes, memories of Robin S, Show Me Love... Thanks for the memories, Matt.
Very nice tutorial, 1 quick question, If you had more then 1 slave how to determine the slave id?
I'm using SoftwareSerial library to keep things simple. Unless you can make each slave accept an ID, using digitalWrite and then ensure you only send data to that Slave ID (eg for a response), I don't know if the way I did this would work. There is undoubtedly an RS485 (or MODBUS) library available these days that works on the Arduino family and which you can assign an ID to a Slave (or read it, if previously set). Best I can suggest, sorry I can't be of more help.
@@RalphBacon Thank you so much, your tutorial help me a lot, though i wanted to understand more about master and multiple slave. Once again thank you so much.
What Arduino plugin are you using for your eclipse IDE installation? Didn't know there was even a plugin for eclipse prior to this video.
It's end of life now, but still very useable: eclipse.baeyens.it/
Thank you Sir for another great video!!! Question: what is the relation between baud rate and admissible transmission distance? Half baudrate means double distance or is it more complicated? Here's an idea for some future video: PCA9615 that converts I2C to a differential line. Looks quite nice for long distance communications with sensors and there's surprisingly little amount of info online. Best regards
It's not quite that mathematical, Alex. The lower baud rate ensures less risk of corruption over longer distances. The only way to know whether your baud rate works is to try it. But what works today may not work tomorrow when the microwave next door (or a hairdryer) is switched on!
Regarding the PCA9615, that deice does indeed look intriguing. I wonder if it could be coupled with a TCA9548A I2C multiplexer, that would be interesting too?
...3 wire UART comm are simpler.(RX,RX,gnd)..not sure about its range
Hello, I have a question: is this a 485 communication.
Is it possible with a "D1 MINI WEMOS Pro 4M 16M" using "Tasmota" e.g. B. to control a "JUNTEK DPM8624 60V24A Programmable DC DC Digital Adjustable Step Down Voltage Power Supply Buck Converter 485 Communication"?
Hmm.. are we talking about THIS device: s.click.aliexpress.com/e/_DE0lb5h
That device is controlled via a standard USB-to-Serial (TTL) adapter, just like the ones we use in an Arduino environment. Nothing is mentioned about using RS485, although the protocol might be used as part of that Serial comms... but seems unlikely.
Let me know if it is another device.
@@RalphBacon OK. I saw somewhere that you can use "TTL to RS485 Module UART Port Converter Module EIG88" to control the device. watch?v=yOcoux9IbzM&t=218s
Hi, great video, I have a question, is it possible to connect multiple slaves (rs485 output sensors) to MAX 485 (to A- B), and read slave values from Arduino, Thanks in advance
Yes, the RS485 protocol is similar in some ways to I2C and you can hang multiple devices off it. I think I mention this in the video?
Nick's page says he is using an LTC1480 and that is a 3v3 part. the boards from Aliexpress are 5v because they use the MAX485 chip
The LTC1480 is certainly advertised as a 3v3 part but can take up to 7v. I suspect that is why Nick's using the full, Arduino-friendly 5v supply thus avoiding any level shifting requirements.
The module from BangGood and from AliExpress for less than a Dollar is a MAX458 chip, the data sheet lists that as 5v. Searching Maxim, the matrix for 3v3 to5v does not list the MAX485 chip. I gave you a thumbs up for a great video and your contributions to the community. My needs are for the EXP32/8266 chips that are 3v3.
Interestingly there two sides to the RS485. the external connection side can take a very large swing of voltages as the chip is looking for differential signals on the two lines as the means of detecting data and not any actual voltage. The receiver side has a very large voltage range the LTC1480 is -7 to 12V. The MAX485 is slightly more. That allows a 3v3 ESP8266 device to connect to a PLC or automobile based network that is running at 12 volts.
In a side note, I personally try to buy the mainstream parts. I assume there is a flood of them and that brings the lower costs and keeps the chip in production. I suspect that one of the main supply outlets will start with 3v3 and 5v tolerant parts and make us all happy. Thanks again for your educational videos !
You are most welcome Dave -in-NJ, I'm glad you like the videos. Nice to hear from you.
Ralph Bacon ... Nick Gammon, some unintentional pun in there somewhere ;)
Well, he's smokin' that's for sure! The same thought did occur to me but thought best not to say anyth.... oh, too late!
A crack(l)ing coincidence.
Matt Cocker the things I learn here :-)
Great project Ralph, Can you help me fixing issue. My master somehow not receiving anything back. It only sending. Not sure if slave is even getting message.
Make sure your TX/RX pair go to RX/TX. Put lots of Serial.print() statements in the code so you can see what, if anything, is happening. Debugging is all part of learning C++ (as I have just spent most of the day tracking down a bug, very laborious, lots of display statements, I know how time-consuming and tedious it can be - but it must be done. Don't give up, you know the sketch works, it can only be your modules and/or the wiring.
@@RalphBacon Yes trying same, would it be possible for you to share exact wiring picture, so it might help me debug if i am missing anything from video. Also i am using 2 nano, for which i used Tx & Rx pin and changed code to use 0,1 pin.
@@RalphBacon Finally i am getting on both Serial monitor, thanks it took me long to fix it. But i still have issue, the data is always reverse ? mark, i did looked at baud rate and its 9600 on both Serial monitor and program. Any idea what could be i am doing wrong here?
Thx for the good video! i tried it out immediately but unfortunately only got This: Received:?
in the Responders Serial Monitor. Did i wire something incorrectly? pls help
So you got a question mark as the received data? Hmm, sounds like corruption or transmission speed incorrect or mismatched. When I get stuck like this I just liberally sprinkle my code with Serial.print statements so I can trace the data from one module to another, and see exactly where it got changed. Try that first, Dominik.
@@RalphBacon thx for the quick response, ill try it out later
Amazing video! Which ide are you using?
I'm using Eclipse with Arduino: eclipse.baeyens.it
Hi Ralph its Bob tried your Blog but no confirmation email back so will leave it with you, All the best and blog looks good!!
I think you will get an email back when a new post is sent, Bob. I'll experiment on one of my old email addresses and see what happens. Thanks for your kind words and keep tuned!
Great Videos Ralph - keep up the good work. (You kind of sound a bit like Pierce Morgan - but a much kinder, smarter version. )
Let's not forget _poorer_ version! I'm not sure whether to be flattered or offended at the comparison (although I have some sympathy with Pierce and his say-it-like-I-see-it manner). Let's hope I'm not as abrasive as him, though! Thanks for the kind words, Rube, and thanks for posting.
Ralph S Bacon Piers surely has a 'say it as I see it' manner, but sadly he is too vain to wear glasses ;-)
i was told that the RS is Recommended Standard...? thanks...:/
It could be viewed as that. I'm sure Radio Spares will be delighted to hear it too!
thanks, but i shock see price on banggood, in my country maybe equal $0.3
That would depend on which country is your country, Rabizza! If Banggood is too expensive try AliExpress.
Very long wires run outdoors = think about lightning protection.
A very good point there, JH. I must admit I imagined in my mind that everyone buries their cables but I guess they could equally string them on poles like telephone wires. Now I know you can get ADSL surge protectors so maybe you can get some other form of surge protection for standard "data" wiring, I just don't know but it's certainly something that should be considered. Thanks for the post.
If you have long overhead cable runs it may be possible to include a degree of protection (up to about 15kV) by using opto-isolated transceivers like the LTM2881. Obviously nothing can protect completely against a direct lightning strike. Ouch!
I'll keep mine buried, it just seems safer. Thanks for that update, Brian.
Please help us arduino to delta hmi how to connect and relay operate.
I've half understood the question but you need to rephrase it. Are you looking to operate a relay using RS485 comms, a pair of Arduinos and a touch screen (HMI) made by Delta?
SoftwareSerial doesn't work with big sketches
When you say "doesn't work" do you mean you run out of memory space, ellpancha?
Hi, thanks good information
Thank you, Sunil, appreciated!
You will find my comment on your blog.
Found and replied to Nick! Thanks for posting.
As i promised before, here is the code for using struct with RS485.
Same usage of pins as your sketches Ralph.
But i added 3 led's to each bord to show sending, recieving and errors.
www.digihz.com/ArduinoCode/RS485SenderStructV3.zip
www.digihz.com/ArduinoCode/RS485ResponderStructV3.zip
Picture of my sender / responder. www.digihz.com/ArduinoCode/Sender_Responder.jpg
I will supply a new version soon where the sender sends some configuration struct data to the responder, and the responder sends back sensor values.
Sometimes you want to send some configuration values to a slave from a master and once that slave recieves the configuration , then the slave starts to continiously send sensor data back to the master.
Nicely done, Hans! And well documented too, a man after my own heart. Thanks for sharing, I hope others have a look too.
@@RalphBacon so you tried the sketches with leds connected? Or did you just have time to look at the code Ralph?
Led' s are more informative i think and fun to look at to.
Yes, documentation is allways important, not only for others, but for yourself to when you look at a code 5 years later :)
I just looked at the code, Hans. But I could see what you were doing. An old Dev Mgr of mine said that we were commenting our code for the next programmer who had to maintain that codebase - who would probably be yourself in 6 months time!!! See, we all think alike.
@@RalphBacon ok Ralph. But I think that you should try it in real life... (could be good code for your Bluetooth to to use Easytransfer). But mayby by tomorrow I have the other example finished about sending configuration data from "sender" and "responder" sending back sensor data.
Great info Ralph!
And i had a problem with one of my RS485 modules. I could not get it to work at all at first.
But...After checking the RS485 module i noticed that the chip on the module was not soldered correctly at all (1 side of the chip had all 4 legs not even making contact with the circuit board!)
After replacing the module with another one, everything worked out fine.
SO!!!! Check your modules if you are not getting it to work, Ralphs code IS working.
I tested with 50 meters of new telephone cable (still unwrapped from package with 4 leads (using 2 of them) and it worked like a charm, but as Ralph and Nick Gammon states....use a common ground wire to to make the transfer more reliable).
I am playing around with EasyTransfer by Bill Porter www.billporter.info/2011/05/30/easytransfer-arduino-library/
Github:github.com/madsci1016/Arduino-EasyTransfer
to be able to send and recieve structs, and will post an update here later with the code.
Glad you got it all working, Hans!
Release the magic smoke from it!
I think someone did that already!
I made a new version , same hardware connection as before, only the code is different.
www.digihz.com/ArduinoCode/RS485SenderStructV4.zip
www.digihz.com/ArduinoCode/RS485ResponderStructV4.zip
Picture of my sender / responder. www.digihz.com/ArduinoCode/Sender_Responder.jpg
This version (V4) is for sending and recieving in different intervals depending on if the sender and responder are connected or not.
Added some error handler function to clean up the code a bit.
This example simulate the use of up to 7 pir sensors connected to the responder. (You don't really connect them :) )
INFO:Use the led's, disconnect the sender or responder or the RS485 data line and see what happens, that will make you understand everything i think.
That looks very neat, Hans. And from I can see in the photo, you've used the same coloured wires for each module, good consistency! You'll be wanting a video on LoRa next! Oh, wait! What's just arrived in my mailbox...
@@RalphBacon thank you Ralph.
I don't know anything about LoRa.
I concentrate working on arduino pro mini, arduino Nano and nodemcu 8266.
LoRa = LOng RAnge radio, a bit like Bluetooth/nRF24L01/433 Serial Transmitters but can have a HUGE range. The record is about 200 Km. OK, in normal use several Km. Keep tuned for a future video on this, you might find it interesting and possibly even useful!
@@RalphBacon Of course I will look at it. Wireless solutions are fun and neat, but I prefer wired connections for reability more.
Have a nice weekend Ralph.
RS485 !!!
Er, yes, RS485, Kenn! Works well. In fact I have seen several more RS485 modules lately, perhaps it is being used more.
@@RalphBacon It has been two decades since I heard someone talking about it but it still has its uses [I nearly puke at yet another BlueTooth boombox folks insist on using an use tech in ignorance ).
Thanks but it’s just too long and rambling for me
The wires from a RS485 device can be long and rambling too, though, so I guess I got caught up in my subject matter. All my videos end up at the 30 minute length, so I hope I don't ramble too much in the others.
love you man.. wanna give you hug right now.. been battling rs485 for over a week now and getting nowhere.. this opened up the opportunity for me to go to the next phase in my home automation system im building. go to this link. www.dropbox.com/s/3renihvj2xt1y7h/20191007_031146.mp4?dl=0
want to have remote arduino nanos around the house detecting motion and writing a numeric code back to main controller with 8 ch dimmer board. codes will specify which rooms detect motion and which havent... if (motion_livingroom == High) write 10001 across rs485 to dimmer control panel. if (motion_kitchen == high) write 20001 ...ect..ect
need help with if statements to write certain codes for certain conditions...
OK, hug duly accepted (hey, I'm British, we don't go in much for actual physical contact) but the sentiment is nice. Regarding help with your project I recommend the Arduino forum which has many experts literally just waiting to help you if you clearly specify what you are stuck on and what you have done so far to get over the hurdles. forum.arduino.cc/