Emulating the physical properties HP Memristor using Arduino and Potentiometer

// include the SPI library 
#include <SPI.h>
// Define I/0 pins 
#define SLAVESELECT 4 // set pin 4 as the slave select for the DigPot
// opcodes 
#define INCREASE_W0  4
#define INCREASE_W1  20
#define DECREASE_W0  8 
#define DECREASE_W1  24
#define WRITE_W0 0
#define WRITE_W1 16
#define init_W0 230
#define init_W1 0 

//Memristor parameter definition and default values 
#define Init_state 128 //initial resistance can go from 1-255 
const double Ron = 2000.0;
const double Roff = 50000.0;
const double D = 0.000000001;
const double uv = 0.0000000000001;
float VT = 0.2; // Memristor threshold voltage 
float Vth = -0.2; 
double dwdt, dw, w, Imem, Vmem, wlast, winit, Number;
double dt = 0.000015;
double Rinit = 45000.0;
int N;
int Rw = 75; //wiper resistance 
long Iteration = 0;
double J = 1.0;
double p_coeff = 2.0;

double sign_multiply;
double noise = 0.00000000000000001;
int POBVoltageValue;
double POBvoltage;
int WiperVoltageValue;
double Wipervoltage;
double Imessage;
double wmessage;

void setup() {
 // put your setup code here, to run once:
pinMode(A0, INPUT);
pinMode(A1, INPUT);
//pinMode(DAC0, OUTPUT);
//pinMode(DAC1, OUTPUT);
SPI.begin(SLAVESELECT); // initialize SPI:
Serial.begin(9600); //initialize serial communication at 9600 bits per second:
SendMessage("Debug Channel","Memristor Emulator!"); // through debug channel 
Serial.write('\n'); //debug 
//set initial wiper condition (Rinit)
digitialPotWrite(WRITE_W0, init_W0);
analogReadResolution(12); //change the arduino DueADC/DAC resolution to 12 bits 
analogWriteResolution(12); 
analogWrite(DAC0, 2047);  //Force the DAC0 pin to a reference voltage of 1.65v 
dw = (uv*Ron)/D;
winit = D/10;
wlast = winit; 
Rmem = Rinit; 
}

void loop() {
 // put your main code here, to run repeatedly:
analogWrite(DAC1, sine[1]);
delayMicroseconds(2);
if (Iteration = 0){
digitalPotWrite(WRITE_W0, init_W0); //set initial wiper condition (Rinit) 
}
Iteration++;
POBVoltageValue = analogRead(A0); //read the input on analog pin 0:
WiperVoltageValue = analogRead(A1); //read the input on analog pin 1:
//Convert the analog reading (which goes from 0 - 4095) to voltage (0 - 3.3V);
POBvoltage = POBVoltageValue * (3.3 / 4095.0); 
Wipervoltage = WiperVoltageValue * (3.3 / 4095.0);
Vmem = Wipervoltage - POBvoltage; 
Imem = Vmem/Rmem; 
Imessage = 1000000.0 * Imem; 
dwdt = dw * Imem;
if (func(Imem)== 1){ 
sign_multiply = 0.0;
if (w = 0){
sign.mulitply = 1.0;}}
if (func(Imem) = -1){
sign_multiply = 0.0;
if (w = D){
sign_multiply = -1.0; }}
if ((abs (Vmem)) < VT){
w = wlast; } 
else {
w = dwdt*dt*J*(1-(pow(pow((w/D)-05,2)+0.75,p_coeff)))+

wlast+(sign_multply*noise);}
if (w >= D){
w=D;} 
if (w <= 0){
w=0;}
Rmem=(Ron*w/D+Roff*(1-w/D));
wlast=w;
Number = (((Rmem - Rw)*256)/Roff);
N = round(Number); 
wmessage = 1000000000*w;
digitalPotWrite(WRITE_W0, N); // Update DigPot 
// Time Plot 
TimePlot(Imessage,"Current_behaviour","Current_TimePlot");
Serial.println("{TIMEPLOT:Current_TimePlot| set | title=Curent}");
Serial.println("{TIMEPLOT:Current_TimePlot| set | x-label=Time}");
Serial.println("{TIMEPLOT:Current_TimePlot| set | y-label=Current(uA)}"); 

TimePlot(Vmem,"Input_Voltage","Voltage_TimePlot");
Serial.println("{TIMEPLOT:Voltage_TimePlot| set | title=Voltage}");
Serial.println("{TIMEPLOT:Voltage_TimePlot| set | x-label=Time}");
Serial.println("{TIMEPLOT:Voltage_TimePlot| set | y-label=Voltage}");

// XY Plot 
XYPlot(Vmem, Imessage,"lissajous","Lissajous_XYPlot");
Serial.println("{XYPLOT:Lissajous_XYPlot| set | title= i-v Plot}");
Serial.println("{XYPLOT:Lissajous_XYPlot| set | x-label=Voltage}");
Serial.println("{XYPLOT:Lissajous_XYPlot| set | y-label=Current uA}");

TableData("Current",Imessage,"Current flowing through Memristor");
TableData("Voltage",Vmem,"Voltage across through Memristor");

TableData("Wiper",Wipervoltage,"Wiper Voltage");
TableData("POB",POBvoltage, "POB Voltage");
TableData("Memristance",Rmem,"Current memristance value");
TableData("Number",Number,"Current DigPot number");
TableData("width",wmessage,"doped area");
delayMicroseconds(10); // Sampling Frequency '
}
int func(double arg){
int sign; 
sign = (arg >= 0.0 ? 1 : -1);
return sign;}
void digitalPotWrite(int command, int value) {
// send in the command and wiper address via SPI:
SPI.transfer(SLAVESELECT, command, SPI_CONTINUE);
SPI.transfer(SLAVESELECT, value);}
void SendMessage(String ChannelName, String Message){
Serial.print("{MESSAGE:");
Serial.print(ChannelName);
Serial.print("|data|");
Serial.print(Message);
Serial.println("}");}
void SendMessage(String Message){
Serial.print("{MESSAGE");
Serial.print("|data|");
Serial.print(Message);
Serial.println("}");}
void TimePlot(float data, String seriesName, String channelName){
Serial.print("{TIMEPLOT:");
Serial.print(channelName);
Serial.print("|data|");

Serial.print(seriesName);
Serial.print("|T|");
Serial.print(data, 3);
Serial.println("}");}
void XYPlot(float xData, float yData, String seriesName, String channelName){
Serial.print("{XYPLOT:");
Serial.print(channelName);
Serial.print("|data|");
Serial.print(seriesName);
Serial.print("|");
Serial.print(xData);
Serial.print(yData);
Serial.println("}");}
void TableData(String Name, double Value, String Description){
Serial.print("{TABLE");
Serial.print("|SET|");
Serial.print(Name);
Serial.print("|");
Serial.print(Value);
Serial.print("|");
Serial.print(Description);
Serial.println("}");}


}
}

