Morgan NgChen Hongyujavier hengDesmond Chad
Published

Smart Retail Inventory Management

Monitor stock levels efficiently allocate workers, monitor temperature of the stocks and prevent theft

IntermediateFull instructions provided225
Smart Retail Inventory Management

Things used in this project

Story

Read more

Schematics

Circuit Diagram

1.Block Diagram

2.Block Diagram

Code

RFID and PIR Sensor Python Code

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


setScreenColor(0x000000)
rfid_0 = unit.get(unit.RFID, unit.PORTA)
pir_3 = unit.get(unit.PIR, unit.PORTB)


IsRunning2 = None
IsRunning3 = None
IsRunning = None



label0 = M5TextBox(81, 51, "Tap Card", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
label4 = M5TextBox(56, 7, "Intruder!!!", lcd.FONT_DejaVu40, 0xFFFFFF, rotate=0)
image0 = M5Img(100, 86, "res/intru120px.jpg", True)
label3 = M5TextBox(91, 214, "Detecting...", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
label1 = M5TextBox(230, 86, "Text", lcd.FONT_Default, 0x000000, rotate=0)




label3.setText('Detecting...')
label4.setText('Intruder!!!')
label4.hide()
image0.changeImg("res/default.jpg")
image0.hide()
while True:
  label0.setPosition(81, 51)
  label0.setText('Device is off')
  label3.hide()
  IsRunning3 = False
  if btnA.isPressed():
    IsRunning = True
  if btnB.isPressed():
    IsRunning2 = True
  while IsRunning == True:
    label0.setPosition(104, 53)
    label0.setText('Tap card')
    if rfid_0.isCardOn():
      label1.setText(str(rfid_0.readUid()))
      if (rfid_0.readUid()) == 'a4ce732b32':
        label0.setPosition(59, 51)
        label0.setText('Access Granted')
        rgb.setColorAll(0x33ff33)
        speaker.tone(1000, 200)
        IsRunning = False
        image0.hide()
        label4.hide()
        rgb.setColorAll(0x000000)
        wait(1)
      else:
        IsRunning3 = True
        while IsRunning3 == True:
          label4.setText('Intruder!!!')
          image0.show()
          speaker.tone(1500, 200)
          rgb.setColorAll(0xff0000)
          if rfid_0.isCardOn():
            label1.setText(str(rfid_0.readUid()))
            if (rfid_0.readUid()) == 'a4ce732b32':
              label0.setPosition(59, 51)
              label0.setText('Access Granted')
              rgb.setColorAll(0x33ff33)
              speaker.tone(1000, 200)
              IsRunning = False
              IsRunning3 = False
              image0.hide()
              label4.hide()
              rgb.setColorAll(0x000000)
              wait(1)
            else:
              label0.setPosition(85, 50)
              label0.setText('Wrong card')
              rgb.setColorAll(0xff0000)
              speaker.tone(100, 500)
              rgb.setColorAll(0x000000)
              wait(1)
  while IsRunning2 == True:
    label0.setPosition(104, 53)
    label0.setText('Tap card')
    if (pir_3.state) == 1:
      label0.hide()
      label3.hide()
      label4.show()
      image0.show()
      speaker.tone(1500, 200)
      rgb.setColorAll(0xff0000)
    else:
      label0.show()
      label3.show()
      label4.hide()
      image0.hide()
      rgb.setColorAll(0x000000)
    if rfid_0.isCardOn():
      label1.setText(str(rfid_0.readUid()))
      if (rfid_0.readUid()) == 'a4ce732b32':
        label0.setPosition(59, 51)
        label0.setText('Access Granted')
        rgb.setColorAll(0x33ff33)
        speaker.tone(1000, 200)
        IsRunning2 = False
        image0.hide()
        label4.hide()
        rgb.setColorAll(0x000000)
        wait(1)
      else:
        IsRunning3 = True
        while IsRunning3 == True:
          label4.setText('Intruder!!!')
          image0.show()
          speaker.tone(1500, 200)
          rgb.setColorAll(0xff0000)
          if rfid_0.isCardOn():
            label1.setText(str(rfid_0.readUid()))
            if (rfid_0.readUid()) == 'a4ce732b32':
              label0.setPosition(59, 51)
              label0.setText('Access Granted')
              rgb.setColorAll(0x33ff33)
              speaker.tone(1000, 200)
              IsRunning3 = False
              IsRunning2 = False
              image0.hide()
              label4.hide()
              rgb.setColorAll(0x000000)
              wait(1)
            else:
              label0.setPosition(85, 50)
              label0.setText('Wrong card')
              rgb.setColorAll(0xff0000)
              speaker.tone(100, 500)
              rgb.setColorAll(0x000000)
              wait(1)
  wait_ms(2)

ENV(II) and TOF sensor python code

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


setScreenColor(0x222222)
env2_0 = unit.get(unit.ENV2, unit.PAHUB0)
pahub_0 = unit.get(unit.PAHUB, unit.PORTA, 0x70)
tof_2 = unit.get(unit.TOF, unit.PAHUB1)


DesiredTemperature = None
IsRunning = None
Distance = None



label1 = M5TextBox(190, 25, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label3 = M5TextBox(90, 106, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
image1 = M5Img(190, 140, "res/2_.jpg", True)
label2 = M5TextBox(190, 72, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label5 = M5TextBox(31, 72, "Desired Temperature:", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label4 = M5TextBox(32, 106, "Stock:", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label0 = M5TextBox(32, 26, "Current Temperature:", lcd.FONT_Default, 0xFFFFFF, rotate=0)

from numbers import Number



def buttonC_wasPressed():
  global DesiredTemperature, IsRunning, Distance
  DesiredTemperature = (DesiredTemperature if isinstance(DesiredTemperature, Number) else 0) + 1
  label2.setText(str(DesiredTemperature))
  pass
btnC.wasPressed(buttonC_wasPressed)

def buttonC_wasDoublePress():
  global DesiredTemperature, IsRunning, Distance
  DesiredTemperature = (DesiredTemperature if isinstance(DesiredTemperature, Number) else 0) + -1
  label2.setText(str(DesiredTemperature))
  pass
btnC.wasDoublePress(buttonC_wasDoublePress)


DesiredTemperature = 27
label1.setText(str(env2_0.temperature))
label2.setText(str(DesiredTemperature))
while True:
  image1.hide()
  if btnA.isPressed():
    IsRunning = True
    while IsRunning == True:
      image1.hide()
      Distance = int(((tof_2.distance) / 10))
      if Distance >= 32:
        image1.show()
        rgb.setColorAll(0xff0000)
        speaker.tone(1800, 750)
        label3.setText('Please restock')
        wait(1)
        rgb.setColorAll(0xffcc00)
      elif Distance >= 24:
        label3.setText('Stock is 40% Full')
        rgb.setColorAll(0xff0000)
      elif Distance >= 14:
        label3.setText('Stock is 60% Full')
        rgb.setColorAll(0xff6600)
      elif Distance >= 8:
        label3.setText('Stock is 80% Full')
        rgb.setColorAll(0x006600)
      elif Distance >= 4:
        label3.setText('Stock is Full')
        rgb.setColorAll(0x000099)
      if btnB.isPressed():
        IsRunning = False
  rgb.setColorAll(0x000000)
  wait(0.75)
  rgb.setColorAll(0xffff00)
  if DesiredTemperature > (env2_0.temperature) + 1:
    while DesiredTemperature > (env2_0.temperature) + 1:
      speaker.tone(800, 200)
      rgb.setColorAll(0xff0000)
      wait_ms(500)
      rgb.setColorAll(0x000000)
      wait_ms(500)
  elif DesiredTemperature < (env2_0.temperature) - 1:
    while DesiredTemperature < (env2_0.temperature) - 1:
      speaker.tone(1800, 200)
      rgb.setColorAll(0xff0000)
      wait_ms(500)
      rgb.setColorAll(0x000000)
      wait_ms(500)
  wait_ms(2)

Credits

Morgan Ng

Morgan Ng

1 project • 0 followers
Chen Hongyu

Chen Hongyu

1 project • 1 follower
javier heng

javier heng

1 project • 1 follower
Desmond Chad

Desmond Chad

1 project • 0 followers

Comments