diff --git a/basics/ESP32-pinout-mapping.png b/basics/ESP32-pinout-mapping.png new file mode 100644 index 0000000..66c2f34 Binary files /dev/null and b/basics/ESP32-pinout-mapping.png differ diff --git a/basics/README.md b/basics/README.md index a487ffe..8a26a47 100644 --- a/basics/README.md +++ b/basics/README.md @@ -55,3 +55,26 @@ screen -r ``` To kill a screen session press `Ctrl-A` then `k`. You will be prompted to confirm with `y\n` whether to kill the session or not. + +## Memory Usage + +These two functions can help you determine approximate memory usage. + +``` +import gc +import os + +def df(): + + s = os.statvfs('//') + return ('{0} MB'.format((s[0]*s[3])/1048576)) + +def free(full=False): + gc.collect() + F = gc.mem_free() + A = gc.mem_alloc() + T = F+A + P = '{0:.2f}%'.format(F/T*100) + if not full: return P + else : return ('Total:{0} Free:{1} ({2})'.format(T,F,P)) +``` \ No newline at end of file diff --git a/motors/README.md b/motors/README.md index 3caedac..5f8af30 100644 --- a/motors/README.md +++ b/motors/README.md @@ -10,4 +10,20 @@ servos using PWM. A large amount of the content for this read my comes from the on [PCA9685 with Micropython](https://learn.adafruit.com/micropython-hardware-pca9685-pwm-and-servo-driver/micropython) The git repo https://github.com/adafruit/micropython-adafruit-pca9685 is still up. Look at it's -[Docs](https://micropython-pca9685.readthedocs.io/en/latest/) \ No newline at end of file +[Docs](https://micropython-pca9685.readthedocs.io/en/latest/) + +``` +Description: +Brand: DSSERVO +Item: DS3218 20KG Digital Servo +Operating Voltage: 4.8 ~ 6.8 DC Volts +Torque: 18kg.cm(5V), 21.5kg.cm(6.8V) +Speed: 0.16sec/60°(5V), 0.14sec/60°(6.8V) +Dead Brand: 3μs +Motor Type: DC Motor +Gear Type: 25T Copper & Aluminum +Working Frequence: 50-333Hz +Totation: 180°(PWM 500-2500μs) / 270°(PWM 500-2500μs) +Weight: 60 g (2.12 oz) +Size: 40 x 20 x 40.5 mm ( 1.58 x 0.79 x 1.60 in) +``` \ No newline at end of file diff --git a/motors/main.py b/motors/main.py index e69de29..fa95a0a 100644 --- a/motors/main.py +++ b/motors/main.py @@ -0,0 +1,156 @@ +import machine +import servo +import time + +i2c = machine.I2C(scl=machine.Pin(22), sda=machine.Pin(21)) + +# Tower pro MG90s +servos = servo.Servos(i2c, address=0x40, freq=50, min_us=600, max_us=2400, degrees=180) + +INIT_POSITIONS = [ + (0, 40), + (1, 90), + (2, 130), + (3, 90), + (4, 60), + (5, 90), + (6, 130), + (7, 90) +] + + +def init_legs(): + for i, a, in INIT_POSITIONS: + servos.position(i, a) + + +def tip_forward(pause=1): + servos.position(7, 150) + servos.position(1, 30) + time.sleep(pause) + init_legs() + + +def tip_back(pause=1): + servos.position(3, 150) + servos.position(5, 30) + time.sleep(pause) + init_legs() + + +def lean_left(pause=1): + servos.position(7, 150) + servos.position(5, 30) + servos.position(3, 60) + servos.position(1, 120) + time.sleep(pause) + init_legs() + + +def lean_left(pause=1): + servos.position(7, 150) + servos.position(5, 30) + servos.position(3, 60) + servos.position(1, 120) + time.sleep(pause) + init_legs() + + +def lean_right(pause=1): + servos.position(7, 60) + servos.position(5, 120) + servos.position(3, 150) + servos.position(1, 30) + time.sleep(pause) + init_legs() + + +def look_left(pause=1): + servos.position(0, 10) + servos.position(2, 100) + servos.position(4, 30) + servos.position(6, 100) + time.sleep(pause) + init_legs() + + +def look_right(pause=1): + servos.position(0, 70) + servos.position(2, 160) + servos.position(4, 90) + servos.position(6, 160) + time.sleep(pause) + init_legs() + + +def all_move(pause=1): + moves = (tip_forward, tip_back, lean_left, lean_right, look_left, look_right, turn_left, turn_right, turn_right, turn_left) + for move in moves: + move(pause=pause) + time.sleep(0.5) + + +def turn_left(pause=None): + servos.position(0, 10) + servos.position(2, 100) + servos.position(4, 30) + servos.position(6, 100) + time.sleep(0.1) + servos.position(7, 120) + servos.position(6, 160) + time.sleep(0.1) + servos.position(7, 90) + time.sleep(0.1) + servos.position(3, 120) + servos.position(2, 160) + time.sleep(0.1) + servos.position(3, 90) + time.sleep(0.1) + servos.position(5, 30) + servos.position(4, 90) + time.sleep(0.1) + servos.position(5, 90) + time.sleep(0.1) + servos.position(1, 30) + servos.position(0, 90) + time.sleep(0.1) + servos.position(1, 90) + time.sleep(0.1) + init_legs() + + +def turn_right(pause=None): + servos.position(0, 70) + servos.position(2, 160) + servos.position(4, 90) + servos.position(6, 160) + time.sleep(0.1) + # front left + servos.position(1, 30) + servos.position(0, 10) + time.sleep(0.1) + servos.position(1, 90) + time.sleep(0.1) + # back right + servos.position(5, 30) + servos.position(4, 30) + time.sleep(0.1) + servos.position(5, 90) + time.sleep(0.1) + # front right + servos.position(7, 120) + servos.position(6, 60) + time.sleep(0.1) + servos.position(7, 90) + time.sleep(0.1) + # back left + servos.position(3, 120) + servos.position(2, 60) + time.sleep(0.1) + servos.position(3, 90) + time.sleep(0.1) + + init_legs() + + +init_legs()