Hubduino setup confusion

Setting up my first ever Arduino Mega2560 with a W5100 Ethernet Shield to be used as a Hubduino on HE but I’ve found this to be a rather daunting task.

I’ve read through the setup over and over again but as a Noob to an Arduino I am confused as hell.

I’m unsure what Arduino Sketch to use for the setup below?

8 x Digital Inputs to monitor both motion and or door contacts

4 x Outputs that I can drive from HE.

Any help would be greatly appreciated.

The example sketches are just that, examples. For specific cases you would need to take one of the ST_Anything examples and modify it to suit. You might want to start with the ST_Anything_Multiples_EthernetW5100 sketch and set up one of your contacts using the pins indicated in the sketch. Upload the sketch and verify that opening and closing the contact shows up in the serial monitor in the Arduino IDE. Once you have one contact working, modify the ST_Anything_Multiples sketch to add a second contact or motion sensor. Upload the sketch and test. Repeat.

1 Like

Cheers, I’ll give that a go.
Thanks for the help.
Just out of interest, is there anyone who’s wanted the same or a similar setup that maybe, I know this is pushing it, has the sketch the could send me, pretty pls?

Take a look at the following sketch as an example...

1 Like

There will not be anyone that has something even close. There are just too many possibilities. The ST_Anything_Multiples_EthernetW5100 sketch should upload without doing any editing. Once you have it uploaded and you can see output from the serial monitor, shut it down. Read through the sketch to find out what pins are being used for one of your contacts and just connect those pins. Reconnect the Arduino and monitor the output.
This is all about learning. Have fun.

1 Like

I just want to say a massive THANK YOU to ogiewon!!
Dan, you have made my day with your patience and help getting my Hubduino up and running.
Cannot Thank you enough :+1: :+1: :+1:

1 Like

I'm looking to do the same project as well. I just ordered my first Arduino (mega) and the ethernet shield. I will be converting an old alarm system contact sensors and have about 24 of them. Do you know how many of the I/O's on the mega would support contact sensors? I.E. Normally Closed(NC) magnetic contacts. I'm just a little confused on which I/O's I can use for these.

I know that pins 4,10,50-53 are reserved. Does that mean I can use 11-13, A0-A9, and 22-49 for contact sensors?

Sketch Pins

#define PIN_4_RESERVED 4 //reserved by W5x00 Shield on both UNO and MEGA
#define PIN_1O_RESERVED 10 //reserved by W5x00 Shield on both UNO and MEGA
#define PIN_11_RESERVED 11 //reserved by W5x00 Shield on UNO
#define PIN_12_RESERVED 12 //reserved by W5x00 Shield on UNO
#define PIN_13_RESERVED 13 //reserved by W5x00 Shield on UNO
#define PIN_50_RESERVED 50 //reserved by W5x00 Shield on MEGA
#define PIN_51_RESERVED 51 //reserved by W5x00 Shield on MEGA
#define PIN_52_RESERVED 52 //reserved by W5x00 Shield on MEGA
#define PIN_53_RESERVED 53 //reserved by W5x00 Shield on MEGA

//Analog Pins
#define PIN_WATER_1 A0 //SmartThings Capability "Water Sensor"
#define PIN_WATER_2 A1 //SmartThings Capability "Water Sensor"
#define PIN_ILLUMINANCE_1 A2 //SmartThings Capability "Illuminance Measurement"
#define PIN_ILLUMINANCE_2 A3 //SmartThings Capability "Illuminance Measurement"
#define PIN_VOLTAGE_1 A4 //SmartThings Capability "Voltage Measurement"
#define PIN_VOLTAGE_2 A5 //SmartThings Capability "Voltage Measurement"
#define PIN_SMOKE_3 A8 //SmartThings Capability "Smoke Detector"
#define PIN_SMOKE_4 A9 //SmartThings Capability "Smoke Detector"

//Digital Pins
#define PIN_TEMPERATUREHUMIDITY_1 22 //SmartThings Capabilities "Temperature Measurement" and "Relative Humidity Measurement"
#define PIN_TEMPERATUREHUMIDITY_2 23 //SmartThings Capabilities "Temperature Measurement" and "Relative Humidity Measurement"
#define PIN_MOTION_1 24 //SmartThings Capability "Motion Sensor"
#define PIN_MOTION_2 25 //SmartThings Capability "Motion Sensor"
#define PIN_CONTACT_1 26 //SmartThings Capability "Contact Sensor"
#define PIN_CONTACT_2 27 //SmartThings Capability "Contact Sensor"
#define PIN_SWITCH_1 28 //SmartThings Capability "Switch"
#define PIN_SWITCH_2 29 //SmartThings Capability "Switch"
#define PIN_TIMEDRELAY_1 30 //SmartThings Capability "Relay Switch"
#define PIN_TIMEDRELAY_2 31 //SmartThings Capability "Relay Switch"
#define PIN_SMOKE_1 32 //SmartThings Capability "Smoke Detector"
#define PIN_SMOKE_2 33 //SmartThings Capability "Smoke Detector"
#define PIN_ALARM_1 34 //SmartThings Capability "Alarm"
#define PIN_ALARM_2 40 //SmartThings Capability "Alarm"
#define PIN_STROBE_2 41 //SmartThings Capability "Alarm"
#define PIN_CO_1 42 //SmartThings Capability "Carbon Monoxide Detector"
#define PIN_CO_2 43 //SmartThings Capability "Carbon Monoxide Detector"

