Help needed with home automation RS485 bus (Sketch)


#1

newbie alert

Am beginning a rather complex home automation and monitoring project integrating the following:

Existing solar hot water / heating system controller
Existing Heating controls / thermostats two zones
Pellet furnace controls
Electric usage monitoring
Lighting controls

Planning to use Arduino Yun as master for mega and nano slaves for the various monitors and controls.

The first challenge is to connect the devices and get them to work together.

Contemplated using 1wire bus to connect all the devices, but instead opted for RS485 due to distance and interference problems. Will likely run a cat7 cable throughout the house to cover power to the devices, RS485 and still have two free pairs left to eventually use for 10/100 ethernet.

Using the wiring and sketch example at https://arduino-info.wikispaces.com/SoftwareSerialRS485Example I successfully got the Yun and a clone nano to ‘talk’ to each other and get the onboard led to blink properly.

Next step would be to get the Yun working again with Cayenne including the RS485 sketch, attach a couple of temp sensors and relay to the Nano and see if I can get it to show in the Cayenne console… any suggestions how best to proceed? Is it possible to get sensors and controls to show up in Cayenne from a remote slave device via RS485?

I had the Yun set up in Cayenne before, but of course the new RS485 sketch wiped that out. Here’s what I have so far…

Thanks!
Brian


#2

RS485 is a pretty old standard (whose only saving grace is the distance it was designed to cover). Why do you not prefer WiFi or LORA wireless? Is a hard wire required?

I’m using my own devices, which work well…for all my purposes (home automation, alarm and security, access control, lighting and landscape control).

I’m not entirely sure Gigabit can run on only 2 pairs, so…let me know how it works. I’m thinking if only 2 pairs are presented to the router/switch, it will default to 10bT.

I personally wouldn’t run +Vcc current through communications wire (usually 24 or 26 gauge).

As an installer, I can’t justify the expense of CAT7, -when Cat5e is so much cheaper with the same (usable) capabilities. -just a shout from the peanut gallery! :slight_smile:


#3

I wanted to try RS485 because of the low cost, simple hardware vs adding additional wifi coverage. Walls here are 20 plus inches of wifi killing stone. There are also rooms involved for heating and electrical systems that are outside the home in separate small buildings. Aside from that overall power considerations would be lower. A few bucks for a nano and RS485 adapter vs adding wifi shields or more expensive hardware. CAT7 might be overkill but some of the paths it would take is near power and other signal sources so would rather spend a few bucks more to stay on the safe side and not have to worry too much about getting power to the modules since it could be supplied by a pair or two if needed from a single power supply. Cost wise I think there would be little if any difference. A clone nano and RS485 adapter costs around 8 bucks. Two pairs should work for 10/100 ethernet if I ever need it, otherwise may serve as spares if any break or degrade over time.

Thanks for the feedback though! Do let me know if any of my rationalizations seem out of whack.


#4

all sounds reasonable to me. :slight_smile:


#5

You can run a considerable about of power even through Cat5e https://en.wikipedia.org/wiki/Power_over_Ethernet#Power_capacity_limits


#6

What kind of power levels are present in PPPOE runs? Just curious. My previous Philippines wifi service used PPPOE to power the receiver in the antenna on the roof.

William


#7

According to wiki : https://en.wikipedia.org/wiki/Power_over_Ethernet thanks adam! saw your post after posting this

Category 5 cable uses 24 AWG conductors, which can safely carry 360 mA at 50 V according to the latest TIA ruling.[citation needed] The cable has eight conductors (only half of which are used for power) and therefore the absolute maximum power transmitted using direct current is 50 V × 0.360 A × 2 = 36 W. Considering the voltage drop after 100 m (330 ft), a PD would be able to receive 31.6 W. The additional heat generated in the wires by PoE at this current level (4.4 W per 100 m cable) limits the total number of cables in a bundle to be 100 cables at 45 °C (113 °F), according to the TIA. This can be somewhat alleviated by the use of Category 6 cable which uses 23 AWG conductors.

