Smart Home Automation using W5100S-EVB-Pico

To turn normal devices to smart devices by creating an automated environment by making use of W5100s-evb-pico
ORIGINAL POST
By Albin Joseph
components
Hardware Components
WIZnet W5100S-EVB-Pico
X 1
ElectroPeak 0.96" OLED 64x128 Display Module
X 2
8 channel relay module
X 1
plywood
X 1
Acrylic sheets
X 1
chloroform
X 1
cd drive
X 1
Breadboard (generic)
X 2
Li-Ion Battery 1000mAh
X 1
Jumper wires (generic)
X 10
Software Apps and online services
Apple Siri
Google Assistant SDK
Amazon Alexa Alexa Skills Kit
Youtube Video Link
details

123.png

Contents:-

1) Quick Intro to W5500-EVB-Pico

  • 1) Quick Intro to W5500-EVB-Pico

2) Intro to Project / Aim of the Project

  • 2) Intro to Project / Aim of the Project

3) Block Diagram of the Project

  • 3) Block Diagram of the Project

4) Hardware and Material Used

  • 4) Hardware and Material Used

5) Problems Challenges and Solutions

  • 5) Problems Challenges and Solutions

6) R&D

  • 6) R&D

7) Flow Diagram for Alexa and Google Assistant

with Developer Console Images

  • 7) Flow Diagram for Alexa and Google Assistantwith Developer Console Images

8) Sample Shortcuts Code and Shortcuts

Achievement

  • 8) Sample Shortcuts Code and ShortcutsAchievement

9) Circuit Python Code and Adafruit IO Dashboard

  • 9) Circuit Python Code and Adafruit IO Dashboard

10) Results and Conclusion

  • 10) Results and Conclusion

2

Problem Statement

To convert normal home devices to smart home devices by

creating an automated environment at a cheaper cost by

making use of W5100s-evb-pico with internet connectivity

and by proving it with a mini home demo model to create a

similar environment as that of an actual home.

3

1) Quick Intro to W5500-EVB-Pico

W5500-EVB-Pico is a microcontroller evaluation board based on the Raspberry Pi RP2040 and fully hardwired TCP/IP controller W5500 – and basically works the same as Raspberry Pi Pico board but with additional Ethernet via W5500.

Raspberry Pi Pico Clone

  • Raspberry Pi Pico Clone

Ethernet (W5500 Hardwired TCP/IP CHIP)

It is one of the best things on the planet from Wiznet!

More details can be found I the following link :-

https://docs.wiznet.io/Product/iEthernet/W5500/w5500- evb-pico/

📷 📷

4

2) Intro to Project / Aim of the Project

The Aim of the project is to turn normal home devices to smart devices by creating an automated environment with the help of W5100s-evb-pico with internet connectivity to create a low cost home automation setup.

The Below was the proposed project flyer…. But things changed… changed for good… you will find out.

5

3) Block Diagram of the Project

The above Block Diagram shows the interaction flow (behind the scenes) of what actually happens when you interact with your favourite assistant !

6

4) Hardware and Material Used

W5500-EVB-Pico ————————————– x 1

0.9 Inch OLED Display ——————————– x2

Bread Board ——————————————– x1 8 Channel Relay Module —————————- x1 Mini fans ———————————————— x2 DC Motor and Fan Blade —————————- x1 0.5μF capacitor for DC Motor ———————- x1

Acrylic Sheets 3 types ——————————– x5

Plywood 2 types ————————————— x2

False Ceiling Lights ———————————— x3 Old CD/DVD Drive ————————————- x1

📷 📷 📷 📷 📷 📷 📷 📷 📷 📷 📷

7

5) Problems, Challenges and Solutions

There were many challenges faced starting from gathering the right parts but the main issue that was face was when the I tried to use a DC Motor fan, somehow the back EMF and magnetic interference was causing the relay module to stop functioning as soon as the motor starts and because the relay malfunctioned it was resetting the circuit python program and used to go on this reset loop finally causing the board to freeze and I had to end up nuking the board and re-flashing circuit python and the code.Well actually there seemed two ways to solve this problem and the first and easy way was to replace the dc motor (which is used as hall fan) to a tiny propeller which would instantly solve the problem, but instead I went the tough way to solve this problem and started to learn about the reason behind it and solve it, it took me almost 3 weeks to find the solution to this, and at the end I was able to solve it using a 0.5μF capacitor which was connected in parallel to the DC motor along with a 1 ohm resistor, which did the job, but also a varistor could have been used too to solve this which unfortunately seemed to be very rare to find.

The other problem faced was to stick the Acrylic sheets together the available solvents and glue was not at all strong enough to hold it in place so I had to research and develop a solvent along with my father, the solvent was made by dropping acrylic pieces into Chloroform and using that solution to weld it together after cleaning up with alcohol The Acrylic sticks together due to chemical bonding.

8

6) R&D

First thing to start off with the project was to create an actual house model and it was almost impossible to join the acrylic sheets together it seemed to fall off one by one causing a tiny domino effect. Somehow I had to figure out a way to fix those sheets together so after a bit of research me along with my dad was able to drop some acrylic sheets into chloroform to prepare its on solvent which made it bond at a molecular level.

The other part where the R&D was done was on the software side… well I could have made use of IFTTT (Short for IF This Then That) a 3rd party service that can be used to connect Adafruit IO’s feeds with Google Assistant or Alexa and can also be used to connect Siri with Adafruit IO’s feeds by making use of webhooks provided by IFTTT which seemed easy and pretty straight forward right? And indeed it was my first plan and that is why you did see IFTTT on my initial project proposal flyer.

I was also wondering if I could just make Api calls and directly interact with Adafruit IO feeds as I was graving to know how it worked and I started to feel it to myself, “What if I could get rid of IFTTT, after all it is just a 3rd party” and so I ended up in this Adafruit IO’s Api page which is located athttps://io.adafruit.com/api/docs/#adafruit-io-http-api but most of it just showed how to fetch the data from in and not how to make use of it to trigger a feed, so after a few

9

trial and error I was able to find the right method to send the value to trigger the feed using curl in terminal which led a way to completely let go of IFTTT and send out POST request to actually trigger the Adafruit Io’s feed, it has also made it possible for me to later found a way to integrate it into Siri without using webhooks and directly sending requests to Adafruit IO’s feeds and I can bet you can never find how it is done on shortcuts over the internet as I did search for the same across many forms, articles, YouTube videos and tutorial points they all just seemed know how to connect shortcuts to Adafruit IO’s feed only with IFTTT. more of these details can be found in module 10 of this document.

10

7) Flow Diagram for Alexa and Google Assistant

11

12

Alexa Developer console :-

📷📷

13

Google Assistant Developer Console:-

📷 📷

14

8) Sample Shortcuts Code and Shortcuts Achievement

The below pictures shows the shortcuts dashboard and a few code snippets:-

Siri Shortcuts Dashboard:-

Sample Shortcuts Code POST Method:-

15

The most difficult part faced in Apple shortcuts was to make a proper POST request which would send the value to Adafruit IO, usually people just make use of a 3rd party service called IFTTT to get a webhook which actually behind the scenes perform a post request however the correct Api format to make a https based POST request via Apple shortcuts in unavailable on the internet which seemed to be a small but great achievement to completely get rid of any 3rd party service especially IFTTT.

16

9) Circuit Python Code and Adafruit IO Dashboard

1. # Albin’s Code

import board
import board

