------------------------------------------------------------------------------------------
どうもL293DではIC自体の電源は不要のようだ 次のようにPWMできた Elegoo Code
#define ENABLE 5
#define DIRA 3
#define DIRB 4
int i;
void setup() {
//---set pin direction
pinMode(ENABLE,OUTPUT);
pinMode(DIRA,OUTPUT);
pinMode(DIRB,OUTPUT);
Serial.begin(9600);
}
void loop() {
//---back and forth example
Serial.println("One way, then reverse");
digitalWrite(ENABLE,HIGH); // enable on
for (i=0;i<5;i++) {
digitalWrite(DIRA,HIGH); //one way
digitalWrite(DIRB,LOW);
delay(500);
digitalWrite(DIRA,LOW); //reverse
digitalWrite(DIRB,HIGH);
delay(500);
}
digitalWrite(ENABLE,LOW); // disable
delay(2000);
Serial.println("fast Slow example");
//---fast/slow stop example
digitalWrite(ENABLE,HIGH); //enable on
digitalWrite(DIRA,HIGH); //one way
digitalWrite(DIRB,LOW);
delay(3000);
digitalWrite(ENABLE,LOW); //slow stop
delay(1000);
digitalWrite(ENABLE,HIGH); //enable on
digitalWrite(DIRA,LOW); //one way
digitalWrite(DIRB,HIGH);
delay(3000);
digitalWrite(DIRA,LOW); //fast stop
delay(2000);
Serial.println("PWM full then slow");
//---PWM example, full speed then slow
analogWrite(ENABLE,255); //enable on
digitalWrite(DIRA,HIGH); //one way
digitalWrite(DIRB,LOW);
delay(2000);
analogWrite(ENABLE,180); //half speed
delay(2000);
analogWrite(ENABLE,128); //half speed
delay(2000);
analogWrite(ENABLE,50); //half speed
delay(2000);
analogWrite(ENABLE,128); //half speed
delay(2000);
analogWrite(ENABLE,180); //half speed
delay(2000);
analogWrite(ENABLE,255); //half speed
delay(2000);
digitalWrite(ENABLE,LOW); //all done
delay(10000);
}
--------------------------------------------------------------------------- tb67h450:rs to picow gnd,vm to 5v supply(+),
vref to 3.3/5v of picow,gnd to picow and 5v supply(-)
from machine import Pin,PWM
import network
import socket
import time
import utime
led = Pin(2,Pin.OUT)
IN1 = Pin(14,Pin.OUT)
IN2 = Pin(15,Pin.OUT)
#IN1=PWM(Pin(1))
#IN2=PWM(Pin(2))
#IN1.freq(100)
#IN2.freq(100)
#max_duty=65025
led.value(1)
time.sleep(2)
led.value(0)
def front():
led.value(1)
IN1.value(1)
IN2.value(0)
utime.sleep(0.5)
IN1.value(0)
IN2.value(0)
utime.sleep(0.5)
#IN1.duty_u16(0)
#for i in range(50,70):
# IN2.duty_u16(int(max_duty*i*0.01))
# utime.sleep(0.1)
#IN1.duty_u16(0)
#IN2.duty_u16(0)
#utime.sleep(1)
def back():
led.value(0)
IN1.value(0)
IN2.value(1)
utime.sleep(0.5)
IN1.value(0)
IN2.value(0)
utime.sleep(0.5)
#IN2.duty_u16(0)
#for i in range(50,70):
# IN2.duty_u16(int(max_duty*i*0.01))
# utime.sleep(0.1)
#IN1.duty_u16(0)
#IN2.duty_u16(0)
#utime.sleep(1)
ssid = 'RPI_PICO_AP'
password = '12345678'
# ap code configuration code
ap = network.WLAN(network.AP_IF)
ap.config(essid=ssid, password=password)
ap.active(True) #activating
while ap.active() == False:
pass
print('Connection is successful')
print(ap.ifconfig())
#wifi接続
#ssid = 'WifiのID'
#Password = 'Password'
###wlan = network.WLAN(network.STA_IF)
##wlan.active(True)
#wlan.connect(ssid,Password)
#wlan.isconnected()
#while not wlan.isconnected():
# pass
#Open socket
addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1]
s = socket.socket()
s.bind(addr)
s.listen(1)
print('listening on', ap.ifconfig()[0]) # wlan change to ap fof softap mode
#html
def home_page():
html = """<html>
<title>LED ON/OFF</title>
<center>
<h>LED ON/OFF</h1>
<p><a href="/ON"><input type="button" value="ON"></a>
<a href="/OFF"><input type="button" value="OFF"></a></p>
</center>
<html>"""
return html
while True:
cl,addr = s.accept()
request = cl.recv(1024)
request = str(request)
if request.find("/ON") ==6:
front()
if request.find("/OFF") ==6:
back()
response = home_page()
cl.send(response)
cl.close()
:: まずthonnyで電波をとめる、あと、PCのコネクトを閉じる 以後は同様に
だめなら再起動でreuseaddressをリセット
0 件のコメント:
コメントを投稿