So with Cat7 @ 23 or even 22 awg should be just fine for running a few Nano’s or other Arduino’s. Since each pair is shielded and another shield around that there shouldn’t be much heat problem running even a bit more… I’m not expecting heavy loads, just some sensors and relays. I could power each Arduino with wall warts, but would probably be nice to be able to power down / reset from a central point.

So power wise think it’s quite ok as extra pairs will be available if needed.


#8

I amended the title for help with applying an Arduino sketch which is my next step. Does anyone know of any good examples out there with multiple Arduino’s on RS485 with remote sensors and/or relays? Below the Master and Slave sketches that I loaded before and seemed to work. I’ve googled around, but unfortunately my sketch knowledge is very limited :frowning: Any pointers or even general directions appreciated!

Master:

/* YourDuino SoftwareSerialExample1
   - Connect to another Arduino running "YD_SoftwareSerialExampleRS485_1Remote"
   - Connect this unit Pins 10, 11, Gnd
   - Pin 3 used for RS485 direction control
   - To other unit Pins 11,10, Gnd  (Cross over)
   - Open Serial Monitor, type in top window. 
   - Should see same characters echoed back from remote Arduino

   Questions: terry@yourduino.com 
*/

/*-----( Import needed libraries )-----*/
#include <SoftwareSerial.h>
/*-----( Declare Constants and Pin Numbers )-----*/
#define SSerialRX        10  //Serial Receive pin
#define SSerialTX        11  //Serial Transmit pin

#define SSerialTxControl 3   //RS485 Direction control

#define RS485Transmit    HIGH
#define RS485Receive     LOW

#define Pin13LED         13

/*-----( Declare objects )-----*/
SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX

/*-----( Declare Variables )-----*/
int byteReceived;
int byteSend;

void setup()   /****** SETUP: RUNS ONCE ******/
{
  // Start the built-in serial port, probably to Serial Monitor
  Serial.begin(9600);
  Serial.println("YourDuino.com SoftwareSerial remote loop example");
  Serial.println("Use Serial Monitor, type in upper window, ENTER");
  
  pinMode(Pin13LED, OUTPUT);   
  pinMode(SSerialTxControl, OUTPUT);    
  
  digitalWrite(SSerialTxControl, RS485Receive);  // Init Transceiver   
  
  // Start the software serial port, to another device
  RS485Serial.begin(4800);   // set the data rate 

}//--(end setup )---


void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  digitalWrite(Pin13LED, HIGH);  // Show activity
  if (Serial.available())
  {
    byteReceived = Serial.read();
    
    digitalWrite(SSerialTxControl, RS485Transmit);  // Enable RS485 Transmit   
    RS485Serial.write(byteReceived);          // Send byte to Remote Arduino
    
    digitalWrite(Pin13LED, LOW);  // Show activity    
    delay(10);
    digitalWrite(SSerialTxControl, RS485Receive);  // Disable RS485 Transmit       
  }
  
  if (RS485Serial.available())  //Look for data from other Arduino
   {
    digitalWrite(Pin13LED, HIGH);  // Show activity
    byteReceived = RS485Serial.read();    // Read received byte
    Serial.write(byteReceived);        // Show on Serial Monitor
    delay(10);
    digitalWrite(Pin13LED, LOW);  // Show activity   
   }  

}//--(end main loop )---

/*-----( Declare User-written Functions )-----*/

//NONE
//*********( THE END )***********

Slave / Remote:

/* YourDuino SoftwareSerialExample1Remote
   - Used with YD_SoftwareSerialExampleRS485_1 on another Arduino
   - Remote: Receive data, loop it back...
   - Connect this unit Pins 10, 11, Gnd
   - To other unit Pins 11,10, Gnd  (Cross over)
   - Pin 3 used for RS485 direction control   
   - Pin 13 LED blinks when data is received  
   
   Questions: terry@yourduino.com 
*/

/*-----( Import needed libraries )-----*/
#include <SoftwareSerial.h>
/*-----( Declare Constants and Pin Numbers )-----*/
#define SSerialRX        10  //Serial Receive pin
#define SSerialTX        11  //Serial Transmit pin

#define SSerialTxControl 3   //RS485 Direction control
#define RS485Transmit    HIGH
#define RS485Receive     LOW