import busio
import busio

import digitalio
import digitalio

import time
import time

from random import randint
from random import randint

from adafruit_wiznet5k.adafruit_wiznet5k import *
from adafruit_wiznet5k.adafruit_wiznet5k import *

import adafruit_wiznet5k.adafruit_wiznet5k_socket as socket
import adafruit_wiznet5k.adafruit_wiznet5k_socket as socket

10.
from adafruit_io.adafruit_io import IO_MQTT
from adafruit_io.adafruit_io import IO_MQTT

import adafruit_minimqtt.adafruit_minimqtt as MQTT
import adafruit_minimqtt.adafruit_minimqtt as MQTT

from secrets import secrets
from secrets import secrets

14.
15. from time import sleep
16.
17. # /////////////Display Import\\\\ 18.
import displayio
import displayio

import terminalio
import terminalio

import adafruit_displayio_ssd1306
import adafruit_displayio_ssd1306

from adafruit_display_text import label
from adafruit_display_text import label

23.
24. # /////////////////////////////////////// 25.
26. displayio.release_displays()
27.
# ///////////////LIVE SERIAL DISPLAY///////////////
# ///////////////LIVE SERIAL DISPLAY///////////////

i2c = busio.I2C (scl=board.GP1, sda=board.GP0) # This RPi Pico way to call I2C
i2c = busio.I2C (scl=board.GP1, sda=board.GP0) # This RPi Pico way to call I2C

display_bus = displayio.I2CDisplay (i2c, device_address = 0x3C) # The address of my
Board
display_bus = displayio.I2CDisplay (i2c, device_address = 0x3C) # The address of my
Board

display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=55)
display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=55)

# ///////////////LIVE SERIAL DISPLAY///////////////
# ///////////////LIVE SERIAL DISPLAY///////////////

33.
34. # Set your Adafruit IO Username and Key in secrets.py
35.
aio_username = secrets["aio_username"]
aio_username = secrets["aio_username"]

aio_key = secrets["aio_key"]
aio_key = secrets["aio_key"]

38.
##SPI
##SPI

SPI0_SCK = board.GP18
SPI0_SCK = board.GP18

SPI0_TX = board.GP19
SPI0_TX = board.GP19

SPI0_RX = board.GP16
SPI0_RX = board.GP16

17
43. SPI0_CSn = board.GP17 44.
#Reset
#Reset

W5x00_RSTn = board.GP20
W5x00_RSTn = board.GP20

