-
Notifications
You must be signed in to change notification settings - Fork 1
/
hwsw.tex
2505 lines (2259 loc) · 150 KB
/
hwsw.tex
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\subsection{Radio Transceiver}
For the radio transceiver of WHCS the chip that we decided to use is Nordic
Semiconductor{}'s NRF24L01+. This chip meets all the requirements that we set
for our radio transceiver. The NRF is also a very popular chip that is easy to
find and rarely out of stock. This is a benefit to the manufacturability of
WHCS because NRFs are cheap and easy to buy in bulk. Alternatively we could
have chosen to use an XBee radio device which implements the zigbee 802.15.4
IEEE standard, however we did not see the need for this. XBee devices are also
more expensive than the NRF chips that we have decided to utilize.
\subsubsection{Operating Principles and Usability of NRF24L01+}
The NRF24L01+ is a radio transceiver that operates in the ISM (Industrial,
Scientific, and Medical) radio band. The range of channels for the NRF is
2.4GHz to 2.527 GHz, however because the designated ISM band that we are using
only ranges from 2.4GHz to 2.5GHz we will not be able to use all of the NRF{}'s
available channels. With the NRF we are capable of sending payloads with a
maximum size of 32 bytes per transmission from module to module. We will be
able to change the data length from 1 to 32 bytes in order to find the optimal
mix between reliability and speed. Every NRF chip has the ability to
simultaneously store 1 transmission address and 6 receiving addresses. The
first receiving address is utilized if the auto{}-acknowledgement feature is
enabled, so effectively there are 5 receiving addresses. This capability gives
us flexibility for implementing our network because we make decisions such as
having a dedicated address to each node in the network as well as an address
for broadcasts of certain types. The addresses of the NRF are 5 bytes wide so
we will be able to have many NRF modules within the network. A very useful
feature of the NRF is the ability to enable auto{}-acknowledgement. When this
feature is activated the receipt of a transmission from one NRF to the other is
auto{}-acked without the need from any upper level software. This simplifies
the work necessary for creating our own network of NRF chips. We will be able
to confirm the receipt of data therefore increasing reliability. This
auto{}-ack also allows the NRF to perform retries up to a given limit, so just
in case there is noise during the transmission the NRF will repeatedly try to
transmit again. The NRF also allows for low power mode and long range mode.
For WHCS we will be able to tweak whether or not to use long range mode or not
depending on the performance of the system within its environment.
The NRF requires 3.3v of electricity to operate so all parts of WHCS will
require a 3.3v line. The datasheet lists the current consumption while in
receive mode as 18mA. This will be the most common mode for the NRF chips
present in WHCS so they can be ready to receive commands at any time. The chip
receives commands from a microcontroller through SPI (Serial Peripheral
Interface). This is great because the NRF design philosophy fits perfectly with
our microcontroller based base station and control modules. Beside the standard
MOSI, MISO, and SCK for SPI, the NRF also has a csn pin for telling it to
receive commands, ce pin for telling to to transmit or receive at that moment,
and an interrupt pin for notifying the microcontroller of important situations.
The csn pin will allow the SPI bus to be shared with other components such as
the LCD being used for the base station. The interrupt wire pin can be
monitored in order to listen for data received, data sent, and data failed to
send notifications. In total the NRF will take up 6 pins whilst three of the
pins will be shareable with other SPI components.
\subsubsection{Driver Use Case}
The NRF chip that we have decided to use for communication in WHCS will need to
have a driver written for it. This will help keep the way we interface with the
NRF consistent and will provide clean code. All of the network code that we
write for the base station and the control modules will be relying on the
integrity of the NRF driver that we write. The driver provides the foundation
and if it is not reliable then none of the code we write for our system will be
reliable. The focus for the development of the NRF driver is elegance. We want
everything the NRF driver offers to be simple yet accomplish everything
necessary. We have developed the use case diagram pictured in
\autoref{fig:nrf-usecase-diagram} as a guideline for the development of the NRF
driver. The NRF driver should provide the functionality included in the use
case diagram in an easy to use format. These will be the most common uses of
the NRF.
\ucfgfx[scale=0.4]{fig:nrf-usecase-diagram}{a51-img001.png}{NRF Driver Use-case Diagram}
The core use of the NRF driver is transmitting and receiving payloads. Every
other use case is a supporting role for the final goal of transmission. The
basis of the driver will be reading and writing registers. Everything will
build off of this capability, especially reading and writing the payload for
transmission. Other use cases such as changing power mode, checking the status
of the chip, and changing from a transmitter to a receiver will be special
forms of writing to a register. Thus reading and writing to registers is a use
of the driver, however it will be abstracted in a way that provides ease of
use. A user of the NRF driver will spend most of the time setting addresses,
writing payloads, transmitting payloads, and analyzing interrupts. These use
cases need to be implemented perfectly to provide a strong foundation for the
networking of WHCS.
\subsubsection{Driver Class Diagram}
It was decided that the best design approach for implementing the NRF driver
was as a class in C++. We will be using Atmel ATMega microcontrollers in WHCS so C++
is supported as a development language. Using C++ allows us to create a class
that can leverage object oriented programming techniques such as encapsulation.
The class diagram for the driver is shown in \autoref{fig:nrf-class-diagram}.
Primitive functions such as ReadByte and WriteByte can be hidden from a user
while PowerUp will be exposed as a public function. Using C++ also gives us the
ability to use a constructor when using the WHCSNrf class, and in this
constructor we can assign the only thing varying between uses of the NRF, the
chip enable pin and the chip select not pin. Assigning the ce pin and the csn
pin are the first step of using the NRF driver. Any communication between the
microcontroller and the NRF will rely on the proper assignment of these pins.
%\begin{wrapfigure}{r}{0.5\textwidth}
% \begin{center}
% \includegraphics[width=0.48\textwidth]{a51-img002.png}
% \end{center}
% \caption{NRF Class Diagram}
% \label{fig:nrf-class-diagram}
%\end{wrapfigure}
\ucfgfx[scale=0.5]{fig:nrf-class-diagram}{a51-img002.png}{NRF Class Diagram}
Usage of the NRF driver will involve first constructing the class by telling
the microcontroller which pins the NRF is connected to. Then the user will be
doing everything necessary to customize the way that data is transmitted and
received. The driver exposes the common settings in an easy to access manner.
Enabling things such as auto{}-acknowledgement and the number of retries for
the transceiver can be done with the call of a function with simple parameters.
Setting the address for receiving and transmitting data can be done in one line
of code. The SetTxAddr function will be one of the most utilized function for
an NRF involved in a network constantly sending payloads to other chips. A
typical use will involve powering up the NRF with the PowerUp call, setting the
transmission address, writing a payload, and then transmitting a payload. With
this driver, the user does not need to know the registers involved with the
NRF. The hardware interactions with the chip are all abstracted away.
\subsubsection{Network Library}
\label{sec:network-library}
In order for WHCS to be networked, a set of networking functions will have to
be constructed on top of the radio driver to form a network library or
\textbf{NetLib}. Abstraction of the raw driver will allow for the concept of a
\textbf{node} to be created. The network will consist of a set of nodes capable
of direct communication and reception of \textbf{logical packets}. These
packets will contain metadata describing their purpose and the data that they
contain. By dividing up the required network features of WHCS in to packets, we
will have a library of datagrams. These datagrams no longer have to worry about
low-level details such as when to transmit -- they merely have to worry about
who they are sending to and receiving from. This can be seen in
\autoref{fig:netlib-uml}.
\ucfgfx[scale=0.75]{fig:netlib-uml}{netlib-uml}{Network Library Class Diagram}
Similar to network protocols today, WHCS will implement a lightweight protocol
stack similar to the OSI model. The physical layer is handled by the NRF chip
itself, the logical link layer by the NRF driver, and all other layers by the
NetLib. In WHCS's case, our version of an ``Internet Protocol'' would be to
assign each node with unique ID that can be targeted by other nodes for sending
and receiving data. In terms of the transport layer, our application would be
similar to User Datagram Protocol, which is ``best effort'' in terms of
reliability. We plan on adding additional code and sequencing to allow for this
unreliable medium to withstand lost packets. The NRF already provides the
ability to retransmit on a non-acked frame, but this will just fail after a
certain amount of attempts. This would handle transient errors, but not a
complete loss of connectivity, which would occur if the base station lost
power.
In order to keep the network topology simple, we opt to have a simple module to
base network. This means modules will talk directly to the base station and to
no other modules. This is a simplification based on the underlying radio's
range and our project requirements. We do not need a complicated mesh network
as all of the nodes will be within range of the base station during their
lifetime. For larger or noisier households this architecture would break down,
but for the purposes of an initial design, this configuration will do the job.
Additionally, the network topology is not fixed in hardware - it is merely
additional code that needs to be written and implemented in to the overall
design. More research could be done along the direction of a full mesh network,
but only if necessary for good performance. The direct benefit of this simple
architecture is that is easy to test and easy to program. The logic will only
expect transactions to occur between two nodes. That fact will drive the
construction of a specific and optimized network communication protocol that
doesn't waste unnecessary bytes during transmission. The lower the byte count
for each transmission, the more likely the packet will reach the destination in
tact.
\paragraph{Modes of operation}
Before diving in to the specific functions required for implementing a robust
NetLib, we will discuss the high-level modality of the library. The state of a
network link can be broken in to the following modes:
\begin{itemize}
\item Joining
\item Communicating
\item Idling
\item Leaving
\end{itemize}
The network library will be in the \textbf{joining} mode when it is first
powered on or in the event of a disassociation. The node will attempt to join
on to a local network of nodes through a master node that is defined at the
initial hardware configuration of the network. The joining process will have
its own state machine describing the required processes for association on the
WHCS network. The \textbf{communicating} mode will be active if the node is
joined to a network and if there are data to be sent or received. Otherwise the
node will be in the \textbf{idling} state, which will include a reduction in
power consumption. If for some reason the network needs to be reconfigured
dynamically, the base station or a control module can begin the
\textbf{leaving} mode. This will free any resources present for maintaining
state on the active network join and prevent the leaving node from
communicating on the network. A graphical overview of the NetLib modes and the
transitions between modes is shown in \autoref{fig:netlib-state-overview}.
\ucfgfx[scale=0.65]{fig:netlib-state-overview}{netlib-state-overview}{the overall state machine for the network library}
\paragraph{Join mode detail}
The join mode will be fired when a new node wants to associate to an existing
WHCS network as maintained by a base station. The base station will be the
arbiter of all communication for the WHCS network and as such will also handle
initial join requests. It is the node's responsibility to know and maintain any
necessary access tokens for a join request along with the required channel of
the network. Having the required channel is required for the sender and
receiver to communicate. An optional (as per the setup configuration) will be
communicated during a join request. The base station will validate the joining
node and grant or deny access to the WHCS network. This process is necessary to
provide some assurance and tracking for the active nodes on the network.
\paragraph{Communicate mode detail}
Once a node has been successfully joined to the WHCS network, it will be able
to communicate directly with the base station as its network gateway. All
communication will flow through this node, which will process the data, and if
required, generate a response. This response may be directed back at the
transmitting node, such as an acknowledgement of the packet. Packets of control
modules have the ability to change state in the base station through the use of
``update packets.'' These packets will provide some periodic or event
information about the transmitting node. This could include arbitrary data an
is parsed based off of the node type. For example, a temperature node will have
a specific data format that the base station will know how to unmarshal and
store.
The overall flow of the communicate mode will be to pump out packets to be
sent, wait for any responses, and generate any actions as required by the
packets. This loop will be performed by any node with a radio. The base station
is the only special case as it has to receive from multiple nodes
simultaneously.
\paragraph{Idle mode detail}
The idle mode is the simplest mode for the NetLib. This state is where the
library has no data to send or receive. During this mode, the underlying radio
is free to sleep in order to conserve power usage. Also interrupts would be
used to avoid polling the radio for new data, which would eat a lot of power.
When a new packet is received or one needs to be sent, the radio would be woken
up and enter in to the communication mode.
\paragraph{Leaving mode detail}
The final mode of the network library is the leaving state. This is the state
where the node decided or is ordered to leave the network. It will disassociate
from the WHCS network thereby causing its state and all of the resources
associated with the join to be freed. Additional cleanup will be performed in
order to get the library ready for a new join request. Any outstanding packet
sends or received will be canceled harshly and any potential data will be lost.
A safer shutdown would assert that the radio must be in the idle mode. That way
no data will be lost to the leave transition.
%\begin{table}[H]
%\centering
%\begin{tabular}{|l|l|l|l|}
%\hline
%\bfseries Command & \bfseries Response & \bfseries Description & \bfseries Direction \\ \hline
%ASSOC & ASSOC\_RESP & NODE\_TYPE, & Node to Base Station \\ \hline
%DATA & N/A & DATA\_TYPE, DATA & Node to Base Station \\ \hline
%REQ\_DATA & DATA & DATA\_TYPE, DATA\_PARAMS... & Base Station to Node \\ \hline
%ACTION & ACTION\_RESP & ACTION\_TYPE, ACTION\_PARAMS... & Base Station to Node \\ \hline
%\hline
%\end{tabular}
%\caption{FILL IT IN}
%\label{tab:netlib-cmd}
%\end{table}
\subsection{Microcontrollers}
For the proper operation of WHCS microcontrollers will need to be installed
into all of the control modules as well as the base station. This meant
research was needed to choose what the best microcontroller for each of the
modules was. The base station is a bit more hefty than the control modules so
the design considerations are different for the two. The first step was to
figure out what family of microcontrollers to use.
\subsubsection{Microcontroller Brand}
Choosing the microcontroller brand would set the path for all the development
that we do with the microcontroller. Every other choice would stem from this
decision so we wanted to make a smart choice. We weighed out the documentation,
support, ease of acquisition, ease of use, and community for the brands that we
considered. Our initial choice was Texas Instruments because of the use of the
MSP430 launchpad board in the UCF curriculum. The fact that using the MSP430
was required in EEL 4742 (Embedded Systems) meant that everyone was already at
least somewhat familiar with it. The familiarity factor was a plus for the
MSP, and we all knew that T.I. has very good, albeit lengthy, documentation for
their chips. A quick look at digikey showed that MSP430 microcontroller chips
were well in stock so there would be no problem acquiring them if they were the
chip that we wanted to use. The thing that we were unsure about with using
Texas Instruments chips was the community surrounding the brand. For example if
we encountered a problem rewriting a fuse on the microcontroller would we be
able to find a forum of people who knew how to solve the problem, and things of
that nature.
While we researched Texas Instruments based microcontrollers we also researched
the Atmel brand. We knew Atmel is very popular especially because they produce
the chip used on the Arduino development boards. We checked how the Atmel chips
were documented by looking at the datasheet for the Atmega 88, and were pleased
with how well things were laid out. Digikey had most of the common brands of
Atmel chips in stock so acquisition would be no problem. We didn{}'t feel the
need to consider any other brands because we felt that between the two choices
we looked into they could both suit our needs. Atmel offered chips and brand
support similar to that of Texas Instruments, so for whatever kind of chip we
required we could use Atmel or T.I. For us the choice came down to how
prominent the communities for the two brands are. Ultimately we decided that
the Atmel brand had a very pervasive community that was sure to aid us in our
utilization of any chips produced by the company. While the MSP430 was familiar
to all of us the Texas Instruments chips did not seem as broadly used across
the open source populus. So our final decision was to use the Atmel brand of
microcontrollers for WHCS.
\subsubsection{Base Station Microcontroller}
The base station is the center of operations for WHCS so it needs the most
computing power. It has the most data structures to take care of, the most
commands to process, and the longest compiled program. The microcontroller for
the base station also needs to be able to connect to the LCD screen, the radio
transceiver, and BlueTooth transceiver all at the same time. So taking all
these things into consideration for choosing the microcontroller was important.
We needed a large amount of pins to interface with all the peripherals,
especially because we knew we wanted a parallel interface LCD. A large amount
of flash memory was also a trait that we looked for since we knew the base
station would be doing a lot, thus making its program long. The first big
decision was whether to use an ARM based microcontroller for our base station
since it was the brains of the system. ARM microcontrollers have much higher
processing power, but also introduce complexity. Many ARM microcontrollers
don{}'t have on board flash memory so that is an added layer of design that is
needed to get the unit working. After considering the processing necessary in
the base station and the bandwidth of the network in WHCS we realized that an
ARM based microcontroller would not be necessary. There was not enough data to
be processed to warrant the use of an ARM microcontroller. Using an ARM unit
would introduce design complexity for a solution that could be attained through
easier means.
Eventually our research efforts landed us upon the Atmega series of Atmel
microcontrollers. These microcontrollers are often thought of as the flagship
Atmel chips in the DIY community and they did seem highly capable. The chips
were cheap, had plenty of pins, plenty of on{}-chip peripheral support such as
the UART, were easy to program, and were highly available. After browsing the
Atmega series of chips we narrowed down the chip that we would be using for the
base station to the three chips listed in \autoref{tab:atmega-chips}. The table
shows that the lowest maximum operating frequency between the three is 16 MHz
which is more than capable of powering the low bandwidth network of WHCS. 16
MHz is enough to handle communication, the LCD display and interrupt vectors,
so all the chips are viable options in that feature. The 8 KB of flash memory
was low compared to the 32 KB offered by the other two so we actually took that
chip out of the running when we considered that the base station would have a
large routine. When we were down to choosing between the Atmega328 and the
Atmega32A we realized that the Atmega32A was actually the only option between
the two chips that would work. The reason for this was the number of I/O pins.
We had picked the LCD, radio transceiver, and BlueTooth chip that we would be
using and the Atmega32A was the only chip with enough I/O pins to support all
the peripherals. Our final decision was to use the Atmega32A as the
microcontroller for the base station.
\begin{table}[H]
\centering
\begin{tabular}{|l|l|l|l|}
\hline
{\color{black} Atmega MCU} &
{\color{black} Flash Memory (KB)} &
{\color{black} Max I/O Pins} &
{\color{black} Max freq. (MHz)}\\\hline
{\color{black} Atmega88} &
{\color{black} 8} &
{\color{black} 23} &
{\color{black} 20}\\\hline
{\color{black} Atmega328} &
{\color{black} 32} &
{\color{black} 23} &
{\color{black} 20}\\\hline
{\color{black} Atmega32A} &
{\color{black} 32} &
{\color{black} 32} &
{\color{black} 16}\\\hline
\end{tabular}
\caption{comparison of ATMega chips}
\label{tab:atmega-chips}
\end{table}
After we had decided to use the Atmega32A as the microcontroller for the base
station there were still some things that needed researching to make it usable.
The main issue was disabling the JTAG interface on port C to make the pins
usable as general I/O. After researching the data sheet and the community
forums we found that to be able to use port C pins as GPIO the JTAG fuse must
be disabled. Otherwise setting these pins on port C to high or low will have no
effect.
\subsubsection{Control Module' Microcontrollers}
The control modules are the parts of WHCS that do the interacting with the
endpoint appliances. The microcontroller that we selected for the control
modules would have to have the pin count and processing capabilities necessary
to be able to interface with any of the appliances. This means that the
microcontroller would need to have gpio pins for activating relays for the
outlets and lights, and it would also need to be able to do analog to digital
conversion for sensors. The control modules also receive commands from the base
station and send status replies back, so the control module microcontroller
would have to have an SPI interface for utilizing the radio transceiver that we
chose for WHCS.
The list of constraints on the selection of the control modules{}'
microcontroller was not long. The control modules were not going to be as
demanding as the base station. We could choose a minimalistic chip for the
control modules, but we knew it would help with the design and development
process if we used a microcontroller similar to the one in the base station for
the control modules. This led us back to the ATmega series. Referring back to
\autoref{tab:atmega-chips} we see the three main ATmega series chips that we
researched. All the chips had the SPI interface necessary to communicate with
the radio transceiver. They all had enough pins to interface with the most
demanding control module, and the all had analog to digital conversion
capabilities. Any one of the three chips would have been able to satisfy the
needs of the control modules. The ATmega88 was the first chip out of the three
that was removed from consideration for the base station. This was because the
on{}-chip flash memory was quite low. We decided not to use it in the control
modules for the same reason. The ATmega328 is only slightly more expensive than
the ATmega328 but has 4 times the flash memory. The ATmega32A, while useful for
the base station, would have been overkill for the control modules. The amount
of pins on the ATmega32A would have taken up too much room on the board.
Therefore we decided to use the ATmega328 for the control modules.
For the control module microcontroller we also put research into using an
ATtiny microcontroller. The ATtiny series of Atmel microcontrollers are meant
to be low power and low pin count. If we could use an eight pin or similarly
sized microcontroller for the control module boards then it would save space
and therefore money on the printed circuit board. One issue that turned us away
from the ATtiny series was the lack of SPI and UART hardware modules on the low
pin count chips. For the chips that had SPI and UART support the pin count was
upwards of 20. This meant that there would be no large savings in terms of pin
count from the ATmega328 to a viable ATtiny chip. Thus we saw no reason to use
an ATtiny chip for the control modules rather than an ATmega chip.
\subsubsection{Development Environment}
To begin utilizing the microcontrollers that we chose we had to decide upon a
development environment to use. We believed that having everyone in the group
use the same environment would allow for easier collaboration and shorten
development time. Research showed that there were two popular choices for
writing programs for Atmel chips, Atmel Studio and WinAVR. Each of these two
environments had pros and cons. \autoref{tab:compare-atmel} shows relevant comparisons
between the two environments that led to the decision of what to use. The first
thing that we considered when choosing a development environment was cost. We
knew that certain IDEs, such as Visual Studio, require a license in order to
use. We thought that since Atmel Studio was based off of Visual Studio that it
probably required a similar license. After looking into this issue we found
that Atmel Studio is free and WinAVR is also free. Knowing both are free we
took under consideration that part of the group mainly uses Linux.
Unfortunately neither of these development environments are usable on linux so
we all agreed to use the Windows operating system to host whichever option we
chose. Our next consideration was which IDE worked best along with the
programmer that we decided to use for the microcontroller. We decided to use an
AVR Pocket Programmer which uses a program called AVRDude for programming Atmel
microcontrollers. The Atmel Studio development environment could be set up so
the Pocket Programmer could be activated with the press of a button. This
capability was a noticeable win over WinAVR which elongated the process. The
feature that made Atmel Studio the clear winner of the two was the fact that it
provided so much sample code. Things such as the utilizing the UART or the SPI
interface for certain chips were about three clicks away while in Atmel Studio.
While the two IDEs did have many similarities, we all agreed that Atmel Studio
was the best choice for developing for our Atmel microcontrollers.
\begin{table}[H]
\centering
\begin{tabular}{|l|l|l|}
\hline
&
{\color{black} Atmel Studio} &
{\color{black} WinAVR}\\\hline
{\color{black} Free} &
{\color{black} Yes} &
{\color{black} Yes}\\\hline
{\color{black} Linux Compatible} &
{\color{black} No} &
{\color{black} No}\\\hline
{\color{black} Integrated Compiler} &
{\color{black} Yes (GNU)} &
{\color{black} Yes (GNU)}\\\hline
{\color{black} AVRDude Integration} &
{\color{black} Yes} &
{\color{black} No}\\\hline
{\color{black} Sample Projects} &
{\color{black} Yes} &
{\color{black} No}\\\hline
\end{tabular}
\caption{Comparison of Atmel Studio and WinAVR}
\label{tab:compare-atmel}
\end{table}
\subsubsection{Microcontroller Additions}
To ensure that the microcontrollers we use on the base station and the control
modules are operating at their full capabilities we will be adding external
crystals to their circuits. The external crystals will boost the
microcontrollers operating frequency from their factory ratings of 1 MHz to the
native frequency of the crystal. Because the lowest max operating frequency
for the microcontrollers we chose is 16 MHz this is the frequency we looked for
when choosing a crystal to use for the microcontrollers. We have decided to use
the NDK NX5032GA{}-16.000000MHZ{}-LN{}-CD{}-1 as the crystal for our
microcontrollers. This microcontroller has a 16 MHz operating frequency and has
the simple two connection design. For adding the crystal to our microcontroller
we will be using the circuit pictured in \autoref{fig:mcu-crystal}. The crystal
connects to the XTAL pins on the microcontroller and the microcontroller gets
its driving wave from the crystal. As the diagram shows there are two
capacitors that must be utilized to get the circuit working. These capacitors
are $C_{1}$ and $C_{2}$ and there is an equation for
choosing their value.
\ucfgfx[width=6.006cm,height=7.038cm]{fig:mcu-crystal}{a62expected5pages-img001.png}{Microcontroller Crystal Schematic}
The equation is for choosing the values for $C_{1}$ and
$C_{2}$ is shown in \autoref{eqn:req-cap} where
$C_{stray}$ is dependent on board layout and is approximately 2-5 pF
and $C_{L}$ is a property of the crystal. For our calculations we
used $C_{stray}$ = 3pF. $C_{1}$ also is equal to
$C_{2}$ so this simplifies the calculations. The value of
$C_{L}$ for the crystal we listed is shown as 8pF in the datasheet.
Using the given equation we found that the best value for the capacitors
$C_{1}$ and $C_{2}$ necessary in the crystal circuit was
10pF.
\begin{equation}
C_{L} = (C_1 * C_2) / (C_1+C_2) + C_{stray}
\label{eqn:req-cap}
\end{equation}
To make the external crystals work with the microcontrollers, certain fuses
must be set through a programmer connected to the microcontroller. The
datasheets for the microcontrollers have a fuse list that can be used to make
the proper alterations for incorporating an external crystal into the design.
There is also a free online fuse calculator tool for AVR microcontrollers at
\cite{link2} that can be used to quickly get the
necessary fuses that must be changed for any sort of microcontroller alteration
such as changing the operating frequency.
To get the microcontrollers running the code we right needs to be programmed
onto the chips flash memory. Atmega microcontrollers use SPI to transfer
programs to the chip. There are different programmers that can be used to
complete the task of uploading code to the microcontroller. We put research
into which programmer to use in order to be the most cost effective with our
design. The two programmers that our decision came down to are listed in
\autoref{tab:comparison-of-prog}. Atmel has a programmer called the AVRISP mkII. This
programmer is supported by the designers of the chips so it is sure to work
when ordered however it also comes with a large price tag compared to other
options. The online vendor SparkFun offers a product called AVR Pocket
Programmer for \$15 that accomplishes all that we need to get our programs onto
our microcontrollers. The programmer relies on an open source program called
AVRDUDE to get the hex file from the development computer to the chips flash
memory. The program is free and the pocket programmer is much cheaper than the
Atmel programmer which costs \$34 if ordered from the Atmel site. The AVR
Pocket Programmer was a clear winner when it came time to choose the programmer
for our microcontrollers.
\begin{table}[H]
\centering
\begin{tabular}{|l|l|l|l|}
\hline
{\color{black} Programmer} &
{\color{black} Supplier} &
{\color{black} Price} &
{\color{black} Atmel Studio Compatible}\\\hline
{\color{black} AVRISP mkII} &
{\color{black} Atmel} &
{\color{black} \$34} &
{\color{black} Yes}\\\hline
{\color{black} Pocket AVR Programmer} &
{\color{black} SparkFun} &
{\color{black} \$14.95} &
{\color{black} Yes}\\\hline
\end{tabular}
\caption{Comparison of Two Different AVR Programmers}
\label{tab:comparison-of-prog}
\end{table}
\subsection{BlueTooth Chip}
The BlueTooth device for WHCS will enable the base station to communicate with
the mobile phone controller. Our guidelines for choosing a BlueTooth device
included ease of use, reliability, size, cost, availability, and documentation.
There were a multitude of BlueTooth devices to choose from. Special attention
was paid to how well the BlueTooth device could connect to a microcontroller
UART. Two BlueTooth devices, the HC{}-05 and the RN{}-41, showed the most
promise. Our research of the two devices showed that they both had their
advantages and either one could be implemented in our design. After careful
consideration we chose to utilize the HC{}-05 in our design, however the
RN{}-41 could still replace the HC{}-05 if necessary.
An important factor for considering the BlueTooth devices was if the internal
settings of the BlueTooth devices could be changed and if possible how. Such
internal settings include things such as the device{}'s BlueTooth name, baud
rate, and passcode. These things need to be changed from their default settings
or else many BlueTooth devices would have similar names, and they would all
have default passcodes. We want to implement good security into WHCS so we need
to be able to change the default passcode for the BlueTooth device. Also the
baud rate is usually low in BlueTooth devices by default, which can be bumped
up depending on the microcontroller being used. A BlueTooth device that could
not be programmed easily was not an option.
\subsubsection{RN-41}
The RN{}-41 is a BlueTooth module designed by Microchip. This module is
designed to be an all inclusive solution for embedded BlueTooth. It is clear
that a lot of design went into this chip because it is very high quality and
the data sheet is very thorough. Along with the high quality of the module
comes the high cost. Of the two considered BlueTooth modules the RN{}-41 was
much more expensive with a price of \$21.74 from Microchip. The high price tag
makes it a less appealing option out of the BlueTooth devices because they are
effectively accomplishing the same thing. The module itself appears well
designed visually and it has dimensions of 25.8x13.2mm so it is not obtrusive
and could fit well onto a PCB. There are 24 pins on this device and the
datasheet gives the dimensions down to the pin spacing allowing for easy PCB
layout design. The RN{}-41 makes communicating with microcontroller UARTs easy
by simplifying RS{}-232 down to the Rx and Tx wires. This means the only
connections necessary for using the RN{}-41 with a microcontroller are power,
ground, Rx, and Tx. The microcontroller{}'s that we have decided to use include
Rx and Tx pins that hook up directly to the RN{}-41. From the
microcontroller{}'s point of view the BlueTooth device does not even exist. The
RN{}-41 acts as a transparent man{}-in{}-the middle and simply relays messages
from a BlueTooth device to the microcontroller and vice versa. This is perfect
for our design because the RN{}-41 could just be plug and play. With an
advertised 100 meter transmission range the RN{}-41 meets the requirements we
set for distance of BlueTooth reception. According to the datasheet the
RN{}-41 has a maximum baud rate of 921K which means it goes above and beyond
the transmission rates necessary for communicating between the mobile device
and the base station.
The RN{}-41 has a manageable means of programming the internal settings. When
the RN{}-41 is on, sending {}``\$\$\$'' over the UART lines puts the chip into
command mode. From here there are a list of commands that can be passed in
order to inquire or manipulate the state of the module. There are advantages
and disadvantages to this approach. It is great that it is easy to program the
RN{}-41 just by passing certain data while it is wired normally, however in the
event that the sequence {}``\$\$\$'' was ever passed during operation it could
throw off the whole system. This is not a terrible thing but it is worthy of
consideration.
\subsubsection{HC-05}
\label{sec:bt-hc-05}
The HC{}-05 is a BlueTooth module that shares many similarities with the
RN{}-41. It is of comparable size to the RN{}-41 with dimensions of 27x13mm.
HC{}-05 modules are also commonly sold along with a breakout board with male
headers. This makes it an option to have the PCB include female headers and use
them for installing the HC{}-05. Our intention for the base station containing
the BlueTooth module is to have the PCB board hidden, so using female headers
for plugging in the HC{}-05 to the PCB is a viable option. The module is
advertised as a low power class 2 BlueTooth device with power consumption for
communication listed at 8 mA. This is lower power consumption than the RN{}-41.
The max signal range is not listed in the data sheet, however we have tested
this chip and have achieved a signal range of more than 50m which is more than
enough for what we desired in our BlueTooth chip. Just like the RN{}-41 the
HC{}-05 communicates to microcontrollers by simplifying RS{}-232 and only using
the Rx and Tx pin. The maximum supported baud rate is 460800 which will allow
for very fast data transfer and will exceed the needs of communication speeds
in our system.
The HC{}-05 comes with default settings similar to most BlueTooth modules. The
default baud rate is 9600 and the default passcode is 1234. In order to change
this the module must be accessed in AT mode. AT mode is entered by utilizing
pin 11 {}``key{}'' on the HC{}-05. When this pin is held high, the module
enters AT mode on startup and is ready to take commands. This means that
whenever we want to program the BlueTooth module we will need to use a
microcontroller with a UART connection to a terminal as well as a UART
connection to the HC{}-05. This will require the implementation of a software
Rx and Tx pin. This will only need to be done once because once the BlueTooth
module has been programmed it retains that configuration. The requirement of
holding the key pin high during startup of the module eliminates the danger of
entering the programming mode during normal operation.
For WHCS we have decided to use the HC{}-05 as our BlueTooth module instead of
the RN{}-41. \autoref{tab:bluetooth-compare} shows highlights of the features of each
BlueTooth module that led to the decision. The main factors deciding this were
the cheaper price of the HC{}-05 and the fact that they both accomplish the
same thing. The table shows clearly that the HC{}-05 is a much more affordable
option. The two chips were comparable in size, features, wiring, layout, and
usability however at the price of \$6.64 the HC{}-05 cost less than half of the
RN{}-41. The RN{}-41 is the second best choice and can serve as a fallback if
HC{}-05 chips went out of stock or an unforeseen circumstance occurred.
\begin{table}[H]
\begin{tabular}{|l|l|l|l|l|l|}
\hline
&
{\bfseries Cost} &
{\bfseries Range (meters)} &
{\bfseries Breakout Option} &
{\bfseries Configurable} &
{\bfseries Size}\\\hline
{\color{black} RN{}-41} &
{\color{black} \$21.70} &
{\color{black} 100} &
{\color{black} No} &
{\color{black} Yes} &
{\color{black} 25.8x13.2mm}\\\hline
{\color{black} HC{}-05} &
{\color{black} \$6.64} &
{\color{black} 50+} &
{\color{black} Yes} &
{\color{black} Yes} &
{\color{black} 27x13mm}\\\hline
\end{tabular}
\caption{comparison of the BlueTooth chips}
\label{tab:bluetooth-compare}
\end{table}
\subsection{LCD}
Being able to interface with WHCS like a normal wall thermostat is one of our
project goals. Having a centralized display that can quickly display the most
important information for homeowners would be step up from traditional ``dumb''
thermostats. With a simple LCD combined with a touchscreen, users would have a
way to control and query their home without having to find their phone.
To make this a reality, we have chosen the versatile, premade, and well
supported Adafruit 2.8" TFT LCD\cite{link3} with a resistive touchscreen.
Internally, the display is driven by the feature-rich
ILI9341 chipset.\cite{link22}
This chip is specifically created for a 240x320 pixel LCD with a focus on
small, power-conscious mobile devices. Another reason we chose to buy this from
Adafruit and not integrate the chip directly is due to the complexity of the
design. Also, with the abstracted product, there are
plenty
of usage examples\cite{link23}and Adafruit's
excellent
technical documentation.\cite{link24} This combined with Adafruit's
libraries\cite{link25}, assure
that integrating the LCD will be straight forward. The one issue with
this solution is with the ILI9341 driver code: it was written to target the
Arduino platform. Now, the Arduino platform is fairly close to bare AVR, minus
the remapped pin numbers and some support libraries, so porting Adafruit's
library would be a feasible solution. Our plan is to use the existing driver
along with the chip datasheet to create a library specific to our needs. That
way we get full control over the port placement and the experience of creating
an LCD driver.
\subsubsection{Capabilities}
In terms of capabilities, we have summarized the main features of the LCD module in \autoref{tab:lcd-features}
\begin{table}[H]
\centering
\begin{tabular}{|l|l|}
\hline
\bfseries Specification & \bfseries Description \\ \hline
Resolution & 240x360 \\ \hline
Colors & 262K @ 18bits, 65K @ 16bits \\ \hline
Voltage Input & 3.3 - 5V \\ \hline
Weight & 40 grams \\ \hline
Dimensions (LCD itself) & 2.8" diagonal \\ \hline
MCU Interface & Multiple. See \autoref{sec:lcd-driver}\\ \hline
Touchscreen technology & Resistive (one finger)\\
\hline
\end{tabular}
\caption{a brief summary of the pertinent features of the LCD module}
\label{tab:lcd-features}
\end{table}
These features are more than sufficient for out application as most of the
drawing we will be doing will be non-realtime. Nearly all of the displayed
information will be text and UI element, which don't change often. For an
overview of our UI elements, see \autoref{sec:ui-lib}.
One of the beneficial features of the LCD is that it gives developers a choice
of which interface to use. The broken out interfaces are 4-bit SPI and 8-bit
parallel. For prototyping, we used the low pin count SPI interface, but for our
final design, we will be using the 8-bit interface to avoid having to wait for
lengthy SPI transfers. Also, our NRF radio will be using the SPI bus, which
should have priority over that channel. You may view a high level overview of
the LCD module in \autoref{fig:lcd-high-level}.
\ucfgfx[width=\textwidth]{fig:lcd-high-level}{lcd-high-level}{a high level outline of the LCD pin configuration and specifications}
Another feature of Adafruit's module is the resistive touchscreen present on top of the
LCD. With this, we don't just have to display information about WHCS, we can
receive commands as well. Using this simple interface, we plan on creating a
featureful UI library to communicate up-to-date information about the home
while allowing for user control. The specific interface for the touchscreen
requires 4 pins, 2 of which must be connected to the MCU's Analog to Digital
Converter. By reading the resistance of the touchscreen, we would be able to
calculate the position of a single finger.
Finally, one extra component on the LCD module is an SD card slot. We are free
to read and write directly to this card to store large images, such as logos
for display on the LCD. We plan on storing at least our logo, but we may also
store fancy UI badges such as arrows ($\leftarrow,\rightarrow$), X's
($\otimes$), checkboxes (
\makebox[0pt][l]{$\square$}\raisebox{.15ex}{\hspace{0.1em}$\checkmark$}), and
anything else we can think of.
\subsubsection{ILI9341 Driver}
\label{sec:lcd-driver}
In order to perform the required operations for drawing pixels to the LCD, we
need a robust driver to manage the state of the ILI9341 chip. This driver will
have to implement primitives for choosing a position to draw and the ability to fill
pixels.
\paragraph{Choosing where to draw}
The ILI9341 works like many chips in which it has a command set for controlling
display parameters. One of these commands will set the window in which pixel
data is drawn. Before a batch drawing operation, a window is selected by
specifying the column and page addresses. These are set using the
\textbf{Column Address Set (0x2A)} and the \textbf{Page Address Set (0x2B)}
commands. From this point, the RAMWR command is sent followed by \emph{N}
different 16-bit pixel colors. This scheme of setting the window and filling
the pixels is why the graphics transfers end up being so slow, which is
discussed more in \autoref{par:lcd-perf}.
\paragraph{LCD State Management}
Beyond just drawing pixels, the LCD module has a wide variety of bonus features
that could assist us in making a fully-featured interface. One of these is
vertical scrolling, which could enable us to cheaply draw familiar UI elements,
such as list views. The most intensive state management comes from the early
initialization of the LCD module straight from power on. This requires a long
incantation of LCD commands with equally archaic parameters in order to reach
the initialized zen. Luckily, there are multiple examples of slightly different
LCD initialization sequences online for reference. In terms of power
management, the LCD controller provides a command set to set the power mode.
Although, the base station will be on wall power, being able to dim the screen
and save energy would be a useful feature.
\paragraph{LCD Performance}
\label{par:lcd-perf}
Due to the real-time nature of microcontrollers, everything must be juggled as
quickly as possible in order to have a good responsive design. A user event
such as a touch event followed by a graphics redraw should never take prioirity
over more important operations, such as sending and receving from the radios.
This is a common theme
throughout real time environments, so much so that highly specialized Real Time
Operating Systems have been created to provide \emph{assurance} that some
operation/action will complete within a specified amount of time. We don't have that luxury -- instead we must consider performance before we hit any performance walls.
The slowest part about managing the LCD are the synchronous transfer of
commands and pixel data between the MCU and the graphics controller. Each
ILI9341 command is 8-bits and before any pixel operation the CAS and PAS
commands need to be set. These commands have two 16-bit arguments.
For settting just one arbitrary pixel 104 bits would need to be sent. This is a
considerable overhead, so care must be taken to perform pixel operations in
batch. Obviously, an algorithm that generates random pixels on the screen would have very
low performance.
One other hit to potential performance is the lack of double buffering. The LCD
chip only has enough RAM for one set of graphics memory, which means active
drawing occurs on the viewing surface. In modern day graphics pipelines, double
buffering and even \emph{triple} buffering are common place as they eliminate
tearing and free the developer from having to clear the screen. On modern day
graphics cards, clearing the screen is an extremely cheap operation -- on the
ILI9341, it's just as expensive as every other drawing operation.
\missingfigure{class diagram}
\subsubsection{Touchscreen Driver}
The touchscreen will need code dedicated to polling the X+, X-, Y+, and Y- pins
of the LCD. These will give voltage readings that can be used to calculate the
position of a single touch. They can be read by using the built-in ATMega ADC.
Due to their not being a dedicated touch controller,
interrupts cannot be used to sense sharp changes. This will add to the
processing time of the microcontroller's main loop as it will constantly have
to perform ADC operations and comparisons.
\subsubsection{Graphics Driver}
Unlike the previous ILI9341 driver, our graphics driver will be in charge of
taking the low-level primitives exported by the LCD driver and using them to
draw useful screen elements. These include text, lines, rectangles, circles,
and images. The driver will essentially contain a set of routines for drawing
these objects given a set of parameters such as length/width for rectangles,
radius and position for circles, and bitmap lookup-tables for the text. These
functions and more are already created by Adafruit, but for the experience and
control of designing the graphics routines, we choose to implement our own.
Due to the unique hardware and software constraints (i.e limited clock speed
and memory), we must take care to not exceed the capabilities of the hardware.
This means floating point operations, which may be required for shapes such as
a circle must be optimized or not used at all. A quick optimization for
floating point operations would be to use a $sin()$ lookup table and only
integer multiplications. These performance issues will be addressed as needed
and only if necessary. By avoiding unnecessary optimizations, we will save
valuable time for building out the library.
\paragraph{Algorithms Necessary}
The functionality of graphics driver depends on some core algorithms for
efficiently creating meaningful screen objects. One of these core algorithms is
Bresenham's
line algorithm.\cite{link26} This algorithm needs to be efficiently implemented as it will
be the base for nearly every derived graphics operation. For example, a
transparent rectangle has four sides which results in four calls to this line
drawing function.
If there were any need for UI elements to be at different depths, then each UI
element would have to have its
\paragraph{Character Lookup Table}
In order to convey useful information, we will need to display text to the
user. This text will be stored in an efficient lookup table for quick drawing
operations similar. On a limited embedded
system like this, there is a limited amount of time that can be dedicated for
font rendering. To save on time, we will use an existing font available online.
Adafruit also bundles a font in with their graphics library that is implemented
as a function instead of a block of memory.
Due to the very limited constraints of the microcontrollers, we will have to
store this character lookup table in PROGMEM. This will embed the bitfile in to
flash, which then has to be read out using the AVR LDM instruction. This incurs
a performance hit, but storing the characters in memory is impossible given
only 2048 bytes for the Atmega32-A.
\subsubsection{UI Library}
\label{sec:ui-lib}
An LCD is nothing without a good library driving it. Even if all possible
shapes and text can be drawn, without a good user interface library, the system
is a painting. WHCS aims to have an LCD users \emph{want} to interact with.
This will be accomplished with a feature rich UI library that enables text,
buttons, lists, and images to be drawn and organized simply. A sample WHCS home screen is mocked up and shows the required controls in \autoref{fig:ui-mockup-home}.
In normal UI libraries, such as the Android View hierarchy, UI elements can be added on the
fly. Unfortunately, unless the UI elements for WHCS are extremely low memory,
storing dynamic UI elements may prove to be too costly for the microcontroller.
Until further testing is done, there is no way to say that this is possible or
not beyond data structure size predictions.
\ucfgfx[scale=0.60]{fig:ui-mockup-home}{ui-mockup}{A mockup of WHCS' home screen with each
control identified}
\paragraph{View Abstraction}
When constructing a UI library, we will use an Object Oriented class hierarchy
to describe the controls. All drawable controls will have the View class and
their parent, which will serve to contain all of the common properties that a
control can have. This includes basic drawing and placement information, such
as width, height, and X-Y position. This is illustrated in \autoref{fig:ui-generic}.
\ucfgfx[scale=0.80]{fig:ui-generic}{ui-generic}{View abstraction properties}
Making this abstraction allows for code reuse and simplifies the design of
individual components. Specific components will derive directly from the View
class or each other to form more and more complex UI elements. Using
\autoref{fig:ui-mockup-home}, we have created a UML representation of a
potential view hierarchy, including properties and methods. This can be seen in
\autoref{fig:ui-lib-uml}.
\ucfgfx[scale=0.63]{fig:ui-lib-uml}{ui-lib-uml}{UML representation of the View hierarchy.}
This hierarchy is modeled after Android's UI abstraction. This is done because
reinventing the wheel for UI elements would cost developer time. Android has
more than proven that the hierarchy works in practice as well.
\subsection{Android Application} For most WHCS users the mobile application
will be the only physical interaction they have with the application. When we
set out for development we wanted to make an easy to use application that would
attract users to stick with our system. Operability and usability were
emphasized in our design process. We wanted an appealing U.I. without
complexity, after all we are targeting a simple solution to home automation.
\subsubsection{Development Environment} Android is the mobile operating system
that we chose to utilize for our BlueTooth enabled phone. The Android operating
system is accessed through the Java language, which is a staple in the UCF
curriculum therefore everyone in our group is versed in it. Developing on
Android is also a free endeavour where as developing on an iPhone requires
enrolling in the Apple Developer Program. These programs actually cost a good
amount of money that is unnecessary to spend. The Windows Phone platform is
another option for the BlueTooth enabled phone, but they are very unpopular so
we chose not to target this platform. With our target narrowed down to the
Android operating system, we had to research what the best environment for
developing our application would be. There were three options that we
considered for managing the Android project each with their own perks: command
line tools, Eclipse, and Android Studio.
The first development environment we considered for our Android project was
creating our own project structure and using command line build tools. There
are also debug tools available on the command line for Android projects. These
tools would be necessary in order to do our testing on Android Virtual Machines
running on our computers. This approach favors people who are command line or
terminal oriented. Linux is popular within our group and the ability to do
things from the terminal is appealing so this approach seemed like a good one.
We realized that with the design we had in mind for our project, it would
become quite large and it might be difficult to handle without a dedicated IDE
(Interactive Development Environment). This led us to looking into using
Eclipse for developing our Android application. Eclipse seemed like a natural
choice because it is what is recommended for using in the Java oriented UCF
programming classes. The Android SDK provides an add{}-on for Eclipse that
makes it a viable Android development environment. We were able to get this
running and create sample Android applications. Inside of Eclipse the project
structure for Android applications is laid out nicely. The debug tools are all
organized at the top of the screen resulting in an easier development
experience than debugging from the command line. The problem with using Eclipse
as our IDE is that Eclipse is notorious for being slow and unwieldy.
\color{black} Recently Google released a development environment named Android
Studio that is made specifically for developing Android Applications. No one in
our group had any prior experience using this IDE, however we realized that due
to it being tailored specifically for Android it was probably better than
anything else. This turned out to be correct, because it was much easier for us
to create an Android project and navigate our code from within this IDE. We
also decided to use Android Studio because it has built in Git support for
source control. This meant that as we were
writing our code we could easily submit our changes to a remote Git repository.
\subsubsection{Use Case Diagram} The central use cases for WHCS are toggling
the state of certain devices within the home and monitoring certain states.
For example a user of WHCS will spend most of the time turning on lights,
checking whether a light is on, or checking the temperature reading of a
certain sensor. There are certain other use cases that are necessary in order
for WHCS to be a functioning application, as well as to make it have a robust
feel. Features like speech activation and creating endpoint groups are
usability features that are not necessary in order to accomplish the central
goals of WHCS. Connecting to the base station the first time you use the
application is a necessary use case that must be incorporated into the
application. \autoref{fig:android-usecase} shows the use case diagram for the
WHCS application.
The design for the WHCS application involves making sure that performing the
common use cases such as checking status and toggling endpoints are very fast.
The user should be able to perform these tasks without having any knowledge of
how the application works. Speech recognition will be a supporting feature so
it does not need to be a central focus like the area that will visualize the
control modules. When the user wants to perform speech activation it will
involve pressing a button to prompt the speech recognizer, and then giving a
command to the WHCS. In order to make the speech activation feature more