350296b2e389587ca3c5ceee9f7f6a5fabcf5c77
Chip-dat/raspberry-pi-dat/RPI-SBC-dat/RPI-SDK-dat/RPI-SDK-dat.md
| ... | ... | @@ -1,4 +1,9 @@ |
| 1 | 1 | |
| 2 | 2 | # RPI-SDK-dat |
| 3 | 3 | |
| 4 | -- [[led-rgb-panel-chip-log-dat]] |
|
| ... | ... | \ No newline at end of file |
| 0 | +- [[led-rgb-panel-chip-log-dat]] |
|
| 1 | + |
|
| 2 | + |
|
| 3 | +- [[servo-dat]] |
|
| 4 | + |
|
| 5 | + |
Tech-dat/acturator-dat/motor-dat/servo-dat/servo-HDK-dat/2025-12-26-14-01-00.png
| ... | ... | Binary files /dev/null and b/Tech-dat/acturator-dat/motor-dat/servo-dat/servo-HDK-dat/2025-12-26-14-01-00.png differ |
Tech-dat/acturator-dat/motor-dat/servo-dat/servo-HDK-dat/servo-HDK-dat.md
| ... | ... | @@ -0,0 +1,5 @@ |
| 1 | + |
|
| 2 | +# servo-HDK-dat |
|
| 3 | + |
|
| 4 | + |
|
| 5 | + |
|
| ... | ... | \ No newline at end of file |
Tech-dat/acturator-dat/motor-dat/servo-dat/servo-SDK-dat/servo-RPI-angle0-dat.md
| ... | ... | @@ -0,0 +1,47 @@ |
| 1 | +# servo-RPI-angle0-dat.md |
|
| 2 | + |
|
| 3 | +A minimal script to hold a hobby servo at 0° (zero degrees) using BCM GPIO5 (physical pin 29). |
|
| 4 | + |
|
| 5 | +Save as `servo_hold_0_gpio5.py` on the Pi and run with `sudo python3 servo_hold_0_gpio5.py`. |
|
| 6 | + |
|
| 7 | +```python |
|
| 8 | +#!/usr/bin/env python3 |
|
| 9 | +"""Hold servo at 0° on BCM GPIO5 until Ctrl-C.""" |
|
| 10 | +import time |
|
| 11 | +import RPi.GPIO as GPIO |
|
| 12 | + |
|
| 13 | +SERVO_PIN = 5 # BCM numbering |
|
| 14 | +FREQ = 50 |
|
| 15 | + |
|
| 16 | +# Tune these for your servo if needed |
|
| 17 | +MIN_DUTY = 2.5 |
|
| 18 | +MAX_DUTY = 12.5 |
|
| 19 | + |
|
| 20 | +def angle_to_duty(angle: float) -> float: |
|
| 21 | + a = max(0.0, min(180.0, float(angle))) |
|
| 22 | + return MIN_DUTY + (a / 180.0) * (MAX_DUTY - MIN_DUTY) |
|
| 23 | + |
|
| 24 | +GPIO.setmode(GPIO.BCM) |
|
| 25 | +GPIO.setup(SERVO_PIN, GPIO.OUT) |
|
| 26 | + |
|
| 27 | +pwm = GPIO.PWM(SERVO_PIN, FREQ) |
|
| 28 | +# Start PWM and keep the duty cycle that corresponds to 0° so the servo actively holds position |
|
| 29 | +duty_0 = angle_to_duty(0) |
|
| 30 | +pwm.start(duty_0) |
|
| 31 | + |
|
| 32 | +try: |
|
| 33 | + print('Holding 0° on GPIO5 (pin 29). Press Ctrl-C to stop.') |
|
| 34 | + while True: |
|
| 35 | + time.sleep(1) |
|
| 36 | +except KeyboardInterrupt: |
|
| 37 | + pass |
|
| 38 | +finally: |
|
| 39 | + pwm.stop() |
|
| 40 | + GPIO.cleanup() |
|
| 41 | +``` |
|
| 42 | + |
|
| 43 | +Notes: |
|
| 44 | +- Keep the PWM running (do not set duty to 0) so the servo actively holds position. |
|
| 45 | +- Ensure servo V+ is powered by a suitable 5V supply and servo GND is tied to Pi GND. |
|
| 46 | +- Remove or weaken any external pull-down on the signal line—strong pull-downs prevent the Pi from driving the PWM. |
|
| 47 | + |
Tech-dat/acturator-dat/motor-dat/servo-dat/servo-SDK-dat/servo-RPI-dat.md
| ... | ... | @@ -0,0 +1,66 @@ |
| 1 | +# servo-RPI-dat.md |
|
| 2 | + |
|
| 3 | +A minimal Raspberry Pi Python demo to rotate a standard hobby servo left and right using BCM GPIO5 (physical pin 29). |
|
| 4 | + |
|
| 5 | +Save the script below as `servo_demo_gpio5.py` on your Pi and run it with `sudo python3 servo_demo_gpio5.py`. |
|
| 6 | + |
|
| 7 | +```python |
|
| 8 | +#!/usr/bin/env python3 |
|
| 9 | +"""Servo demo on BCM GPIO5 (physical pin 29). |
|
| 10 | +Uses RPi.GPIO to generate 50Hz PWM and maps angle 0-180 to duty cycle. |
|
| 11 | +Adjust MIN_DUTY / MAX_DUTY if your servo needs different values. |
|
| 12 | +""" |
|
| 13 | +import time |
|
| 14 | +import RPi.GPIO as GPIO |
|
| 15 | + |
|
| 16 | +SERVO_PIN = 5 # BCM numbering |
|
| 17 | +FREQ = 50 # 50Hz for standard servos |
|
| 18 | + |
|
| 19 | +# Duty cycle values may need tuning per servo (these are common defaults) |
|
| 20 | +MIN_DUTY = 2.5 # ~0 degrees |
|
| 21 | +MAX_DUTY = 12.5 # ~180 degrees |
|
| 22 | + |
|
| 23 | +GPIO.setmode(GPIO.BCM) |
|
| 24 | +GPIO.setup(SERVO_PIN, GPIO.OUT) |
|
| 25 | + |
|
| 26 | +pwm = GPIO.PWM(SERVO_PIN, FREQ) |
|
| 27 | +pwm.start(0) |
|
| 28 | + |
|
| 29 | +def angle_to_duty(angle: float) -> float: |
|
| 30 | + """Convert 0-180 angle to duty cycle between MIN_DUTY and MAX_DUTY.""" |
|
| 31 | + if angle < 0: |
|
| 32 | + angle = 0 |
|
| 33 | + if angle > 180: |
|
| 34 | + angle = 180 |
|
| 35 | + return MIN_DUTY + (angle / 180.0) * (MAX_DUTY - MIN_DUTY) |
|
| 36 | + |
|
| 37 | + |
|
| 38 | +def set_angle(angle: float, settle: float = 0.5) -> None: |
|
| 39 | + duty = angle_to_duty(angle) |
|
| 40 | + pwm.ChangeDutyCycle(duty) |
|
| 41 | + time.sleep(settle) |
|
| 42 | + # Stop driving PWM to reduce jitter on some servos |
|
| 43 | + pwm.ChangeDutyCycle(0) |
|
| 44 | + |
|
| 45 | + |
|
| 46 | +try: |
|
| 47 | + print('Press Ctrl-C to exit. Sweeping servo by angle: 0 -> 90 -> 180') |
|
| 48 | + while True: |
|
| 49 | + set_angle(0) |
|
| 50 | + time.sleep(1) |
|
| 51 | + set_angle(90) |
|
| 52 | + time.sleep(1) |
|
| 53 | + set_angle(180) |
|
| 54 | + time.sleep(1) |
|
| 55 | +except KeyboardInterrupt: |
|
| 56 | + pass |
|
| 57 | +finally: |
|
| 58 | + pwm.stop() |
|
| 59 | + GPIO.cleanup() |
|
| 60 | +``` |
|
| 61 | + |
|
| 62 | +Notes: |
|
| 63 | +- Use BCM numbering (GPIO5). Physical pin 29 corresponds to BCM GPIO5. |
|
| 64 | +- Run the script on the Pi (not on Windows): `sudo python3 servo_demo_gpio5.py`. |
|
| 65 | +- If the servo jitters or doesn't reach endpoints, adjust `MIN_DUTY` and `MAX_DUTY` slightly. |
|
| 66 | + |
Tech-dat/acturator-dat/motor-dat/servo-dat/servo-SDK-dat/servo-sdk-dat.md
| ... | ... | @@ -0,0 +1,83 @@ |
| 1 | + |
|
| 2 | +# servo-sdk-dat.md |
|
| 3 | + |
|
| 4 | + |
|
| 5 | + |
|
| 6 | +- [[servo-RPI-dat]] - [[servo-RPI-angle0-dat]] |
|
| 7 | + |
|
| 8 | + |
|
| 9 | +- ESP32Servo |
|
| 10 | + |
|
| 11 | + |
|
| 12 | +ESP32 LEDC official libarry |
|
| 13 | + |
|
| 14 | +https://docs.espressif.com/projects/arduino-esp32/en/latest/api/ledc.html?highlight=ledcWrite |
|
| 15 | + |
|
| 16 | + |
|
| 17 | + |
|
| 18 | + |
|
| 19 | +## 'ledcSetup' was not declared in this scope |
|
| 20 | + |
|
| 21 | + |
|
| 22 | +If you prefer to use the latest ESP32 core version, you need to update your code to reflect the new LEDC API. |
|
| 23 | +- `ledcSetup() and ledcAttachPin()` are no longer used. |
|
| 24 | +- You can now use `analogWrite(pin, value)` for basic PWM, where value is the duty cycle. |
|
| 25 | +- For more advanced control, use `ledcAttachChannel(pin, freq, resolution, channel)` to attach a pin to a specific PWM channel and then `ledcWrite(pin, duty)` to set the duty cycle. The channel will be automatically attributed if not specified. |
|
| 26 | + |
|
| 27 | + |
|
| 28 | +### New Code (ESP32 Core >= 3.0.0): |
|
| 29 | + |
|
| 30 | +``` |
|
| 31 | +const int LED_PIN = 2; |
|
| 32 | +const int FREQ = 5000; |
|
| 33 | +const int RESOLUTION = 8; // Not directly used in ledcWrite(), but useful for calculating duty cycle |
|
| 34 | + |
|
| 35 | +void setup() { |
|
| 36 | + // Option 1: Use analogWrite for basic PWM |
|
| 37 | + // analogWrite(LED_PIN, 128); // Sets initial duty cycle |
|
| 38 | + |
|
| 39 | + // Option 2: Use ledcAttachChannel for more control |
|
| 40 | + ledcAttachChannel(LED_PIN, FREQ, RESOLUTION, 0); // Attaches pin to channel 0 |
|
| 41 | +} |
|
| 42 | + |
|
| 43 | +void loop() { |
|
| 44 | + // Option 1: Use analogWrite |
|
| 45 | + // analogWrite(LED_PIN, 128); |
|
| 46 | + // delay(1000); |
|
| 47 | + // analogWrite(LED_PIN, 0); |
|
| 48 | + // delay(1000); |
|
| 49 | + |
|
| 50 | + // Option 2: Use ledcWrite |
|
| 51 | + ledcWrite(LED_PIN, 128); // 50% duty cycle for 8-bit resolution |
|
| 52 | + delay(1000); |
|
| 53 | + ledcWrite(LED_PIN, 0); |
|
| 54 | + delay(1000); |
|
| 55 | +} |
|
| 56 | + |
|
| 57 | +``` |
|
| 58 | + |
|
| 59 | +### Old Code (ESP32 Core < 3.0.0): |
|
| 60 | + |
|
| 61 | +``` |
|
| 62 | +const int LED_PIN = 2; |
|
| 63 | +const int FREQ = 5000; |
|
| 64 | +const int LED_CHANNEL = 0; |
|
| 65 | +const int RESOLUTION = 8; |
|
| 66 | + |
|
| 67 | +void setup() { |
|
| 68 | + ledcSetup(LED_CHANNEL, FREQ, RESOLUTION); |
|
| 69 | + ledcAttachPin(LED_PIN, LED_CHANNEL); |
|
| 70 | +} |
|
| 71 | + |
|
| 72 | +void loop() { |
|
| 73 | + ledcWrite(LED_CHANNEL, 128); // 50% duty cycle for 8-bit resolution |
|
| 74 | + delay(1000); |
|
| 75 | + ledcWrite(LED_CHANNEL, 0); |
|
| 76 | + delay(1000); |
|
| 77 | +} |
|
| 78 | +``` |
|
| 79 | + |
|
| 80 | + |
|
| 81 | +## servo 360 |
|
| 82 | + |
|
| 83 | + |
Tech-dat/acturator-dat/motor-dat/servo-dat/servo-sdk-dat.md
| ... | ... | @@ -1,78 +0,0 @@ |
| 1 | - |
|
| 2 | -# servo-sdk-dat.md |
|
| 3 | - |
|
| 4 | -- ESP32Servo |
|
| 5 | - |
|
| 6 | - |
|
| 7 | -ESP32 LEDC official libarry |
|
| 8 | - |
|
| 9 | -https://docs.espressif.com/projects/arduino-esp32/en/latest/api/ledc.html?highlight=ledcWrite |
|
| 10 | - |
|
| 11 | - |
|
| 12 | - |
|
| 13 | - |
|
| 14 | -## 'ledcSetup' was not declared in this scope |
|
| 15 | - |
|
| 16 | - |
|
| 17 | -If you prefer to use the latest ESP32 core version, you need to update your code to reflect the new LEDC API. |
|
| 18 | -- `ledcSetup() and ledcAttachPin()` are no longer used. |
|
| 19 | -- You can now use `analogWrite(pin, value)` for basic PWM, where value is the duty cycle. |
|
| 20 | -- For more advanced control, use `ledcAttachChannel(pin, freq, resolution, channel)` to attach a pin to a specific PWM channel and then `ledcWrite(pin, duty)` to set the duty cycle. The channel will be automatically attributed if not specified. |
|
| 21 | - |
|
| 22 | - |
|
| 23 | -### New Code (ESP32 Core >= 3.0.0): |
|
| 24 | - |
|
| 25 | -``` |
|
| 26 | -const int LED_PIN = 2; |
|
| 27 | -const int FREQ = 5000; |
|
| 28 | -const int RESOLUTION = 8; // Not directly used in ledcWrite(), but useful for calculating duty cycle |
|
| 29 | - |
|
| 30 | -void setup() { |
|
| 31 | - // Option 1: Use analogWrite for basic PWM |
|
| 32 | - // analogWrite(LED_PIN, 128); // Sets initial duty cycle |
|
| 33 | - |
|
| 34 | - // Option 2: Use ledcAttachChannel for more control |
|
| 35 | - ledcAttachChannel(LED_PIN, FREQ, RESOLUTION, 0); // Attaches pin to channel 0 |
|
| 36 | -} |
|
| 37 | - |
|
| 38 | -void loop() { |
|
| 39 | - // Option 1: Use analogWrite |
|
| 40 | - // analogWrite(LED_PIN, 128); |
|
| 41 | - // delay(1000); |
|
| 42 | - // analogWrite(LED_PIN, 0); |
|
| 43 | - // delay(1000); |
|
| 44 | - |
|
| 45 | - // Option 2: Use ledcWrite |
|
| 46 | - ledcWrite(LED_PIN, 128); // 50% duty cycle for 8-bit resolution |
|
| 47 | - delay(1000); |
|
| 48 | - ledcWrite(LED_PIN, 0); |
|
| 49 | - delay(1000); |
|
| 50 | -} |
|
| 51 | - |
|
| 52 | -``` |
|
| 53 | - |
|
| 54 | -### Old Code (ESP32 Core < 3.0.0): |
|
| 55 | - |
|
| 56 | -``` |
|
| 57 | -const int LED_PIN = 2; |
|
| 58 | -const int FREQ = 5000; |
|
| 59 | -const int LED_CHANNEL = 0; |
|
| 60 | -const int RESOLUTION = 8; |
|
| 61 | - |
|
| 62 | -void setup() { |
|
| 63 | - ledcSetup(LED_CHANNEL, FREQ, RESOLUTION); |
|
| 64 | - ledcAttachPin(LED_PIN, LED_CHANNEL); |
|
| 65 | -} |
|
| 66 | - |
|
| 67 | -void loop() { |
|
| 68 | - ledcWrite(LED_CHANNEL, 128); // 50% duty cycle for 8-bit resolution |
|
| 69 | - delay(1000); |
|
| 70 | - ledcWrite(LED_CHANNEL, 0); |
|
| 71 | - delay(1000); |
|
| 72 | -} |
|
| 73 | -``` |
|
| 74 | - |
|
| 75 | - |
|
| 76 | -## servo 360 |
|
| 77 | - |
|
| 78 | - |