47.
print(" ""HOME AUTOMATION" "n" " WIZNET CONTEST" "n" "
print(" ""HOME AUTOMATION" "n" " WIZNET CONTEST" "n" "

sleep(4)
sleep(4)

print("n" " Created by" "n" " " "Albin Joseph")
print("n" " Created by" "n" " " "Albin Joseph")

sleep(4)
sleep(4)

52.
print("Pinging Adafruit IO""n"" Wiznet5k (DHCP)")
print("Pinging Adafruit IO""n"" Wiznet5k (DHCP)")

# Setup your network configuration below
# Setup your network configuration below

# random MAC, later should change this value on your vendor ID
# random MAC, later should change this value on your vendor ID

MY_MAC = (0x00, 0x01, 0x02, 0x03, 0x04, 0x05)
MY_MAC = (0x00, 0x01, 0x02, 0x03, 0x04, 0x05)

IP_ADDRESS = (192, 168, 1, 100)
IP_ADDRESS = (192, 168, 1, 100)

SUBNET_MASK = (255, 255, 255, 0)
SUBNET_MASK = (255, 255, 255, 0)

GATEWAY_ADDRESS = (192, 168, 1, 1)
GATEWAY_ADDRESS = (192, 168, 1, 1)

DNS_SERVER = (8, 8, 8, 8)
DNS_SERVER = (8, 8, 8, 8)

61.
ethernetRst = digitalio.DigitalInOut(W5x00_RSTn)
ethernetRst = digitalio.DigitalInOut(W5x00_RSTn)

ethernetRst.direction = digitalio.Direction.OUTPUT
ethernetRst.direction = digitalio.Direction.OUTPUT

64.
# For Adafruit Ethernet FeatherWing
# For Adafruit Ethernet FeatherWing

cs = digitalio.DigitalInOut(SPI0_CSn)
cs = digitalio.DigitalInOut(SPI0_CSn)

# For Particle Ethernet FeatherWing
# For Particle Ethernet FeatherWing

# cs = digitalio.DigitalInOut(board.D5)
# cs = digitalio.DigitalInOut(board.D5)

69.
70. spi_bus = busio.SPI(SPI0_SCK, MOSI=SPI0_TX, MISO=SPI0_RX) 71.
# Reset W5x00 first
# Reset W5x00 first

ethernetRst.value = False
ethernetRst.value = False

time.sleep(1)
time.sleep(1)

ethernetRst.value = True
ethernetRst.value = True

76.
# Initialize ethernet interface with DHCP
# Initialize ethernet interface with DHCP

eth = WIZNET5K(spi_bus, cs, is_dhcp=True, mac=MY_MAC, debug=False)
eth = WIZNET5K(spi_bus, cs, is_dhcp=True, mac=MY_MAC, debug=False)

79.
print("Chip Version:", eth.chip)
print("Chip Version:", eth.chip)

print("MAC Address:", [hex(i) for i in eth.mac_address])
print("MAC Address:", [hex(i) for i in eth.mac_address])

print("My IP address is:", eth.pretty_ip(eth.ip_address))
print("My IP address is:", eth.pretty_ip(eth.ip_address))

83.
### Code ###
### Code ###

# Define callback methods which are called when events occur
# Define callback methods which are called when events occur

# pylint: disable=unused-argument, redefined-outer-name
# pylint: disable=unused-argument, redefined-outer-name

87. def 88. 89. 90. 91. 92. 93. 94. 95. def 96. 97. 98. 99. 100. 101. 102. 103. 104. 105. 106. 107. 108.
connected(clinet):
# This function will be called when the mqtt_client is connected # successfully to the broker.
print("Connected to Adafruit IO!")
# Subscribe to Group
io.subscribe(group_key=group_name)
disconnected(clinet):
# This method is called when the mqtt_client disconnects # from the broker.
print("Disconnected from Adafruit IO!")
def subscribe(client, userdata, topic, granted_qos):
# This method is called when the client subscribes to a new feed. print("Subscribed to {0} with QOS level {1}".format(topic, granted_qos))
def message(client, topic, message):
# Method called when a client's subscribed feed has a new value. print(" {0}: {1}".format(topic, message))
# Board LED CONTROL ////////////////////////////////////////////////////////////////////////////////////
109. BoardLed = digitalio.DigitalInOut(board.GP25) 110. BoardLed.direction = digitalio.Direction.OUTPUT 111.
" "2022")
18
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
ExternalLed = digitalio.DigitalInOut(board.GP2)
ExternalLed = digitalio.DigitalInOut(board.GP2)

ExternalLed.direction = digitalio.Direction.OUTPUT
ExternalLed.direction = digitalio.Direction.OUTPUT

125.
def on_ExternalLed_msg(client, topic, message):
def on_ExternalLed_msg(client, topic, message):

# Method called when a client's subscribed feed has a new value.
# Method called when a client's subscribed feed has a new value.

print(" {0}: {1}".format(topic, message))
print(" {0}: {1}".format(topic, message))

if message == "on":
if message == "on":

ExternalLed.value = True
ExternalLed.value = True

elif message == "off":
elif message == "off":

ExternalLed.value = False
ExternalLed.value = False

else:
else:

print("Unexpected message on ExternalLed feed")
print("Unexpected message on ExternalLed feed")

135.
136. # KITCHEN FAN CONTROL
////////////////////////////////////////////////////////////////////////////////////
KitchenFan = digitalio.DigitalInOut(board.GP7)
KitchenFan = digitalio.DigitalInOut(board.GP7)

KitchenFan.direction = digitalio.Direction.OUTPUT
KitchenFan.direction = digitalio.Direction.OUTPUT

139.
def on_KitchenFan_msg(client, topic, message):
def on_KitchenFan_msg(client, topic, message):

# Method called when a client's subscribed feed has a new value.
# Method called when a client's subscribed feed has a new value.

print(" {0}: {1}".format(topic, message))
print(" {0}: {1}".format(topic, message))

if message == "on":
if message == "on":

KitchenFan.value = True
KitchenFan.value = True

elif message == "off":
elif message == "off":

KitchenFan.value = False
KitchenFan.value = False

else:
else:

print("Unexpected message on KitchenFan feed")
print("Unexpected message on KitchenFan feed")

149.
150. # BEDROOM FAN CONTROL
////////////////////////////////////////////////////////////////////////////////////
BedroomFan = digitalio.DigitalInOut(board.GP6)
BedroomFan = digitalio.DigitalInOut(board.GP6)

BedroomFan.direction = digitalio.Direction.OUTPUT
BedroomFan.direction = digitalio.Direction.OUTPUT

153.
def on_BedroomFan_msg(client, topic, message):
def on_BedroomFan_msg(client, topic, message):

# Method called when a client's subscribed feed has a new value.
# Method called when a client's subscribed feed has a new value.

print(" {0}: {1}".format(topic, message))
print(" {0}: {1}".format(topic, message))

if message == "on":
if message == "on":

BedroomFan.value = True
BedroomFan.value = True

elif message == "off":
elif message == "off":

BedroomFan.value = False
BedroomFan.value = False

else:
else:

print("Unexpected message on BedroomFan feed")
print("Unexpected message on BedroomFan feed")

163.
164. # HALL FAN CONTROL GPIO PIN CONTROL
////////////////////////////////////////////////////////////////////////////////////
165.
#
#

#
#

168.
#
#

#
#

#
#

#
#

#
#

#
#

#
#

176. # 177. #
HallFan = digitalio.DigitalInOut(board.GP22) HallFan.direction = digitalio.Direction.OUTPUT
def on_HallFan_msg(client, topic, message):
Method called when a client's subscribed feed has a new value.
print(" {0}: {1}".format(topic, message)) if message == "on":
HallFan.value = True elif message == "off":
HallFan.value = False else:
print("Unexpected message on HallFan feed")
def on_BoardLed_msg(client, topic, message):
# Method called when a client's subscribed feed has a new value. print(" {0}: {1}".format(topic, message))
if message == "on":
BoardLed.value = True elif message == "off":
BoardLed.value = False else:
print("Unexpected message on BoardLed feed")
# External LED CONTROL ////////////////////////////////////////////////////////////////////////////////////
19
178. 179. #
////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////
180.
181. # Relay CONTROL System (Low/False is ON
)////////////////////////////////////////////////////////////////////////////////////
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.
HallLight = digitalio.DigitalInOut(board.GP14)
HallLight = digitalio.DigitalInOut(board.GP14)

HallLight.direction = digitalio.Direction.OUTPUT
HallLight.direction = digitalio.Direction.OUTPUT

HallLight.value = True
HallLight.value = True

234.
def on_HallLight_msg(client, topic, message):
def on_HallLight_msg(client, topic, message):

# Method called when a client's subscribed feed has a new value.
# Method called when a client's subscribed feed has a new value.

print(" {0}: {1}".format(topic, message))
print(" {0}: {1}".format(topic, message))

if message == "on":
if message == "on":

HallLight.value = False
HallLight.value = False

elif message == "off":
elif message == "off":

HallLight.value = True
HallLight.value = True

else:
else:

print("Unexpected message on HallLight feed")
print("Unexpected message on HallLight feed")

244.
# //////// RelayTest \\\
RelayTest = digitalio.DigitalInOut(board.GP9) RelayTest.direction = digitalio.Direction.OUTPUT RelayTest.value = True
def on_RelayTest_msg(client, topic, message):
# Method called when a client's subscribed feed has a new value. print(" {0}: {1}".format(topic, message))
if message == "on":
RelayTest.value = False elif message == "off":
RelayTest.value = True else:
print("Unexpected message on RelayTest feed")
# //////// HALL FAN CONTROL (RELAY) \\\\
HallFan = digitalio.DigitalInOut(board.GP15) HallFan.direction = digitalio.Direction.OUTPUT HallFan.value = True
def on_HallFan_msg(client, topic, message):
## Method called when a client's subscribed feed has a new value.
print(" {0}: {1}".format(topic, message)) if message == "on":
HallFan.value = False elif message == "off":
HallFan.value = True else:
print("Unexpected message on HallFan feed")
# HallFanRelay = digitalio.DigitalInOut(board.GP15)
# HallFanRelay.direction = digitalio.Direction.OUTPUT # HallFanRelay.value = True
# def on_HallFanRelay_msg(client, topic, message):
## Method called when a client's subscribed feed has a new value.
# # # # #
print(" {0}: {1}".format(topic, message)) if message == "on":
HallFanRelay.value = False elif message == "off":
HallFanRelay.value = True else:
print("Unexpected message on HallFanRelay feed") //////// HALL LIGHT \\\")

# Initialize an Adafruit IO MQTT Client
# Initialize an Adafruit IO MQTT Client

io = IO_MQTT(mqtt_client)
io = IO_MQTT(mqtt_client)

311.
# Setup the callback methods above
# Setup the callback methods above

io.on_connect = connected
io.on_connect = connected

io.on_disconnect = disconnected
io.on_disconnect = disconnected

# //////// BEDROOM LIGHT \\\
BedroomLight = digitalio.DigitalInOut(board.GP13) BedroomLight.direction = digitalio.Direction.OUTPUT BedroomLight.value = True
def on_BedroomLight_msg(client, topic, message):
# Method called when a client's subscribed feed has a new value. print(" {0}: {1}".format(topic, message))
if message == "on":
BedroomLight.value = False elif message == "off":
BedroomLight.value = True else:
print("Unexpected message on BedroomLight feed") # //////// KITCHEN LIGHT \\\
KitchenLight = digitalio.DigitalInOut(board.GP12) KitchenLight.direction = digitalio.Direction.OUTPUT KitchenLight.value = True
def on_KitchenLight_msg(client, topic, message):
# Method called when a client's subscribed feed has a new value. print(" {0}: {1}".format(topic, message))
if message == "on":
KitchenLight.value = False elif message == "off":
KitchenLight.value = True else:
# //////// GateButton \\\
print("Unexpected message on KitchenLight feed") # *************GATE AUTOMATION*************
GateButton = digitalio.DigitalInOut(board.GP8) GateButton.direction = digitalio.Direction.OUTPUT GateButton.value = True
def on_GateButton_msg(client, topic, message):
# Method called when a client's subscribed feed has a new value. print(" {0}: {1}".format(topic, message))
if message == "on":
GateButton.value = False sleep(1)
GateButton.value = True print("Gate triggered!!") message == "off"
else:
print("GATE Triggered" "n" "with Adafruit IO" "n" "
" "!!")
# ////////////////////////////////////////////////////////////////////////////////////
# Initialize MQTT interface with the ethernet interface
MQTT.set_socket(socket, eth)
# Initialize a new MQTT Client object
mqtt_client = MQTT.MQTT( broker="io.adafruit.com", username=secrets["aio_username"], password=secrets["aio_key"], is_ssl=False,
21
io.on_message = message
io.on_message = message

io.on_subscribe = subscribe
io.on_subscribe = subscribe

317.
# Set up a callback for the BoardLed feed //////////////////////////////////////////
# Set up a callback for the BoardLed feed //////////////////////////////////////////

io.add_feed_callback("BoardLed", on_BoardLed_msg)
io.add_feed_callback("BoardLed", on_BoardLed_msg)

320.
321. # Set up a callback for the ExternalLed feed
//////////////////////////////////////////
322. io.add_feed_callback("ExternalLed", on_ExternalLed_msg) 323.
# Set up a callback for the KitchenFan feed //////////////////////////////////////////
# Set up a callback for the KitchenFan feed //////////////////////////////////////////

io.add_feed_callback("KitchenFan", on_KitchenFan_msg)
io.add_feed_callback("KitchenFan", on_KitchenFan_msg)

326.
# Set up a callback for the BedroomFan feed //////////////////////////////////////////
# Set up a callback for the BedroomFan feed //////////////////////////////////////////

io.add_feed_callback("BedroomFan", on_BedroomFan_msg)
io.add_feed_callback("BedroomFan", on_BedroomFan_msg)

329.
# Set up a callback for the HallFan feed //////////////////////////////////////////
# Set up a callback for the HallFan feed //////////////////////////////////////////

io.add_feed_callback("HallFan", on_HallFan_msg)
io.add_feed_callback("HallFan", on_HallFan_msg)

332.
333. # //////////////////////////////////////////////////////////////////////////////////// 334.
# Set up a callback for the RelayTest feed //////////////////////////////////////////
# Set up a callback for the RelayTest feed //////////////////////////////////////////

io.add_feed_callback("RelayTest", on_RelayTest_msg)
io.add_feed_callback("RelayTest", on_RelayTest_msg)

337.
338. ## Set up a callback for the HallFanRelay feed
//////////////////////////////////////////
339. # io.add_feed_callback("HallFanRelay", on_HallFanRelay_msg) 340.
# Set up a callback for the HallLight feed //////////////////////////////////////////
# Set up a callback for the HallLight feed //////////////////////////////////////////

io.add_feed_callback("HallLight", on_HallLight_msg)
io.add_feed_callback("HallLight", on_HallLight_msg)

343.
344. # Set up a callback for the BedroomLight feed
//////////////////////////////////////////
345. io.add_feed_callback("BedroomLight", on_BedroomLight_msg) 346.
347. # Set up a callback for the KitchenLight feed
//////////////////////////////////////////
348. io.add_feed_callback("KitchenLight", on_KitchenLight_msg) 349.
# Set up a callback for the GateButton feed //////////////////////////////////////////
# Set up a callback for the GateButton feed //////////////////////////////////////////

io.add_feed_callback("GateButton", on_GateButton_msg)
io.add_feed_callback("GateButton", on_GateButton_msg)

352.
## Group name
## Group name

group_name = "weatherstation" # Comenting Throws error need to check
group_name = "weatherstation" # Comenting Throws error need to check

355.
## Feeds within the group
## Feeds within the group

temp_feed = "weatherstation.temperature" # omenting Throws error need to check
temp_feed = "weatherstation.temperature" # omenting Throws error need to check

humid_feed = "weatherstation.humidity" # Comenting Throws error need to check
humid_feed = "weatherstation.humidity" # Comenting Throws error need to check

359.
# Connect to Adafruit IO
# Connect to Adafruit IO

print("Connecting to Adafruit IO...")
print("Connecting to Adafruit IO...")

io.connect()
io.connect()

363.
364. # ////////////////////////////ADD ON
SUBSCRIPTION////////////////////////////////////////////////////////
365.
# # Subscribe to all messages on the BoardLed feed
# # Subscribe to all messages on the BoardLed feed

io.subscribe("BoardLed")
io.subscribe("BoardLed")

368.
# # Subscribe to all messages on the ExternalLed feed
# # Subscribe to all messages on the ExternalLed feed

io.subscribe("ExternalLed")
io.subscribe("ExternalLed")

371.
# Subscribe to all messages
# Subscribe to all messages

io.subscribe("KitchenFan")
io.subscribe("KitchenFan")

374.
# Subscribe to all messages
# Subscribe to all messages

io.subscribe("BedroomFan")
io.subscribe("BedroomFan")

377.
# # Subscribe to all messages on the HallFan feed
# # Subscribe to all messages on the HallFan feed

io.subscribe("HallFan")
io.subscribe("HallFan")

on the KitchenFan feed on the BedroomFan feed
22
380.
381. # ////////////////////////////RELAY
SUBSCRIPTION////////////////////////////////////////////////////////
382.
# # Subscribe to all messages on the RelayTest feed
# # Subscribe to all messages on the RelayTest feed

io.subscribe("RelayTest")
io.subscribe("RelayTest")

385.
# Subscribe to all messages on the HallFanRelay feed
# Subscribe to all messages on the HallFanRelay feed

# io.subscribe("HallFanRelay")
# io.subscribe("HallFanRelay")

388.
# # Subscribe to all messages on the HallLight feed
# # Subscribe to all messages on the HallLight feed

io.subscribe("HallLight")
io.subscribe("HallLight")

391.
# # Subscribe to all messages on the BedroomLight feed
# # Subscribe to all messages on the BedroomLight feed

io.subscribe("BedroomLight")
io.subscribe("BedroomLight")

394.
# # Subscribe to all messages on the KitchenLight feed
# # Subscribe to all messages on the KitchenLight feed

io.subscribe("KitchenLight")
io.subscribe("KitchenLight")

397.
# # Subscribe to all messages on the GateButton feed
# # Subscribe to all messages on the GateButton feed

io.subscribe("GateButton")
io.subscribe("GateButton")

400.
401. # //////////////////////////////////////////////////////////////////////////////////// 402.
403. print("Connected to Adafruit IO")
print(" HandShake
print(" HandShake

print("WAITING FOR INPUT")
print("WAITING FOR INPUT")

406.
while True:
while True:

io.loop()
io.loop()

409

The Board was programmed using Circuit python, there were a few difficulties where the code was unresponsive and was required to be nuked with the flash_nuke.uf2 file.The editor that was widely used for this project was the Mu Editor and sometimes Visual Studio Code seemed easier for search. Below is the code used in the project:-

1.10) Results and Conclusion

Well the results were great! Automated gates lights and fans all powered by the lone board W5500-EVB-Pico programmed with circuit python, connected to Adafruit IO which was a possibility only because of Wiznet’s brilliant idea of adding an Ethernet (RJ45) port powered by the great W5500 hardwired TCP/IP chip and equally important wiznet 5k ethernet library and adafruit library which inspired and helped me complete this amazing project successfully.

I was also able to learn and gain a lot of experience from this project and I’m really grateful for this grand opportunity wiznet provided to us.

Please Note:-A video on this project including a working demo is being prepared which will be shared soon.

The below images in the following pages shows some images that I have captured :-

24

📷📷

25

📷📷

26

📷📷

27

📷📷

28

29

30

📷📷

31

📷📷

32

33

📷📷

34

📷📷📷

35

📷📷

36

123.png

Contents:-

1) Quick Intro to W5500-EVB-Pico

  • 1) Quick Intro to W5500-EVB-Pico

2) Intro to Project / Aim of the Project

  • 2) Intro to Project / Aim of the Project

