Muhammad ShaffeeqJia WeiReagzaJeriel
Published

EGC177 - Urban Farming (AgriFarm Hub)

Imagine a world where the health and productivity of your urban farm are constantly monitored and optimized in real-time.

BeginnerShowcase (no instructions)9
EGC177 - Urban Farming (AgriFarm Hub)

Things used in this project

Story

Read more

Schematics

Block Diagram (Main Circuit)

Block Diagram (Secondary Circuit)

Main M5Stack Circuit

Secondary M5Stack Circuit

A2 Poster

Foam Board

Code

Main M5Stack Code

Python
from m5stack import *
from m5ui import *
from uiflow import *
import time
import unit
remoteInit()

setScreenColor(0x222222)
pahub_0 = unit.get(unit.PAHUB, unit.PORTA, 0x70)
pbhub_0 = unit.get(unit.PBHUB, unit.PAHUB0)
env2_0 = unit.get(unit.ENV2, unit.PAHUB1)
servo_0 = unit.get(unit.SERVO, unit.PORTB)
tof_0 = unit.get(unit.TOF, unit.PAHUB2)


Temperature = None
Moisture = None
Humidity = None
Illumination = None
Water_Capacity = None



rectangle0 = M5Rect(0, 103, 320, 1, 0xFFFFFF, 0xFFFFFF)
rectangle1 = M5Rect(159, 103, 1, 137, 0xFFFFFF, 0xFFFFFF)
image0 = M5Img(0, 140, "res/thermometer.png", True)
label0 = M5TextBox(56, 166, "label0", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
label1 = M5TextBox(134, 166, "C", lcd.FONT_DejaVu24, 0xffffff, rotate=0)
image2 = M5Img(0, 0, "res/logo (3).png", True)
image1 = M5Img(166, 140, "res/water_level.png", True)
label2 = M5TextBox(234, 166, "label2", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)





def gauge_1_callback():
  global Temperature, Moisture, Humidity, Illumination, Water_Capacity, pahub_0, pbhub_0, env2_0, servo_0, tof_0 
  return Temperature
def gauge_3_callback():
  global Temperature, Moisture, Humidity, Illumination, Water_Capacity, pahub_0, pbhub_0, env2_0, servo_0, tof_0 
  return Moisture
def gauge_2_callback():
  global Temperature, Moisture, Humidity, Illumination, Water_Capacity, pahub_0, pbhub_0, env2_0, servo_0, tof_0 
  return Humidity
def gauge_4_callback():
  global Temperature, Moisture, Humidity, Illumination, Water_Capacity, pahub_0, pbhub_0, env2_0, servo_0, tof_0 
  return Illumination
lcd.qrcode('https://flow.m5stack.com/remote?id=undefined', 72, 32, 176)
servo_0.write_angle(0)
while True:
  Temperature = env2_0.temperature
  Humidity = env2_0.humidity
  Moisture = int((pbhub_0.analogRead(0)))
  Water_Capacity = tof_0.distance
  Illumination = pbhub_0.analogRead(2)
  label0.setText(str(Temperature))
  if Moisture >= 550:
    servo_0.write_angle(180)
  elif Moisture < 550:
    servo_0.write_angle(0)
  if Water_Capacity <= 70:
    label2.setText('Full')
    rgb.setColorAll(0x3333ff)
  elif Water_Capacity > 70 and Water_Capacity <= 100:
    label2.setText('High')
    rgb.setColorAll(0x33ff33)
  elif Water_Capacity > 100 and Water_Capacity <= 130:
    label2.setText('Moderate')
    rgb.setColorAll(0xffff00)
  elif Water_Capacity <= 170:
    label2.setText('Low')
    rgb.setColorAll(0xff0000)
  else:
    label2.setText('Empty')
    rgb.setColorAll(0xff0000)
    speaker.tone(800, 200)
    wait_ms(10)
  if Illumination >= 400:
    pbhub_0.setColor(1, 0, 3, 0xffffff)
  elif Illumination < 400:
    pbhub_0.setColor(1, 0, 3, 0x000000)
  wait_ms(2)

Secondary M5Stack Code

Python
from m5stack import *
from m5ui import *
from uiflow import *
import time
import unit


setScreenColor(0x222222)
rfid_0 = unit.get(unit.RFID, unit.PORTA)
servo_0 = unit.get(unit.SERVO, unit.PORTB)






label0 = M5TextBox(61, 185, "label0", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
image0 = M5Img(118, 57, "res/default.jpg", False)
image1 = M5Img(118, 57, "res/default.jpg", False)
image2 = M5Img(118, 55, "res/denied.png", True)


servo_0.write_angle(0)
while True:
  if rfid_0.isCardOn():
    if (rfid_0.readUid()) == '24b0fd2b42':
      label0.setText('Authorized Entry')
      image0.hide()
      image2.hide()
      image1.changeImg("res/granted.jpg")
      rgb.setColorAll(0x33cc00)
      servo_0.write_angle(180)
      wait(3)
    else:
      label0.setText('Access Denied')
      image0.hide()
      image1.hide()
      image2.changeImg("res/denied.jpg")
      rgb.setColorAll(0xff0000)
  else:
    label0.setText('Scan Your Card')
    rgb.setColorAll(0x000000)
    image2.hide()
    image1.hide()
    image0.changeImg("res/tap.jpg")
    servo_0.write_angle(0)
  wait_ms(2)

Credits

Muhammad Shaffeeq

Muhammad Shaffeeq

1 project • 2 followers
Jia Wei

Jia Wei

1 project • 1 follower
Reagza

Reagza

1 project • 1 follower
Jeriel

Jeriel

0 projects • 1 follower

Comments