IOT

Thermal print head for a parking management system based on Raspberry Pi pico and STONE TFT LCD

Brief introduction

Thermal printers are very common in our daily life, and there are examples of thermal printers in restaurants, parking lots and shopping. This article will focus on the application of thermal printers in parking systems.

Materials to be used

  • STONE STWI101WT-01
  • FTP thermal printer head
  • Raspberry Pi pico
    • Coin-operated machine
    FunctionThe 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.The design processAt first I wanted to use the Raspberry Pi pico to make a small printer. Then in the process of selecting components I think the thermal printer is more convenient to achieve, after determining the program, I began to purchase hardware. In fact, in the process of online procurement I found that there are many thermal printers with good driver circuits, most of them are made by using stm’s chip, and they are designed with their own set of instructions. For example, by using his instructions to let the printer print characters or go paper, but this printer practicality is very high, but there is no value of learning. It is to send instructions through the serial port on the line, you can manipulate the printer. So I thought I’d buy a print head and develop it myself. Then about the print head, I chose a ftp thermal print head.The ftp thermal print head
  • This print head should be available internationally, the basic principles are similar. The left side is a stepper motor. Then the middle head is 6 heating units. Each heating unit has 64 heating points on it. So a total of 384 heating points. Then below is a latch. Below the latch is a shift register. Finally, there is a clock signal to be provided. So the whole principle of operation is to provide a clock signal to the print head and then send a data every clock period, after sending 384 clock signals and 384 data, the data in the shift register will be stored in the latch. Then the latch is set to low level. Then the 384 heating points will choose to heat or not to heat according to whether each data is 0 or 1. At the same time, let the stepper motor rotate to drive the thermal paper to design the desired character.After I got the thermal print head, I went ahead and asked for a datasheet and it was a 30pin fpc cable. So it’s obviously not very convenient to connect to the pico directly with it. So I thought I’d better design a backplane circuit.I have a STONE serial screen is 12v power supply, and then I look at the thermal print head printing voltage of a reference value is 7.6v, the maximum value is 8v, then provide it with a voltage of about 7.6v. It also has a logic voltage is 3.3v, and then the Raspberry Pi pico maximum support 5v power supply and it has a 3.3v output voltage, then the power supply design can use two dcdc, with 12v power supply, one dcdc output 7.6v to power the thermal print head, the other dcdc output 5v to the pico, and then use the 3.3v from the pico to power the thermal print head logic voltage. Then 12v lead the way directly to the serial screen.
  • By the way, the stepper motor for that thermal print head also needs to be driven. I have an integrated Darlington tube integrator. But it’s too big, and it’ s a straight plug-in, so just buy a driver chip. Then this aspect of the drive motor is also OK.Printing requires the design of a font, basically everyone is using spi flash for font storage, which is a huge project. Only ascii code is more than 100, so you need to buy another SPF flash. Then the whole planning is almost like this.
    STONE Designer (GUI Designer software)From:https://www.stoneitech.com/support/download/software
  • Design the circuitThen the following began to design the circuit. First find the power supply, in fact, at the beginning I used a three-terminal voltage regulator, because the circuit is simple, after being made, the heating situation was more serious during debugging, very hot to touch, so I change to use dcdc. Just follow the chip data sheet directly to do the circuit diagram. I chose mt2492 here, but I ignored an important parameter is the print head operating current, the maximum output current of this chip is 2A, but the print head operating current of 2.3A, a difference of 0.3A, it can also be used, but the efficiency is not so high, we’ ll talk about the specific effect later.
  • Then the motor driver chip that I bought is lv8548, see the print head data sheet, which has a stepper motor drive timing diagram, according to its timing, to provide it with a four-way pwm signal on it.
  • Then is the flash chip, with by25q32bs, capacity of 32Mbit is quite large, and connected to the pico, waiting to be called by the pico.
  • After that, 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.
  • After done and can be used is as shown below, leaving a pin header receptacle on the board for the Raspberry Pi pico, you can directly plugged into it.
    The Raspberry Pi pico
  • Turn on the power, first not connected to the pico and print head, measure the output voltage of the dcdc, in the normal case one is about 7.5v, the other one is about 5v.
  • Then connect the print head, serial screen, and pico, measure the logic voltage is about 3.3v, after no problem, you can write the program.
    ProgramI intend to first adjust the stepper motor, this part is easy to adjust, look at the timing diagram in the data sheet, 8 clock periods, every clock period should separately give the motor’s four pins a logic signal, after 8 periods the motor will turn up, and then adjust the speed, but in the middle we have to add a delay to adjust the duty ratio otherwise it turns too fast, the delay time I set is about 5ms and then after letting it turn you must give the level to low, otherwise the motor does not seem to turn in fact the internal coil is still on the power, after a long time you can smell the burning smell.Then write the function, put the body in a loop, the number of cycles represents the length of motor rotation, the function looks a little long, put it somewhere else alone and wait for the call.
  • This is the function after a few changes, the speed and duration will be transmitted in the main program. It still needs a lot of optimization.Then is the point of adjusting the print head, this part is difficult for me, it needs a clock signal, the data sheet is written in the maximum 8M, I thought it needed a signal of about 8M frequency, it’ difficult, first I measured the frequency with io flip level, the difference is too much.  And then I want to use pio, and I researched a whole day but the result is not good, my personal skills are limited, probably I need to deeply study the rp2040 chip manual.Then flip the level 384 periods to try, it is a workflow like this, initialize the data input 1 pin, latch 1 pin, clock signal 1 pin, 6 print unit pins, and then in addition to the latch all other pull low , and then send one data within one clock period, after cycling 384 times to set the latch to 0, to set the 6 print unit to 1, and then which point has data which point will be heated. After the implementation of the set, pull the level back.Then after the program was written and started testing, it really didn’t work, actually because too many print units were controlled but the current was not enough, then change it to give less two print units high level and test again.
  • It’s really working! It printed a horizontal line.That means there is no lower limit on the clock frequency, then you can run the stepper motor to print a vertical line. pico dual thread, then let the other thread to synchronous run the motor, then write the program and run. The vertical line comes out.
  • With the horizontal and vertical lines, then get a diagonal line, pay attention to one print unit has 64 points, that defines a length, such as 32, and then cycle 32 times 384 periods, each period only set the first 64 data to 1 and set the next 320 data to 0, and then 32 times each time only in the first unit to print a point and then cycle incremental, combined with the speed of the stepper motor to adjust, and finally adjusted out 64 * 32 size of the diagonal line, you can also first spell out a letter Z.  
  • Then the outline of the program is there, if you want to print the word you need to do the font first. First do a capital letter A, 32 * 32 size, with a list of definitions, I am planning to do here with pin.value (), so make the font, then use 32 rows and 32 columns of binary values to be called, take out to do a shift and then pass to pin.value (), so this is the process of implementation.
  • With 0 as the background and 1 as the foreground, the actual implementation process then looks like this.
  • The most external large cycle 32 is representing the cycle of 32 lines, that is, print 32 lines, and then the first 32 cycles inside is to heat half of the first heating unit, then the remaining 352 periods will be set to 0, and then minus 1 from 31 each time until 0, you can count the first line of the points that need to be heated from left to right, and then every 384 periods to be completed once the latch set 0 and the heating unit set 1 and then you can print, and then one A word out after looping 32 times again.
  • Still bold, this kind of dot matrix word, there are tools online can be done directly, the front plus 0b and then add a comma on the back, and then you play according to your own ideas, the font is actually initially intended to be stored in the flash chip, but I adjust a long time it still can not be opened.
  • I don’t know where the problem is, after I have time I will adjust again, the good thing is that pico itself has 16mbit size flash, store an ascii library is still enough, then I am so stored.
  • Define it with a dictionary, put it in a separate piece, and call it back in the main program. Then after debugging, the available version looks like this.from machine import Pinfrom time import sleepimport _threadimport rp2from array import arrayimport ascii_kuimport speed_motor#import sysdelaytime = 0.0000001 # Printer clock delaymotor = 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 motormov_bit = 0PRINTER_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 libraryshuru = input(“Please enter text:”)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) > 12:#     motor_speed = len(shuru) % 6#     if (len(shuru) % 6) == 0:#         motor_speed = 12# else:#     motor_speed = len(shuru)# print(motor_speed)motor_speed = len(shuru)line = (len(shuru) // 12) + 1if (len(shuru) % 12) == 0:    line -= 1lins = 0supper = 0slower = 0# _thread.start_new_thread(motor.run_stop, (0.005*motor_speed, 26*line))_thread.start_new_thread(motor.run_stop, (motor_speed, 1))# _thread.start_new_thread(motor.run_stop, (0.03, 56))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)        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)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)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()I am separate control printing unit, because the current is not enough so like this, but in order to print clear, making my printing speed becomes particularly slow, the more words the slower, and then the lowercase letters is 24 * 32 dot matrix, that it is less print points to use, but can not give it to leave 32 heating points of space then the character spacing is large, so the capital letters and lowercase letters are separated, the numbers are still 32 * 32. Then print can achieve the basic functions, but there are two auxiliary functions have not done, one is the lack of paper detection and overheating protection, the circuit part has been done, the program I still has no time to do it.Temporarily first manual attention to renew the paper and do not let the heating head heating it for a long time.The next step is to do the coin acceptor, and I found that the circuit forgot to leave a wiring port for the coin acceptor, so I’ll connect the wires from the back of the board.Fortunately, only one signal line to be used for the coin acceptor, and then look at my pico, there is a GP28 available on the right side, but, after connecting, the signal can not be measured, so I changed to use the GP22, the same program I do not understand why the GP28 can not be used.
  • Finally, the whole program is attached.from machine import UART,Pinfrom time import sleepimport _threadimport rp2from array import arrayimport ascii_kuimport speed_motorfrom os import uname#import sysuart1 = 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 delaycoin = Pin(22, Pin.IN,Pin.PULL_UP)coin_num = 0motor = 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 motormov_bit = 0PRINTER_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 -= 1lins = 0supper = 0slower = 0danjia = 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 +=                         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 += 1def 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 = Falsedef floor2def():    passdef floor3def():    passdef 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()
  • Source: Plato Data Intelliigence