本帖最后由 刘睿鹏 于 2025-1-26 20:02 编辑
【制作背景】
众所周知,商铺运营最大的成本就是人工成本,大多用在了清点库存,雇佣收银员上。那么,如果有一个智能系统能完成这些工作,那将会大大降低商铺的运营成本,而今天我想给大家分享的就是这样一个项目-------自助收银机。【项目功能】
1.顾客可以自行通过扫描商品上的二维码的方式选择商品
2.选择完成后点击确定按钮打开支付二维码(我的代码里用的行空板官网的二维码大家记得改!)
3.支付完成后按按钮结束购物,返回开始的扫描界面
【所需材料】
1.行空板M10;
2.数字大按钮模块;
3.Husky 人工智能摄像头;
4.Mind+1.8;
【制作方法】
1.打开Mind+,点击左下的扩展按钮
2.选择行空板,MQTT-py,代码生成器三个库,再点击Pingpong库,选择HUSKYLENS AI摄像头和数字大按钮模块
3.连接远程终端10.1.2.3(先连上行空板USB接口再做这一步)
4.将siot库更新至V2详见https://mindplus.dfrobot.com.cn/dashboard5.在浏览器中搜索10.1.2.3(一定要连接行空板!!!不然会加载不出来)
然后点击应用开关,打开siot的界面,再点击新建主题。
6.回到Mind+,我们先连接上硬件。
把HUSKY人工智能摄像头连接到任意一个I2C接口(4pin )
把按钮模块连接到行空板P21引脚(3pin )
(连接不同不影响,只要在最后稍作修改代码就行了。)
7.点击右上角的可视化界面按钮
进入可视化编辑之后点击新建项目,命个名(随便)。
从左边的框里选择柱状图,把名字改为“销售数量统计”,把各个柱子的名字分别改为商品1至商品6。(这里假设分别为商品1~6,分别单价为1~6元)。
8.训练HUSKY识别二维码
我用了前六个分别表示1~6号商品。
启动HUSKY,切换到标签的算法,长按按钮选择二级菜单,选择学习多个,学习标签。
详见网址https://wiki.dfrobot.com.cn/_SKU ... E%E8%AF%86%E5%88%AB
9.最后一步了!编写代码
功能实现:
预设变量goods 1~6作为总数(假设均为30个),顾客买一个东西减一个
MQTT初始化:点击齿轮按钮,设置参数如下
通过行空板多线程threading 库来分别执行扫描和付款两个界面
图形代码:
文本代码
- # -*- coding: UTF-8 -*-
-
- # MindPlus
- # Python
- import siot
- import threading
- from unihiker import GUI
- from pinpong.board import Board
- from pinpong.board import Board,Pin
- from pinpong.extension.unihiker import *
- from pinpong.libs.dfrobot_huskylens import Huskylens
-
- # 事件回调函数
- def u_thread1_function():
- global x,a1,a2,a3,b1,b2,b3,c1,c2,c3,d1,d2,d3,e1,e2,e3,f1,f2,f3,goods1,goods2,goods3,goods4,goods5,goods6,y,tot,a,b,c,d,e,f
- tot = 0
- u_gui.clear()
- u_gui.add_button(text="确认付款",x=20,y=280,w=100,h=30,onclick=button_click1)
- u_gui.draw_text(text="欢迎使用自助结账机",x=0,y=0,font_size=19, color="#0000FF")
- u_gui.draw_text(text="请扫描商品条形码,支付完成按按钮",x=0,y=35,font_size=11, color="#0000FF")
- u_gui.draw_text(text="总计:",x=120,y=280,font_size=15, color="#0000FF")
- x=u_gui.draw_digit(text="0",x=177,y=287,font_size=15, color="#0000FF")
- u_gui.draw_text(text="元",x=200,y=280,font_size=15, color="#0000FF")
- while True:
- p_huskylens.command_request()
- if p_huskylens.is_appear(1, "blocks"):
- goods1 = (goods1 - 1)
- a1=u_gui.draw_text(text="商品1",x=0,y=y,font_size=14, color="#0000FF")
- a2=u_gui.draw_digit(text="1",x=100,y=(5 + y),font_size=14, color="#0000FF")
- a3=u_gui.draw_text(text="元",x=130,y=y,font_size=14, color="#0000FF")
- y = (y + 18)
- tot+=1
- a+=1
- elif p_huskylens.is_appear(2, "blocks"):
- goods2 = (goods2 - 1)
- b1=u_gui.draw_text(text="商品2",x=0,y=y,font_size=14, color="#0000FF")
- b2=u_gui.draw_digit(text="2",x=100,y=(5 + y),font_size=14, color="#0000FF")
- b3=u_gui.draw_text(text="元",x=130,y=y,font_size=14, color="#0000FF")
- y = (y + 18)
- tot+=2
- b+=1
- elif p_huskylens.is_appear(3, "blocks"):
- goods3 = (goods3 - 1)
- c1=u_gui.draw_text(text="商品3",x=0,y=y,font_size=14, color="#0000FF")
- c2=u_gui.draw_digit(text="3",x=100,y=(5 + y),font_size=14, color="#0000FF")
- c3=u_gui.draw_text(text="元",x=130,y=y,font_size=14, color="#0000FF")
- y = (y + 18)
- tot+=3
- c+=1
- elif p_huskylens.is_appear(4, "blocks"):
- goods4 = (goods4 - 1)
- d1=u_gui.draw_text(text="商品4",x=0,y=y,font_size=14, color="#0000FF")
- d2=u_gui.draw_digit(text="4",x=100,y=(5 + y),font_size=14, color="#0000FF")
- d3=u_gui.draw_text(text="元",x=130,y=y,font_size=14, color="#0000FF")
- y = (y + 18)
- tot+=4
- d+=1
- elif p_huskylens.is_appear(5, "blocks"):
- goods5 = (goods5 - 1)
- e1=u_gui.draw_text(text="商品5",x=0,y=y,font_size=14, color="#0000FF")
- e2=u_gui.draw_digit(text="5",x=100,y=(5 + y),font_size=14, color="#0000FF")
- e3=u_gui.draw_text(text="元",x=130,y=y,font_size=14, color="#0000FF")
- y = (y + 18)
- tot+=5
- e+=1
- elif p_huskylens.is_appear(6, "blocks"):
- goods6 = (goods6 - 1)
- f1=u_gui.draw_text(text="商品6",x=0,y=y,font_size=14, color="#0000FF")
- f2=u_gui.draw_digit(text="6",x=100,y=(5 + y),font_size=14, color="#0000FF")
- f3=u_gui.draw_text(text="元",x=130,y=y,font_size=14, color="#0000FF")
- y = (y + 18)
- tot+=6
- f+=1
- x.config(text=tot)
- def button_click1():
- global thread1,thread2,a,b,c,d,e,f
- thread2=u_gui.start_thread(u_thread2_function)
- u_gui.stop_thread(thread1)
- def u_thread2_function():
- global thread1,thread2,y,a,b,c,d,e,f
- z=u_gui.draw_qr_code(text="https://unihiker.com",x=70,y=100,w=100)
- while not (p_p21_in.read_digital()):
- pass
- siot.publish_save(topic="siot/智慧商店", data=str(a)+","+str(b)+","+str(c)+","+str(d)+","+str(e)+","+str(f))
- z.remove()
- y = 50
- thread1=u_gui.start_thread(u_thread1_function)
- u_gui.stop_thread(thread2)
-
-
- siot.init(client_id="8458671784972747",server="10.1.2.3",port=1883,user="siot",password="dfrobot")
- Board().begin()
- u_gui=GUI()
- siot.connect()
- siot.loop()
- p_p21_in=Pin(Pin.P21, Pin.IN)
- y = 50
- goods_ls = []
- a = 0
- b = 0
- c = 0
- d = 0
- e = 0
- f = 0
- # 分别为商品1,2,3,4,5,6的总个数均为30个
- # 设它们的单价分别为1,2,3,4,5,6元
- goods1 = 30
- goods2 = 30
- goods3 = 30
- goods4 = 30
- goods5 = 30
- goods6 = 30
- siot.getsubscribe(topic="siot/智慧商店")
- p_huskylens = Huskylens()
- thread1=u_gui.start_thread(u_thread1_function)
-
- while True:
- pass
复制代码
大功告成!
|