KaixinTong Gia LinhClarisKFan Yuheng
Published

Retail shop monitoring

Our project aims to enhance customers experience in a retail store through a pick locker, temperature monitoring system and a stock detector

IntermediateProtip84
Retail shop monitoring

Things used in this project

Story

Read more

Code

Main M5Stack Code

C/C++
from m5stack import *
from m5ui import *
from uiflow import *
import unit

setScreenColor(0x222222)
env2_0 = unit.get(unit.ENV2, unit.PAHUB0)
tof_0 = unit.get(unit.TOF, unit.PAHUB5)
pahub_0 = unit.get(unit.PAHUB, unit.PORTA)
servo_0 = unit.get(unit.SERVO, unit.PORTB)


Stock_Level = None



label0 = M5TextBox(13, 14, "Temperature:", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label2 = M5TextBox(121, 14, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label1 = M5TextBox(26, 42, "Humidity:", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label3 = M5TextBox(121, 42, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label4 = M5TextBox(25, 76, "Pressure:", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label5 = M5TextBox(121, 76, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
image0 = M5Img(189, 17, "res/coolTemp.png", True)
image1 = M5Img(189, 14, "res/Hightemp.png", True)
label12 = M5TextBox(13, 122, "Stock Level:", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label13 = M5TextBox(140, 122, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label14 = M5TextBox(13, 161, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)


# Describe this function...
def Stock_level():
  global Stock_Level
  label12.setText('Stock level')
  label13.setText(str(Stock_Level))
  Stock_Level = tof_0.distance
  if float(Stock_Level) < 130:
    label14.setText('Stock is available. ')
    servo_0.write_angle(180)
  elif float(Stock_Level) >= 130:
    label14.setText('Stock is empty')
    servo_0.write_angle(0)



while True:
  label2.setText(str(env2_0.temperature))
  label3.setText(str(env2_0.humidity))
  label5.setText(str(env2_0.pressure))
  if (env2_0.temperature) <= 24:
    rgb.setColorAll(0x3366ff)
    speaker.tone(1800, 200)
    image0.changeImg("res/default.jpg")
    image0.show()
    image1.hide()
  elif (env2_0.temperature) > 24 and (env2_0.temperature) <= 26:
    image0.hide()
    image1.hide()
    rgb.setColorAll(0x33cc00)
  else:
    rgb.setColorAll(0xcc0000)
    image0.hide()
    image1.changeImg("res/default.jpg")
    image1.show()
  Stock_level()
  wait_ms(2)

Secondary M5Stack code

C/C++
from m5stack import *
from m5ui import *
from uiflow import *
import time
import unit

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






label0 = M5TextBox(27, 43, "Text", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
image0 = M5Img(74, 73, "res/Tap.jpg", True)
image1 = M5Img(86, 73, "res/Verified.png", True)
image2 = M5Img(182, 96, "res/error.jpg", True)

# Describe this function...
def Smart_Locker():
  if rfid_0.isCardOn():
    if (rfid_0.readUid()) == '806cf4fac':
      image0.hide()
      label0.setText('Authorized Entry')
      image1.changeImg("res/default.jpg")
      image1.show()
      rgb.setColorAll(0x33ff33)
      servo_0.write_angle(180)
      speaker.sing(889, 1)
      if btnA.isPressed():
        pass
      else:
        wait(10)
        servo_0.write_angle(0)
        image1.hide()
    else:
      image0.hide()
      label0.setText('Access Denied, Try Again')
      image2.changeImg("res/default.jpg")
      image2.show()
      rgb.setColorAll(0xff0000)
      speaker.sing(147, 2)
  else:
    label0.setText('Scan your card here:')
    rgb.setColorAll(0x3366ff)
    image0.changeImg("res/default.jpg")
    image0.show()


def buttonA_wasPressed():
  # global params
  servo_0.write_angle(0)
  label0.setText('Locker closed , please wait')
  image1.hide()
  pass
btnA.wasPressed(buttonA_wasPressed)


servo_0.write_angle(0)
image0.show()
image1.hide()
image2.hide()
image0.hide()
while True:
  Smart_Locker()
  wait_ms(2)

Credits

Kaixin
1 project • 0 followers
Tong Gia Linh
1 project • 0 followers
ClarisK
1 project • 0 followers
Fan Yuheng
1 project • 0 followers

Comments