Hi all, I’ve bought a 4-20mA T Click board link and I found this sketch on LibStock:
const boolean outputToSerial = true;
const int multiplier = 1000;
const int slaveSelectPin = 10; // click SHIELD SLot 1 = D10, Slot 2 = D9
const float minCurrent = 4 * multiplier;
const float maxCurrent = 20 * multiplier;
const float minScaledCurrent = 800; //Not sure where this value came from
const float maxScaledCurrent = 4095; //four MSB of the MCP4921 are control bits, leaving 12 for data
float mAScaledF;
int mAScaled;
int mAScaledInt;
int mA;
byte mAScaled_Hi;
byte mAScaled_Lo;
void setup() {
// set the slaveSelectPin as an output:
pinMode (slaveSelectPin, OUTPUT);
pinMode (11, OUTPUT);
pinMode (13, OUTPUT);
digitalWrite(slaveSelectPin,HIGH);
digitalWrite(13,LOW);
digitalWrite(11,LOW);
// initialize serial:
if (outputToSerial) {
Serial.begin(9600);
}
}
void loop() {
for (mA = minCurrent; mA <= maxCurrent; mA++){ //Cycle from 4.000mA to 20.000mA in 0.001mA increments
//The scaling formula below scales 4-20 to 800-4095
mAScaledF = ((((float)mA - minCurrent) / (maxCurrent - minCurrent)) * (maxScaledCurrent - minScaledCurrent) + minScaledCurrent);
mAScaled = (int) mAScaledF;
mAScaled_Hi = (mAScaled >> 8) &0x0F;
mAScaled_Hi |= 0x30;
mAScaledInt = (mAScaled_Hi << 8);
mAScaled_Lo = mAScaled;
mAScaledInt |= mAScaled_Lo;
// output values to serial port:
if (outputToSerial) {
Serial.print("mA = ");
Serial.println((float)mA / multiplier);
Serial.print("f");
Serial.println(mAScaledF);
Serial.print("d");
Serial.println(mAScaled, DEC);
Serial.print("x");
Serial.println(mAScaled, HEX);
Serial.print("b");
Serial.println(mAScaled, BIN);
Serial.print("High Byte: ");
Serial.println(mAScaled_Hi,BIN);
Serial.print("Low Byte: ");
Serial.println(mAScaled_Lo,BIN);
Serial.println(mAScaledInt,BIN);
}
// The standard Arduino SPI library cannot handle data larger than 8 bits
// so we cannot make use of the SPI.transfer() function to send our packet.
// Instead, we have to bit bang the value in using shiftOut().
// Enable the slave device
digitalWrite(13,LOW);
digitalWrite(11,LOW);
digitalWrite(slaveSelectPin,LOW);
// Do this for MSBFIRST serial
// shift out highbyte
shiftOut(11, 13, MSBFIRST, (mAScaledInt >> 8));
// shift out lowbyte
shiftOut(11, 13, MSBFIRST, mAScaledInt);
// Disable the slave device
digitalWrite(slaveSelectPin,HIGH);
}
}
However, even if I’m sure that connections are good, there’s no output from the board.
I connected the VLOOP to a Proportional Valve but nothing happen (seems unconnected).
Am I supposed to provide additional voltage to the loop (between the valve and the t-click board)?
The valve itself is feeded with 24v.
Also, this image is present on the LibStock page of the board:
Valve is VPPM by FESTO;
EDIT: I had to provide Voltage to the loop, according to XTR Datasheet!