Hello,
I'm a beginner im Arduino programing and I'm having dificulties to write a code to potenciometric mode and square wave voltammetry on a potenciostat/galvanostat that I'm development. If someone can help me, please, this is a ciclic voltammetry code that I just have.
Thanks!
// Cyclic Voltammetry
float CVstartVolt; //
float CVpeakVolt; //
float CVscanRate; //
int CVwaveType;
// Changing Resolution
float gain = 100.0;
// Changing Quiet Time (This is the time held at initial voltage before sampling begins)
float quietTime = 0.200;
int quietTimeMillis = round(quietTime*1000.0);
// Changing Sampling Speed
float sampleRateFloat;
int sampleRate;
int samplingDelay; //(value in µs) >> 1/samplingDelay = Sampling Rate
float samplingDelayFloat; //(value in µs) >> 1/samplingDelay = Sampling Rate
//---------------------------------------------------------------------------------Pin Assignments
const int refPin = A3; // Main Analog Input
const int readPin = A2; // Main Analog Input
const int outPin = A14;
const int sp4tOne = 11; // Resolution Switch 1
const int sp4tTwo = 10; // Resolution Switch 2
const int ledPin = 13; //LED pin
const int refCounterShortSwitch = 9; //in2
const int workingElectrodeSwitch = 8; //in4
const int counterElectrodeSwitch = 7; //in1
elapsedMicros usec = 0;
//---------------------------------------------------------------------------------Instructions
String inStruct; // Main instructions from USB
String twoStruct;
String threeStruct;
String fourStruct;
String fiveStruct;
String sixStruct;
double value = 0; // ADC reading value
double ref = 0; //Ref reading value
float aRef = 2.0468; // Analog Reference
float aRefMid = 0.0;
float DACaRef = 3.3;
float DCoffset = 0.0;//0.25/gain; //measured analytically
float DACaRefMid = (aRefMid + DCoffset)*4095.0/DACaRef;
float DACoff = aRef * 4095.0 / DACaRef;
float referenceElectrodeVoltage = 0.220;
//---------------------------------------------------------------------------------Setup
//#include <ADC.h>
//ADC *adc = new ADC(); // adc object
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(readPin, INPUT);
pinMode(outPin, OUTPUT);
pinMode(sp4tOne, OUTPUT);
pinMode(sp4tTwo, OUTPUT);
pinMode(refCounterShortSwitch, OUTPUT);
pinMode(workingElectrodeSwitch, OUTPUT);
pinMode(counterElectrodeSwitch, OUTPUT);
analogWriteResolution(12);
analogReadAveraging(32);
analogReadRes(16);
float averageSum = 0;
for (int32_t i = 0; i < 50; i++) {
averageSum += analogRead(refPin) * aRef / 65535.0; // analog read == # out of 2^16
}
aRefMid = averageSum/50.0;
DACaRefMid = (aRefMid + DCoffset)*4095.0/DACaRef;
while (usec < 5000);
usec = usec - 5000;
}
//---------------------------------------------------------------------------------Main Loop
void loop() {
analogWrite(A14, DACaRefMid); //Maintain almost (small voltage due to op-Amp offset) zero at electrode.
digitalWrite(refCounterShortSwitch, LOW);
digitalWrite(workingElectrodeSwitch, HIGH);
digitalWrite(counterElectrodeSwitch, HIGH);
if (Serial.available()) {
// Interprets commands from computer
// All commands must be terminated with a comma ","
inStruct = Serial.readStringUntil('!');
twoStruct = Serial.readStringUntil('@');
threeStruct = Serial.readStringUntil('#');
fourStruct = Serial.readStringUntil('$');
fiveStruct = Serial.readStringUntil('%');
sixStruct = Serial.readStringUntil('^');
}
if (inStruct.startsWith("cycVolt")) {
CVstartVolt = twoStruct.toFloat();
CVpeakVolt = threeStruct.toFloat();
CVscanRate = fourStruct.toFloat();
CVwaveType = fiveStruct.toInt();
cycVolt();
}