Work Space
작업실 works

DcMortor
import RPi.GPIO as GPIO 
from time import sleep

GPIO.setmode(GPIO.BOARD)

ina1 = 33
ina2 = 35
ena = 37

inb1 = 31
inb2 = 29
enb = 23

GPIO.setup(ina1,GPIO.OUT)
GPIO.setup(ina2,GPIO.OUT)
GPIO.setup(ena,GPIO.OUT)

GPIO.setup(inb1,GPIO.OUT)
GPIO.setup(inb2,GPIO.OUT)
GPIO.setup(enb,GPIO.OUT)

pa=GPIO.PWM(ena,1000)
pa.start(25)

pb=GPIO.PWM(enb,1000)
pb.start(25)

print("\n")
print("The default speed & direction of motor is LOW & Forward.....")
print("r-run s-stop f-forward b-backward l-low m-medium h-high e-exit")
print("\n") 

while(1):

 x=input("")
# a ----- 
 if x=='ar':
 print("a run")
 if(temp1==1):
 GPIO.output(ina1,GPIO.HIGH)
 GPIO.output(ina2,GPIO.LOW)
 print("a forward")
 x='z'
 else:
 GPIO.output(ina1,GPIO.LOW)
 GPIO.output(ina2,GPIO.HIGH)
 print("a backward")
 x='z'

 elif x=='as':
 print("a stop")
 GPIO.output(ina1,GPIO.LOW)
 GPIO.output(ina2,GPIO.LOW)
 x='z'

 elif x=='af':
 print("a forward")
 GPIO.output(ina1,GPIO.HIGH)
 GPIO.output(ina2,GPIO.LOW)
 temp1=1
 x='z'

 elif x=='ab':
 print("a backward")
 GPIO.output(ina1,GPIO.LOW)
 GPIO.output(ina2,GPIO.HIGH)
 temp1=0
 x='z'
# a -----

# b ----- 
 if x=='br':
 print("b run")
 if(temp2==1):
 GPIO.output(inb1,GPIO.HIGH)
 GPIO.output(inb2,GPIO.LOW)
 print("forward")
 x='z'
 else:
 GPIO.output(inb1,GPIO.LOW)
 GPIO.output(inb2,GPIO.HIGH)
 print("backward")
 x='z'

 elif x=='bs':
 print("b stop")
 GPIO.output(inb1,GPIO.LOW)
 GPIO.output(inb2,GPIO.LOW)
 x='z'

 elif x=='bf':
 print("b forward")
 GPIO.output(inb1,GPIO.HIGH)
 GPIO.output(inb2,GPIO.LOW)
 temp2=1
 x='z'

 elif x=='bb':
 print("b backward")
 GPIO.output(inb1,GPIO.LOW)
 GPIO.output(inb2,GPIO.HIGH)
 temp2=0
 x='z'
# b -----

 elif x=='al':
 print("a low")
 pa.ChangeDutyCycle(25)
 x='z'

 elif x=='am':
 print("a medium")
 pa.ChangeDutyCycle(50)
 x='z'

 elif x=='ah':
 print("a high")
 pa.ChangeDutyCycle(75)
 x='z'
 
 elif x=='bl':
 print("b low")
 pb.ChangeDutyCycle(25)
 x='z'

 elif x=='bm':
 print("b medium")
 pb.ChangeDutyCycle(50)
 x='z'

 elif x=='bh':
 print("b high")
 pb.ChangeDutyCycle(75)
 x='z'
 
 
 elif x=='e':
 GPIO.cleanup()
 break
 
 else:
 print("<<< wrong data >>>")
 print("please enter the defined data to continue.....")

Translate Speech
Change the line 151 in google_trans_new/google_trans_new.py which is: response = (decoded_line + ']') to response = decoded_line  위치는 : /home/pi/.local/lib/python3.9/site-packages/google_trans_new 
 
 
 
 
 
 
 from google_speech import Speech
from google_trans_new import google_translator 

translator = google_translator() 
translate_text = translator.translate("안녕하세요 ", lang_tgt='en') 

speech = Speech(translate_text, 'en')
speech.play()

print(translate_text)
 
 
 
 
 
 
 
 
 
 from googletrans import Translator
from google_speech import Speech
from time import sleep

stringWord="ダウンタウンD.C.は、ホワイトハウスの近くに抗議し、挑発の別の夜の後に燃えます"

