menu

Back To Home

Saturday, December 21, 2019

SPI potentiometer AD8402 and arduino uno R3

This video will show you the SPI communication between IC and arduino board.

Pin connection from IC AD8402 SPI potentiometer to arduino uno R3:

PIN B1 - Connect 10kohm to gnd arduino.
PIN W1- Connect 220ohm to LED and to gnd arduino.
PIN VDD - Connect to VCC
PIN RS - Connect to VCC
PIN CLK- Connect to PIN13
PIN SDI- Connect to PIN11
PIN SHDN- Connect to VCC
PIN CS- Connect to PIN10

Datasheet for AD8402:

Arduino program:

#include<SPI.h>

 int ss=10; 
void setup() {
  // put your setup code here, to run once:
pinMode(ss,OUTPUT);
SPI.begin();
}


void setLed(int reg,int level)
{
  digitalWrite(ss,LOW);
  SPI.transfer(reg);
  SPI.transfer(level);
   digitalWrite(ss,HIGH);
  
}


void loop() {
  // put your main code here, to run repeatedly:
  
for(int j=50;j<=255;j++)
{
  setLed(0,j);
  delay(20);
}

for(int j=255;j>=50;j--)
{
  setLed(0,j);
  delay(20);
}

}



                            

No comments:

Post a Comment