[PYTHON] Use raspberryPi and Julius (speech recognition). ⑤ i2c character display

Related article

It's been a long way so far, and I don't know what it is anymore, but I would like to leave it as a reference site for myself. Use raspberryPi and julus (speech recognition). ① Microphone Use julius (speech recognition) on raspberry Pi. ② Installation Use raspberry Pi and Julius (speech recognition). ③ Dictionary creation Use raspberry Pi and Julius (speech recognition). ④ L Chika Use raspberry Pi and Julius (speech recognition). ⑤ i2c character display

What to use

AQM0802 (using the completed version of the i2c connection small display) Jumper wire (male-female) 4-5 raspberryPi 3B+ USB microphone

Connect AQM0802

Set the i2c usage of Raspberry Pi. The pin layout is UDD, RESET, SCL, SDA, GND from the top, so wire with reference to the image below. image.png Quoted from Using LCD Module with Raspberry Pi

Check the connection.

$ sudo i2cdetect -y 1

image.png I was able to confirm that it was connected with 3e.

Create a file as a trial and display it on the display ``` $ sudo apt-get -y install i2c-tools $ nano I2C_LCD_TEST.sh ```

I2C_LCD_TEST.sh


#!/bin/sh

# AQM0802A Raspberry Pi I2C control
# http://www.neko.ne.jp/~freewing/
# http://akizukidenshi.com/catalog/g/gP-06669/

# sudo nano I2C_LCD_TEST.sh
# sudo chmod 755 I2C_LCD_TEST.sh
# ./I2C_LCD_TEST.sh

#AQM0802A LCD initialization
# 0x38 0x39 Function Set
i2cset -y 1 0x3e 0x00 0x38 0x39 i

# 0x10 Bias selection/Internal OSC frequency adjust
# 0x70 Contrast set(low byte)
# 0x56 Power/ICON control/Contrast set(high byte)
# 0x6C Follower control
i2cset -y 1 0x3e 0x00 0x10 0x70 0x56 0x6C i
sleep 0.3

# 0x38 Function Set
i2cset -y 1 0x3e 0x00 0x38 i

# 0x02 Return Home
i2cset -y 1 0x3e 0x00 0x02 i

# 0x0C Display ON/OFF control
# i2cset -y 1 0x3e 0x00 0x0C i

# 0x0F Display ON/OFF control
i2cset -y 1 0x3e 0x00 0x0F i

# 0x01 Clear Display
i2cset -y 1 0x3e 0x00 0x01 i
sleep 0.5

# 0x40 CGRAM addres = 0x00 CHARACTER CODE = 0x00
i2cset -y 1 0x3e 0x00 0x40 b
i2cset -y 1 0x3e 0x40 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 i
# 0x40 CGRAM addres = 0x08 CHARACTER CODE = 0x01
i2cset -y 1 0x3e 0x00 0x48 b
i2cset -y 1 0x3e 0x40 0x1F 0x1E 0x1D 0x1C 0x1B 0x1A 0x19 0x18 i

#1st line DDRAM address= 0x00
i2cset -y 1 0x3e 0x00 0x80 b
# "=FREE =="
i2cset -y 1 0x3e 0x40 0x3D 0x46 0x52 0x45 0x45 0x20 0x3D 0x3D i
sleep 0.5

#2nd line DDRAM address= 0x40
i2cset -y 1 0x3e 0x00 0xc0 b
# "== WING="
i2cset -y 1 0x3e 0x40 0x3D 0x3D 0x20 0x57 0x49 0x4E 0x47 0x3D i
$ chmod 755 I2C_LCD_TEST.sh
$ sudo ./I2C_LCD_TEST.sh

How to connect the I2C communication type LCD module AQM0802A to GPIO of Raspberry Pi 3 is being tried as it is. You can see that the display works.

Note about the command

# Screen initialization
$ i2cset -y 1 0x3e 0x00 0x38 0x39 0x14 0x70 0x56 0x6c i
$ i2cset -y 1 0x3e 0x00 0x38 0x0c 0x01 i
$ i2cset -y 1 0x3e 0x00 0x80

#Erase everything and move the cursor to the beginning of the first line
sudo i2cset -y 1 0x3e 0 0x38 0x0d 0x01 i

#Display specified data continuously
 sudo i2cset -y 1 0x3e 0x40 [data1] [data2] [data3]  i

#Start a new line and move the cursor to the beginning
sudo i2cset -y 1 0x3e 0x00 0xc0 i

0x3e is the write target (I2CBUS). i is "block data", a specification to write data continuously. b is a normal write in bytes. Character display of AQM0802 Quote Display characters on LCD display with Raspberry Pi zero Detailed explanation of I2C command of Rasberry PI

The word display is created by referring to the character patterns of AQM0802.

#Thank You
sudo i2cset -y 1 0x3e 0x40 0xb1 0xd8 0xb6 0xde 0xc4 0xb3  i
Ari Kato U

