Home Automation - Automatic Blinds Datasheet by DigiKey Kit (VA)

6‘ MICRDCHIP 99 User Guide
Home Automation -
Automatic Blinds
Home Automation - Automatic Blinds
Introduction
Author: Johan Lofstad, Microchip Technology Inc.
This document presents an “Automatic Blinds” design using the AVR®-IoT WG Board, a MikroElektronika Stepper 2
Click and a stepper motor. All of these parts bundled together is the Home Automation Kit. The blinds can be
controlled from a web interface in the cloud. As there are no sensors to detect when the blinds are fully extended,
there is a need to calibrate a start/stop position. A calibration sequence is included to handle this issue. It is
recommended to read the Getting Started with the Home Automation kit before proceeding, found here: http://
www.microchip.com/DS50002957.
Tip:  The finished source code can be accessed at https://start.atmel.com/#examples under the name
AVR IoT WG Sensor Node with Stepper 2 Click. Under “Example Configuration”, select AUTOMATIC
BLINDS.
Tip:  3D models of a Miniature Blinds can be downloaded at https://github.com/microchip-pic-avr-
solutions/avr-home-automation-3d-models. These miniature blinds can be printed and used to test the
system presented in this user guide.
© 2020 Microchip Technology Inc. User Guide DS50002958A-page 1
Table of Contents
Introduction.....................................................................................................................................................1
1. System Design........................................................................................................................................ 3
1.1. Adding a new Command to the Command Line Interface............................................................4
2. Revision History...................................................................................................................................... 7
The Microchip Website...................................................................................................................................8
Product Change Notification Service..............................................................................................................8
Customer Support.......................................................................................................................................... 8
Microchip Devices Code Protection Feature.................................................................................................. 8
Legal Notice................................................................................................................................................... 8
Trademarks.................................................................................................................................................... 9
Quality Management System......................................................................................................................... 9
Worldwide Sales and Service.......................................................................................................................10
Home Automation - Automatic Blinds
© 2020 Microchip Technology Inc. User Guide DS50002958A-page 2
sun Assume mm: are wumsn a” the way up PDSHIon u x $ No Rah-Ale We mom! Wm! 1 5W" 5‘9"?“ posman : 0 X sxeps secnnd Yecewved "om mm V95 M5,, mamasman , posmou ‘ x
1. System Design
The automatic blinds have the following specifications:
The blinds can be controlled remotely from the cloud
The blinds can be controlled locally from a Command Line Interface (CLI)
The blinds can go to any position between winded all the way up and fully extended
The input to the system is a position between 0 and 100. Zero represents winded all the way up, and 100
represents fully extended
The user can calibrate the blinds for her/his setup
The system remembers its state through a power loss
Precision is a major advantage of using a stepper motor. For every step, the number of degrees moved is known
exactly. Due to this unique property, the motor can be controlled in an open loop. There is no need for any sensors to
track the position of the motor, as the position can always be deducted as long as the starting position is known. The
following code steps precisely:
// For all steps, do one pulse
for(uint16_t i = 0; i < number_of_steps; i++){
MOTOR_ST_toggle_level();
_delay_ms(1);
MOTOR_ST_toggle_level();
_delay_ms(1);
}
Whenever the stepper motor rotates, the blinds are extended a fixed distance. The number of rotations required to
extend the blinds fully is found through an initial calibration sequence. The calibration sequence is accessed through
the command line interface the AVR®-IoT Board is shipped with. The blinds are set in their initial position, winded up.
When the calibration sequence starts, the motor rotates X steps every second until a stop command is received. The
number of accumulated steps is saved as “max position” and is the number of rotations to go from position zero (fully
winded) to fully extended. A flowchart of this calibration sequence can be seen in Figure 1-1. A calibration is started
through a “calibration” command in the CLI.
Figure 1-1. Flowchart of the Calibration Sequence
Start
Assume blinds are winded all the
way up position = 0 Rotate the motor
X steps Wait 1
second
Stop signal
received from
user?
position += X
No
max_position =
position + X
Yes
Finish
The input to the system is a position between 0 and 100. Zero represents winded up, and 100 represents fully
extended. To control the system from the cloud, open the AVR®-IoT landing page by opening “CLICK_ME.HTM” in
the Curiosity Drive and adding a “position” slider, as shown in Figure Figure 1-2. When the “Send to Device” button is
pressed, the position slider value is sent as a JSON message. This is done in the same manner as the speed slider
Home Automation - Automatic Blinds
System Design
© 2020 Microchip Technology Inc. User Guide DS50002958A-page 3
Sliders posmnn L0 Current: 24 Mm a Step 1 Max ‘00
from the Getting Started guide, which explains the sending and receiving of messages in more detail. The following
code is called whenever a position is received from the cloud.
void blinds_goto_position(uint16_t position){
if(position > max_position()){
return;
}
uint16_t steps_to_take;
if(position > current_position()){
motor_set_direction(MOTOR_DIRECTION_COUNTER_CLOCKWISE);
steps_to_take = position - current_position();
}else{
motor_set_direction(MOTOR_DIRECTION_CLOCKWISE);
steps_to_take = current_position() - position;
}
motor_step_precise(steps_to_take, true);
write_current_position(position);
}
Figure 1-2. A Position Slider to Control the Blinds Position
The max_position and current_position variables are stored in the EEPROM, persisting through a power loss. A
driver for writing to Flash and EEPROM can be found in Atmel START under the name “Flash”. It provides
FLASH_0_read_eeprom_byte(eeprom_adr_t eeprom_adr) and FLASH_0_write_eeprom_byte(eeprom_adr_t
eeprom_adr, uint8_t data). Notice that they read and write in eight bits, while the position is stored as a 16-bit integer.
It is necessary to do some bit-shifting.
#define MAX_POS_ADDRESS (24)
#define CUR_POS_ADDRESS (26)
static inline uint16_t max_position(void){
return FLASH_0_read_eeprom_byte(MAX_POS_ADDRESS + 1) |
(FLASH_0_read_eeprom_byte(MAX_POS_ADDRESS) << 8);
}
static inline void write_max_position(uint16_t position){
FLASH_0_write_eeprom_byte(MAX_POS_ADDRESS + 1, position & 0xFF);
FLASH_0_write_eeprom_byte(MAX_POS_ADDRESS, position >> 8);
}
1.1 Adding a new Command to the Command Line Interface
As mentioned in the Getting Started Guide, the AVR®-IoT Boards firmware ships with a Command Line Interface
(CLI). This section explains how to add a new command to initiate the calibration sequence described in Figure 1-1.
Home Automation - Automatic Blinds
System Design
© 2020 Microchip Technology Inc. User Guide DS50002958A-page 4
The source code for the CLI can be found under cli/cli.c. The first step is making the function which is called when our
command is issued:
static void calibrate_blinds(char *pArg){
blinds_calibrate();
}
The *pArg argument is a pointer to any supplied argument in the command line. For instance, calibrate 200 would
make *pArg = 200. Next, the command must be added to const struct cmd commands[].
const struct cmd commands[] = {{"reset", reset_cmd},
{"reconnect", reconnect_cmd},
{"wifi", set_wifi_auth},
{"key", get_public_key},
{"device", get_device_id},
{"cli_version", get_cli_version},
{"version", get_firmware_version},
{"debug", set_debug_level},
{"calibrate", calibrate_blinds}};
To access the command line, a tool such as the MPLAB® Data Visualizer can be used. It can be downloaded at
https://gallery.microchip.com/packages?q=MPLAB-Data-Visualizer. When opened, initiate a connection to the COM
port of the AVR®-IoT Board by clicking the “play icon” on the left-hand side. At the right-hand side of the terminal, find
“Source” under “Input” and select the COM port. See Figure 1-3.
Home Automation - Automatic Blinds
System Design
© 2020 Microchip Technology Inc. User Guide DS50002958A-page 5
o E—MMW x - Sena‘ Dons 4r _,",
Figure 1-3. Opening a Command Line Link in MPLAB® X Data Visualizer
Home Automation - Automatic Blinds
System Design
© 2020 Microchip Technology Inc. User Guide DS50002958A-page 6
2. Revision History
Doc. Rev. Date Comments
A 02/2020 Initial document release
Home Automation - Automatic Blinds
Revision History
© 2020 Microchip Technology Inc. User Guide DS50002958A-page 7
The Microchip Website
Microchip provides online support via our website at http://www.microchip.com/. This website is used to make files
and information easily available to customers. Some of the content available includes:
Product Support – Data sheets and errata, application notes and sample programs, design resources, user’s
guides and hardware support documents, latest software releases and archived software
General Technical Support – Frequently Asked Questions (FAQs), technical support requests, online
discussion groups, Microchip design partner program member listing
Business of Microchip – Product selector and ordering guides, latest Microchip press releases, listing of
seminars and events, listings of Microchip sales offices, distributors and factory representatives
Product Change Notification Service
Microchip’s product change notification service helps keep customers current on Microchip products. Subscribers will
receive email notification whenever there are changes, updates, revisions or errata related to a specified product
family or development tool of interest.
To register, go to http://www.microchip.com/pcn and follow the registration instructions.
Customer Support
Users of Microchip products can receive assistance through several channels:
Distributor or Representative
Local Sales Office
Embedded Solutions Engineer (ESE)
Technical Support
Customers should contact their distributor, representative or ESE for support. Local sales offices are also available to
help customers. A listing of sales offices and locations is included in this document.
Technical support is available through the website at: http://www.microchip.com/support
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices:
Microchip products meet the specification contained in their particular Microchip Data Sheet.
Microchip believes that its family of products is one of the most secure families of its kind on the market today,
when used in the intended manner and under normal conditions.
There are dishonest and possibly illegal methods used to breach the code protection feature. All of these
methods, to our knowledge, require using the Microchip products in a manner outside the operating
specifications contained in Microchip’s Data Sheets. Most likely, the person doing so is engaged in theft of
intellectual property.
Microchip is willing to work with the customer who is concerned about the integrity of their code.
Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code
protection does not mean that we are guaranteeing the product as “unbreakable.”
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection
features of our products. Attempts to break Microchip’s code protection feature may be a violation of the Digital
Millennium Copyright Act. If such acts allow unauthorized access to your software or other copyrighted work, you
may have a right to sue for relief under that Act.
Legal Notice
Information contained in this publication regarding device applications and the like is provided only for your
convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with
Home Automation - Automatic Blinds
© 2020 Microchip Technology Inc. User Guide DS50002958A-page 8
your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER
EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION,
INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR
FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip
devices in life support and/or safety applications is entirely at the buyer’s risk, and the buyer agrees to defend,
indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such
use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights unless
otherwise stated.
Trademarks
The Microchip name and logo, the Microchip logo, Adaptec, AnyRate, AVR, AVR logo, AVR Freaks, BesTime,
BitCloud, chipKIT, chipKIT logo, CryptoMemory, CryptoRF, dsPIC, FlashFlex, flexPWR, HELDO, IGLOO, JukeBlox,
KeeLoq, Kleer, LANCheck, LinkMD, maXStylus, maXTouch, MediaLB, megaAVR, Microsemi, Microsemi logo, MOST,
MOST logo, MPLAB, OptoLyzer, PackeTime, PIC, picoPower, PICSTART, PIC32 logo, PolarFire, Prochip Designer,
QTouch, SAM-BA, SenGenuity, SpyNIC, SST, SST Logo, SuperFlash, Symmetricom, SyncServer, Tachyon,
TempTrackr, TimeSource, tinyAVR, UNI/O, Vectron, and XMEGA are registered trademarks of Microchip Technology
Incorporated in the U.S.A. and other countries.
APT, ClockWorks, The Embedded Control Solutions Company, EtherSynch, FlashTec, Hyper Speed Control,
HyperLight Load, IntelliMOS, Libero, motorBench, mTouch, Powermite 3, Precision Edge, ProASIC, ProASIC Plus,
ProASIC Plus logo, Quiet-Wire, SmartFusion, SyncWorld, Temux, TimeCesium, TimeHub, TimePictra, TimeProvider,
Vite, WinPath, and ZL are registered trademarks of Microchip Technology Incorporated in the U.S.A.
Adjacent Key Suppression, AKS, Analog-for-the-Digital Age, Any Capacitor, AnyIn, AnyOut, BlueSky, BodyCom,
CodeGuard, CryptoAuthentication, CryptoAutomotive, CryptoCompanion, CryptoController, dsPICDEM,
dsPICDEM.net, Dynamic Average Matching, DAM, ECAN, EtherGREEN, In-Circuit Serial Programming, ICSP,
INICnet, Inter-Chip Connectivity, JitterBlocker, KleerNet, KleerNet logo, memBrain, Mindi, MiWi, MPASM, MPF,
MPLAB Certified logo, MPLIB, MPLINK, MultiTRAK, NetDetach, Omniscient Code Generation, PICDEM,
PICDEM.net, PICkit, PICtail, PowerSmart, PureSilicon, QMatrix, REAL ICE, Ripple Blocker, SAM-ICE, Serial Quad
I/O, SMART-I.S., SQI, SuperSwitcher, SuperSwitcher II, Total Endurance, TSHARC, USBCheck, VariSense,
ViewSpan, WiperLock, Wireless DNA, and ZENA are trademarks of Microchip Technology Incorporated in the U.S.A.
and other countries.
SQTP is a service mark of Microchip Technology Incorporated in the U.S.A.
The Adaptec logo, Frequency on Demand, Silicon Storage Technology, and Symmcom are registered trademarks of
Microchip Technology Inc. in other countries.
GestIC is a registered trademark of Microchip Technology Germany II GmbH & Co. KG, a subsidiary of Microchip
Technology Inc., in other countries.
All other trademarks mentioned herein are property of their respective companies.
© 2020, Microchip Technology Incorporated, Printed in the U.S.A., All Rights Reserved.
ISBN: 978-1-5224-5593-6
Quality Management System
For information regarding Microchip’s Quality Management Systems, please visit http://www.microchip.com/quality.
Home Automation - Automatic Blinds
© 2020 Microchip Technology Inc. User Guide DS50002958A-page 9
’8‘ MICFIDCHIP User Guide
AMERICAS ASIA/PACIFIC ASIA/PACIFIC EUROPE
Corporate Office
2355 West Chandler Blvd.
Chandler, AZ 85224-6199
Tel: 480-792-7200
Fax: 480-792-7277
Technical Support:
http://www.microchip.com/support
Web Address:
http://www.microchip.com
Atlanta
Duluth, GA
Tel: 678-957-9614
Fax: 678-957-1455
Austin, TX
Tel: 512-257-3370
Boston
Westborough, MA
Tel: 774-760-0087
Fax: 774-760-0088
Chicago
Itasca, IL
Tel: 630-285-0071
Fax: 630-285-0075
Dallas
Addison, TX
Tel: 972-818-7423
Fax: 972-818-2924
Detroit
Novi, MI
Tel: 248-848-4000
Houston, TX
Tel: 281-894-5983
Indianapolis
Noblesville, IN
Tel: 317-773-8323
Fax: 317-773-5453
Tel: 317-536-2380
Los Angeles
Mission Viejo, CA
Tel: 949-462-9523
Fax: 949-462-9608
Tel: 951-273-7800
Raleigh, NC
Tel: 919-844-7510
New York, NY
Tel: 631-435-6000
San Jose, CA
Tel: 408-735-9110
Tel: 408-436-4270
Canada - Toronto
Tel: 905-695-1980
Fax: 905-695-2078
Australia - Sydney
Tel: 61-2-9868-6733
China - Beijing
Tel: 86-10-8569-7000
China - Chengdu
Tel: 86-28-8665-5511
China - Chongqing
Tel: 86-23-8980-9588
China - Dongguan
Tel: 86-769-8702-9880
China - Guangzhou
Tel: 86-20-8755-8029
China - Hangzhou
Tel: 86-571-8792-8115
China - Hong Kong SAR
Tel: 852-2943-5100
China - Nanjing
Tel: 86-25-8473-2460
China - Qingdao
Tel: 86-532-8502-7355
China - Shanghai
Tel: 86-21-3326-8000
China - Shenyang
Tel: 86-24-2334-2829
China - Shenzhen
Tel: 86-755-8864-2200
China - Suzhou
Tel: 86-186-6233-1526
China - Wuhan
Tel: 86-27-5980-5300
China - Xian
Tel: 86-29-8833-7252
China - Xiamen
Tel: 86-592-2388138
China - Zhuhai
Tel: 86-756-3210040
India - Bangalore
Tel: 91-80-3090-4444
India - New Delhi
Tel: 91-11-4160-8631
India - Pune
Tel: 91-20-4121-0141
Japan - Osaka
Tel: 81-6-6152-7160
Japan - Tokyo
Tel: 81-3-6880- 3770
Korea - Daegu
Tel: 82-53-744-4301
Korea - Seoul
Tel: 82-2-554-7200
Malaysia - Kuala Lumpur
Tel: 60-3-7651-7906
Malaysia - Penang
Tel: 60-4-227-8870
Philippines - Manila
Tel: 63-2-634-9065
Singapore
Tel: 65-6334-8870
Taiwan - Hsin Chu
Tel: 886-3-577-8366
Taiwan - Kaohsiung
Tel: 886-7-213-7830
Taiwan - Taipei
Tel: 886-2-2508-8600
Thailand - Bangkok
Tel: 66-2-694-1351
Vietnam - Ho Chi Minh
Tel: 84-28-5448-2100
Austria - Wels
Tel: 43-7242-2244-39
Fax: 43-7242-2244-393
Denmark - Copenhagen
Tel: 45-4450-2828
Fax: 45-4485-2829
Finland - Espoo
Tel: 358-9-4520-820
France - Paris
Tel: 33-1-69-53-63-20
Fax: 33-1-69-30-90-79
Germany - Garching
Tel: 49-8931-9700
Germany - Haan
Tel: 49-2129-3766400
Germany - Heilbronn
Tel: 49-7131-72400
Germany - Karlsruhe
Tel: 49-721-625370
Germany - Munich
Tel: 49-89-627-144-0
Fax: 49-89-627-144-44
Germany - Rosenheim
Tel: 49-8031-354-560
Israel - Ra’anana
Tel: 972-9-744-7705
Italy - Milan
Tel: 39-0331-742611
Fax: 39-0331-466781
Italy - Padova
Tel: 39-049-7625286
Netherlands - Drunen
Tel: 31-416-690399
Fax: 31-416-690340
Norway - Trondheim
Tel: 47-72884388
Poland - Warsaw
Tel: 48-22-3325737
Romania - Bucharest
Tel: 40-21-407-87-50
Spain - Madrid
Tel: 34-91-708-08-90
Fax: 34-91-708-08-91
Sweden - Gothenberg
Tel: 46-31-704-60-40
Sweden - Stockholm
Tel: 46-8-5090-4654
UK - Wokingham
Tel: 44-118-921-5800
Fax: 44-118-921-5820
Worldwide Sales and Service
© 2020 Microchip Technology Inc. User Guide DS50002958A-page 10