https://raspida.com/keyboard-set-raspi-config
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
Libcameraコマンド群(スティルとかヴィデオとか)
https://hellobreak.net/raspberry-pi-bullseye-libcamera/ に詳しい
64ビットOSになってOSがBullseyeになったためらしい
最新OS64ビットではraspistillは廃止 libcameraになっていた
https://www.indoorcorgielec.com/resources/raspberry-pi/camera-setup/ にくわしい
https://stackoverflow.com/questions/27777547/missing-libmmal-so-with-picamera-library やにこい しかもpicameraはまだ64bit対応していないだとか。。。
撮影と録音はwebcam-with-microphoneでいくしかない
ーーーーー python3 motor-server.py --------------------------
from http.server import HTTPServer, BaseHTTPRequestHandler
import motor
import RPi.GPIO as GPIO
class MotorServerHandler(BaseHTTPRequestHandler):
# get access
def do_GET(self):
path = self.path
print("path=", path)
body = "ok"
if path == "/":
f = open("motor-client.html", encoding='utf-8')
body = f.read()
f.close()
if path == "/forward":
motor.forward()
elif path == "/back":
motor.backward()
elif path == "/left":
motor.lturn()
elif path == "/right":
motor.rturn()
elif path == "/stop":
motor.stop()
else:
print("command unknown")
self.send_response(200)
self.send_header('Content-Type', 'text/html;charset=utf-8')
self.end_headers()
self.wfile.write(body.encode('utf-8'))
try:
#server start
addr = ('', 8081)
httpd = HTTPServer(addr, MotorServerHandler)
print("server start on port 8081")
httpd.serve_forever()
except KeyboardInterrupt:
pass
httpd.socket.close()
GPIO.cleanup()
ーーmotor.pyーーーーーーーーーーーーーーーーーーーーー
import RPi.GPIO as GPIO
#from time import sleep
GPIO.setmode(GPIO.BCM)
GPIO.setup(24,GPIO.OUT)
GPIO.setup(25,GPIO.OUT)
GPIO.setup(20,GPIO.OUT)
GPIO.setup(21,GPIO.OUT)
p0=GPIO.PWM(24,50)
p1=GPIO.PWM(25,50)
p2=GPIO.PWM(20,50)
p3=GPIO.PWM(21,50)
p0.start(0)
p1.start(0)
p2.start(0)
p3.start(0)
def forward():
p0.ChangeDutyCycle(0)
p1.ChangeDutyCycle(70)
p2.ChangeDutyCycle(0)
p3.ChangeDutyCycle(70)
#sleep(0.5)
def backward():
p0.ChangeDutyCycle(70)
p1.ChangeDutyCycle(0)
p2.ChangeDutyCycle(70)
p3.ChangeDutyCycle(0)
#sleep(0.5)
def rturn():
p0.ChangeDutyCycle(70)
p1.ChangeDutyCycle(0)
p2.ChangeDutyCycle(0)
p3.ChangeDutyCycle(70)
#sleep(0.5)
def lturn():
p0.ChangeDutyCycle(0)
p1.ChangeDutyCycle(70)
p2.ChangeDutyCycle(70)
p3.ChangeDutyCycle(0)
#sleep(0.5)
def stop():
p0.ChangeDutyCycle(0)
p1.ChangeDutyCycle(0)
p2.ChangeDutyCycle(0)
p3.ChangeDutyCycle(0)
#sleep(1)
----------------motor-client.html--------------------------------------------------
<!DOCTYPE html><html><head><meta chatset="utf-8">
<meta name="viewport" content="width=device-width">
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<style> button { font-size:30px; border-radius:6px; } </style>
</head><body style="text-align:center; font-size:30px;">
<script>
function send(cmd) { $.get(cmd); $('#msg').html(cmd); }
</script><p>
<button onclick="send('forward')">↑</button><br>
<button onclick="send('left')">←</button>
<button onclick="send('stop')">□</button>
<button onclick="send('right')">→</button><br>
<button onclick="send('back')">↓</button><br>
<p id="msg"></p>
</p></body></html>
----------------------------------------------------------
0 件のコメント:
コメントを投稿