diff --git a/blink/main.py b/blink/main.py index 09c2286..1933248 100644 --- a/blink/main.py +++ b/blink/main.py @@ -1,12 +1,19 @@ +# A led blinking every half second for five times. import time from machine import Pin +# create an output pin on pin #2 +# because for ESP-12 board the led light using GPIO2 which is pin2. +# the led operate in "inverted" mode, which means the pin value is '1' will set +# the led off, and pin value "0" will set the led on. led = Pin(2, Pin.OUT) -for i in range(3): - time.sleep(.5) - led.value(1) +# set the value high to turn the led off. +led.value(1) +time.sleep(1) +for i in range(5): time.sleep(.5) led.value(0) - + time.sleep(.5) + led.value(1) diff --git a/boot.py b/boot.py index 91135a5..28a5587 100644 --- a/boot.py +++ b/boot.py @@ -7,7 +7,8 @@ import time import machine -sta_if = network.WLAN(network.STA_IF); sta_if.active(True) +sta_if = network.WLAN(network.STA_IF) +sta_if.active(True) try: with open("passwords.txt") as f: @@ -24,8 +25,9 @@ sta_if.connect(station, password) - for i in range(15): - print(".") + #for i in range(15): + for i in range(30): + print(".", end=' ') if sta_if.isconnected(): break @@ -36,3 +38,5 @@ break else: print("Connection could not be made.\n") +if sta_if.isconnected(): + print("\nConnected as: {}".format(sta_if.ifconfig()[0])) diff --git a/dc_motor/DC_motor_control_over_WiFi.txt b/dc_motor/DC_motor_control_over_WiFi.txt new file mode 100644 index 0000000..4016894 --- /dev/null +++ b/dc_motor/DC_motor_control_over_WiFi.txt @@ -0,0 +1,21 @@ +DC motor control over WiFi +1. The NodeMCU board pin 12 and pin 13 is connected to the motor driver (L293D) +pin 2 and pin 7 to control the motor rotating forward or backward or stop. +The pin values corresponding to motor direction is as follows: +Pin2 = 0 Pin7 = 0 ---> motor stop +Pin2 = 1 Pin7 = 0 ---> motor forward +Pin2 = 0 Pin7 = 1 ---> motor backward +There are four buttons on our motor control web page for controlling motor's +on/off/forward/backward. + +2. The speed of the motor is also controlled by sending different PWM duty cycle +through pin14 to the L293D enable pin. +We have four button on our motor control web page for controlling the speed: +25 duty cycle, 50 duty cycle, 75 duty cycle and 100 duty cycle. + +3. The speed of the motor can also be controlled by a position transducer using +the only analog input pin A0. The analogy input pin converts the position +transducer voltage output into digital value(0, 1023). This digital value is then +used as input parameter for the pwm.duty() function to control the speed of the +motor seamlessly. We have a button on our motor control web page to test this +stepless speed control. diff --git a/dc_motor/main.py b/dc_motor/main.py new file mode 100644 index 0000000..062598e --- /dev/null +++ b/dc_motor/main.py @@ -0,0 +1,201 @@ +# This code controls a DC motor speed and direction over Wifi using +# Nodemcu esp8266 and L293D motor driver. +# http://localhost:8080/motor_control is the homepage for DC motor control. +try: + import usocket as socket +except: + import socket + +response_404 = """HTTP/1.0 404 NOT FOUND + +
Motor is on