From 441352559abac889be9092b25b79addd9257df83 Mon Sep 17 00:00:00 2001 From: tuz Date: Wed, 15 Oct 2025 00:41:38 -0500 Subject: [PATCH] update(General) --- .gitignore | 1 + docs/arduino.md | 6 ++ docs/object.md | 4 ++ docs/thonny.md | 34 ----------- src/ESP32/5_common_cathode.py | 10 +--- src/ESP32/6_motor.py | 106 +++++++++++++++++++++++++++++++++ src/ESP32/6_motor_v1.py | 47 +++++++++++++++ src/ESP32/7_potenciometro.py | 34 +++++++++++ src/ESP32/README.md | 58 +++++++++++++++++- src/ESP32/template/3_button.py | 4 +- 10 files changed, 260 insertions(+), 44 deletions(-) create mode 100644 docs/arduino.md create mode 100644 docs/object.md create mode 100644 src/ESP32/6_motor.py create mode 100644 src/ESP32/6_motor_v1.py create mode 100644 src/ESP32/7_potenciometro.py diff --git a/.gitignore b/.gitignore index e69de29..330b830 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1 @@ +**/.nvim/ diff --git a/docs/arduino.md b/docs/arduino.md new file mode 100644 index 0000000..7b2bb54 --- /dev/null +++ b/docs/arduino.md @@ -0,0 +1,6 @@ +# Arduino + +`arduino` + + +# IDE diff --git a/docs/object.md b/docs/object.md new file mode 100644 index 0000000..66ef4aa --- /dev/null +++ b/docs/object.md @@ -0,0 +1,4 @@ +# Object + + +## led diff --git a/docs/thonny.md b/docs/thonny.md index cbad482..aa856ea 100644 --- a/docs/thonny.md +++ b/docs/thonny.md @@ -15,37 +15,3 @@ cd thonny-4.1.7 ``` ### Windows - - - -## Code - -### (HIGH) status -led.value(1) -led.on() - -### (LOW) status - -led.value(0) -led.off() - - -### Pin -led_placa = Pin(2, Pin.OUT, value=1) - -### Button -boton_up = Pin(4, Pin.IN, Pin.PULL_DOWN) - - -## Mod - -### Time - -import utime - -utime.sleep() - -utime.sleep_ms() - -utime.sleep_us() - diff --git a/src/ESP32/5_common_cathode.py b/src/ESP32/5_common_cathode.py index c857061..4f9e52d 100644 --- a/src/ESP32/5_common_cathode.py +++ b/src/ESP32/5_common_cathode.py @@ -1,11 +1,7 @@ - from machine import Pin import utime from time import sleep - - - class taller2: # display_common_cathode catodos = ( @@ -71,7 +67,7 @@ class taller2: self.bit = self.bit << 1 -def main(): +def main(): secmentos = { 'a': Pin(13, Pin.OUT, value=0), 'b': Pin(12, Pin.OUT, value=0), @@ -82,10 +78,10 @@ def main(): 'g': Pin(25, Pin.OUT, value=0), 'dp': Pin(32, Pin.OUT, value=0) } - + for key, value in secmentos.items(): value.on() - utime.sleep_ms(160) + utime.sleep_ms(500) value.off() program = taller2() diff --git a/src/ESP32/6_motor.py b/src/ESP32/6_motor.py new file mode 100644 index 0000000..884b9ef --- /dev/null +++ b/src/ESP32/6_motor.py @@ -0,0 +1,106 @@ +from machine import Pin +import utime + + +class taller3: + pin_board = Pin(2, Pin.OUT, value = 0) + pin_yellow = Pin(25, Pin.OUT, value = 0) + pin_white = Pin(26, Pin.OUT, value = 0) + pin_green = Pin(27, Pin.OUT, value = 0) + + # Pin input + # 34 + button_1 = Pin(32, Pin.IN, Pin.PULL_UP) + button_2 = Pin(35, Pin.IN, Pin.PULL_UP) + button_3 = Pin(34, Pin.IN, Pin.PULL_UP) + + In1 = Pin(5, Pin.OUT, value = 0) + In2 = Pin(18, Pin.OUT, value = 0) + In3 = Pin(19, Pin.OUT, value = 0) + In4 = Pin(21, Pin.OUT, value = 0) + + motor_pin = {In1, In2, In3, In4} + + s1 = Stepper.create(In1, In2, In3, In4) + s1.step(1018, -1) + + paso_1 = ( + int('1000', 2), + int('0100', 2), + int('0010', 2), + int('0001', 2) + ) + + paso_2 = ( + int('1100', 2), + int('0110', 2), + int('0011', 2), + int('1001', 2) + ) + + medio_paso = { + int('1000', 2), + int('1100', 2), + int('0100', 2), + int('0110', 2), + int('0011', 2), + int('0001', 2), + int('1001', 2), + } + + SLEEP_MS = 500 + DELAY_MS = 120 + + sentido = True + config - 1 + + + bobinas = list() + + def __init__(self): + for i in motor_pin: + bobinas.append(i) + + while True: + if not button_1.value(): + utime.sleep_ms(self.DEBOUNCE_MS) + print("btn1") + pin_green.value(not pin_green.value()) + motor_int_1.value(not motor_int_1.value()) + continue + + if not button_2.value(): + utime.sleep_ms(self.DEBOUNCE_MS) + print("btn2") + pin_white.value(not pin_white.value()) + motor_int_2.value(not motor_int_2.value()) + continue + + if not button_3.value(): + utime.sleep_ms(self.DEBOUNCE_MS) + print("btn3") + pin_yellow.value(not pin_yellow.value()) + motor_int_3.value(not motor_int_3.value()) + continue + +def main(): + program = taller3() + + + +if __name__ == '__main__': + main() + + + + if not self.button_2.value(): + utime.sleep_ms(self.DEBOUNCE_MS) + print("btn2") + self.pin_white.value(not self.pin_white.value()) + continue + + if not self.button_3.value(): + utime.sleep_ms(self.DEBOUNCE_MS) + print("btn3") + self.pin_yellow.value(not self.pin_yellow.value()) + continue diff --git a/src/ESP32/6_motor_v1.py b/src/ESP32/6_motor_v1.py new file mode 100644 index 0000000..eabc114 --- /dev/null +++ b/src/ESP32/6_motor_v1.py @@ -0,0 +1,47 @@ +from machine import Pin +import utime + +class taller3: + DEBOUNCE_MS = 100 + SLEEP_MS = 100 + DELAY_MS = 120 + + LOW = 0 + HIGH = 1 + + button_1 = Pin(13, Pin.IN, Pin.PULL_UP) + button_2 = Pin(12, Pin.IN, Pin.PULL_UP) + button_3 = Pin(14, Pin.IN, Pin.PULL_UP) + button_4 = Pin(27, Pin.IN, Pin.PULL_UP) + + In1 = Pin(5, Pin.OUT, value = 0) + In2 = Pin(18, Pin.OUT, value = 0) + In3 = Pin(19, Pin.OUT, value = 0) + In4 = Pin(21, Pin.OUT, value = 0) + + motor_pin = {In1, In2, In3, In4} + + def __init__(self): + pass + + def run(self): + while True: + utime.sleep_ms(300) + if not self.button_1.value(): + print("btn1") + if not self.button_2.value(): + print("btn2") + if not self.button_3.value(): + print("btn3") + if not self.button_4.value(): + print("btn4") + + + +def main(): + program = taller3() + program.run() + +if __name__ == '__main__': + main() + diff --git a/src/ESP32/7_potenciometro.py b/src/ESP32/7_potenciometro.py new file mode 100644 index 0000000..bea6d5b --- /dev/null +++ b/src/ESP32/7_potenciometro.py @@ -0,0 +1,34 @@ +from machine import ADC +from utime import sleep +def main(): + # True: Raspberry Pi Pico + # False: NodeMCU ESP8266 + placa = False + + if placa: + potenciometro = ADC(26) #Raspberry Pi Pico ADC0 + else: + # ESP32 + potenciometro = ADC(34) + # potenciometro = ADC(0) #NodeMCU8266v3 ADC0 + factor_10 = 3.3 / (1023) #Se puede leer con read() + + factor_16 = 3.3 / (65535) + + while True: + + if not placa: #NodeMCU ESP8266 + bits = potenciometro.read(); + volts_10 = bits * factor_10 + print('\nValor en 10 bits: {}, y en volts: {}'.format(bits, volts_10)) + + bits_16 = potenciometro.read_u16(); + volts_16 = bits_16 * factor_16 + + + print('Valor en 16 bits: {}, y en volts: {}'.format(bits_16, volts_16)) + sleep(1) + + +if __name__ == '__main__': + main() diff --git a/src/ESP32/README.md b/src/ESP32/README.md index 23b09d8..2ace696 100644 --- a/src/ESP32/README.md +++ b/src/ESP32/README.md @@ -23,6 +23,62 @@ `"MicroPython family" = "ESP32"` `"variant" = "Espressif ESP32 / WROOM"` - + `"version" = "1.26.1` + +## Thonny + +### Template +```py +from machine import Pin +import utime + +LOW = 0 +HIGH = 1 + +def main(): + print("template") + +if __name__ == '__main__': + main() +``` + +### Pin + +#### Led + +```py +# (High) status +led.value(1) +led.on() + +# (Low) status +led.value(0) +led.off() + + +led_placa = Pin(2, Pin.OUT, value = 1) +``` + +#### Button + +```py +boton_down = Pin(4, Pin.IN, Pin.PULL_DOWN) +boton_up = Pin(4, Pin.IN, Pin.PULL_UP) +``` + +#### Time + +```py +import utime + +utime.sleep() + +utime.sleep_ms() + +utime.sleep_us() +``` + + + diff --git a/src/ESP32/template/3_button.py b/src/ESP32/template/3_button.py index c44067b..4cbb4bf 100644 --- a/src/ESP32/template/3_button.py +++ b/src/ESP32/template/3_button.py @@ -10,10 +10,10 @@ def main(): while True: if button_up.value() == 1: - pin_board.value(not pin_placa.value()) + pin_board.value(not pin_board.value()) sleep(1) if button_up2.value() == 1: - pin_board.value(not pin_placa.value()) + pin_board.value(not pin_board.value()) sleep(1) if __name__ == '__main__':