#define Pin13LED         13

/*-----( Declare objects )-----*/
SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX

/*-----( Declare Variables )-----*/
int byteReceived;
int byteSend;

void setup()   /****** SETUP: RUNS ONCE ******/
{
  // Start the built-in serial port, probably to Serial Monitor
  Serial.begin(9600);
  Serial.println("SerialRemote");  // Can be ignored
  
  pinMode(Pin13LED, OUTPUT);   
  pinMode(SSerialTxControl, OUTPUT);  
  
  digitalWrite(SSerialTxControl, RS485Receive);  // Init Transceiver
  
  // Start the software serial port, to another device
  RS485Serial.begin(4800);   // set the data rate 
}//--(end setup )---


void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  //Copy input data to output  
  if (RS485Serial.available()) 
  {
    byteSend = RS485Serial.read();   // Read the byte 
    
    digitalWrite(Pin13LED, HIGH);  // Show activity
    delay(10);              
    digitalWrite(Pin13LED, LOW);   
    
    digitalWrite(SSerialTxControl, RS485Transmit);  // Enable RS485 Transmit    
    RS485Serial.write(byteSend); // Send the byte back
    delay(10);   
    digitalWrite(SSerialTxControl, RS485Receive);  // Disable RS485 Transmit      
//    delay(100);
  }// End If RS485SerialAvailable
  
}//--(end main loop )---

/*-----( Declare User-written Functions )-----*/
//NONE

//*********( THE END )***********

In the examples above from https://arduino-info.wikispaces.com/SoftwareSerialRS485Example it seems these sketches apply to two arduino’s chatting with each other but I don’t see anything identifying how to addresses more than two… with identifiers for each, much less read a remote sensor… I’ll try to add another Nano or the Mega this evening time permitting and have a 100 meter roll of 22awg Cat7 ordered for further testing… Plenty of sensors and relays on hand :wink: Again any help with appropriate sketches appreciated! Thanks!!


#9

Found this interesting resource I’m reviewing that seems to answer some of my questions on addressing multiple Arduino’s and querying sensors… might be a good starting point if anyone wants to chip in.

http://www.gammon.com.au/forum/?id=11428

Over the next few days will be doing a graphical layout of the house, device locations and RS485 bus path for reference. I’ll post it here when done.


#10

Managed to make a quick diagram. I know… pretty ambitious… eek… Red line is the proposed RS485 bus, can be wired pretty much as shown with existing tubing already in place. Total length around 200-250 meters. Something like 10 or 11 Arduino’s spread around for dedicated tasks collecting temp, weather, electric current data and controlling switches, pumps, lights and fans. Enough to keep me tinkering around for quite a while…


#11

To keep me busy until Cat7 cable arrives and can start installing it, will likely start with the furnace… I’ve already played around some with the sensors involved and done some very basic sketches that work on the bench. This can run stand alone and only have a couple months left for heating so guess nothing lost trying it out first. I’ll learn more about sketches along the way which will likely be helpful down the road with the bus project. Here’s the basic idea:

It’s a furnace that burns pellets, now using sunflower husk pellets but any will do. The challenges are:
-Efficiency - when burning efficiently, flue temps should be somewhere between 250 and 300 Celsius. Have a Max 6685 K thermocouple setup that I’ve tested out and works fine for these higher temps… http://www.ebay.it/itm/331799566913?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT Fuel and air mix can be controlled by the blower fan and feed motor that are currently manually adjusted. I plan to try out these 220 volt 4KW dimmer/motor controls http://www.ebay.it/itm/262256129441?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT I first thought about using stepper motors to turn the knob up and down but in the end it’s only a potentiometer so looking at replacint the pot with a digital potentiometer of the same/similar value. I’m ok with soldering and electronic type stuff. Will just have to play around with the air/fuel/flue temp to find a good algorithm to try and maintain the flue temp within range when the unit is on.

-Monitoring- With the already installed flow meter, I should be able to monitor flow and in/out temperatures and use that to calculate and log thermal output BTU or KWH. The output temp DS18bB20 in the diagram will actually be inside the boiler itself and serve as both boiler and output temp since they are the same.