translator = Translator()
#result = translator.translate('안녕하세요.', dest='ja')
result = translator.translate(stringWord, dest='ko')
print(' -> ', result.text)
speech = Speech(result.text, 'ko')
speech.play()
sleep(2)
result = translator.translate(stringWord, dest='en')
print(' -> ', result.text)
speech = Speech(result.text, 'en')
speech.play()
sleep(2)
result = translator.translate(stringWord, dest='ja')
print(' -> ', result.text)
speech = Speech(result.text, 'ja')
speech.play()

SSH file share
Host  root user가 아닌 사용자 실행은 아래로 변경 
 
 sudo vi /etc/fuse.conf 
 # /etc/fuse.conf - Configuration file for Filesystem in Userspace (FUSE)

# Set the maximum number of FUSE mounts allowed to non-root users.
# The default is 1000.
mount_max = 1000

# Allow non-root users to specify the allow_other or allow_root mount options.
user_allow_other 
 
 
 
 Client 
 #!/bin/sh

/usr/bin/sshfs -o allow_other hyunsu@192.168.0.10:/data /home/pi/Desktop/sshf

exit 0

OCR Translate
이미지를 읽어서 번역하여 읽어주는 프로그램 
 
 
 
 
 
 
 import pytesseract
import cv2
import os
from PIL import Image
import numpy as np
import re
from google_speech import Speech
from google_trans_new import google_translator

translator = google_translator()

imgPath = '/home/pi/Desktop/work/doc.jpg'

if __name__=="__main__":
 print("START ... ")
 print(pytesseract.get_languages(config=''))
 ocrString = pytesseract.image_to_string(Image.open(imgPath), lang='kor+eng')
 #print(">>>> " + ocrString.strip())
 regex = re.sub('[-=+,#/\?:^.@*\"※~ㆍ!』‘|\(\)\[\]`\'…》\”\“\’·]', ' ', ocrString.strip())
 print(">>>> " + regex.strip())
 translate_text = translator.translate(regex.strip(), lang_tgt='ko')
 print(">>>> " + translate_text)
 speech = Speech(translate_text, 'ko')
 speech.play()
 
 
 
 read image

Proxy server
Proxy Server  
 #!/usr/bin/python
# This is a simple port-forward / proxy, written using only the default python
# library. If you want to make a suggestion or fix something you can contact-me
# at voorloop_at_gmail.com
# Distributed over IDC(I Don't Care) license
import socket
import select
import time
import sys

# Changing the buffer_size and delay, you can improve the speed and bandwidth.
# But when buffer get to high or delay go too down, you can broke things
buffer_size = 4096
delay = 0.0001
forward_to = ('localhost', 8081)

class Forward:
 def __init__(self):
 self.forward = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

 def start(self, host, port):
 try:
 self.forward.connect((host, port))
 return self.forward
 except Exception as e:
 print(">"+ str(e) )
 return False

class TheServer:
 input_list = []
 channel = {}

 def __init__(self, host, port):
 self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 self.server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
 self.server.bind((host, port))
 self.server.listen(200)

 def main_loop(self):
 self.input_list.append(self.server)
 while 1:
 time.sleep(delay)
 ss = select.select
 inputready, outputready, exceptready = ss(self.input_list, [], [])
 for self.s in inputready:
 if self.s == self.server:
 self.on_accept()
 break

 self.data = self.s.recv(buffer_size)
 if len(self.data) == 0:
 self.on_close()
 break
 else:
 self.on_recv()

 def on_accept(self):
 forward = Forward().start(forward_to[0], forward_to[1])
 clientsock, clientaddr = self.server.accept()
 if forward:
 print(">"+ str(clientaddr) + "has connected")
 self.input_list.append(clientsock)
 self.input_list.append(forward)
 self.channel[clientsock] = forward
 self.channel[forward] = clientsock
 else:
 print(">"+ "Can't establish connection with remote server.")
 print(">"+ "Closing connection with client side" + str(clientaddr))
 clientsock.close()

 def on_close(self):
 print(">"+ str(self.s.getpeername()) + "has disconnected")
 #remove objects from input_list
 self.input_list.remove(self.s)
 self.input_list.remove(self.channel[self.s])
 out = self.channel[self.s]
 # close the connection with client
 self.channel[out].close() # equivalent to do self.s.close()
 # close the connection with remote server
 self.channel[self.s].close()
 # delete both objects from channel dict
 del self.channel[out]
 del self.channel[self.s]

 def on_recv(self):
 data = self.data
 # here we can parse and/or modify the data before send forward
 #print(">"+ str(data))
 self.channel[self.s].send(data)

if __name__ == '__main__':
 server = TheServer('', 8080)
 try:
 server.main_loop()
 except KeyboardInterrupt:
 print(">"+ "Ctrl C - Stopping server")
 sys.exit(1) 
  