savin some code

master
Drew Bednar 4 years ago
parent 7c80611054
commit f6262ba212

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

@ -0,0 +1,9 @@
# Blue tooth with the ZS-040 module
## Resources
- https://protosupplies.com/product/hc-05-zs-040-bluetooth-module/
- https://docs.micropython.org/en/latest/esp32/quickref.html#uart-serial-bus
- https://learn.adafruit.com/introducing-the-adafruit-bluefruit-le-uart-friend/command-mode-1
- https://learn.sparkfun.com/tutorials/serial-communication/rules-of-serial

@ -0,0 +1,23 @@
"""
This modul implements a simple serial connection to the ZS-040 and will echo out to the console
any messages it receives. This board is a Bluetooth SPP (Serial Port Protocol) module.
When powered on the device will broadcast as BT-05 by default. Default passwords are usually 1234 or 0000.
"""
from machine import Pin, UART
from utime import sleep_ms
BT_STATE_PIN = Pin(5, Pin.IN)
uart = UART(2, baudrate=38400, tx=17, rx=16, bits=8, stop=1, parity=None)
while True:
if BT_STATE_PIN.value():
if uart.any():
data = uart.read(1)
print(data.decode('utf8'))
else:
print("No data. Sleeping")
else:
print("No Bluetooth device paired.")
sleep_ms(500)

@ -0,0 +1,42 @@
from machine import Pin
import utime
MOTOR_LEFT_DIR = True # False if Reverse
MOTOR_RIGHT_DIR = True # False if Reverse
ENCODER_LEFT_COUNT = 0
ENCODER_RIGHT_COUNT = 0
ENCODER_LEFT_PIN = Pin(4, Pin.IN)
ENCODER_RIGHT_PIN = Pin(5, Pin.IN)
def handle_encoder_left(pin):
global ENCODER_LEFT_COUNT
if MOTOR_LEFT_DIR:
ENCODER_LEFT_COUNT += 1
else:
ENCODER_LEFT_COUNT -= 1
def handle_encoder_right(pin):
global ENCODER_RIGHT_COUNT
if MOTOR_RIGHT_DIR:
ENCODER_RIGHT_COUNT += 1
else:
ENCODER_RIGHT_COUNT -= 1
def main():
global MOTOR_LEFT_DIR
ENCODER_LEFT_PIN.irq(trigger=Pin.IRQ_RISING, handler=handle_encoder_left)
ENCODER_RIGHT_PIN.irq(trigger=Pin.IRQ_RISING, handler=handle_encoder_right)
while True:
print("LEFT: {} , RIGHT: {}".format(ENCODER_LEFT_COUNT, ENCODER_RIGHT_COUNT))
utime.sleep(3)
print("LEFT: {} , RIGHT: {}".format(ENCODER_LEFT_COUNT, ENCODER_RIGHT_COUNT))
utime.sleep(3)
print("LEFT: {} , RIGHT: {}".format(ENCODER_LEFT_COUNT, ENCODER_RIGHT_COUNT))
utime.sleep(3)
print("SWITCH DIR")
MOTOR_LEFT_DIR = not MOTOR_LEFT_DIR
Loading…
Cancel
Save