//Dimmer Switch Pins
#define PIN_DIMMERLEVEL_1 44 //SmartThings Capability "Switch Level" NOTE: MUST BE A PWM CAPABLE PIN!
#define PIN_DIMMERSWITCH_1 45 //SmartThings Capability "Switch"
#define PIN_DIMMERLEVEL_2 46 //SmartThings Capability "Switch Level" NOTE: MUST BE A PWM CAPABLE PIN!
#define PIN_DIMMERSWITCH_2 47 //SmartThings Capability "Switch"

//Garage Door Pins
#define PIN_DOORCONTROL_CONTACT_1 35 //SmartThings Capabilty "Door Control"
#define PIN_DOORCONTROL_RELAY_1 36 //SmartThings Capabilty "Door Control"
#define PIN_DOORCONTROL_CONTACT_2 37 //SmartThings Capabilty "Door Control"
#define PIN_DOORCONTROL_RELAY_2 38 //SmartThings Capabilty "Door Control"

//Pushbutton Pins
#define PIN_BUTTON1 48 //SmartThings Capabilty Button / Holdable Button
#define PIN_BUTTON2 49 //SmartThings Capabilty Button / Holdable Button

Definitely all of the unreserved Digital Pins, as they all support Internal Pullup resistors, IIRC. This would include pins 2-3,5-9,11-49. I am not certain about the Analog Pins A0-A15 when used as Digital Inputs.

Suffice it to say, the Arduino MEGA 2560 has plenty of GPIO pins for contact sensors.

1 Like

Awesome! Thank you. And thank you for your amazing work on this. I was looking at the Konnected product but ran across your project. It's amazing how much you can do with these Arduinos and how cost effective they are.

1 Like

Thank you again for sharing this amazing project. I received my Arduino hardware yesterday and was up and running in under an hour. Everything is working wonderfully. Just wanted to express my appreciation for all your hard work.

2 Likes

Seems that the max number of sensors I can use is 30? Getting this error if I try to include more than 30 sensors although I have available pins.

"You've exceeded maximum number of sensors; edit Constants.h"

Any chance you know of a fix?

Yes. In the ST_Anything Arduino Library folder, you will find a file named “constants.h”. Edit this file to increase the Maximum number of sensors to a slightly larger value to accommodate your requirements.

			#if defined(BOARD_MEGA) || defined(BOARD_MKR1000) || defined(BOARD_ESP8266) || defined(BOARD_ESP32)
				//Maximum number of SENSOR objects
				static const byte MAX_SENSOR_COUNT=30;					//Used to limit the number of sensor devices allowed.  Be careful on Arduino UNO due to 2K SRAM limitation 
				//Maximum number of EXECUTOR objects
				static const byte MAX_EXECUTOR_COUNT=20;

Also, in the same file, I would recommend disabling the automatic periodic REFRESH. By default this updates the hub every 5 minutes with the current status of all devices. In your case, this is going to cause responsiveness issues, as the system cannot do anything else while this update occurs.

Uncomment the following line of code in constants.h by removing the “//“ at the start of the line.

//#define DISABLE_REFRESH		//If uncommented, will disable periodic refresh of the sensors and executors states to the ST Cloud - improves performance, but may reduce data integrity
2 Likes

Thank you Dan!

1 Like

Sorry to keep bothering you Dan, but I’m not much of a programmer. I just know enough to get by. I’ve made the changes you suggested but now the parent device keeps going to not present until I activate a contact sensor. I’m guessing The 5 min refresh that I disabled keeps the driver updated like a “heart beat”. I’m wondering if there is a workaround like only refreshing on of the sensors etc to keep the present/not present functionality working. I’d like to know if the Arduino ever actually drops off.
Thanks again!

So I found the refresh function in the Everything.cpp file:

And I'm thinking I can change it so it only updates one of the sensors so at least the Hubitat will know the Arduino is still connected? I'm sure you have a better method. Just poking around trying to learn.

The simplest solution would be to simply add one Polling Sensor, like a Temperature sensor, to your Arduino Mega. Then set its polling interval to something like 300 seconds. This will make sure some data is sent periodically to allow the 'presence' of the parent device to behave correctly.

Perfect...great idea. Thank you again.

1 Like