-Pump- The pump should only turn on when the boiler temp reaches a set temperature, usually 60 Celsius. If I can get things running as planned, I might try also regulating the pump to speed up when the boiler temp rises, and slow down when boiler temp falls… - we’ll see…

-Pellet level- I’m constantly forgetting to fill the damned thing up and hate getting up in the middle of the night to do so… I 've played around with the ultrasound sensor, but yet to see if it will measure up with pellets instead of my hand… otherwise will have to find some other level measuring method. I guess knowing the dimensions and level, could also calculate consumption in kilograms per operating hour and also actual BTU/KWH per kilogram burned to check efficiency at different flue temps…

5 sensors
1 x 4 relays
2 motor controls (maybe 3 including future pump mod)

Can a nano handle it? Am I heading in the right direction?

Apologies if I’m posting all this in the wrong section but thought this would be a good place to document my plans and get any tips/advice/critique along the way… along with reporting what works out and what doesn’t.

Thanks!


#13

There are plenty of devices being powered by PoE that draw a lot more power than an Arduino + sensors. Is this poor design too? http://www.cisco.com/c/en/us/products/collateral/physical-security/video-surveillance-6000-series-ip-cameras/datasheet-c78-735951.html


#15

Very kewl! :slight_smile: For you, Brian-
RS485 can be made star topography- kind of…
http://e2e.ti.com/support/interface/industrial_interface/f/142/t/402084
Ah! I see now that you will run RS485 2-pair wires through Cat7 cable, using RJ45 connectors? I understand now…and perhaps use the (2) spare pairs to carry +Vcc? Well, you may need a couple “voltage boost” power supplies every 50 linear foot of wire. That’s kind of a lot of devices you propose to put on that bus.


#16

Hi Bill!
Thanks for that resource :slight_smile: The loopbacks are a bit exaggerated on the diagram with the only long loopback going to the roof and back for the collector temperature and possible weather station, really only need outside temp to control the heating temp sent to the radiators in the house via an automatic 3 way valve. I could try and use the K thermocouple or even a PT1000 and adjust the line resistance factors to the thermocouple (i’ve seen a couple sketches that do this). This loopback is only 20 meters or so in total so we’ll see. Yes, adding it all up I might have to use some of those 3 extra pairs to beef things up a bit or use an occasional wall wart. I’ll keep track of the loads etc as the system grows and adapt from there. Already decided to go with 22AWG Cat7 instead of 23AWG thanks to your constructive critique. One of the reasons for trying this ‘my way’ is that I have a 3kw online sinewave UPS system in the office already as short power outages are fairly frequent here. I really don’t need the ethernet capability as most of the house and some of the outside area is wired anyway, so really have three 22awg pairs available for power… 100 meters of cable is on the way so will be able to do some testing and measurements next week as time permits. I’ll let ya know when I have some more data. Again Thanks!


#17

Update

My main challenge was the distance from remote sensors beyond normal 1wire range. I ran across this product that should allow more centralized sensing and control without the need for multiple arduino’s thus requiring multiple arduino’s that would talk on a bus to relay the temp/sensor values.

https://github.com/resol-de/RESOLino_Pt1000 should soon be updated with a 16 channel example sketch.

It’s an 8 channel Pt100, Pt1000, KTY, NTC or PTC shield. Since my current solar/heating controller uses PT1000 should work out well without having to put new sensors and wiring everywhere. According to the vendor two boards can be used for 16 channels that would cover all my temp sensor needs making the installation much more simple.

My current system also controls the speed of the pump to the solar and pellet heater to achieve max temp from these circuits, slowing down when sun is lower and speeding up in full sunlight. I’ve seen PWM control of 220V motors is a bit tricky so am looking at these pumps that should be able to be controlled directly by PWM http://www.grundfos.com/products/find-product/upm3-solar.html

datasheet https://net.grundfos.com/Appl/ccmsservices/public/literature/filedata/Grundfosliterature-5439390.pdf

I’ll be working on this through the summer so will update as things progress, but thought I’d drop this info in for others doing similar projects.

As always constructive critique and suggestions appreciated!


#18

Very nice! Can’t wait to see a project post for this!