#Hello
sudo i2cset -y 1 0x3e 0x40 0xba 0xdd 0xc6 0xc1 0xca i
Hello

Try to move Julius and AQM0802 in cooperation ### Display the prepared characters for what you say. Start Julius in module mode and execute the following file.

test_i2c001.py


#!usr/bin/env python
# -*- coding: utf-8 -*-
import smbus
import time
import subprocess
import socket
import string

i2c = smbus.SMBus(1) # 1 is bus number
addr02=0x3e #lcd
_command=0x00
_data=0x40
_clear=0x01
_home=0x02
display_On=0x0f
LCD_2ndline=0x40+0x80
 
#LCD AQM0802/1602
def command( code ):
        i2c.write_byte_data(addr02, _command, code)
        time.sleep(0.1)
  
def writeLCD( message ):
        mojilist=[]
        for moji in message:
                mojilist.append(ord(moji)) 
        i2c.write_i2c_block_data(addr02, _data, mojilist)
        time.sleep(0.1)
 
def init ():
        command(0x38)
        command(0x39)
        command(0x14)
        command(0x73)
        command(0x56)
        command(0x6c)
        command(0x38)
        command(_clear)
        command(display_On)
        
def ari ():
        arigatoulist=[0xb1, 0xd8, 0xb6, 0xde, 0xc4, 0xb3]
        i2c.write_i2c_block_data(addr02, _data, arigatoulist)
        time.sleep(0.1)
        print(arigatoulist)

def konnichiha():
        konnichihalist=[0xba, 0xdd, 0xc6, 0xc1, 0xca]
        i2c.write_i2c_block_data(addr02, _data, konnichihalist)
        time.sleep(0.1)
  
HOST = '127.0.0.1'   #IP address of julius server
PORT = 10500         #julius server listening port
DATESIZE = 1024     #Number of received data bytes

class Julius:

    def __init__(self):

        self.sock = None

    def run(self):

        #Connect to julius server with socket communication
        with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as self.sock:
            self.sock.connect((HOST, PORT))

            strTemp = "" #Variable to store spoken words
            fin_flag = False #End of story flag

            while True:

                #Receive data from julius server
                data = self.sock.recv(DATESIZE).decode('utf-8')

                for line in data.split('\n'):
                    #From the received data<WORD>Extract the words written after and store them in a variable.
                    # <WORD>After, the spoken words are listed.
                    index = line.find('WORD="')
                    if index != -1:
                        #Store the words spoken in strTemp
                        strTemp = strTemp + line[index+6:line.find('"',index+6)]
                        
                    #For received data</RECOGOUT>'If there is, the story ends ⇒ Set the flag to True
                    if '</RECOGOUT>' in line:
                        fin_flag = True

                #Execute a print statement for each word spoken
                if fin_flag == True:
                    if 'Thank you' in strTemp:
                        print("You are welcome")
                        init ()
                        command(_clear)
                        ari()
                    elif 'Hello' in strTemp:
                        print("Good evening")
                        init ()
                        command(_clear)
                        konichiwa()
                    else:
                        print("Spoken words:" + strTemp)
                    
                    fin_flag = False
                    strTemp = ""

if __name__ == "__main__":

    julius = Julius()
    julius.run()

Convert what you said and display it in Echolalia. (Julius original dictionary words only)

Create a Japanese dictionary file according to the character patterns of AQM0802.

nihongo.py


nihongo = {"Ah":0xb1,
          "I":0xb2,
          "U":0xb3,
          "e":0xb4,
          "O":0xb5,
          "Or":0xb6,
          "Ki":0xb7,
          "Ku":0xb8,
          "Ke":0xb9,
          "This":0xba,
          "Sa":0xbb,
          "Shi":0xbc,
          "Su":0xbd,
          "Se":0xbe,
          "So":0xbf,
          "Ta":0xc0,
          "Chi":0xc1,
          "Tsu":0xc2,
          "hand":0xc3,
          "When":0xc4,
          "Nana":0xc5,
          "To":0xc6,
          "Nu":0xc7,
          "Ne":0xc8,
          "of":0xc9,
          "Is":0xca,
          "Hi":0xcb,
          "Fu":0xcc,
          "What":0xcd,
          "Ho":0xce,
          "Ma":0xcf,
          "Mi":0xd0,
          "Mu":0xd1,
          "Me":0xd2,
          "Also":0xd3,
          "Or":0xd4,
          "Yu":0xd5,
          "Yo":0xd6,
          "Et al.":0xd7,
          "Ri":0xd8,
          "Ru":0xd9,
          "Re":0xda,
          "Ro":0xdb,
          "Wow":0xdc,
          "Hmm":0xdd,
          "To":0xa6,
          "Ah":0xa7,
          "I":0xa8,
          "U":0xa9,
          "Eh":0xaa,
          "Mm":0xab,
          "Ya":0xac,
          "Shu":0xad,
          "Yo":0xad,
          "Tsu":0xaf,
          "But":"182 222",
          "Gi":"183 222",
          "Gu":"184 222",
          "Ge":"185 222",
          "Go":"186 222",
          "Za":"187 222",
          "Ji":"188 222",
          "Zu":"189 222",
          "Ze":"190 222",
          "I'm sorry":"191 222",
          "Is":"192 222",
          "Ji":"193 222",
          "Zu":"194 222",
          "so":"195 222",
          "Do":"196 222",
          "If":"202 222",
          "And":"203 222",
          "Bu":"204 222",
          "Be":"205 222",
          "Bo":"206 222",
          "Pa":"202 223",
          "Pi":"203 223",
          "Pu":"204 223",
          "Pe":"205 223",
          "Po":"206 223"
           }

