An oligonucleotide synthesizer is a device used in biochemistry to assemble DNA and/or RNA synthetically. One way to do so is by using a DNA electrowetter device, which is essentially a complex of electrodes that are used to alternate charges to move a droplet containing nucleotide and reagents from one electrode to another. This is what I have been working on with arduino, using an arduino Uno and and SD card reader to take a text file containing a string of nucleotide characters like A, G, C, T, or U, and activate different solenoid valves on reading the corresponding letters. So far, the electrode portion of my device is working, however the solenoid valves wont activate, and the serial monitor data that I could find on the IDE software wont display on the LCD screen.
The biggest issue is that I get the correct electrode response on the serial monitor, however the error: "card failed to initialize" always comes up with it.
Here is my full code:
// PINS
/* MIT Open-Source LICENSE:
*
* Copyright 2018 Charles Grassin
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
// PINS
#define PIN_FEEDBACK (A0)
#define PIN_LE (A1)
#define PIN_CLK (A2)
#define PIN_BL (A3)
#define PIN_DI (A4)
#define PIN_SWA (12)
#define PIN_SWB (11)
#include <Arduino.h>
#include <stdint.h>
#include <SD.h>
#include <SPI.h>
#include <AFMotor.h>
#define MAX_LINE_LEN 80
#include <LiquidCrystal.h>
int solenoidPin1 = 11;
int solenoidPin2 = 11;
int solenoidPin3 = 3;
int solenoidPin4 = 3;
int solenoidPin5 = 5;
int solenoidPin6 = 5;
int solenoidPin7 = 6;
int solenoidPin8 = 6;
// SETTINGS
#define ELECTRODE_ARRAY_WIDTH 8
#define ELECTRODE_ARRAY_HEIGHT 8
const byte HV507_LOOKUP_TABLE [] = {4,5,6,7,12,13,15,14,20,22,23,21,28,31,30,29,36,39,38,37,47,46,45,44,55,62,61,53,54,63,60,52,51,59,56,49,58,50,57,48,43,42,41,40,34,33,32,35,26,25,24,27,18,16,17,19,9,8,10,11,0,1,2,3};
#define BAUD_RATE 115200
#define SERIAL_BUFFER_LENGTH 10
#define TEST_PROG
// VARS
bool electrodes[ELECTRODE_ARRAY_WIDTH][ELECTRODE_ARRAY_HEIGHT];
char serialBuffer[SERIAL_BUFFER_LENGTH];
uint8_t currentIndex=0;
// Electrode array code
void clearElectrodes() {
for (int x = 0; x <ELECTRODE_ARRAY_WIDTH ; x++)
for (int y = 0; y <ELECTRODE_ARRAY_HEIGHT ; y++)
setElectrode(x,y,false);
}
void setElectrodes() {
for (int x = 0; x <ELECTRODE_ARRAY_WIDTH ; x++)
for (int y = 0; y <ELECTRODE_ARRAY_HEIGHT ; y++)
setElectrode(x,y,true);
}
void setElectrode(int x,int y,bool state) {
if(state != electrodes[x][y]) {
electrodes[x][y]=state;
sendElectrode(x,y);
}
}
void sendElectrode(int x,int y){
Serial.print(x);
Serial.print(",");
Serial.print(y);
Serial.print(",");
Serial.print(electrodes[x][y]);
Serial.print("\n");
}
// Refer to HV507 datasheet
void writeHV507() {
digitalWrite(PIN_LE, LOW);
digitalWrite(PIN_CLK, LOW);
for (int i = 0; i <64 ; i++) {
digitalWrite(PIN_DI,electrodes[HV507_LOOKUP_TABLE[i]%8][HV507_LOOKUP_TABLE[i]/8]);
digitalWrite(PIN_CLK, HIGH);
digitalWrite(PIN_CLK, LOW);
}
digitalWrite(PIN_LE, HIGH);
digitalWrite(PIN_LE, LOW);
}
void setup() {
Serial.begin(BAUD_RATE);
pinMode(PIN_LE, OUTPUT);
digitalWrite(PIN_LE,LOW);
pinMode(PIN_CLK, OUTPUT);
digitalWrite(PIN_CLK,LOW);
pinMode(PIN_BL, OUTPUT);
digitalWrite(PIN_BL,HIGH);
pinMode(PIN_DI, OUTPUT);
digitalWrite(PIN_DI,LOW);
pinMode(PIN_SWA, INPUT_PULLUP);
pinMode(PIN_SWB, INPUT_PULLUP);
clearElectrodes();
writeHV507();
digitalWrite(PIN_BL,HIGH);
for (int x = 0; x <ELECTRODE_ARRAY_WIDTH ; x++)
for (int y = 0; y <ELECTRODE_ARRAY_HEIGHT ; y++)
sendElectrode(x,y);
const int cs = 4;
if (!SD.begin(cs))
{
Serial.println("Card failed to initialize, or not present");
return;
}
Serial.println("card initialized.");
// open the file named ourfile.txt
File myfile = SD.open("ourfile.txt");
// if the file is available, read the file
if (myfile)
{
while (myfile.available())
{
Serial.write(myfile.read());
}
myfile.close();
}
// if the file cannot be opened give error report
else {
Serial.println("error opening the text file");
}
Serial.print("Initializing card...");
pinMode(53, OUTPUT);
pinMode(solenoidPin1, OUTPUT);
pinMode(solenoidPin2, OUTPUT);
pinMode(solenoidPin3, OUTPUT);
pinMode(solenoidPin4, OUTPUT);
pinMode(solenoidPin5, OUTPUT);
pinMode(solenoidPin6, OUTPUT);
pinMode(solenoidPin7, OUTPUT);
pinMode(solenoidPin8, OUTPUT);
}
#ifdef TEST_PROG
int step = 0;
long unsigned int lastT = millis();
#endif
void loop() {
{
if(serialReadCommand()){
writeHV507();
}
// Test program
#ifdef TEST_PROG
if(millis()-lastT>500){
lastT = millis();
switch(step){
case 0: setElectrode(4,3,false);
setElectrode(4,4,true);
break;
case 1:setElectrode(4,4,false);
setElectrode(4,5,true);
break;
case 2:setElectrode(4,5,false);
setElectrode(5,5,true);
break;
case 3:setElectrode(5,5,false);
setElectrode(5,4,true);
break;
case 4:setElectrode(5,4,false);
setElectrode(5,3,true);
break;
case 5:setElectrode(5,3,false);
setElectrode(4,3,true);
break;
case 6:setElectrode(3,4,true);
setElectrode(4,3,true); }
writeHV507();
}
writeHV507();
step ++;
if(step > 5) step = 0;
}
#endif
if (char Str2[8] = {isAlpha('A'||'a')})
{
digitalWrite(solenoidPin1, HIGH); //Switch Solenoid ON
delay(1000); //Wait 1 Second
digitalWrite(solenoidPin1, LOW); //Switch Solenoid ON
delay(1000); //Wait 1 Second
digitalWrite(solenoidPin6, HIGH);
delay(1000);
digitalWrite(solenoidPin6, LOW);
digitalWrite(solenoidPin7, HIGH);
delay(1000);
digitalWrite(solenoidPin7, LOW);
}
if (char Str2[8] = {isAlpha('G'||'g')})
{
digitalWrite(solenoidPin2, HIGH); //Switch Solenoid ON
delay(1000); //Wait 1 Second
digitalWrite(solenoidPin2, LOW); //Switch Solenoid ON
delay(1000); //Wait 1 Second
digitalWrite(solenoidPin6, HIGH);
delay(1000);
digitalWrite(solenoidPin6, LOW);
digitalWrite(solenoidPin7, HIGH);
delay(1000);
digitalWrite(solenoidPin7, LOW);
}
if (char Str2[8] = {isAlpha('C'||'c')})
{
digitalWrite(solenoidPin3, HIGH); //Switch Solenoid ON
delay(1000); //Wait 1 Second
digitalWrite(solenoidPin3, LOW); //Switch Solenoid ON
delay(1000); //Wait 1 Second
digitalWrite(solenoidPin6, HIGH);
delay(1000);
digitalWrite(solenoidPin6, LOW);
digitalWrite(solenoidPin7, HIGH);
delay(1000);
digitalWrite(solenoidPin7, LOW);
}
if (char Str2[8] = {isAlpha('T'||'t')})
{
digitalWrite(solenoidPin4, HIGH); //Switch Solenoid ON
delay(1000); //Wait 1 Second
digitalWrite(solenoidPin4, LOW); //Switch Solenoid ON
delay(1000); //Wait 1 Second
digitalWrite(solenoidPin6, HIGH);
delay(1000);
digitalWrite(solenoidPin6, LOW);
digitalWrite(solenoidPin7, HIGH);
delay(1000);
digitalWrite(solenoidPin7, LOW);
}
if (char Str2[8] = {isAlpha('U'||'u')})
{
digitalWrite(solenoidPin5, HIGH); //Switch Solenoid ON
delay(1000); //Wait 1 Second
digitalWrite(solenoidPin5, LOW); //Switch Solenoid ON
delay(1000); //Wait 1 Second
digitalWrite(solenoidPin6, HIGH);
delay(1000);
digitalWrite(solenoidPin6, LOW);
digitalWrite(solenoidPin7, HIGH);
delay(1000);
digitalWrite(solenoidPin7, LOW);
}
if (char Str2[8] = {'\0'}){
digitalWrite(solenoidPin8, HIGH); //Switch Solenoid ON
delay(1000); //Wait 1 Second
digitalWrite(solenoidPin8, LOW); //Switch Solenoid ON
delay(1000); //Wait 1 Second
}
}
uint8_t serialReadCommand(){
uint8_t number_of_commands = 0;
while (Serial.available() > 0) {
char recieved = Serial.read();
serialBuffer[currentIndex] = recieved;
currentIndex ++;
if (currentIndex >= SERIAL_BUFFER_LENGTH) {
// Invalid command: command is too long
currentIndex = 0;
}
if (recieved == '\n' || recieved == '\r') {
// Close string
serialBuffer[currentIndex-1] = '\0';
// Clear buffer for next serial transaction
currentIndex = 0;
// Split the string
char* commaIndex = strchr(serialBuffer, ',');
if (commaIndex==NULL) {
// Invalid command: command is malformed
continue;
}
commaIndex[0] = '\0';
char* secondCommaIndex = strchr(commaIndex+1, ',');
if (secondCommaIndex==NULL) {
// Invalid command: command is malformed
continue;
}
secondCommaIndex[0] = '\0';
int x = atoi(serialBuffer);
int y = atoi(commaIndex+1);
if(x<0 || x>=ELECTRODE_ARRAY_WIDTH || y<0 || y>=ELECTRODE_ARRAY_HEIGHT){
// Invalid command: out of bound
continue;
}
setElectrode(x,y,strcmp(secondCommaIndex+1,"0")!=0);
number_of_commands += 1;
}
}
return number_of_commands;
}
/*void btnMatrixTest(){
for (int y = 0; y <ELECTRODE_ARRAY_WIDTH ; y++)
for (int x = 0; x <ELECTRODE_ARRAY_HEIGHT ; x++){
clearElectrodes();
electrodes[x][y]=true;
writeHV507();
Serial.print(x);
Serial.print("\t");
Serial.println(y);
delay(500);
while(digitalRead(PIN_SWA)){}
}
}*/
Here is my circuit (excluding electrode wires as they are functional)
I couldn't include the LCD screen since the circuit software didn't have the correct one, being a small 4 pin (GND, VCC, SCL, SDA) screen for arduino.
Are there any suggestions as to why this isn't working?