SPI应用 用SPI控制一个数字电位器
Controlling a Digital Potentiometer Using SPI
In this tutorial you will learn how to control the AD5206 digital potentiometer(数字电位计) using Serial Peripheral Interface (SPI). For an explanation of SPI see the SPI Library reference.
Digital potentiometers are useful when you need to vary the resistance in a circuit electronically rather than by hand. Example applications include LED dimming调光, audio signal conditioning and tone generation. In this example we will use a six channel digital potentiometer to control the brightness of six LEDs. The steps we will cover for implementing实施 SPI communication can be modified for use with most other SPI devices.
Hardware Required 硬件准备
- Arduino or Genuino board
- AD5206 Digital Potentiometer
- 6 LEDs
- 6 220 ohm resistors
- hook-up wires电子安装线
- breadboard
Introduction to the AD5206 Digital Potentiometer
Click for for the AD5206's datasheet.
The AD5206 is a 6 channel digital potentiometer. (AD5206是8通道的数字电位器)。 This means it has six variable resistors (potentiometers) built in for individual electronic control. There are three pins on the chip for each of the six internal variable resistors, and they can be interfaced with just as you would use a mechanical potentiometer. The individual variable resistor pins are labeled Ax, Bx and Wx, ie. A1, B1 and W1. For example, in this tutorial we will be using each variable resistor as a voltage divider by pulling one side pin (pin B) high, pulling another side pin (pin A) low and taking the variable voltage output of the center pin (Wiper滑片). In this case, the AD5206 provides a maximum resistance of 10k ohm, delivered in 255 steps (255 being the max, 0 being the least).(可以得到最大电阻10K欧姆,最小0欧模,分为255步幅)
Circuit 电路图
image developed using Fritzing. For more circuit examples, see the Fritzing project page
Schematic 原理图
- 1 Code 代码
- 2
- 3 /*
- 4
- 5 Digital Pot Control 数字电位器的控制
- 6
- 7
- 8
- 9 This example controls an Analog Devices AD5206 digital potentiometer.
- 10
- 11 The AD5206 has 6 potentiometer channels. Each channel's pins are labeled
- 12
- 13 A - connect this to voltage
- 14
- 15 W - this is the pot's wiper, which changes when you set it
- 16
- 17 B - connect this to ground.
- 18
- 19 每隔通道有三个端,A,B,W,A接工作电压,W接滑动端,C接地
- 20
- 21 The AD5206 is SPI-compatible, and to command it, you send two bytes, one with the channel number (0 - 5) and one with the resistance value for the channel (0 - 255).
- 22
- 23
- 24
- 25 The circuit:
- 26
- 27 * All A pins of AD5206 connected to +5V
- 28
- 29 * All B pins of AD5206 connected to ground
- 30
- 31 * An LED and a 220-ohm resisor in series connected from each W pin to ground
- 32
- 33 每个W引脚的LED串220欧电阻
- 34
- 35 * CS - to digital pin 10 (SS pin) 片选引脚CS接到控制板的引脚10
- 36
- 37 * SDI - to digital pin 11 (MOSI pin) SDI引脚接到控制板的引脚11
- 38
- 39 * CLK - to digital pin 13 (SCK pin) CLK 引脚接到控制板的引脚13
- 40
- 41
- 42
- 43 created 10 Aug 2010
- 44
- 45 by Tom Igoe
- 46
- 47
- 48 Thanks to Heather Dewey-Hagborg for the original tutorial, 2005
- 49
- 50
- 51
- 52 */
- 53
- 54
- 55
- 56 // inslude the SPI library:
- 57
- 58 #include <SPI.h>
- 59
- 60
- 61
- 62 // set pin 10 as the slave select for the digital pot:
- 63
- 64 const int slaveSelectPin = 10; // 从选择引脚
- 65
- 66
- 67
- 68 void setup()
- 69
- 70 {
- 71
- 72 pinMode(slaveSelectPin, OUTPUT); // set the slaveSelectPin as an output
- 73
- 74 SPI.begin(); // initialize SPI
- 75
- 76 }
- 77
- 78
- 79
- 80 void loop()
- 81
- 82 {
- 83
- 84 // go through the six channels of the digital pot: 循环数字电位器的六个通道
- 85
- 86 for (int channel = 0; channel < 6; channel++)
- 87
- 88 {
- 89
- 90 // change the resistance on this channel from min to max: 电阻从小到大
- 91
- 92 for (int level = 0; level < 255; level++)
- 93
- 94 {
- 95
- 96 digitalPotWrite(channel, level);
- 97
- 98 delay(10);
- 99
- 100 }
- 101
- 102 delay(100); // wait a second at the top
- 103
- 104 // change the resistance on this channel from max to min: 电阻从大到小
- 105
- 106 for (int level = 0; level < 255; level++)
- 107
- 108 {
- 109
- 110 digitalPotWrite(channel, 255 - level);
- 111
- 112 delay(10);
- 113
- 114 }
- 115
- 116 }
- 117
- 118 }
- 119
- 120
- 121
- 122 void digitalPotWrite(int address, int value)
- 123
- 124 {
- 125
- 126 // take the SS pin low to select the chip: SS引脚置低选中该芯片
- 127
- 128 digitalWrite(slaveSelectPin, LOW);
- 129
- 130 // send in the address and value via SPI:
- 131
- 132 SPI.transfer(address); //传送地址
- 133
- 134 SPI.transfer(value); //传送数值
- 135
- 136 // take the SS pin high to de-select the chip: SS引脚置高释放该芯片
- 137
- 138 digitalWrite(slaveSelectPin, HIGH);
- 139
- 140 }
运行效果:从第1通道开始,每个通道的LED,从最暗到最亮,0.1秒后,再从最亮到最暗。
SPI应用 用SPI控制一个数字电位器的更多相关文章
- 求s=a+aa+aaa+aaaa+aa...a的值,其中a是一个数字。例如2+22+222+2222+22222(此时共有5个数相加),几个数相加有键盘控制。
package com.lw.HomeWork1;//包名 2 import java.util.Scanner; public class Demo18 { /** * @param args */ ...
- 求s=a+aa+aaa+aaaa+aa...a的值,其中a是一个数字。 例如2+22+222+2222+22222(此时共有5个数相加),几个数相加有键盘控制。
代码: package com.liron.p1; import java.io.IOException; import java.util.Scanner; /** * 求s=a+aa+aaa+aa ...
- Java初学者作业——编写Java程序,在控制台中输入一个数字,要求定义方法实现找出能够整除该数字的所有数字。
返回本章节 返回作业目录 需求说明: 编写Java程序,在控制台中输入一个数字,要求定义方法实现找出能够整除该数字的所有数字. 实现思路: 定义方法findNums(),用于实现查找所有能够整除指定数 ...
- python基础练习题(题目 求s=a+aa+aaa+aaaa+aa…a的值,其中a是一个数字。例如2+22+222+2222+22222(此时共有5个数相加),几个数相加由键盘控制)
day11 --------------------------------------------------------------- 实例018:复读机相加 题目 求s=a+aa+aaa+aaa ...
- windows 系统中打开一个数字证书所经历的过程
今天在使用Outlook express调试CSP程序时,发现数字证书总是加载不上(提示该数字证书已经被破坏),使用断点进去跟踪一下,发现在CSP程序中调用CPVerifySignature ...
- SPI接口扫盲 SPI定义/SPI时序(CPHA CPOL)
SPI接口扫盲 douqingl@gmail.com 为何要写这篇文档?百度上找出来的SPI接口中文描述都说的太过简略,没有一篇文档能够详尽的将SPI介绍清楚的.wikipedia英文版[注释 ...
- SPI通信协议(SPI总线)学习
1.什么是SPI? SPI是串行外设接口(Serial Peripheral Interface)的缩写.是 Motorola 公司推出的一 种同步串行接口技术,是一种高速的,全双工,同步的通信总线. ...
- Dubbo 扩展点加载机制:从 Java SPI 到 Dubbo SPI
SPI 全称为 Service Provider Interface,是一种服务发现机制.当程序运行调用接口时,会根据配置文件或默认规则信息加载对应的实现类.所以在程序中并没有直接指定使用接口的哪个实 ...
- 联盛德 HLK-W806 (四): 软件SPI和硬件SPI驱动ST7735液晶LCD
目录 联盛德 HLK-W806 (一): Ubuntu20.04下的开发环境配置, 编译和烧录说明 联盛德 HLK-W806 (二): Win10下的开发环境配置, 编译和烧录说明 联盛德 HLK-W ...
随机推荐
- 【转】ANDROID LOLLIPOP SCREEN CAPTURE AND SHARING
https://datatheorem.github.io/android/2014/12/26/android-screencapture/ https://www.youtube.com/watc ...
- day46:jQuery
目录 1.jQuery初识 2.选择器 3.文本操作 4.class类值操作 5.css样式操作 6.值操作 7.注意点:button按钮提交form表单数据 8.jquery选择器补充 9.模态对话 ...
- Redis适配采坑记
Redis适配采坑记 相对于其他的适配,Redis可以说是非常简单的其中只发现一个坑 问题一: 问题描述: redis认证失败 问题详解: redis连接配置时,本地需要采用password属性,远程 ...
- Java实现打开google浏览器
说明: 博主的Google浏览器版本:75.0.3770.142,如果运行异常,需要自行查找对应版本的驱动(chromedriver.exe) 需要的jar包: https://pan.baidu.c ...
- W5300中文手册
如果链接没了就Q我吧1178875532 链接:https://pan.baidu.com/s/1HcNJN_T6QJCvPWymU1sFDQ 提取码:suBB
- oracle之三闪回flashback
闪回 flashback 5.1 flashback 的功能:1)利用undo data回溯或撤销提交的数据,2)flashback log 使database 可以恢复到过去某个时间点,可以作为不完 ...
- oracle之序列
序列 15.1 序列是生成唯一整数值的结构,它的典型用途是用于主键值. 结合真题演示伪列nextval, currval用法 CREATE SEQUENCE dept_deptnoINCREMENT ...
- JWT伪造攻击
JWT修改伪造攻击 什么是JWT? JSON Web Token(JSON Web令牌)是一种跨域验证身份的方案.JWT不加密传输的数据,但能够通过数字签名来验证数据未被篡改(但是做完下面的WebGo ...
- SpringCloud实战 | 第四篇:SpringCloud整合Gateway实现API网关
一. 前言 微服务实战系列是基于开源微服务项目 有来商城youlai-mall 版本升级为背景来开展的,本篇则是讲述API网关使用Gateway替代Zuul,有兴趣的朋友可以进去给个star,非常感谢 ...
- JavaScript 流程控制-分支
JavaScript 流程控制-分支 1.流程控制 在一个程序执行的过程中,各条代码的执行顺序对程序的结果是有直接影响的,很多时候我们要通过控制代码的执行顺序来实现我们要完成的功能. 简单理解:流程控 ...