3) Block Diagram of the Project

  • 3) Block Diagram of the Project

4) Hardware and Material Used

  • 4) Hardware and Material Used

5) Problems Challenges and Solutions

  • 5) Problems Challenges and Solutions

6) R&D

  • 6) R&D

7) Flow Diagram for Alexa and Google Assistant

with Developer Console Images

  • 7) Flow Diagram for Alexa and Google Assistantwith Developer Console Images

8) Sample Shortcuts Code and Shortcuts

Achievement

  • 8) Sample Shortcuts Code and ShortcutsAchievement

9) Circuit Python Code and Adafruit IO Dashboard

  • 9) Circuit Python Code and Adafruit IO Dashboard

10) Results and Conclusion

  • 10) Results and Conclusion

2

Problem Statement

To convert normal home devices to smart home devices by

creating an automated environment at a cheaper cost by

making use of W5100s-evb-pico with internet connectivity

and by proving it with a mini home demo model to create a

similar environment as that of an actual home.

3

1) Quick Intro to W5500-EVB-Pico

W5500-EVB-Pico is a microcontroller evaluation board based on the Raspberry Pi RP2040 and fully hardwired TCP/IP controller W5500 – and basically works the same as Raspberry Pi Pico board but with additional Ethernet via W5500.

Raspberry Pi Pico Clone

  • Raspberry Pi Pico Clone