test_i2c003.py


#!usr/bin/env python
# -*- coding: utf-8 -*-
import smbus
import time
import subprocess
import socket
import string
from nihongo import nihongo

i2c = smbus.SMBus(1) # 1 is bus number
addr02=0x3e #lcd
_command=0x00
_data=0x40
_clear=0x01
_home=0x02
display_On=0x0f
LCD_2ndline=0x40+0x80
 
#LCD AQM0802/1602
def command( code ):
        i2c.write_byte_data(addr02, _command, code)
        time.sleep(0.1)
 
def word( message ):
        kotoba = []
        for moji in message:
            kotoba.append(moji)
            
        wordlist = []
        for idx in range(0, len(kotoba)):
            a = kotoba[idx]
            val = nihongo[a]
            if type(val) is int:
                wordlist.append(val)
            else:
                nums = val.split()
                for i in range(2):
                    wordlist.append(int(nums[i]))
        print(wordlist)
        i2c.write_i2c_block_data(addr02, _data, wordlist)
        time.sleep(0.1)
        
def init ():
        command(0x38)
        command(0x39)
        command(0x14)
        command(0x73)
        command(0x56)
        command(0x6c)
        command(0x38)
        command(_clear)
        command(display_On)
 
 
HOST = '127.0.0.1'   #IP address of julius server
PORT = 10500         #julius server listening port
DATESIZE = 1024     #Number of received data bytes
 
class Julius:
 
    def __init__(self):
 
        self.sock = None
 
    def run(self):
 
        #Connect to julius server with socket communication
        with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as self.sock:
            self.sock.connect((HOST, PORT))
 
            strTemp = "" #Variable to store spoken words
            fin_flag = False #End of story flag
 
            while True:
 
                #Receive data from julius server
                data = self.sock.recv(DATESIZE).decode('utf-8')
 
                for line in data.split('\n'):
                    #From the received data<WORD>Extract the words written after and store them in a variable.
                    # <WORD>After, the spoken words are listed.
                    index = line.find('WORD="')
                    if index != -1:
                        #Store the words spoken in strTemp
                        strTemp = strTemp + line[index+6:line.find('"',index+6)]
 
                    #For received data</RECOGOUT>'If there is, the story ends ⇒ Set the flag to True
                    if '</RECOGOUT>' in line:
                        fin_flag = True
 
                #Execute a print statement for each word spoken
                if fin_flag == True:
                    print(strTemp[4:-3])
                    init ()
                    command(_clear)
                    word(strTemp[4:-3])
                  
                    fin_flag = False
                    strTemp = ""
 
if __name__ == "__main__":
 
    julius = Julius()
    julius.run()

I was able to display the recognized words on the display What was why "Thank you", "Hello". I want to recreate the dictionary and see if other words can be displayed.

Reference [Use AQM0802 (small LCD module with i2c connection) with Raspberry Pi](https://www.cloverfield.co.jp/2019/06/12/%E3%83%A9%E3%82%BA%E3%83 % 91% E3% 82% A4% E3% 81% A7aqm0802i2c% E6% 8E% A5% E7% B6% 9A% E5% B0% 8F% E5% 9E% 8Blcd% E3% 83% A2% E3% 82% B8 % E3% 83% A5% E3% 83% BC% E3% 83% AB% E3% 82% 92% E4% BD% BF% E3% 81% 8A% E3% 81% 86 /) [Using LCD module with Raspberry Pi](http://sea-mountain.hatenablog.jp/entry/2013/09/21/231242) [I2C connection AQM series character display LCD is used for Raspberry Pi (1) AQM0802](https://www.denshi.club/pc/raspi/i2caqmlcdarduinode1-aqm0802.html)

Recommended Posts

Use raspberryPi and Julius (speech recognition). ⑤ i2c character display
Use raspberryPi and julius (speech recognition). ① Microphone edition
Use raspberryPi and Julius (speech recognition). ④ L Chika
Use julius (speech recognition) on raspberryPi. ② Installation
Use raspberry Pi and Julius (speech recognition). ③ Dictionary creation
Speech synthesis and speech recognition by Microsoft Project Oxford