Materials to be used
1、STONE STWI101WT-01
2、FTP thermal printer head
3、Raspberry Pi pico
4、Coin-operated machine
Function
The control function is displayed on the serial screen, the main interface selects the floor, after entering the main interface selects the parking space, at the same time it will display the parking space number in the text box on the top right, then selects the stay time, it is two scrolling text selectors, then also the same will display the order information in the text box on the top right, according to the fixed unit price which multiplies with the stay time to get the total price. Then only when the parking space and the stay time are selected, you can go to the payment button, otherwise it is invalid. After entering the payment screen, a coin acceptor will be used. Then the screen will show the number of coins to be put in and the number of coins already put in. After the coins have been put in, a payment success message will be displayed. Then you can choose to print a small ticket to print the place number and time on the thermal paper.
Circuit
I have design a circuit by myself in order to drive many components, and the overall circuit diagram is like this, the upper left corner is the communication socket and power supply socket, below there is a buzzer (not actually used in the circuit), there is a light-emitting diode on the right, and the lower right corner is a 30pin fpc for connecting the print head.
Code
1、STONE STWI101WT-01
2、FTP thermal printer head
3、Raspberry Pi pico
4、Coin-operated machine
Function
The control function is displayed on the serial screen, the main interface selects the floor, after entering the main interface selects the parking space, at the same time it will display the parking space number in the text box on the top right, then selects the stay time, it is two scrolling text selectors, then also the same will display the order information in the text box on the top right, according to the fixed unit price which multiplies with the stay time to get the total price. Then only when the parking space and the stay time are selected, you can go to the payment button, otherwise it is invalid. After entering the payment screen, a coin acceptor will be used. Then the screen will show the number of coins to be put in and the number of coins already put in. After the coins have been put in, a payment success message will be displayed. Then you can choose to print a small ticket to print the place number and time on the thermal paper.
Circuit
I have design a circuit by myself in order to drive many components, and the overall circuit diagram is like this, the upper left corner is the communication socket and power supply socket, below there is a buzzer (not actually used in the circuit), there is a light-emitting diode on the right, and the lower right corner is a 30pin fpc for connecting the print head.
Code
Python:
from machine import UART,Pin
from time import sleep
import _thread
import rp2
from array import array
import ascii_ku
import speed_motor
from os import uname
#import sys
uart1 = UART(0, baudrate = 115200, tx =Pin(0), rx = Pin(1))
floor1 = ['f', 'l', 'o', 'o', 'r','1']
floor2 = ['f', 'l', 'o', 'o', 'r','2']
floor3 = ['f', 'l', 'o', 'o', 'r','3']
button_cmd = [16,1]
selector_cmd = [16,129]
print(uname()[0])
delaytime = 0.0000001 # Printer clock delay
coin = Pin(22, Pin.IN,Pin.PULL_UP)
coin_num = 0
motor = speed_motor.motor_control(2, 3, 4, 5) # Initialize the printer's internal stepper motor pins, corresponding to the a+/a-/b+/b- of the stepper motor
mov_bit = 0
PRINTER_DIN = Pin(20, Pin.OUT)
PRINTER_CLK = Pin(19, Pin.OUT)
PRINTER_LAT = Pin(18, Pin.OUT, Pin.PULL_UP)
STB1 = Pin(6, Pin.OUT, Pin.PULL_DOWN)
STB2 = Pin(7, Pin.OUT, Pin.PULL_DOWN)
STB3 = Pin(8, Pin.OUT, Pin.PULL_DOWN)
STB4 = Pin(9, Pin.OUT, Pin.PULL_DOWN)
STB5 = Pin(14, Pin.OUT, Pin.PULL_DOWN)
STB6 = Pin(15, Pin.OUT, Pin.PULL_DOWN)
lock = _thread.allocate_lock()
ascii_code = ascii_ku.ascii_code() # Importing an ascii character library
# shuru = 'aa'
# line_word = []
# for item in range(len(shuru)):
# line_word.append(shuru[item])
# line_num = len(shuru)
# bottom_line_num = len(shuru)%
# global motor_speed = 0
# global line = 0
# if len(shuru) > 6:
# motor_speed = len(shuru) % 6
# if (len(shuru) % 6) == 0:
# motor_speed = 12
# else:
# motor_speed = len(shuru)
# # print(motor_speed)
#
# line = (len(shuru) // 12) + 1
# if (len(shuru) % 12) == 0:
# line -= 1
lins = 0
supper = 0
slower = 0
danjia = 0
# _thread.start_new_thread(motor.run_stop, (0.005*motor_speed, 26*line))
# _thread.start_new_thread(motor.run_stop, (motor_speed, line))
# _thread.start_new_thread(motor.run_stop, (0.03, 56))
def pay(pay):
global coin_num
line_word = {'line_word1':['s','i','t','e',':','F','1','-','0'],'line_word2':['0','d','a','y','2','h','o','u','r'],'line_word3':['t','o','t','a','l',':','4','.','0'],'line_word4':['T','o','t','a','l',':','4','.','0']}
line_wors = {'line_word1':['U','n','i','t',':','2','.','0','0'],'line_word2':['T','o','t','a','l',':','4','.','0'],
'line_word3':['U','n','i','t',':','2','.','0','0'],'line_word4':['T','o','t','a','l',':','5','.','0']}
# line_word1 = ['S','i','t','e',':','F','1','-','0']
# line_word2 = ['1','D','a','y','1','H','o','u','r']
# line_word3 = ['U','n','i','t',':','2','.','0','0']
# line_word4 = ['T','o','t','a','l',':','5','.','0']
# line_word1[8]=str(pay[0])
# line_word2[0]=str(pay[1])
# line_word2[4]=str(pay[2])
# line_word4[6]=str(pay[3])
(line_word['line_word1'])[8]=str(pay[0])
# (line_word['line_word2'])[0]=str(pay[1])
# (line_word['line_word2'])[4]=str(pay[2])
# (line_word['line_word4'])[6]=str(pay[3])
sleep(1)
uart1.write('ST<{"cmd_code":"set_value","type":"image_value","widget":"image_value4","value":'+str(pay[3])+'}>ET')
# sleep(2)
# print(line_word.get('line_word'+str(1))[0])
# print('zfdszfz',line_word)
# sleep(2)
# uart1.write('ST<{"cmd_code":"set_text","type":"edit","widget":"message5","text":"F1 - '+pay[0]+'"}>ET')
# uart1.sendbreak()
# sleep(1)
# uart1.write('ST<{"cmd_code":"set_text","type":"edit","widget":"message6","text":"'+str(pay[1])+'"}>ET')
# uart1.sendbreak()
# sleep(1)
# # uart1.write('ST<{"cmd_code":"set_text","type":"edit","widget":"message22","text":"'+str(pay[2])+'"}>ET')
# uart1.write('ST<{"cmd_code":"set_text","type":"edit","widget":"message8","text":"'+str(pay[3])+'"}>ET')
while True:
if coin.value()==0:
coin_num += 1
print("Number of coins deposited:",coin_num)
sleep(0.1)
uart1.write('ST<{"cmd_code":"set_value","type":"image_value","widget":"image_value2","value":'+str(coin_num)+'}>ET')
if coin_num == pay[3]:
uart1.write('ST<{"cmd_code":"set_visible","type":"widget","widget":"image37","visible":true}>ET')
if uart1.any()>1:
rx2 = []
data_name2 = ''
bin_data = uart1.read(40)
uart1.sendbreak()
rx1 = list(bin_data)
for item in rx1:
rx2.append(chr(item))
print(rx2)
if rx1[3:5:1] == button_cmd:
data_name_len = rx1[6] - 1
data_name = rx2[7:data_name_len+6:1]
data_name2 = ''.join(data_name)
print(data_name2)
if data_name2 == 'back':
break
elif data_name2 == 'print' and coin_num == pay[3] and rx1[13] == 2:
data_name2=''
_thread.start_new_thread(motor.run_stop, (9, 4))
for iii in range(1,3):
for linss in range(32):
supper=slower=0
for lins in range(9):
# temp_list=ascii_code.code.get(('line_word'+str(iii))[lins])
# print(temp_list,type(temp_list))
if (line_word.get('line_word'+str(iii))[lins]).islower():
word_size24 (ascii_code.code.get(line_word.get('line_word'+str(iii))[lins]), linss%32, lins%12, supper, slower)
slower += 1
else:
last_word_size32 (ascii_code.code.get(line_word.get('line_word'+str(iii))[lins]), linss%32, lins%12, supper, slower)
supper += 1
sleep(6)
# for iii in range(1,2):
# for linss in range(32):
# supper=slower=0
# for lins in range(9):
# # temp_list=ascii_code.code.get(('line_word'+str(iii))[lins])
# # print(temp_list,type(temp_list))
# if (line_wors.get('line_word'+str(iii))[lins]).islower():
# word_size24 (ascii_code.code.get(line_wors.get('line_word'+str(iii))[lins]), linss%32, lins%12, supper, slower)
# slower += 1
# else:
# last_word_size32 (ascii_code.code.get(line_wors.get('line_word'+str(iii))[lins]), linss%32, lins%12, supper, slower)
# supper += 1
# sleep(6)
# for iii in range(1,2):
# for linss in range(32):
# supper=slower=0
# for lins in range(9):
# # temp_list=ascii_code.code.get(('line_word'+str(iii))[lins])
# # print(temp_list,type(temp_list))
# if (line_wors.get('line_word'+str(iii))[lins]).islower():
# word_size24 (ascii_code.code.get(line_wors.get('line_word'+str(iii))[lins]), linss%32, lins%12, supper, slower)
# slower += 1
# else:
# last_word_size32 (ascii_code.code.get(line_wors.get('line_word'+str(iii))[lins]), linss%32, lins%12, supper, slower)
# supper += 1
def floor1def():
day_jia = 0
hour_jia = 0
day_flag = False
hour_flag = False
price_flag = False
posltion = False
zongjia = 0
pay1 = [0,0,0,0]
print("floor1 now")
# uart1.write('ST<{"cmd_code":"set_text","type":"edit","widget":"message3","text":"2.00$/H"}>ET')
uart1.sendbreak()
while True:
if uart1.any()>1:
rx2 = []
data_name2 = ''
bin_data = uart1.read(40)
uart1.sendbreak()
rx1 = list(bin_data)
for item in rx1:
rx2.append(chr(item))
print(rx2)
if rx1[3:5:1] == button_cmd:
data_name_len = rx1[6] - 1
data_name = rx2[7:data_name_len+6:1]
data_name2 = ''.join(data_name)
print(data_name2)
if data_name2 == 'back':
break
elif data_name2 == 'position':
posltion = True
pay1[0]=rx2[15]
write1(rx2[15])
elif data_name2 == 'pay' and posltion and price_flag:
uart1.write('ST<{"cmd_code":"open_win","type":"window","widget":"window7"}>ET')
pay(pay1)
# if data_name2 == 'pay' and posltion = True and (day_flag or hour_flag):
# posltion = True
# uart1.write('ST<{"cmd_code":"open_win","type":"window","widget":"window7"}>ET')
if rx1[3:5:1] == selector_cmd:
data_name_len = rx1[6] - 4
data_name = rx2[7:data_name_len+7:1]
data_name2 = ''.join(data_name)
print(data_name2)
if data_name2 == 'time_day1':
pay1[1]=rx2[19]
write2(ord(rx2[19]))
day_jia = ord(rx2[19])
day_flag = True
elif data_name2 == 'time_hour1':
pay1[2]=rx2[20]
write3(ord(rx2[20]))
hour_jia = ord(rx2[20])
hour_flag = True
if hour_flag or day_flag:
price_flag = True
zongjia = (day_jia*48) + (hour_jia*2)
pay1[3]=zongjia
print(str(zongjia))
uart1.write('ST<{"cmd_code":"set_text","type":"edit","widget":"message4","text":"'+str(zongjia)+'"}>ET')
hour_flag = day_flag = False
def floor2def():
pass
def floor3def():
pass
def write1(num):
#print(ss)
for item in range(49,55):
uart1.write('ST<{"cmd_code":"set_image","type":"image","widget":"image1_'+chr(item)+'","image":"nocar_bg"}>ET')
uart1.write('ST<{"cmd_code":"set_image","type":"image","widget":"image1_'+num+'","image":"selectedcar_bg2"}>ET')
uart1.write('ST<{"cmd_code":"set_text","type":"edit","widget":"message1","text":"F1 - '+num+'"}>ET')
def write2(num):
# danjia = 1
uart1.write('ST<{"cmd_code":"set_text","type":"edit","widget":"message2","text":"'+str(num)+'"}>ET')
# if danjia == 1:
# uart1.write('ST<{"cmd_code":"set_text","type":"edit","widget":"message3","text":"2.00$/H"}>ET')
def write3(num):
# danjia = 1
uart1.write('ST<{"cmd_code":"set_text","type":"edit","widget":"message22","text":"'+str(num)+'"}>ET')
# if danjia == 1:
# uart1.write('ST<{"cmd_code":"set_text","type":"edit","widget":"message3","text":"2.00$/H"}>ET')
def last_word_size32 (word_line, linss, lins, supper, slower):
for mov_bit in range((supper*32)+(slower*24)):
PRINTER_CLK.value(0)
sleep(delaytime)
PRINTER_DIN.value(0)
PRINTER_CLK.value(1)
sleep(delaytime)
for mov_bit in range(31, -1, -1):
word_bit = (word_line[linss] >> mov_bit)&0b00000000000000000000000000000001
PRINTER_CLK.value(0)
sleep(delaytime)
PRINTER_DIN.value(word_bit)
PRINTER_CLK.value(1)
sleep(delaytime)
for mov_bit in range(352-((supper*32)+(slower*24))):
PRINTER_CLK.value(0)
sleep(delaytime)
PRINTER_DIN.value(0)
PRINTER_CLK.value(1)
sleep(delaytime)
if (supper*32)+(slower*24) < 192:
PRINTER_LAT.value(0)
STB1.value(1)
STB2.value(1)
STB3.value(1)
STB4.value(1)
sleep(0.005)
STB1.value(0)
STB2.value(0)
STB3.value(0)
STB4.value(0)
PRINTER_LAT.value(1)
else:
PRINTER_LAT.value(0)
STB4.value(1)
STB5.value(1)
STB6.value(1)
sleep(0.005)
STB4.value(0)
STB5.value(0)
STB6.value(0)
PRINTER_LAT.value(1)
# PRINTER_LAT.value(0)
# STB1.value(1)
# STB2.value(1)
# STB3.value(1)
# STB4.value(1)
# STB5.value(1)
# STB6.value(1)
# sleep(0.005)
# STB1.value(0)
# STB2.value(0)
# STB3.value(0)
# STB4.value(0)
# STB5.value(0)
# STB6.value(0)
# PRINTER_LAT.value(1)
def word_size24 (word_line, linss, lins, supper, slower):
for mov_bit in range((supper*32)+(slower*24)):
PRINTER_CLK.value(0)
sleep(delaytime)
PRINTER_DIN.value(0)
PRINTER_CLK.value(1)
sleep(delaytime)
for mov_bit in range(23, -1, -1):
word_bit = (word_line[linss] >> mov_bit)&0b000000000000000000000001
PRINTER_CLK.value(0)
sleep(delaytime)
PRINTER_DIN.value(word_bit)
PRINTER_CLK.value(1)
sleep(delaytime)
for mov_bit in range(360-((supper*32)+(slower*24))):
PRINTER_CLK.value(0)
sleep(delaytime)
PRINTER_DIN.value(0)
PRINTER_CLK.value(1)
sleep(delaytime)
if (supper*32)+(slower*24) < 192:
PRINTER_LAT.value(0)
STB1.value(1)
STB2.value(1)
STB3.value(1)
sleep(0.005)
STB1.value(0)
STB2.value(0)
STB3.value(0)
PRINTER_LAT.value(1)
else:
PRINTER_LAT.value(0)
STB4.value(1)
STB5.value(1)
STB6.value(1)
sleep(0.005)
STB4.value(0)
STB5.value(0)
STB6.value(0)
PRINTER_LAT.value(1)
# PRINTER_LAT.value(0)
# STB1.value(1)
# STB2.value(1)
# STB3.value(1)
# STB4.value(1)
# STB5.value(1)
# STB6.value(1)
# sleep(0.005)
# STB1.value(0)
# STB2.value(0)
# STB3.value(0)
# STB4.value(0)
# STB5.value(0)
# STB6.value(0)
# PRINTER_LAT.value(1)
while True:
if uart1.any()>1:
rx2 = []
data_name2 = ''
bin_data = uart1.read(40)
uart1.sendbreak()
rx1 = list(bin_data)
for item in rx1:
rx2.append(chr(item))
print(rx2)
if rx2[7:13:1] == floor1:
floor1def()
elif rx2[7:13:1] == floor2:
floor2def()
elif rx2[7:13:1] == floor3:
floor3def()
for linss in range(32):
supper=slower=0
if linss < 32:
for lins in range(len(line_word)):
# if lins//12:
# break
if (line_word[lins].isupper() or line_word[lins].isdigit() or line_word[lins].isspace()):
last_word_size32 (ascii_code.code.get(line_word[lins]), linss%32, lins%12, supper, slower)
supper += 1
elif (line_word[lins].islower()):
word_size24 (ascii_code.code.get(line_word[lins]), linss%32, lins%12, supper, slower)
slower += 1
else:
if linss == 32:
sleep(5.8)
for lins in range(motor_speed):
if (line_word[lins].isupper()):
last_word_size32 (ascii_code.code.get(line_word[12]), linss%32, lins%12, len(line_word))
# elif:
# _thread.start_new_thread(motor.run_stop, (motor_speed, line))
# for linss in range(32):
# for lins in range(len(line_word)):
# if (line_word[lins].isupper()):
# last_word_size32 (ascii_code.code.get(line_word[lins]), linss, lins, len(line_word))
line_word.clear()