Ethernet (W5500 Hardwired TCP/IP CHIP)

It is one of the best things on the planet from Wiznet!

More details can be found I the following link :-

https://docs.wiznet.io/Product/iEthernet/W5500/w5500- evb-pico/

📷 📷

4

2) Intro to Project / Aim of the Project

The Aim of the project is to turn normal home devices to smart devices by creating an automated environment with the help of W5100s-evb-pico with internet connectivity to create a low cost home automation setup.

The Below was the proposed project flyer…. But things changed… changed for good… you will find out.

5

3) Block Diagram of the Project

The above Block Diagram shows the interaction flow (behind the scenes) of what actually happens when you interact with your favourite assistant !

6

4) Hardware and Material Used

W5500-EVB-Pico ————————————– x 1

0.9 Inch OLED Display ——————————– x2

Bread Board ——————————————– x1 8 Channel Relay Module —————————- x1 Mini fans ———————————————— x2 DC Motor and Fan Blade —————————- x1 0.5μF capacitor for DC Motor ———————- x1

Acrylic Sheets 3 types ——————————– x5

Plywood 2 types ————————————— x2

False Ceiling Lights ———————————— x3 Old CD/DVD Drive ————————————- x1

📷 📷 📷 📷 📷 📷 📷 📷 📷 📷 📷

7

5) Problems, Challenges and Solutions

There were many challenges faced starting from gathering the right parts but the main issue that was face was when the I tried to use a DC Motor fan, somehow the back EMF and magnetic interference was causing the relay module to stop functioning as soon as the motor starts and because the relay malfunctioned it was resetting the circuit python program and used to go on this reset loop finally causing the board to freeze and I had to end up nuking the board and re-flashing circuit python and the code.Well actually there seemed two ways to solve this problem and the first and easy way was to replace the dc motor (which is used as hall fan) to a tiny propeller which would instantly solve the problem, but instead I went the tough way to solve this problem and started to learn about the reason behind it and solve it, it took me almost 3 weeks to find the solution to this, and at the end I was able to solve it using a 0.5μF capacitor which was connected in parallel to the DC motor along with a 1 ohm resistor, which did the job, but also a varistor could have been used too to solve this which unfortunately seemed to be very rare to find.

The other problem faced was to stick the Acrylic sheets together the available solvents and glue was not at all strong enough to hold it in place so I had to research and develop a solvent along with my father, the solvent was made by dropping acrylic pieces into Chloroform and using that solution to weld it together after cleaning up with alcohol The Acrylic sticks together due to chemical bonding.

8

6) R&D

First thing to start off with the project was to create an actual house model and it was almost impossible to join the acrylic sheets together it seemed to fall off one by one causing a tiny domino effect. Somehow I had to figure out a way to fix those sheets together so after a bit of research me along with my dad was able to drop some acrylic sheets into chloroform to prepare its on solvent which made it bond at a molecular level.

The other part where the R&D was done was on the software side… well I could have made use of IFTTT (Short for IF This Then That) a 3rd party service that can be used to connect Adafruit IO’s feeds with Google Assistant or Alexa and can also be used to connect Siri with Adafruit IO’s feeds by making use of webhooks provided by IFTTT which seemed easy and pretty straight forward right? And indeed it was my first plan and that is why you did see IFTTT on my initial project proposal flyer.

I was also wondering if I could just make Api calls and directly interact with Adafruit IO feeds as I was graving to know how it worked and I started to feel it to myself, “What if I could get rid of IFTTT, after all it is just a 3rd party” and so I ended up in this Adafruit IO’s Api page which is located athttps://io.adafruit.com/api/docs/#adafruit-io-http-api but most of it just showed how to fetch the data from in and not how to make use of it to trigger a feed, so after a few

9

trial and error I was able to find the right method to send the value to trigger the feed using curl in terminal which led a way to completely let go of IFTTT and send out POST request to actually trigger the Adafruit Io’s feed, it has also made it possible for me to later found a way to integrate it into Siri without using webhooks and directly sending requests to Adafruit IO’s feeds and I can bet you can never find how it is done on shortcuts over the internet as I did search for the same across many forms, articles, YouTube videos and tutorial points they all just seemed know how to connect shortcuts to Adafruit IO’s feed only with IFTTT. more of these details can be found in module 10 of this document.

10

7) Flow Diagram for Alexa and Google Assistant

11

12

Alexa Developer console :-

📷📷

13

Google Assistant Developer Console:-

📷 📷

14

8) Sample Shortcuts Code and Shortcuts Achievement

The below pictures shows the shortcuts dashboard and a few code snippets:-

Siri Shortcuts Dashboard:-

Sample Shortcuts Code POST Method:-

15

The most difficult part faced in Apple shortcuts was to make a proper POST request which would send the value to Adafruit IO, usually people just make use of a 3rd party service called IFTTT to get a webhook which actually behind the scenes perform a post request however the correct Api format to make a https based POST request via Apple shortcuts in unavailable on the internet which seemed to be a small but great achievement to completely get rid of any 3rd party service especially IFTTT.

16

9) Circuit Python Code and Adafruit IO Dashboard

1. # Albin’s Code

import board
import board

import busio
import busio

import digitalio
import digitalio

import time
import time

from random import randint
from random import randint

from adafruit_wiznet5k.adafruit_wiznet5k import *
from adafruit_wiznet5k.adafruit_wiznet5k import *

import adafruit_wiznet5k.adafruit_wiznet5k_socket as socket
import adafruit_wiznet5k.adafruit_wiznet5k_socket as socket

10.
from adafruit_io.adafruit_io import IO_MQTT
from adafruit_io.adafruit_io import IO_MQTT

