Compare commits

..

3 commits

Author SHA1 Message Date
Peter L
761e0f6c8d remote debugging changes 2021-11-10 13:15:26 +01:00
Peter Lorenz
d9c9d673fc Merge branch 'master' of https://git.theater.digital/johannes.payr/pizzabox-ctrl 2021-11-04 14:49:14 +02:00
Peter Lorenz
3002c7f2c2 added pin numbers 2021-11-04 14:44:19 +02:00
2 changed files with 62 additions and 31 deletions

View file

@ -5,27 +5,31 @@ import time
_PWM_MAX = const(65535) _PWM_MAX = const(65535)
_PWM_FREQ = const(2000) _PWM_FREQ = const(2000)
_PIN_EN_MOTOR_VERT = const(0) _PIN_EN_MOTOR_VERT = const(14)
_PIN_A_MOTOR_VERT = const(0) _PIN_A_MOTOR_VERT = const(12)
_PIN_B_MOTOR_VERT = const(0) _PIN_B_MOTOR_VERT = const(13)
_PIN_EN_MOTOR_HOR = const(0) _PIN_EN_MOTOR_HOR = const(15)
_PIN_A_MOTOR_HOR = const(0) _PIN_A_MOTOR_HOR = const(10)
_PIN_B_MOTOR_HOR = const(0) _PIN_B_MOTOR_HOR = const(11)
_PIN_EN_BACKLIGHT = const(0) _PIN_EN_BACKLIGHT = const(17)
_PIN_EN_FRONTLIGHT = const(0) _PIN_A_BACKLIGHT = const(18)
_PIN_B_BACKLIGHT = const(19)
_PIN_EN_FRONTLIGHT = const(16)
_PIN_A_FRONTLIGHT = const(20)
_PIN_B_FRONTLIGHT = const(21)
_PIN_LED_RED_BTN = const(0) _PIN_LED_RED_BTN = const(2)
_PIN_LED_BLU_BTN = const(0) _PIN_LED_BLU_BTN = const(4)
_PIN_RED_BTN = const(0) _PIN_RED_BTN = const(3)
_PIN_BLU_BTN = const(0) _PIN_BLU_BTN = const(5)
_PIN_SENS_END_VERT = const(0) _PIN_SENS_END_VERT = const(9)
_PIN_SENS_CNT_VERT = const(0) _PIN_SENS_CNT_VERT = const(7)
_PIN_SENS_END_HOR = const(0) _PIN_SENS_END_HOR = const(6)
_PIN_SENS_CNT_HOR = const(0) _PIN_SENS_CNT_HOR = const(8)
CMD_MOT_V = 'V' # run vertical motor CMD_MOT_V = 'V' # run vertical motor
CMD_MOT_H = 'H' # run horizontal motor CMD_MOT_H = 'H' # run horizontal motor
@ -90,7 +94,12 @@ pwm_mh.freq(_PWM_FREQ)
pin_mv_a = Pin(_PIN_A_MOTOR_VERT, Pin.OUT) pin_mv_a = Pin(_PIN_A_MOTOR_VERT, Pin.OUT)
pin_mv_b = Pin(_PIN_B_MOTOR_VERT, Pin.OUT) pin_mv_b = Pin(_PIN_B_MOTOR_VERT, Pin.OUT)
pin_mh_a = Pin(_PIN_A_MOTOR_HOR, Pin.OUT) pin_mh_a = Pin(_PIN_A_MOTOR_HOR, Pin.OUT)
pin_mh_b = Pin(_PIN_B_MOTOR_HOR) pin_mh_b = Pin(_PIN_B_MOTOR_HOR, Pin.OUT)
pin_bl_a = Pin(_PIN_A_BACKLIGHT, Pin.OUT)
pin_bl_b = Pin(_PIN_B_BACKLIGHT, Pin.OUT)
pin_fl_a = Pin(_PIN_A_FRONTLIGHT, Pin.OUT)
pin_fl_b = Pin(_PIN_B_FRONTLIGHT, Pin.OUT)
led_blu = Pin(_PIN_LED_BLU_BTN, Pin.OUT) led_blu = Pin(_PIN_LED_BLU_BTN, Pin.OUT)
led_red = Pin(_PIN_LED_RED_BTN, Pin.OUT) led_red = Pin(_PIN_LED_RED_BTN, Pin.OUT)
@ -118,15 +127,16 @@ def motor_hor(*opts):
def _motorctrl(scroll: Scroll, steps: int, *opts): def _motorctrl(scroll: Scroll, steps: int, *opts):
end = scroll.c + steps end = scroll.c + steps
while True: print(f'motorctrl, end={end}, scroll.c={scroll.c}')
err = end - scroll.c #while True:
if abs(err) > 4: # err = end - scroll.c
speed = (err / (2 * steps)) + 0.5 # if abs(err) > 4:
scroll.speed = int(100 * speed) # speed = (err / (2 * steps)) + 0.5
else: # scroll.speed = int(100 * speed)
scroll.speed = 0 # else:
break # scroll.speed = 0
time.sleep_ms(5) # break
# time.sleep_ms(5)
def backlight(*opts): def backlight(*opts):
_fade_led(pwm_bl, *opts) _fade_led(pwm_bl, *opts)
@ -167,6 +177,8 @@ def user_interaction(timeout):
b, r = btn_blu.value(), btn_red.value() b, r = btn_blu.value(), btn_red.value()
if (b + r) < 2: if (b + r) < 2:
tmr.deinit() tmr.deinit()
led_blu.value(0)
led_red.value(0)
return 'B' if not b else 'R' return 'B' if not b else 'R'
time.sleep_ms(50) time.sleep_ms(50)
tmr.deinit() tmr.deinit()
@ -219,6 +231,10 @@ def parseCmd(cmd_str: str):
if __name__ == '__main__': if __name__ == '__main__':
pin_bl_a.value(1)
pin_bl_b.value(0)
pin_fl_a.value(1)
pin_fl_b.value(0)
rxData = '' rxData = ''
while True: while True:
rxBuf = uart0.read(1) rxBuf = uart0.read(1)
@ -226,4 +242,4 @@ if __name__ == '__main__':
rxData += rxBuf.decode('utf-8') rxData += rxBuf.decode('utf-8')
if rxData.endswith('\n'): if rxData.endswith('\n'):
parseCmd(rxData.strip()) parseCmd(rxData.strip())
rxData = '' rxData = ''

