跳至主要内容

博文

目前显示的是 十月, 2021的博文

树莓派头追舵机操作云台

  #!/usr/bin/python import smbus import math import time power_mgmt_1 = 0x6b power_mgmt_2 = 0x6c import RPi.GPIO as GPIO P_SERVO = [ 11 , 12 ] fPWM = 50 a = 10 b = 2 def setup (): global pwm global pwm1 GPIO.setmode(GPIO.BOARD) GPIO.setup(P_SERVO , GPIO.OUT) pwm = GPIO.PWM(P_SERVO[ 0 ] , fPWM) pwm1 = GPIO.PWM(P_SERVO[ 1 ] , fPWM) pwm.start( 0 ) pwm1.start( 0 ) def setDirection (x , y): pwm.ChangeDutyCycle( abs (y) / 10 ) pwm1.ChangeDutyCycle( abs (x)/ 10 ) time.sleep( 0.2 ) def read_byte (adr): return bus.read_byte_data(address , adr) def read_word (adr): high = bus.read_byte_data(address , adr) low = bus.read_byte_data(address , adr + 1 ) val = (high << 8 ) + low return val def read_word_2c (adr): val = read_word(adr) if (val >= 0x8000 ): return -(( 65535 - val) + 1 ) else : return val def dist (a , b): return math.sqrt((a * a) + (b * b)) def get_y_rotation (x , y , z): rad...

树莓派调用舵机云台

# Software PWM Servo.py import RPi.GPIO as GPIO import time P_SERVO = [ 11 , 12 ] fPWM = 50 a = 10 b = 2 def setup (): global pwm global pwm1 GPIO.setmode(GPIO.BOARD) GPIO.setup(P_SERVO , GPIO.OUT) pwm = GPIO.PWM(P_SERVO[ 0 ] , fPWM) pwm1 = GPIO.PWM(P_SERVO[ 1 ] , fPWM) pwm.start( 0 ) pwm1.start( 0 ) def setDirection (direction): duty = a / 180 * direction + b pwm.ChangeDutyCycle( 2 ) pwm1.ChangeDutyCycle( 2 ) time.sleep( 1 ) pwm.ChangeDutyCycle( 12 ) pwm1.ChangeDutyCycle( 12 ) time.sleep( 1 ) print "direction =" , direction , "-> duty =" , duty time.sleep( 1 ) print "starting" setup() for direction in range ( 0 , 10 , 10 ): setDirection(direction) direction = 0 setDirection( 0 ) GPIO.cleanup() print "done"

树莓派调用oled屏幕

  import time import Adafruit_GPIO.SPI as SPI import Adafruit_SSD1306 from PIL import Image from PIL import ImageDraw from PIL import ImageFont import subprocess # Raspberry Pi pin configuration: RST = None       # on the PiOLED this pin isnt used # Note the following are only used with SPI: DC = 23 SPI_PORT = 0 SPI_DEVICE = 0 # Beaglebone Black pin configuration: # RST = 'P9_12' # Note the following are only used with SPI: # DC = 'P9_15' # SPI_PORT = 1 # SPI_DEVICE = 0 # 128x32 display with hardware I2C: disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST) # 128x64 display with hardware I2C: # disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST) # Note you can change the I2C address by passing an i2c_address parameter like: # disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST, i2c_address=0x3C) # Alternatively you can specify an explicit I2C bus number, for example # with the 128x32 display you would use: # disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST, i2c_bus=2) # 128x32 ...