import adafruit_minimqtt.adafruit_minimqtt as MQTT
import adafruit_minimqtt.adafruit_minimqtt as MQTT

from secrets import secrets
from secrets import secrets

14.
15. from time import sleep
16.
17. # /////////////Display Import\\\\ 18.
import displayio
import displayio

import terminalio
import terminalio

import adafruit_displayio_ssd1306
import adafruit_displayio_ssd1306

from adafruit_display_text import label
from adafruit_display_text import label

23.
24. # /////////////////////////////////////// 25.
26. displayio.release_displays()
27.
# ///////////////LIVE SERIAL DISPLAY///////////////
# ///////////////LIVE SERIAL DISPLAY///////////////

i2c = busio.I2C (scl=board.GP1, sda=board.GP0) # This RPi Pico way to call I2C
i2c = busio.I2C (scl=board.GP1, sda=board.GP0) # This RPi Pico way to call I2C

display_bus = displayio.I2CDisplay (i2c, device_address = 0x3C) # The address of my
Board
display_bus = displayio.I2CDisplay (i2c, device_address = 0x3C) # The address of my
Board

display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=55)
display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=55)

# ///////////////LIVE SERIAL DISPLAY///////////////
# ///////////////LIVE SERIAL DISPLAY///////////////

33.
34. # Set your Adafruit IO Username and Key in secrets.py
35.
aio_username = secrets["aio_username"]
aio_username = secrets["aio_username"]

aio_key = secrets["aio_key"]
aio_key = secrets["aio_key"]

38.
##SPI
##SPI

SPI0_SCK = board.GP18
SPI0_SCK = board.GP18

SPI0_TX = board.GP19
SPI0_TX = board.GP19

SPI0_RX = board.GP16
SPI0_RX = board.GP16

17
43. SPI0_CSn = board.GP17 44.
#Reset
#Reset

W5x00_RSTn = board.GP20
W5x00_RSTn = board.GP20