Error Messages

/Users/nas.the.rapper/Documents/Arduino/sketch_may28a/sketch_may28a.ino: In function 'void setup()':
sketch_may28a:47:22: error: no matching function for call to 'SPIClass::begin(int)'
 SPI.begin(SLAVESELECT); // initialize SPI:
                      ^
In file included from /Users/nas.the.rapper/Documents/Arduino/sketch_may28a/sketch_may28a.ino:2:0:
/Users/nas.the.rapper/Desktop/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI/src/SPI.h:159:15: note: candidate: static void SPIClass::begin()
   static void begin();
               ^
/Users/nas.the.rapper/Desktop/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI/src/SPI.h:159:15: note:   candidate expects 0 arguments, 1 provided
sketch_may28a:52:35: error: 'digitialPotWrite' was not declared in this scope
 digitialPotWrite(WRITE_W0, init_W0);
                                   ^
sketch_may28a:53:24: error: 'analogReadResolution' was not declared in this scope
 analogReadResolution(12); //change the arduino DueADC/DAC resolution to 12 bits 
                        ^
sketch_may28a:54:25: error: 'analogWriteResolution' was not declared in this scope
 analogWriteResolution(12); 
                         ^
sketch_may28a:55:13: error: 'DAC0' was not declared in this scope
 analogWrite(DAC0, 2047);  //Force the DAC0 pin to a reference voltage of 1.65v 
             ^
sketch_may28a:59:1: error: 'Rmem' was not declared in this scope
 Rmem = Rinit; 
 ^
/Users/nas.the.rapper/Documents/Arduino/sketch_may28a/sketch_may28a.ino: In function 'void loop()':
sketch_may28a:64:13: error: 'DAC1' was not declared in this scope
 analogWrite(DAC1, sine[1]);
             ^
sketch_may28a:64:19: error: 'sine' was not declared in this scope
 analogWrite(DAC1, sine[1]);
                   ^
sketch_may28a:76:13: error: 'Rmem' was not declared in this scope
 Imem = Vmem/Rmem; 
             ^
sketch_may28a:82:1: error: 'sign' was not declared in this scope
 sign.mulitply = 1.0;}}
 ^
sketch_may28a:83:16: error: lvalue required as left operand of assignment
 if (func(Imem) = -1){
                ^
sketch_may28a:92:8: error: 'sign_multply' was not declared in this scope
 wlast+(sign_multply*noise);}
        ^
/Users/nas.the.rapper/Documents/Arduino/sketch_may28a/sketch_may28a.ino: In function 'void digitalPotWrite(int, int)':
sketch_may28a:136:36: error: 'SPI_CONTINUE' was not declared in this scope
 SPI.transfer(SLAVESELECT, command, SPI_CONTINUE);
                                    ^
/Users/nas.the.rapper/Documents/Arduino/sketch_may28a/sketch_may28a.ino:137:32: warning: invalid conversion from 'int' to 'void*' [-fpermissive]
 SPI.transfer(SLAVESELECT, value);}
                                ^
In file included from /Users/nas.the.rapper/Documents/Arduino/sketch_may28a/sketch_may28a.ino:2:0:
/Users/nas.the.rapper/Desktop/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI/src/SPI.h:244:22: note:   initializing argument 1 of 'static void SPIClass::transfer(void*, size_t)'
   inline static void transfer(void *buf, size_t count) {
                      ^
/Users/nas.the.rapper/Documents/Arduino/sketch_may28a/sketch_may28a.ino: At global scope:
sketch_may28a:178:1: error: expected declaration before '}' token
 }
 ^
exit status 1
no matching function for call to 'SPIClass::begin(int)'

first problem you have is that you did not read how to use the forum and how to ask a question...

read the messages pinned at the top of the forum

Several things.

  1. Please use code comments, makes life easier for us who help.
  2. Did you read the SPI documentation? SPI.begin does not take a parm in the library I know.
  3. Where did you declare SPI. I should see someting like SPI spiInterface.
  4. DigitalPotWritter, where is this declared and impelmented?
  5. Analog Read Resolution, where is this declared?

The SPI lib has an example of how to use SPI to control a digital pot, did you read it?