Writing to SPI MCP4261 from IOS Device

I’m still a newcomer to Arduino and I’m stuck. I’ve been working on my application for over a month and can’t figure out what I’m doing wrong.

I’m using Arduino Manager on my Ipad to talk to a Uno with the Joystick widget. I can get the communication from the Ipad to the Uno working. I’m trying to get the Uno to write to a MCP4261 dual potentiometer chip. I’m pretty sure that the Uno/MCP connection is wired correctly because I have a simple sketch that works fine - it just doesn’t use the Ipad for input. I have hooked up a volt meter on each wiper of the two pots on the MCP. When I use this simplified sketch I get the expected voltage readings on the volt meters. I’ve attached this simple sketch.

I used Arduino Manager Code Generator to get the basic sketch layout done for the Ipad/Uno interface and then modified it following the logic of the simplified sketch.

While the sketch below works fine for the Ipad/Uno interface, and the serial prints look like the correct values are being generated, I can not duplicate the voltage outputs from the simple sketch.

Any suggestions would be greatly appreciated. SORRY FOR THE LONG WINDED POST

SIMPLE SKETCH

#include <SPI.h>
// set pin 4 as the slave select for the digital pot:
const int slaveSelectPin = 4;
int addressx = 18;
int addressy = 0;
int potx = 254;
int poty = 254;

void setup() {
// put your setup code here, to run once:
pinMode (slaveSelectPin, OUTPUT);
// initialize SPI:
SPI.begin();
}
void digitalPotWrite(int addressx, int addressy, int potx, int poty){// addresses = 0 & 18 for the MCP4261-502E/P Digital Potentiometer …they may need to change for other chips.
}
void loop() {
// put your main code here, to run repeatedly:

// take the SS pin low to select the chip:
digitalWrite(slaveSelectPin,LOW);
// send in the address and value via SPI:
SPI.transfer(addressx);
SPI.transfer(potx);
SPI.transfer(addressy);
SPI.transfer(poty);
Serial.print("addressx ");
Serial.print(addressx);
Serial.print("potx ");
Serial.println(potx);
Serial.print(addressy);
Serial.println(poty);
// take the SS pin high to de-select the chip:
digitalWrite(slaveSelectPin,HIGH);
}

THIS IS THE SKETCH I’M TRY TO GET WORKING

#include <SPI.h>
#include “Adafruit_BLE_UART.h”
#include “IOSControllerForBluefruit.h”

/* Start your code (defines) /
/
End your code */

/*
*

  • Prototypes of IOSControllerForBluefruit’s callbacks

*/
void doWork();
void doSync(char *variable);
void processIncomingMessages(char *variable, char *value);
void processOutgoingMessages();
void deviceConnected();
void deviceDisconnected();

/*
*

  • IOSControllerForBluefruit Library initialization

*/
IOSControllerForBluefruit iosController(&doWork,&doSync,&processIncomingMessages,&processOutgoingMessages,NULL,NULL);

/******* Start Global Variable for Widgets *******/
int addressx =18;
int addressy = 0;
int potx;
int poty;
int joyin;

/******* End Global Variable for Widgets *******/

void setup()
{
Serial.begin(9600);
pinMode(4,OUTPUT);
digitalWrite(4,HIGH);
pinMode(10,OUTPUT);
digitalWrite(10,LOW);

/* Start your code (setup) /
/
End your code */
}

void loop() {

iosController.loop();
}

/**
*

  • This function is called periodically and it is equivalent to the standard loop() function

*/
void doWork() {

/* Start your code (doWork) /
/
End your code */
}

/**
*
*

  • This function is called when the ios device connects and needs to initialize the position of switches and knobs

*/
void doSync(char *variable) {
int potx = 127;
int poty = 127;
int joyin = 0;

/* Start your code (doSync) /
/
End your code */
}

/**
*
*

  • This function is called when a new message is received from the iOS device

*/
void processIncomingMessages(char *variable, char *value) {

if (strcmp(variable,“Joy1X”) == 0)

{ joyin = 127 + atoi(value) / 8;
potx = joyin;

// digitalWrite(10,HIGH);
digitalWrite(4,LOW);
SPI.transfer(addressx);
SPI.transfer(potx);
digitalWrite(4,HIGH);
// digitalWrite(10,LOW);
Serial.print("address “);
Serial.print(addressx);
Serial.print(” potx ");
Serial.println(potx);
}
else
{
joyin = 127 + atoi(value) / 8;
poty = joyin;

// digitalWrite(10,HIGH);
digitalWrite(4,LOW);
SPI.transfer(addressy);
SPI.transfer(poty);
digitalWrite(4,HIGH);
// digitalWrite(10,LOW);

Serial.print("address “);
Serial.print(addressy);
Serial.print(” poty ");
Serial.println(poty);

}
}

/* Start your code (processIncomingMessages) /
/
End your code */

/**
*
*

  • This function is called periodically and messages can be sent to the iOS device

*/
void processOutgoingMessages() {

/* Start your code (processOutgoingMessages) /
/
End your code */
}

/* Widgets synchronization callbacks */

/* Widgets operations callbacks */
void joystickJoy1MoveRightCallback(int value) {

/* Start your code (joystickJoy1MoveRightCallback) /
/
End your code */
}

void joystickJoy1MoveLeftCallback(int value) {

/* Start your code (joystickJoy1MoveLeftCallback) /
/
End your code */
}

void joystickJoy1MoveForwardCallback(int value) {

/* Start your code (joystickJoy1MoveForwardCallback) /
/
End your code */
}

void joystickJoy1MoveBackwardCallback(int value) {

/* Start your code (joystickJoy1MoveBackwardCallback) /
/
End your code */
}

/* Analog input preprocess functions */

/**** User Functions *****/

/* Start your code (User Functions) /
/
End your code */