“实验三:旋转电位器实验”的版本间的差异
来自丢石头百科
Yousimaier17(讨论 | 贡献) |
Yousimaier17(讨论 | 贡献) (→电路连接) |
||
(未显示同一用户的3个中间版本) | |||
第6行: | 第6行: | ||
=== 电路连接 === | === 电路连接 === | ||
− | * | + | *[[File:实验三:旋转电位器实验_接线.png|500px]] |
− | |||
− | |||
− | |||
− | |||
=== 主要程序 === | === 主要程序 === | ||
第38行: | 第34行: | ||
== 树莓派 == | == 树莓派 == | ||
=== 电路连接 === | === 电路连接 === | ||
− | * | + | *[[File:实验三:旋转电位器实验_接线2.png|600px]] |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
=== 程序运行 === | === 程序运行 === | ||
第58行: | 第44行: | ||
sudo apt install python3-gpiozero | sudo apt install python3-gpiozero | ||
</pre> | </pre> | ||
− | + | :*其它树莓派上的系统可以使下面命令来安装该库: | |
<pre> | <pre> | ||
sudo pip3 install gpiozero | sudo pip3 install gpiozero | ||
</pre> | </pre> | ||
− | + | :*运行以下语句可以查看树莓派GPIO口定义 | |
<pre> | <pre> | ||
pinout | pinout | ||
第70行: | 第56行: | ||
sudo raspi-config | sudo raspi-config | ||
选择Interfaces oOptions -> SPI -> “Would you like the SPI interface to be enabled? ”选择Yes -> “The SPI interface is enabled” 选择Yes -> 选择finish | 选择Interfaces oOptions -> SPI -> “Would you like the SPI interface to be enabled? ”选择Yes -> “The SPI interface is enabled” 选择Yes -> 选择finish | ||
+ | </pre> | ||
*关闭树莓派。断电情况下,根据提供的电路连接将对应模块接入电路,启动树莓派 | *关闭树莓派。断电情况下,根据提供的电路连接将对应模块接入电路,启动树莓派 | ||
*下载树莓派参考例程,将文件解压后拷贝放在用户名目录下,运行 | *下载树莓派参考例程,将文件解压后拷贝放在用户名目录下,运行 |
2024年12月6日 (五) 11:51的最新版本
Arduino
实验现象
- 通过串口打印电位器滑动端的电压值
电路连接
主要程序
#define Pot A0 //电位器引脚命名 int PotBuffer = 0; //AD读取数据缓存变量 void setup() { Serial.begin(9600); //初始化串口波特率为9600 } void loop() { PotBuffer = analogRead(Pot); //读取AD值 Serial.print("Pot = "); //串口输出“Pot = ” Serial.println(PotBuffer); //串口输出PotBuffer的值 delay(500); //延时500ms Serial.print("Value = "); //串口输出"Value = " Serial.print(PotBuffer*5.0/1024); //串口输出计算后的电压值 Serial.println("V"); //串口输出"V" delay(500); //延时500ms }
树莓派
电路连接
程序运行
Python
- 安装gpiozero库
- 可以使下面命令来安装该库
sudo apt update sudo apt install python3-gpiozero
- 其它树莓派上的系统可以使下面命令来安装该库:
sudo pip3 install gpiozero
- 运行以下语句可以查看树莓派GPIO口定义
pinout
- 打开SPI接口
sudo raspi-config 选择Interfaces oOptions -> SPI -> “Would you like the SPI interface to be enabled? ”选择Yes -> “The SPI interface is enabled” 选择Yes -> 选择finish
- 关闭树莓派。断电情况下,根据提供的电路连接将对应模块接入电路,启动树莓派
- 下载树莓派参考例程,将文件解压后拷贝放在用户名目录下,运行
cd /home/pi/raspberrypi/3/python_gpiozero python Potentiometer.py
- 此时可看见树莓派在不断打印电位器的电压值,若想退出,按ctrl+C即可
- 更多指令请查看gpiozero文档