47.
print(" ""HOME AUTOMATION" "n" " WIZNET CONTEST" "n" "
print(" ""HOME AUTOMATION" "n" " WIZNET CONTEST" "n" "

sleep(4)
sleep(4)

print("n" " Created by" "n" " " "Albin Joseph")
print("n" " Created by" "n" " " "Albin Joseph")

sleep(4)
sleep(4)

52.
print("Pinging Adafruit IO""n"" Wiznet5k (DHCP)")
print("Pinging Adafruit IO""n"" Wiznet5k (DHCP)")

# Setup your network configuration below
# Setup your network configuration below

# random MAC, later should change this value on your vendor ID
# random MAC, later should change this value on your vendor ID

MY_MAC = (0x00, 0x01, 0x02, 0x03, 0x04, 0x05)
MY_MAC = (0x00, 0x01, 0x02, 0x03, 0x04, 0x05)

IP_ADDRESS = (192, 168, 1, 100)
IP_ADDRESS = (192, 168, 1, 100)

SUBNET_MASK = (255, 255, 255, 0)
SUBNET_MASK = (255, 255, 255, 0)

GATEWAY_ADDRESS = (192, 168, 1, 1)
GATEWAY_ADDRESS = (192, 168, 1, 1)

DNS_SERVER = (8, 8, 8, 8)
DNS_SERVER = (8, 8, 8, 8)

61.
ethernetRst = digitalio.DigitalInOut(W5x00_RSTn)
ethernetRst = digitalio.DigitalInOut(W5x00_RSTn)

ethernetRst.direction = digitalio.Direction.OUTPUT
ethernetRst.direction = digitalio.Direction.OUTPUT

64.
# For Adafruit Ethernet FeatherWing
# For Adafruit Ethernet FeatherWing

cs = digitalio.DigitalInOut(SPI0_CSn)
cs = digitalio.DigitalInOut(SPI0_CSn)

# For Particle Ethernet FeatherWing
# For Particle Ethernet FeatherWing

# cs = digitalio.DigitalInOut(board.D5)
# cs = digitalio.DigitalInOut(board.D5)

69.
70. spi_bus = busio.SPI(SPI0_SCK, MOSI=SPI0_TX, MISO=SPI0_RX) 71.
# Reset W5x00 first
# Reset W5x00 first

ethernetRst.value = False
ethernetRst.value = False

time.sleep(1)
time.sleep(1)

ethernetRst.value = True
ethernetRst.value = True

76.
# Initialize ethernet interface with DHCP
# Initialize ethernet interface with DHCP

eth = WIZNET5K(spi_bus, cs, is_dhcp=True, mac=MY_MAC, debug=False)
eth = WIZNET5K(spi_bus, cs, is_dhcp=True, mac=MY_MAC, debug=False)

79.
print("Chip Version:", eth.chip)
print("Chip Version:", eth.chip)

print("MAC Address:", [hex(i) for i in eth.mac_address])
print("MAC Address:", [hex(i) for i in eth.mac_address])

print("My IP address is:", eth.pretty_ip(eth.ip_address))
print("My IP address is:", eth.pretty_ip(eth.ip_address))

83.
### Code ###
### Code ###

# Define callback methods which are called when events occur
# Define callback methods which are called when events occur

# pylint: disable=unused-argument, redefined-outer-name
# pylint: disable=unused-argument, redefined-outer-name

87. def 88. 89. 90. 91. 92. 93. 94. 95. def 96. 97. 98. 99. 100. 101. 102. 103. 104. 105. 106. 107. 108.
connected(clinet):
# This function will be called when the mqtt_client is connected # successfully to the broker.
print("Connected to Adafruit IO!")
# Subscribe to Group
io.subscribe(group_key=group_name)
disconnected(clinet):
# This method is called when the mqtt_client disconnects # from the broker.
print("Disconnected from Adafruit IO!")
def subscribe(client, userdata, topic, granted_qos):
# This method is called when the client subscribes to a new feed. print("Subscribed to {0} with QOS level {1}".format(topic, granted_qos))
def message(client, topic, message):
# Method called when a client's subscribed feed has a new value. print(" {0}: {1}".format(topic, message))
# Board LED CONTROL ////////////////////////////////////////////////////////////////////////////////////
109. BoardLed = digitalio.DigitalInOut(board.GP25) 110. BoardLed.direction = digitalio.Direction.OUTPUT 111.
" "2022")
18
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
ExternalLed = digitalio.DigitalInOut(board.GP2)
ExternalLed = digitalio.DigitalInOut(board.GP2)

ExternalLed.direction = digitalio.Direction.OUTPUT
ExternalLed.direction = digitalio.Direction.OUTPUT

125.
def on_ExternalLed_msg(client, topic, message):
def on_ExternalLed_msg(client, topic, message):

# Method called when a client's subscribed feed has a new value.
# Method called when a client's subscribed feed has a new value.

print(" {0}: {1}".format(topic, message))
print(" {0}: {1}".format(topic, message))

if message == "on":
if message == "on":

ExternalLed.value = True
ExternalLed.value = True

elif message == "off":
elif message == "off":

ExternalLed.value = False
ExternalLed.value = False

else:
else:

print("Unexpected message on ExternalLed feed")
print("Unexpected message on ExternalLed feed")

135.
136. # KITCHEN FAN CONTROL
////////////////////////////////////////////////////////////////////////////////////
KitchenFan = digitalio.DigitalInOut(board.GP7)
KitchenFan = digitalio.DigitalInOut(board.GP7)

KitchenFan.direction = digitalio.Direction.OUTPUT
KitchenFan.direction = digitalio.Direction.OUTPUT

139.
def on_KitchenFan_msg(client, topic, message):
def on_KitchenFan_msg(client, topic, message):

# Method called when a client's subscribed feed has a new value.
# Method called when a client's subscribed feed has a new value.

print(" {0}: {1}".format(topic, message))
print(" {0}: {1}".format(topic, message))

if message == "on":
if message == "on":

KitchenFan.value = True
KitchenFan.value = True

elif message == "off":
elif message == "off":

KitchenFan.value = False
KitchenFan.value = False

else:
else:

print("Unexpected message on KitchenFan feed")
print("Unexpected message on KitchenFan feed")

149.
150. # BEDROOM FAN CONTROL
////////////////////////////////////////////////////////////////////////////////////
BedroomFan = digitalio.DigitalInOut(board.GP6)
BedroomFan = digitalio.DigitalInOut(board.GP6)

BedroomFan.direction = digitalio.Direction.OUTPUT
BedroomFan.direction = digitalio.Direction.OUTPUT

153.
def on_BedroomFan_msg(client, topic, message):
def on_BedroomFan_msg(client, topic, message):

# Method called when a client's subscribed feed has a new value.
# Method called when a client's subscribed feed has a new value.

print(" {0}: {1}".format(topic, message))
print(" {0}: {1}".format(topic, message))

if message == "on":
if message == "on":

BedroomFan.value = True
BedroomFan.value = True

elif message == "off":
elif message == "off":

BedroomFan.value = False
BedroomFan.value = False

else:
else:

print("Unexpected message on BedroomFan feed")
print("Unexpected message on BedroomFan feed")

163.
164. # HALL FAN CONTROL GPIO PIN CONTROL
////////////////////////////////////////////////////////////////////////////////////
165.
#
#

#
#

168.
#
#

#
#

#
#

#
#

#
#

#
#

#
#

176. # 177. #
HallFan = digitalio.DigitalInOut(board.GP22) HallFan.direction = digitalio.Direction.OUTPUT
def on_HallFan_msg(client, topic, message):
Method called when a client's subscribed feed has a new value.
print(" {0}: {1}".format(topic, message)) if message == "on":
HallFan.value = True elif message == "off":
HallFan.value = False else:
print("Unexpected message on HallFan feed")
def on_BoardLed_msg(client, topic, message):
# Method called when a client's subscribed feed has a new value. print(" {0}: {1}".format(topic, message))
if message == "on":
BoardLed.value = True elif message == "off":
BoardLed.value = False else:
print("Unexpected message on BoardLed feed")
# External LED CONTROL ////////////////////////////////////////////////////////////////////////////////////
19
178. 179. #
////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////
180.
181. # Relay CONTROL System (Low/False is ON
)////////////////////////////////////////////////////////////////////////////////////
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.
HallLight = digitalio.DigitalInOut(board.GP14)
HallLight = digitalio.DigitalInOut(board.GP14)

HallLight.direction = digitalio.Direction.OUTPUT
HallLight.direction = digitalio.Direction.OUTPUT

HallLight.value = True
HallLight.value = True

234.
def on_HallLight_msg(client, topic, message):
def on_HallLight_msg(client, topic, message):

# Method called when a client's subscribed feed has a new value.
# Method called when a client's subscribed feed has a new value.

print(" {0}: {1}".format(topic, message))
print(" {0}: {1}".format(topic, message))

if message == "on":
if message == "on":

HallLight.value = False
HallLight.value = False

elif message == "off":
elif message == "off":

HallLight.value = True
HallLight.value = True

else:
else:

print("Unexpected message on HallLight feed")
print("Unexpected message on HallLight feed")

244.
# //////// RelayTest \\\
RelayTest = digitalio.DigitalInOut(board.GP9) RelayTest.direction = digitalio.Direction.OUTPUT RelayTest.value = True
def on_RelayTest_msg(client, topic, message):
# Method called when a client's subscribed feed has a new value. print(" {0}: {1}".format(topic, message))
if message == "on":
RelayTest.value = False elif message == "off":
RelayTest.value = True else:
print("Unexpected message on RelayTest feed")
# //////// HALL FAN CONTROL (RELAY) \\\\
HallFan = digitalio.DigitalInOut(board.GP15) HallFan.direction = digitalio.Direction.OUTPUT HallFan.value = True
def on_HallFan_msg(client, topic, message):
## Method called when a client's subscribed feed has a new value.
print(" {0}: {1}".format(topic, message)) if message == "on":
HallFan.value = False elif message == "off":
HallFan.value = True else:
print("Unexpected message on HallFan feed")
# HallFanRelay = digitalio.DigitalInOut(board.GP15)
# HallFanRelay.direction = digitalio.Direction.OUTPUT # HallFanRelay.value = True
# def on_HallFanRelay_msg(client, topic, message):
## Method called when a client's subscribed feed has a new value.
# # # # #
print(" {0}: {1}".format(topic, message)) if message == "on":
HallFanRelay.value = False elif message == "off":
HallFanRelay.value = True else:
print("Unexpected message on HallFanRelay feed") //////// HALL LIGHT \\\")

# Initialize an Adafruit IO MQTT Client
# Initialize an Adafruit IO MQTT Client

io = IO_MQTT(mqtt_client)
io = IO_MQTT(mqtt_client)

311.
# Setup the callback methods above
# Setup the callback methods above

io.on_connect = connected
io.on_connect = connected

io.on_disconnect = disconnected
io.on_disconnect = disconnected

# //////// BEDROOM LIGHT \\\
BedroomLight = digitalio.DigitalInOut(board.GP13) BedroomLight.direction = digitalio.Direction.OUTPUT BedroomLight.value = True
def on_BedroomLight_msg(client, topic, message):
# Method called when a client's subscribed feed has a new value. print(" {0}: {1}".format(topic, message))
if message == "on":
BedroomLight.value = False elif message == "off":
BedroomLight.value = True else:
print("Unexpected message on BedroomLight feed") # //////// KITCHEN LIGHT \\\
KitchenLight = digitalio.DigitalInOut(board.GP12) KitchenLight.direction = digitalio.Direction.OUTPUT KitchenLight.value = True
def on_KitchenLight_msg(client, topic, message):
# Method called when a client's subscribed feed has a new value. print(" {0}: {1}".format(topic, message))
if message == "on":
KitchenLight.value = False elif message == "off":
KitchenLight.value = True else:
# //////// GateButton \\\
print("Unexpected message on KitchenLight feed") # *************GATE AUTOMATION*************
GateButton = digitalio.DigitalInOut(board.GP8) GateButton.direction = digitalio.Direction.OUTPUT GateButton.value = True
def on_GateButton_msg(client, topic, message):
# Method called when a client's subscribed feed has a new value. print(" {0}: {1}".format(topic, message))
if message == "on":
GateButton.value = False sleep(1)
GateButton.value = True print("Gate triggered!!") message == "off"
else:
print("GATE Triggered" "n" "with Adafruit IO" "n" "
" "!!")
# ////////////////////////////////////////////////////////////////////////////////////
# Initialize MQTT interface with the ethernet interface
MQTT.set_socket(socket, eth)
# Initialize a new MQTT Client object
mqtt_client = MQTT.MQTT( broker="io.adafruit.com", username=secrets["aio_username"], password=secrets["aio_key"], is_ssl=False,
21
io.on_message = message
io.on_message = message

io.on_subscribe = subscribe
io.on_subscribe = subscribe

317.
# Set up a callback for the BoardLed feed //////////////////////////////////////////
# Set up a callback for the BoardLed feed //////////////////////////////////////////

io.add_feed_callback("BoardLed", on_BoardLed_msg)
io.add_feed_callback("BoardLed", on_BoardLed_msg)

320.
321. # Set up a callback for the ExternalLed feed
//////////////////////////////////////////
322. io.add_feed_callback("ExternalLed", on_ExternalLed_msg) 323.
# Set up a callback for the KitchenFan feed //////////////////////////////////////////
# Set up a callback for the KitchenFan feed //////////////////////////////////////////

io.add_feed_callback("KitchenFan", on_KitchenFan_msg)
io.add_feed_callback("KitchenFan", on_KitchenFan_msg)

326.
# Set up a callback for the BedroomFan feed //////////////////////////////////////////
# Set up a callback for the BedroomFan feed //////////////////////////////////////////

io.add_feed_callback("BedroomFan", on_BedroomFan_msg)
io.add_feed_callback("BedroomFan", on_BedroomFan_msg)

329.
# Set up a callback for the HallFan feed //////////////////////////////////////////
# Set up a callback for the HallFan feed //////////////////////////////////////////

io.add_feed_callback("HallFan", on_HallFan_msg)
io.add_feed_callback("HallFan", on_HallFan_msg)

332.
333. # //////////////////////////////////////////////////////////////////////////////////// 334.
# Set up a callback for the RelayTest feed //////////////////////////////////////////
# Set up a callback for the RelayTest feed //////////////////////////////////////////

io.add_feed_callback("RelayTest", on_RelayTest_msg)
io.add_feed_callback("RelayTest", on_RelayTest_msg)

337.
338. ## Set up a callback for the HallFanRelay feed
//////////////////////////////////////////
339. # io.add_feed_callback("HallFanRelay", on_HallFanRelay_msg) 340.
# Set up a callback for the HallLight feed //////////////////////////////////////////
# Set up a callback for the HallLight feed //////////////////////////////////////////

io.add_feed_callback("HallLight", on_HallLight_msg)
io.add_feed_callback("HallLight", on_HallLight_msg)

343.
344. # Set up a callback for the BedroomLight feed
//////////////////////////////////////////
345. io.add_feed_callback("BedroomLight", on_BedroomLight_msg) 346.
347. # Set up a callback for the KitchenLight feed
//////////////////////////////////////////
348. io.add_feed_callback("KitchenLight", on_KitchenLight_msg) 349.
# Set up a callback for the GateButton feed //////////////////////////////////////////
# Set up a callback for the GateButton feed //////////////////////////////////////////

io.add_feed_callback("GateButton", on_GateButton_msg)
io.add_feed_callback("GateButton", on_GateButton_msg)

352.
## Group name
## Group name

group_name = "weatherstation" # Comenting Throws error need to check
group_name = "weatherstation" # Comenting Throws error need to check

355.
## Feeds within the group
## Feeds within the group

temp_feed = "weatherstation.temperature" # omenting Throws error need to check
temp_feed = "weatherstation.temperature" # omenting Throws error need to check

humid_feed = "weatherstation.humidity" # Comenting Throws error need to check
humid_feed = "weatherstation.humidity" # Comenting Throws error need to check

359.
# Connect to Adafruit IO
# Connect to Adafruit IO

print("Connecting to Adafruit IO...")
print("Connecting to Adafruit IO...")

io.connect()
io.connect()

363.
364. # ////////////////////////////ADD ON
SUBSCRIPTION////////////////////////////////////////////////////////
365.
# # Subscribe to all messages on the BoardLed feed
# # Subscribe to all messages on the BoardLed feed

io.subscribe("BoardLed")
io.subscribe("BoardLed")

368.
# # Subscribe to all messages on the ExternalLed feed
# # Subscribe to all messages on the ExternalLed feed

io.subscribe("ExternalLed")
io.subscribe("ExternalLed")

371.
# Subscribe to all messages
# Subscribe to all messages

io.subscribe("KitchenFan")
io.subscribe("KitchenFan")

374.
# Subscribe to all messages
# Subscribe to all messages

io.subscribe("BedroomFan")
io.subscribe("BedroomFan")

377.
# # Subscribe to all messages on the HallFan feed
# # Subscribe to all messages on the HallFan feed

io.subscribe("HallFan")
io.subscribe("HallFan")

on the KitchenFan feed on the BedroomFan feed
22
380.
381. # ////////////////////////////RELAY
SUBSCRIPTION////////////////////////////////////////////////////////
382.
# # Subscribe to all messages on the RelayTest feed
# # Subscribe to all messages on the RelayTest feed

io.subscribe("RelayTest")
io.subscribe("RelayTest")

385.
# Subscribe to all messages on the HallFanRelay feed
# Subscribe to all messages on the HallFanRelay feed

# io.subscribe("HallFanRelay")
# io.subscribe("HallFanRelay")

388.
# # Subscribe to all messages on the HallLight feed
# # Subscribe to all messages on the HallLight feed

io.subscribe("HallLight")
io.subscribe("HallLight")

391.
# # Subscribe to all messages on the BedroomLight feed
# # Subscribe to all messages on the BedroomLight feed

io.subscribe("BedroomLight")
io.subscribe("BedroomLight")

394.
# # Subscribe to all messages on the KitchenLight feed
# # Subscribe to all messages on the KitchenLight feed

io.subscribe("KitchenLight")
io.subscribe("KitchenLight")

397.
# # Subscribe to all messages on the GateButton feed
# # Subscribe to all messages on the GateButton feed

io.subscribe("GateButton")
io.subscribe("GateButton")

400.
401. # //////////////////////////////////////////////////////////////////////////////////// 402.
403. print("Connected to Adafruit IO")
print(" HandShake
print(" HandShake

print("WAITING FOR INPUT")
print("WAITING FOR INPUT")

406.
while True:
while True:

io.loop()
io.loop()

409

The Board was programmed using Circuit python, there were a few difficulties where the code was unresponsive and was required to be nuked with the flash_nuke.uf2 file.The editor that was widely used for this project was the Mu Editor and sometimes Visual Studio Code seemed easier for search. Below is the code used in the project:-

1.10) Results and Conclusion

Well the results were great! Automated gates lights and fans all powered by the lone board W5500-EVB-Pico programmed with circuit python, connected to Adafruit IO which was a possibility only because of Wiznet’s brilliant idea of adding an Ethernet (RJ45) port powered by the great W5500 hardwired TCP/IP chip and equally important wiznet 5k ethernet library and adafruit library which inspired and helped me complete this amazing project successfully.

I was also able to learn and gain a lot of experience from this project and I’m really grateful for this grand opportunity wiznet provided to us.

Please Note:-A video on this project including a working demo is being prepared which will be shared soon.

The below images in the following pages shows some images that I have captured :-

24

📷📷

25

📷📷

26

📷📷

27

📷📷

28

29

30

📷📷

31

📷📷

32

33

📷📷

34

📷📷📷

35

📷📷

36

documents
Code
code.pyPython Circuit Python code for W5100s evb pico and W5500 eve pico
Schematics
Alexa Flow Diagram

COMMENTS

Please Login to comment
  Subscribe  
Notify of
POSTED BY
Reusable S/W