Hey!
i ran into problems with the AD5263 digital potentiometer and hope to get some help here. I use the AD5263 connected to an Arduino Uno R3 to control an ion gun by remote through python. So i want the control 3 of the 4 RDAC channels to control the settings on the ion gun. My Problem is that i can only speak to 2 of 3 used channels.
A short explanation to the code: my python programm sends messages like 'Aon', 'Aoff', 'A210', 'A0', 'E255', 'Eon', 'Eoff', 'M120', 'Moff' and so on, to switch my Magnetron, Extractor or Anode on and it can send a number between 0 and 255 to set the RDACs wiper position.
My Problem here is that i can't talk to the Magnetron part. I tried a loooot of possible adress or bit sequences but it does all nothing. The rest of the code works fine. What adress do i need in the line:
Wire.write(0x10); // 16?? 8?? 3 ??
to talk to RDAC3? It drives me mad. A big thank you to everyone who contributes to my solution!!! Any additional tips to my code are also welcome. This is my most serious Arduino project so far
#include <Wire.h>
int statusPinMagnetron = 2;
int statusPinExtractor = 4;
int statusPinAnode = 7;
int resistorvalue = 0;
void setup() {
Serial.begin(115200);
Wire.begin(); // join i2c bus (for digi poti)
pinMode(statusPinMagnetron, OUTPUT); //declare pins as output
pinMode(statusPinExtractor, OUTPUT);
pinMode(statusPinAnode, OUTPUT);
digitalWrite(statusPinMagnetron, HIGH); //initial condition to switch the devices off
digitalWrite(statusPinExtractor, HIGH); //initial condition to switch the devices off
digitalWrite(statusPinAnode, HIGH); //initial condition to switch the devices off
}
void loop() {
if (Serial.available() > 0) {
Serial.println("serial received"); //bugtracker
String datastring = Serial.readString();
char valuechars[3]; //tranformation neccessary for differ string and resi value
valuechars[0] = datastring[1];
valuechars[1] = datastring[2];
valuechars[2] = datastring[3];
String valuestring = valuechars;
int intconverteddatastring = valuestring.toInt();
if (datastring[1] != 'o') { //set resistorvalue if a number and no onoff state was recieved
resistorvalue = intconverteddatastring;
}
else if (datastring[1] == 'o') {
resistorvalue = 0;
}
if (datastring[0] == "M"[0]) { //commands for changing the magnetron settings
if ((datastring[1] + datastring[2]) == ("on"[0] + "on"[1])) { //switching magnetron on
digitalWrite(statusPinMagnetron, LOW);
Serial.println("Extractor on");
}
else if ((datastring[1] + datastring[2] + datastring[3]) == ("off"[0] + "off"[1] + "off"[2])) { //switching magnetron off
digitalWrite(statusPinMagnetron, HIGH);
Serial.println("Extractor off");
}
else if (datastring[1] != 'o') { // set resistor values
Wire.beginTransmission(0x2c); // transmit to device
Wire.write(0x10); // 16?? 8?? 3 ??
Wire.write(resistorvalue); // sends potentiometer value byte
Wire.endTransmission(); // stop transmitting
}
}
else if (datastring[0] == "E"[0]) { //commands for changing the Extractor settings
if ((datastring[1] + datastring[2]) == ("on"[0] + "on"[1])) { //switching Extractor on
digitalWrite(statusPinExtractor, LOW);
Serial.println("Extractor off");
}
else if ((datastring[1] + datastring[2] + datastring[3]) == ("off"[0] + "off"[1] + "off"[2])) { //switching Extractor off
digitalWrite(statusPinExtractor, HIGH);
Serial.println("Extractor off");
}
else if (datastring[1] != 'o') {
Wire.beginTransmission(0x2c); // transmit to device
Wire.write(0); // 0
Wire.write(resistorvalue); // sends potentiometer value byte
Wire.endTransmission(); // stop transmitting
}
}
else if (datastring[0] == "A"[0]) { //commands for changing the Anode settings
if ((datastring[1] + datastring[2]) == ("on"[0] + "on"[1])) { //switching Anode on
digitalWrite(statusPinAnode, LOW);
Serial.println("Anode on"); //bugtracker
}
else if ((datastring[1] + datastring[2] + datastring[3]) == ("off"[0] + "off"[1] + "off"[2])) { //switching Anode off
digitalWrite(statusPinAnode, HIGH);
Serial.println("Anode off"); //bugtracker
}
else if (datastring[0] != 'o') { // set resistor values
Wire.beginTransmission(0x2c); // transmit to device
Wire.write(32); //
Wire.write(resistorvalue); // sends potentiometer value byte
Wire.endTransmission(); // stop transmitting
}
}
}
}