diff --git a/basics/ESP32-Pinout2.jpeg b/basics/ESP32-Pinout2.jpeg new file mode 100644 index 0000000..b4ec3c9 Binary files /dev/null and b/basics/ESP32-Pinout2.jpeg differ diff --git a/bluetooth/zs_040/README.md b/bluetooth/zs_040/README.md new file mode 100644 index 0000000..2dde71f --- /dev/null +++ b/bluetooth/zs_040/README.md @@ -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 \ No newline at end of file diff --git a/bluetooth/zs_040/bluetooth_serial_echo.py b/bluetooth/zs_040/bluetooth_serial_echo.py new file mode 100644 index 0000000..39add02 --- /dev/null +++ b/bluetooth/zs_040/bluetooth_serial_echo.py @@ -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) \ No newline at end of file diff --git a/ir_encoder/main.py b/ir_encoder/main.py new file mode 100644 index 0000000..1d6f826 --- /dev/null +++ b/ir_encoder/main.py @@ -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 \ No newline at end of file