Arduino to Squirrel

Those delays are not inside the CS part, but before. As Peter said, there’s no reason to have those in there. If you want delays, but them before you drive CS low.

The latest code you posted up there had the address register write commented out (the SPI.write("\x00") before the readblob). This is absolutely required.

Taking that exact code - the squirrel you posted, but with the address write reinstated) - should work in my opinion, modulo wiring errors, etc.

@Hugo I am guessing I must have a communication issue on the SPI. It doesn’t seem to matter if I add back in the write(\x00) and take out the imp.sleep statements. I get reading back that are all over the place and obviously not the information I should be getting. The chip is very different from the MAX31855, so I am worried that it might not be compatible for some reason.

MAX31865 seems basically the same, but debugging your issue remotely is not easy.

At this point I suspect it may be wiring, because the code looks like it should work to me.

@Hugo I understand and appreciate everything you have done to help. If you don’t mind looking over some pics I would be grateful.

Here are the basics of the pinout on the device:
https://drive.google.com/folderview?id=0B9DlEKG0H65LbnEwdllRcFR1djQ&usp=sharing

CS1 - Black - Pin A
CS2 - Orange - Pin B
SDO - White - Pin 9
SDI - Yellow - Pin 8
SCLOCK - Brown - Pin 1

Makedeck P3C3 Board pics

I have the P3V3 Makedeck board and the MAX31865 board plugged directly into a 5V 1.1A power supply.

Well on to other things as this board is not going to cooperate with me and I have other fish to fry.

I have a PID code I am trying to figure out more Arduino to Squirrel code. @smittytone could you highlight how squirrel would account for the void statement and the way they defined the variables in this code?

`/working variables/
unsigned long lastTime;
double Input, Output, Setpoint;
double ITerm, lastInput;
double kp, ki, kd;
int SampleTime = 1000; //1 sec
double outMin, outMax;
bool inAuto = false;

#define MANUAL 0
#define AUTOMATIC 1

#define DIRECT 0
#define REVERSE 1
int controllerDirection = DIRECT;

void Compute()
{
if(!inAuto) return;
unsigned long now = millis();
int timeChange = (now - lastTime);
if(timeChange>=SampleTime)
{
/Compute all the working error variables/
double error = Setpoint - Input;
ITerm+= (ki * error);
if(ITerm > outMax) ITerm= outMax;
else if(ITerm < outMin) ITerm= outMin;
double dInput = (Input - lastInput);

  /*Compute PID Output*/
  Output = kp * error + ITerm- kd * dInput;
  if(Output > outMax) Output = outMax;
  else if(Output < outMin) Output = outMin;

  /*Remember some variables for next time*/
  lastInput = Input;
  lastTime = now;

}
}

void SetTunings(double Kp, double Ki, double Kd)
{
if (Kp<0 || Ki<0|| Kd<0) return;

double SampleTimeInSec = ((double)SampleTime)/1000;
kp = Kp;
ki = Ki * SampleTimeInSec;
kd = Kd / SampleTimeInSec;

if(controllerDirection ==REVERSE)
{
kp = (0 - kp);
ki = (0 - ki);
kd = (0 - kd);
}
}

void SetSampleTime(int NewSampleTime)
{
if (NewSampleTime > 0)
{
double ratio = (double)NewSampleTime
/ (double)SampleTime;
ki *= ratio;
kd /= ratio;
SampleTime = (unsigned long)NewSampleTime;
}
}

void SetOutputLimits(double Min, double Max)
{
if(Min > Max) return;
outMin = Min;
outMax = Max;

if(Output > outMax) Output = outMax;
else if(Output < outMin) Output = outMin;

if(ITerm > outMax) ITerm= outMax;
else if(ITerm < outMin) ITerm= outMin;
}

void SetMode(int Mode)
{
bool newAuto = (Mode == AUTOMATIC);
if(newAuto == !inAuto)
{ /we just went from manual to auto/
Initialize();
}
inAuto = newAuto;
}

void Initialize()
{
lastInput = Input;
ITerm = Output;
if(ITerm > outMax) ITerm= outMax;
else if(ITerm < outMin) ITerm= outMin;
}

void SetControllerDirection(int Direction)
{
controllerDirection = Direction;
}`

Essentially:

‘void’ becomes ‘function’
‘double’, ‘bool’, ‘unsigned long’ and ‘int’ become ‘local’
#define’ becomes ‘const’.

These are not literal translations, but if you change your code accordingly, you’re most of the way there.

Also, this code contains functions but not entry point, so you’ll need some code to trigger SetMode() to be run (since it calls Initialize() )

One more thing: the working variables at the start need to be marked as global, ie.

‘double Input, Output, Setpoint;’ becomes
’Input <- 0;

Output <- 0;

Setpoint <- 0;’

PS. Don’t know why the <br/ > are showing up there, but ignore them

Please, helpe me how to connect to arduino mega?

The right answer to that depends on why you want to connect them, @manuk099, but probably you want to configure one of the imp’s UART buses to talk to the Arduino’s Serial pins.