Hi all,
I have a project where i'm trying to control my drone controller using a PS4 Controller and a set of digital potentiometers to control the stick positions on the drone controller. So far, my best try is to do the digipot through software using shiftout() but the output is really messed up. Everything is fine on the serial monitor but the sticks readout on the drone controller is all over the place.
The example sketch is just supposed to go from full on, smoothly down to off, one channel at a time, then start over, but its going to random channels and values(slightly less random values through channel 3(as in ch0, ch1, ch2, ect.) ) but it is consistent through each loop so i dont think it's my digipot(also i have 2 and they both do the same thing. I'm not really sure how else to describe it without making a video.
I have dug through the internet for anyone using both the USB Host Shield and the AD5206 together with no luck.
Can someone please help me figure out what i'm missing?
AD5206 Datasheet
https://www.analog.com/media/en/technical-documentation/data-sheets/AD5204_5206.pdf
Modified from the DigitalPotControl example in the Arduino IDE.
/*
Digital Pot Control
This example controls an Analog Devices AD5206 digital potentiometer.
The AD5206 has 6 potentiometer channels. Each channel's pins are labeled
A - connect this to voltage
W - this is the pot's wiper, which changes when you set it
B - connect this to ground.
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).
created 10 Aug 2010
by Tom Igoe
Thanks to Heather Dewey-Hagborg for the original tutorial, 2005
*/
const int dataPin = 5;
const int clockPin =7;
const int slaveSelectPin = 6;
void setup() {
Serial.begin(9600);
// set the dataPin, clockPin and slaveSelectPin as outputs:
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(slaveSelectPin, OUTPUT);
// initialize SPI:
// SPI.begin();
}
void loop() {
// go through the six channels of the digital pot:
for (byte channel = 0; channel < 6; channel++) {
// change the resistance on this channel from min to max:
for (byte level = 0; level < 255; level++) {
// digitalPotWrite(channel, level);
//delay(50);
}
// wait a second at the top:
//delay(10);
// change the resistance on this channel from max to min:
for (byte level = 0; level < 255; level++) {
digitalPotWrite(channel, 255 - level);
Serial.print(" Channel: ");
Serial.print(channel, BIN);
Serial.print(" Level: ");
Serial.print(level, BIN);
Serial.println();
delay(10);
}
}
}
void digitalPotWrite(byte address, uint8_t value) {
// take the SS pin low to select the chip:
digitalWrite(slaveSelectPin, LOW);
// send in the address and value via shiftOut()
shiftOut(dataPin, clockPin, MSBFIRST, address);
shiftOut(dataPin, clockPin, MSBFIRST, value);
// take the SS pin high to de-select the chip:
digitalWrite(slaveSelectPin, HIGH);
delay(5);
}
Edit:
I'm basically trying to constantly read the PS4 controller and write to the digipot as much as possible. I didn't think it would work through spi alone before i even started this, thats what i thought the shiftOut() was for but i think i'm doing something wrong.
The datasheet says it uses 3 bits for the address and 8 bits for the value. I think this is what i need to mess with because the shiftOut() thing says it sends out 8 bits at a time. To me, that says its overlapping something and that's causing the sporadic output.
Can someone point me to an example or two that uses this bit bashing shiftOut(), or is this just completely the wrong way to go about doing this?