My favorites
▼
|
Sign in
home-automation-je
home automation
Project Home
Wiki
Issues
Source
Export to GitHub
READ-ONLY: This project has been
archived
. For more information see
this post
.
Search
Search within:
All issues
Open issues
New issues
Issues to verify
for
Advanced search
Search tips
Subscriptions
Issue
1
attachment: Souliss_ex02_FiatLux_eth1.ino
(5.4 KB)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/**************************************************************************
Souliss - Fiat Lux
Fiat Lux is a latin phrase that means Let There Be Light, this example
show how handle light via hardwired pushbutton geographically distributed
over the home, the Android (or any other direct) user interface can also
be used.
It require an Ethernet board based on Wiznet W5100 or Microchip ENC28J60.
Applicable for :
- Lights controller via relay,
- Plugs and other ON/OFF devices.
The first device has
- A coil (relay or other) on Pin 8 and Pin 9
- A couple of inputs on Pin 2 and 3, pulldown required
The Remote Device has
- A couple of inputs on Pin 2 and 3, pulldown required
CONFIGURATION IS MANDATORY BEFORE COMPILING
Before compiling this code, is mandatory the configuration of the framework
this ensure the use of proper drivers based functionalities and requested
communication interface.
Configuration files are located on /conf folder, is suggested to use this
code on one of the boards listed below, the code can also compile on other
boards but may require modification on I/O definitions.
Run this code on one of the following boards:
Board Conf Code Board Model
0x03 Arduino Ethernet (W5100)
0x04 Arduino with Ethernet Shield (W5100)
0x05 Arduino with ENC28J60 Ethernet Shield
******************** Configuration Parameters *********************
Configuration file Parameter
QuickCfg.h #define QC_ENABLE 0x01
QuickCfg.h #define QC_BOARDTYPE 0x03, 0x04, 0x05
Is required an additional IP configuration using the following parameters
QuickCfg.h const uint8_t DEFAULT_BASEIPADDRESS[] = {...}
QuickCfg.h const uint8_t DEFAULT_SUBMASK[] = {...}
QuickCfg.h const uint8_t DEFAULT_GATEWAY[] = {...}
***************************************************************************/
#include "Souliss.h"
#include "Typicals.h"
#include <SPI.h>
#define network_address_1 0x0011
#define network_address_2 0x0012
#define network_my_subnet 0xFF00
#define network_my_supern 0x0000
#define LIGHT1_NODE1 0
#define LIGHT2_NODE1 1
#define LIGHT1_NODE2 0
#define LIGHT2_NODE2 1
// define the shared memory map
U8 memory_map[MaCaco_MEMMAP];
// flag
U8 data_changed = 0;
#define time_base_fast 10 // Time cycle in milliseconds
#define time_base_slow 10000 // Time cycle in milliseconds
#define num_phases 255 // Number of phases
U8 phase_speedy=0, phase_fast=0, phase_slow=0;
unsigned long tmr_fast=0, tmr_slow=0;
void setup()
{
// Setup the network configuration
//
// The vNet address is 11(hex) that is 17(dec), so the IP address is
// the DEFAULT_BASEIPADDRESS[] defined in ethUsrCfg.h plus 17 on last
// octect. If DEFAULT_BASEIPADDRESS[] = {192, 168, 1, 0} the IP address
// for the board will be 192.168.1.17
Souliss_SetAddress(network_address_1, network_my_subnet, network_my_supern);
// Load the address also in the memory_map
Souliss_SetLocalAddress(memory_map, network_address_1);
Souliss_SetRemoteAddress(memory_map, network_address_2, 1);
// Set the typical logic to handle the lights
Souliss_SetT11(memory_map, LIGHT1_NODE1);
Souliss_SetT11(memory_map, LIGHT2_NODE1);
// Define inputs, outputs pins
pinMode(2, INPUT); // Hardware pulldown required
pinMode(3, INPUT); // Hardware pulldown required
pinMode(8, OUTPUT); // Power to relay coil for light 1
pinMode(9, OUTPUT); // Power to relay coil for light 2
}
void loop()
{
if(abs(millis()-tmr_fast) > time_base_fast)
{
tmr_fast = millis();
phase_fast = (phase_fast + 1) % num_phases;
// Execute the code every 5 time_base_fast
if (!(phase_fast % 5))
{
// Retreive data from the communication channel
Souliss_CommunicationData(memory_map, &data_changed);
}
// Execute the code every 31 time_base_fast
if (!(phase_fast % 31))
{
// Get logic typicals once and at every refresh
Souliss_GetTypicals(memory_map, 4);
}
// Execute the code every 51 time_base_fast
if (!(phase_fast % 51))
{
// Open a communication channel with remote nodes
Souliss_CommunicationChannels(memory_map, 4);
}
}
else if(abs(millis()-tmr_slow) > time_base_slow)
{
tmr_slow = millis();
phase_slow = (phase_slow + 1) % num_phases;
// Execute the code every 7 time_base_slow
if (!(phase_slow % 7))
{
// Refresh typical definitions
Souliss_RefreshTypicals();
}
}
if(abs(millis()-tmr_fast) > time_base_fast)
{
tmr_fast = millis();
phase_fast = (phase_fast + 1) % num_phases;
// Execute the code every 3 time_base_fast
if (!(phase_fast % 3))
{
// Use Pin2 as ON/OFF command
Souliss_DigIn(2, Souliss_T1n_ToogleCmd, memory_map, LIGHT1_NODE1);
// Use Pin3 as ON/OFF command
Souliss_DigIn(3, Souliss_T1n_ToogleCmd, memory_map, LIGHT2_NODE1);
// Execute the logic
Souliss_Logic_T11(memory_map, LIGHT1_NODE1, &data_changed);
Souliss_Logic_T11(memory_map, LIGHT2_NODE1, &data_changed);
// Use Pin8 as output on the electrical load
Souliss_DigOut(8, Souliss_T1n_Coil, memory_map, LIGHT1_NODE1);
// Use Pin9 as output on the electrical load
Souliss_DigOut(9, Souliss_T1n_Coil, memory_map, LIGHT2_NODE1);
}
// Execute the code every 5 time_base_fast
if (!(phase_fast % 5))
{
// Retreive data from the communication channel
Souliss_CommunicationData(memory_map, &data_changed);
}
}
}
Powered by
Google Project Hosting