安装系统和必要的系统工具包
sudo sh -c "echo cmdline=init=/opt/scripts/tools/eMMC/init-eMMC-flasher-v3-stm32mp1.sh >> /boot/uEnv.txt"sudo reboot
sudo apt update
sudo apt install linux-headers-$(uname -r) -y
sudo apt install make device-tree-compiler gcc -y
sudo apt install ssh -y
sudo apt install git -y
sudo apt install wget -y
sudo apt update
sudo apt install python3 python3-distutils python3-pyqt5 python3-pip python3-numpy -y
sudo pip3 install python-can pyqtgraph
git clone https://github.com/Seeed-Studio/seeed-linux-dtverlays
cd seeed-linux-dtverlays
make all_stm32mp1 CUSTOM_MOD_FILTER_OUT="jtsn-wm8960" && sudo make install_stm32mp1 CUSTOM_MOD_FILTER_OUT="jtsn-wm8960"
sudo sh -c "echo uboot_overlay_addr0=/lib/firmware/stm32mp1-seeed-ap6236-overlay.dtbo >> /boot/uEnv.txt"
sudo sh -c "echo uboot_overlay_addr1=/lib/firmware/stm32mp1-seeed-spi5-overlay.dtbo >> /boot/uEnv.txt"
sudo sh -c "echo uboot_overlay_addr2=/lib/firmware/stm32mp1-seeed-usart2-overlay.dtbo >> /boot/uEnv.txt"
sudo sh -c "echo uboot_overlay_addr3=/lib/firmware/stm32mp1-seeed-i2c4-overlay.dtbo >> /boot/uEnv.txt"
sudo reboot
sudo pip3 install Seeed-grove.py
import time
from grove.gpio import GPIO
led = GPIO(0, GPIO.OUT)
while True:
led.write(1)
time.sleep(1)
led.write(0)
time.sleep(1)
from grove.i2c import Bus
sudo apt-get install i2c-tools
i2cdetect -y 1
import time
from grove.i2c import Bus
class GroveI2cPca9685:
def __init__(self, bus=None, address=0x40):
self.address = address
self.bus = Bus(bus)
def read_mode1(self):
return self._read_byte(0x00)
def read_mode2(self):
return self._read_byte(0x01)
# i2c bus.
def _read_byte(self, reg):
return self.bus.read_byte_data(self.address, reg)
def main():
pca9685 = GroveI2cPca9685()
print(pca9685.read_mode1())
print(pca9685.read_mode2())
if __name__ == '__main__':
main()
sudo pip install adafruit-pca9685
sudo apt-get install git build-essential python-dev
cd ~ git clone https://github.com/adafruit/Adafruit_Python_PCA9685.git
cd Adafruit_Python_PCA9685
sudo python setup.py install
from __future__ import division
import time
# Import the PCA9685 module.
import Adafruit_PCA9685
# Uncomment to enable debug output.
#import logging
#logging.basicConfig(level=logging.DEBUG)
# Initialise the PCA9685 using the default address (0x40).
pwm = Adafruit_PCA9685.PCA9685()
# Alternatively specify a different address and/or bus:
#pwm = Adafruit_PCA9685.PCA9685(address=0x41, busnum=2)
# Configure min and max servo pulse lengths
servo_min = 150 # Min pulse length out of 4096
servo_max = 620 # Max pulse length out of 4096
# Set frequency to 60hz, good for servos.
pwm.set_pwm_freq(60)
print('Moving servo on channel 15, press Ctrl-C to quit...')
while True:
# Move servo on channel 15 between extremes.
pwm.set_pwm(15, 0, servo_min)
time.sleep(1)
pwm.set_pwm(15, 0, servo_max)
time.sleep(1)
set_pwm_freq(60)函数设定了控制舵机的PWM方波信号频率为60Hz;
set_pwm()函数的第一个参数是通道号,我特别连了15号通道而不是0通道,就是担心此处的"0"同众 多的"0"混在一起。后面的两个参数分别是设置在一个周期中拉高电平和拉低电平的时间点,固定拉高电平的时间点为0,改变拉低电平的时间点就能控制舵机中电机的通电时间,从而控制舵机转动的角度。
往期精彩
1. Funpack第一期开始Fund Back了,成功的同学都奔走相告,分享喜悦吧!
2. Funpack第一期精彩之二:Argon带你用mqtt连OneNET,漂移菌带你跑Linux和驱屏幕
END
硬禾学堂
硬禾团队一直致力于给电子工程师和相关专业的同学,带来规范的核心技能课程,帮助大家在学习和工作的各个阶段,都能有效地提升自己的职业能力。
硬禾学堂
我们一起在电子领域探索前进
关注硬禾服务号,随时直达课堂
点击阅读原文观看更多精彩视频分享