View file

@ -1,14 +1,17 @@
from machine import Pin, Timer from machine import UART, Pin, Timer
import time import time
led = Pin(25, Pin.OUT) led = Pin(25, Pin.OUT)
btn_blu = Pin(2, Pin.IN, Pin.PULL_UP) btn_blu = Pin(5, Pin.IN, Pin.PULL_UP)
btn_red = Pin(3, Pin.IN, Pin.PULL_UP) btn_red = Pin(3, Pin.IN, Pin.PULL_UP)
led_blu = Pin(4, Pin.OUT)
led_red = Pin(2, Pin.OUT)
def user_interaction(timeout): def user_interaction(timeout):
def _toggle_leds(timer): def _toggle_leds(timer):
led.toggle() led_blu.toggle()
led_red.toggle()
tmr = Timer() tmr = Timer()
tmr.init(freq=2, mode=Timer.PERIODIC, callback=_toggle_leds) tmr.init(freq=2, mode=Timer.PERIODIC, callback=_toggle_leds)
startime = time.ticks_ms() startime = time.ticks_ms()
@ -19,6 +22,8 @@ def user_interaction(timeout):
tmr.deinit() tmr.deinit()
return 'B' if not b else 'R' return 'B' if not b else 'R'
tmr.deinit() tmr.deinit()
led_blu.value(0)
led_red.value(0)
return 'T' # Timeout return 'T' # Timeout
def recording(timeout): def recording(timeout):
@ -36,4 +41,14 @@ def recording(timeout):
return 'OK' return 'OK'
if __name__ == '__main__': if __name__ == '__main__':
print(recording(20)) #print(user_interaction(20))
#Print
uart0 = UART(0, baudrate=9600, tx=Pin(0), rx=Pin(1))
rxData = ''
while True:
rxBuf = uart0.read(1)
if rxBuf is not None:
rxData += rxBuf.decode('utf-8')
if rxData.endswith('\n'):
print(rxData.strip())
rxData = ''