Pizero2.vent: Unterschied zwischen den Versionen

Aus OrgaMon Wiki
Zur Navigation springen Zur Suche springen
Zeile 10: Zeile 10:
  # apt install pigpio
  # apt install pigpio


<code>
  #
  #
  # KEMO M240
  # KEMO M240
Zeile 48: Zeile 47:
   pi.hardware_PWM(PWM_GPIO, PWM_FREQUENCY, percent * 10000)
   pi.hardware_PWM(PWM_GPIO, PWM_FREQUENCY, percent * 10000)
   time.sleep(15)
   time.sleep(15)
</code>

Version vom 30. September 2025, 19:35 Uhr

Boot

# /boot/firmware/config.txt

dtoverlay=pwm-2chan

pwm.py

# apt install pigpio
#
# KEMO M240
#  PWM Spannung: 3 V bis 24 V
#  PWM Frequenz: 100 Hz bis 10 kHz
#
# Raspberry Pi Zero
#  PWM0 Pin 18 xor 12, 3,3 V 1 kHz
#  PWM1 Pin 13 xor 19, 3,3 V 1 kHz
#

import pigpio
import time
import random

PWM_GPIO = 18
PWM_FREQUENCY = 1000

random.seed()
pi = pigpio.pi()

#
# Start Motor Full Speed for 4 Seconds
#
ret_code = pi.hardware_PWM(PWM_GPIO, PWM_FREQUENCY, 1000000)
print(ret_code)
time.sleep(4)

# print(pi.get_PWM_range(PWM_GPIO))
# print(pi.get_PWM_real_range(PWM_GPIO)) 

while True:

 #pi.set_PWM_dutycycle(PWM_GPIO, 0)
 percent = random.randint(0,100)
 print("set motor to ", percent, " %")
 pi.hardware_PWM(PWM_GPIO, PWM_FREQUENCY, percent * 10000)
 time.sleep(15)