Compare commits
3 Commits
TruehemeV0
...
TruehemeV_
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5bb6d90735 | ||
|
|
c415b1ffa3 | ||
|
|
ebbec00b9a |
@@ -1,17 +1,17 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////TRUEHEME CODE V0.1.4 - BETA Version (To be Tested)/////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////TRUEHEME CODE V0.1.3 - BETA Version (Tested)/////////////////////////////////////////////////////////////////////
|
||||
//////////NEW Changes: All LED warmup function Added; Limit Switch added;EEPROM storage of DAC values; Stray light sensing; Turing on any one LED///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
#include "ADS1X15.h"
|
||||
#include <EEPROM.h>
|
||||
#include <SPI.h>
|
||||
#include <Wire.h>
|
||||
/////////////////////////////////////////////////////////////////////PLEASE UPDATE DEVICE ID BEFORE UPLOADING TO ANY DEVICE/////////////////////////////////////////////////////////////////
|
||||
String Device_ID = "SNS HCV-000-0008 SNE"; // Device ID SNS HPP1-000-5001 SNE
|
||||
String Device_ID = "SNS HCV-001-0012 SNE"; // Device ID
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
const int LED_available[] = {1,2,3,4}; // List of LEDs available. All Variables with 4 columns (other than ones controlling the LED turning ON sequence) must be filled in this order
|
||||
int LED_sequence[] = {1,2,3,4}; // LED turning ON sequence
|
||||
int Detector_sequence[] = {1,1,1,1}; // Detector sequence (if hardware supports dual pathlength)
|
||||
int LED_dac[] = {1792,2304,2048,1920}; // Preset DAC values for the device
|
||||
int LED_dac[] = {1792,2304,2040,1920}; // Preset DAC values for the device
|
||||
int LED_sample_size[] = {50,50,50,50}; // No. of ADC readings to use for Average ADC calculation
|
||||
int LED_DS_threshold[] = {22000,18000,18000,22000}; // DAC sweep upperlimit for each LED
|
||||
int LED_settling_time[] = {20000,20000,20000,20000}; // Settling time given to each LED
|
||||
@@ -37,10 +37,10 @@ const int PIN_CS_DAC2 = 9; // Chip select
|
||||
const int GAIN_1 = 0x1; // DAC 1X gain (output between 0 - 2.048 Volts)
|
||||
const int GAIN_2 = 0x0; // DAC 2X gain (output between 0 - 4.096 Volts)
|
||||
|
||||
const int PD1G1 = 6; // Programmable gain resistor _______ X gain
|
||||
const int PD1G2 = 8; // Programmable gain resistor _______ X gain
|
||||
const int PD2G1 = 5; // Programmable gain resistor _______ X gain
|
||||
const int PD2G2 = 7; // Programmable gain resistor _______ X gain
|
||||
const int PD1G1 = 6; // Programmable gain resistor _______ohm
|
||||
const int PD1G2 = 8; // Programmable gain resistor _______ohm
|
||||
const int PD2G1 = 5; // Programmable gain resistor _______ohm
|
||||
const int PD2G2 = 7; // Programmable gain resistor _______ohm
|
||||
|
||||
const int LEDR = A2; // Red indicator LED
|
||||
const int LEDB = A0; // Blue indicator LED
|
||||
@@ -49,24 +49,36 @@ const int LEDG = A1; // Green indic
|
||||
const int Limit_Switch = 2; // Limit switch for cuvette sensing
|
||||
const int Buzzer_pin = 3; // Buzzer connection for alert
|
||||
|
||||
ADS1115 ADS(0x48); //
|
||||
const char compile_date[] = __DATE__ " " __TIME__; // Stores date and time when the firmware was uploaded on the arduino
|
||||
String Firmware_location_Auto =__FILE__; // Stores location of the firmware on the computer used for uploading
|
||||
String Firmware_version_Auto =__FILE__; // Stores the firmware version uploaded
|
||||
ADS1115 ADS(0x48);
|
||||
///////////////////////////////////////////DO NOT CHANGE ANY VALUES ABOVE //////////////////////////////////////////////////////////////////////////////////////////////
|
||||
const char compile_date[] = __DATE__ " " __TIME__; //Stores date and time when the firmware was uploaded on the arduino
|
||||
String Firmware_location_Auto=__FILE__; //Stores location of the firmware on the computer used for uploading
|
||||
String Firmware_version_Auto=__FILE__; //Stores the firmware version uploaded
|
||||
int DAC_lower_limit[]= {0,0,0,0};
|
||||
int DAC_upper_limit[]= {4096,4096,4096,4096};
|
||||
unsigned long long intensity_storage = 0;
|
||||
int temp_counter = 0;
|
||||
const int detector_settling_time=2000;
|
||||
const int detector_settling_time_DACsweep=1000;
|
||||
|
||||
int DAC_lower_limit[] = {0,0,0,0}; //
|
||||
int DAC_upper_limit[] = {4096,4096,4096,4096}; //
|
||||
unsigned long long intensity_storage = 0; //
|
||||
int temp_counter = 0; //
|
||||
const int detector_settling_time = 2000; //
|
||||
const int detector_settling_time_DACsweep = 1000;
|
||||
int initialRGBstate = 0;
|
||||
float avg_storage = 0;
|
||||
float avg_green = 0;
|
||||
float avg_blue = 0;
|
||||
float old_green = 0;
|
||||
float old_blue = 0;
|
||||
int initialRGBstate=0;
|
||||
|
||||
int split_counter = 0;
|
||||
int intensity_display = 1;
|
||||
int plotter = 0;
|
||||
|
||||
int j = 0;
|
||||
|
||||
float average_readings = 0;
|
||||
float avg_blank[] = {0,0,0,0};
|
||||
float avg_sample[] = {0,0,0,0};
|
||||
int LED_on_status[] = {0,0,0,0};
|
||||
float avg_blank[]={0,0,0,0};
|
||||
float avg_air_blank[]={0,0,0,0};
|
||||
float avg_sample[]={0,0,0,0};
|
||||
int LED_on_status[]={0,0,0,0};
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void setup()
|
||||
{
|
||||
@@ -87,28 +99,40 @@ void setup()
|
||||
digitalWrite(LEDB, HIGH);
|
||||
SPI.begin();
|
||||
SPI.setClockDivider(SPI_CLOCK_DIV2);
|
||||
ADS.begin();
|
||||
ADS.begin();
|
||||
if(appmode==0)
|
||||
{
|
||||
Serial.print("Initial DAC Settings: ");
|
||||
for (int i =0; i<4;i++)
|
||||
{
|
||||
Serial.print("\t");Serial.print(LED_dac[i]);
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
if(appmode==0)
|
||||
{
|
||||
Serial.print("Process: Setup End; Timestamp: ");Serial.println(millis());
|
||||
}
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void buzzer(int mode = 1)
|
||||
void buzzer(int mode)
|
||||
{
|
||||
for(int i=0;i<mode;i++)
|
||||
if(mode==1)
|
||||
{
|
||||
tone(Buzzer_pin, 2730, 1000);
|
||||
delay(500);
|
||||
}
|
||||
else if (mode==2)
|
||||
{
|
||||
tone(Buzzer_pin, 2730, 5000);
|
||||
}
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void all_LEDs_turnoff()
|
||||
{
|
||||
setOutput(GAIN_1, 0, 1);
|
||||
setOutput(GAIN_1, 0, 2);
|
||||
setOutput(GAIN_1, 0, 3);
|
||||
setOutput(GAIN_1, 0, 4);
|
||||
setOutput(GAIN_1, 0, 1); //LED 1
|
||||
setOutput(GAIN_1, 0, 2); //LED 2
|
||||
setOutput(GAIN_1, 0, 3); //LED 3
|
||||
setOutput(GAIN_1, 0, 4); //LED 4
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void secondary_gain_select(int gain_combo)
|
||||
@@ -129,15 +153,15 @@ void secondary_gain_select(int gain_combo)
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void setOutput(byte gain, unsigned int val, int LEDselect)
|
||||
{
|
||||
byte channel = 0;
|
||||
byte shutdown = 1;
|
||||
if(LEDselect%2 == 0)
|
||||
byte channel=0;
|
||||
byte shutdown=1;
|
||||
if(LEDselect%2==0)
|
||||
{
|
||||
channel = 1;
|
||||
channel=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
channel = 0;
|
||||
channel=0;
|
||||
}
|
||||
byte lowByte = val & 0xff;
|
||||
byte highByte = ((val >> 8) & 0xff) | channel << 7 | gain << 5 | shutdown << 4;
|
||||
@@ -165,6 +189,35 @@ void indicator_LED(char statusLED)
|
||||
digitalWrite(LEDR,(statusLED=='R'));
|
||||
digitalWrite(LEDG,(statusLED=='G'));
|
||||
digitalWrite(LEDB,(statusLED=='B'));
|
||||
/*
|
||||
if(statusLED=='R')
|
||||
{
|
||||
digitalWrite(LEDR,HIGH);
|
||||
digitalWrite(LEDG,LOW);
|
||||
digitalWrite(LEDB,LOW);
|
||||
//Serial.println("RED");
|
||||
}
|
||||
else if(statusLED=='G')
|
||||
{
|
||||
digitalWrite(LEDR,LOW);
|
||||
digitalWrite(LEDG,HIGH);
|
||||
digitalWrite(LEDB,LOW);
|
||||
//Serial.println("G");
|
||||
}
|
||||
else if(statusLED=='B')
|
||||
{
|
||||
digitalWrite(LEDR,LOW);
|
||||
digitalWrite(LEDG,LOW);
|
||||
digitalWrite(LEDB,HIGH);
|
||||
//Serial.println("B");
|
||||
}
|
||||
else
|
||||
{
|
||||
digitalWrite(LEDR,LOW);
|
||||
digitalWrite(LEDG,LOW);
|
||||
digitalWrite(LEDB,LOW);
|
||||
}
|
||||
*/
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
int setDAC_LED()
|
||||
@@ -189,7 +242,7 @@ int setDAC_LED()
|
||||
}
|
||||
}
|
||||
all_LEDs_turnoff();
|
||||
delay(2000);
|
||||
delay(1000);
|
||||
////////////////////////////////////////FIRST FORLOOP TO DISCARD ENDS/////////////////////////////////////////////////
|
||||
for (int j=0;j<4;j++)
|
||||
{
|
||||
@@ -226,7 +279,7 @@ int setDAC_LED()
|
||||
void eeprom_DAC_write()
|
||||
{
|
||||
int led_dac_split[]= {0,0,0,0,0,0,0,0};
|
||||
Serial.println("#GS");
|
||||
Serial.println("#WS");
|
||||
led_dac_split[0] = LED_dac[0]/100;
|
||||
led_dac_split[1] = LED_dac[0]-(led_dac_split[0]*100);
|
||||
led_dac_split[2] = LED_dac[1]/100;
|
||||
@@ -246,7 +299,7 @@ void eeprom_DAC_write()
|
||||
{
|
||||
EEPROM.write(i, led_dac_split[i]);
|
||||
}
|
||||
Serial.println("#GC");
|
||||
Serial.println("#WC");
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void eeprom_DAC_read()
|
||||
@@ -272,61 +325,8 @@ void eeprom_DAC_read()
|
||||
Serial.println("#RC");
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void eeprom_DeviceID_write()
|
||||
{
|
||||
int deviceID_split[]= {0,0,0,0};
|
||||
int D_ID_temp[]={000,0000};
|
||||
Serial.println("#GS");
|
||||
deviceID_split[0] = D_ID_temp[0]/100;
|
||||
deviceID_split[1] = D_ID_temp[0]-(deviceID_split[0]*100);
|
||||
deviceID_split[2] = D_ID_temp[1]/100;
|
||||
deviceID_split[3] = D_ID_temp[1]-(deviceID_split[2]*100);
|
||||
if(appmode==0)
|
||||
{
|
||||
Serial.print(deviceID_split[0]);Serial.print("\t");Serial.println(deviceID_split[1]);
|
||||
Serial.print(deviceID_split[2]);Serial.print("\t");Serial.println(deviceID_split[3]);
|
||||
}
|
||||
for (int i=0;i<4;i++)
|
||||
{
|
||||
EEPROM.write(i+8, deviceID_split[i]);
|
||||
}
|
||||
Serial.println("#GC");
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void eeprom_DeviceID_read()
|
||||
{
|
||||
int led_DeviceID_split[]= {0,0,0,0};
|
||||
int Device_version[]={0,0,0};
|
||||
int Dev_ID[]={0,0,0,0};
|
||||
String Dev_version="000";
|
||||
String D_ID="0000";
|
||||
//Serial.println("#NS");
|
||||
for(int i=8;i<12;i++)
|
||||
{
|
||||
led_DeviceID_split[i-8] = EEPROM.read(i);
|
||||
}
|
||||
Device_version[0] = led_DeviceID_split[0]%10;
|
||||
Device_version[1] = (led_DeviceID_split[1]-(led_DeviceID_split[1]%10))/10;
|
||||
Device_version[2] = led_DeviceID_split[1]%10;
|
||||
Dev_ID[0] = (led_DeviceID_split[2]-(led_DeviceID_split[2]%10))/10;
|
||||
Dev_ID[1] = led_DeviceID_split[2]%10;
|
||||
Dev_ID[2] = (led_DeviceID_split[3]-(led_DeviceID_split[3]%10))/10;
|
||||
Dev_ID[3] = led_DeviceID_split[3]%10;
|
||||
Dev_version = String(Device_version[0])+String(Device_version[1])+String(Device_version[2]);
|
||||
D_ID = String(Dev_ID[0])+String(Dev_ID[1])+String(Dev_ID[2])+String(Dev_ID[3]);
|
||||
if(appmode==0)
|
||||
{
|
||||
Serial.print("Device Version: ");Serial.println(Dev_version);
|
||||
Serial.print("Device ID: ");Serial.println(D_ID);
|
||||
}
|
||||
Device_ID = "SNS HCV-" + Dev_version + "-" + D_ID + " SNE";
|
||||
//Serial.println("#NC");
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void LED_warmup(int warmup_time)
|
||||
{
|
||||
Serial.println("#YS");
|
||||
int warmup_start=millis();
|
||||
int current_time=millis();
|
||||
while((current_time-warmup_start)<warmup_time)
|
||||
@@ -338,7 +338,6 @@ void LED_warmup(int warmup_time)
|
||||
current_time=millis();
|
||||
}
|
||||
all_LEDs_turnoff();
|
||||
Serial.println("#YC");
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -413,6 +412,8 @@ void loop()
|
||||
{
|
||||
ADS.setGain(0);
|
||||
all_LEDs_turnoff();
|
||||
avg_storage = 0;
|
||||
split_counter = 0;
|
||||
if(initialRGBstate==0)
|
||||
{
|
||||
indicator_LED('R');
|
||||
@@ -489,9 +490,6 @@ void loop()
|
||||
{
|
||||
if(data == 'I')
|
||||
{
|
||||
//Serial.println(Device_ID); //Remove code or comment it out
|
||||
//eeprom_DeviceID_write(); //Remove code or comment it out
|
||||
eeprom_DeviceID_read();
|
||||
Serial.println(Device_ID);
|
||||
}
|
||||
else if (data == 'F')
|
||||
@@ -525,7 +523,6 @@ void loop()
|
||||
Serial.println(F("Command 'Y' will do : LED warmup for 5 seconds"));
|
||||
Serial.println(F("Command 'G' will do : Write DAC values temporarily set into permanent EEPROM"));
|
||||
Serial.println(F("Command 'E' will do : Read EEPROM stored DAC values and store in temporary memory"));
|
||||
Serial.println(F("Command 'N' will do : Read EEPROM stored Device ID values and store in temporary memory"));
|
||||
Serial.println(F("Command 'P' will do : Print all ADC values (blank and sample)"));
|
||||
Serial.println(F("Command 'R' will do : Print DAC values stored in temporary memory"));
|
||||
Serial.println(F("Command 'L' will do : Print the status of the limit switch"));
|
||||
@@ -534,11 +531,11 @@ void loop()
|
||||
}
|
||||
else if (data == 'Y')
|
||||
{
|
||||
Serial.println("#YS");
|
||||
Serial.println("#HS");
|
||||
LED_warmup(5000);
|
||||
Serial.println("#YC");
|
||||
Serial.println("#HC");
|
||||
}
|
||||
else if ((data == 'G')||(data == 'E')||(data == 'N'))
|
||||
else if ((data == 'G')||(data == 'E'))
|
||||
{
|
||||
if(data == 'G')
|
||||
{
|
||||
@@ -548,10 +545,6 @@ void loop()
|
||||
{
|
||||
eeprom_DAC_read();
|
||||
}
|
||||
else if(data == 'N')
|
||||
{
|
||||
eeprom_DeviceID_read();
|
||||
}
|
||||
}
|
||||
else if ((data == 'P')||(data == 'R'))
|
||||
{
|
||||
@@ -591,19 +584,17 @@ void loop()
|
||||
else if ((data == '1')||(data == '2')||(data == '3')||(data == '4'))
|
||||
{
|
||||
int LED_ID = data-'0';
|
||||
String ON_msg= "#L" + String(LED_ID) + "ON";
|
||||
String OFF_msg= "#L" + String(LED_ID) + "OF";
|
||||
if(LED_on_status[LED_ID-1]==0)
|
||||
{
|
||||
setOutput(GAIN_1, LED_dac[LED_ID-1], LED_ID);
|
||||
LED_on_status[LED_ID-1]=1;
|
||||
Serial.println(ON_msg);
|
||||
Serial.print("LED ");Serial.print(LED_ID);Serial.println(" ON");
|
||||
}
|
||||
else
|
||||
{
|
||||
setOutput(GAIN_1, 0, LED_ID);
|
||||
LED_on_status[LED_ID-1]=0;
|
||||
Serial.println(OFF_msg);
|
||||
Serial.print("LED ");Serial.print(LED_ID);Serial.println(" OFF");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -751,7 +742,7 @@ void startTask4()
|
||||
all_LEDs_turnoff();
|
||||
delay(100);
|
||||
all_LEDs_turnoff();
|
||||
Serial.println("#OS");
|
||||
Serial.println("#BS");
|
||||
for (int i=0;i<4;i++)
|
||||
{
|
||||
setOutput(GAIN_1, 0, LED_sequence[i]);
|
||||
@@ -764,7 +755,7 @@ void startTask4()
|
||||
{
|
||||
Serial.print(millis());Serial.print("\t");Serial.print("LED1B : "); Serial.print(avg_blank[0]); Serial.print("\t"); Serial.print("LED2B : "); Serial.print(avg_blank[1]); Serial.print("\t"); Serial.print("LED3B : "); Serial.print(avg_blank[2]); Serial.print("\t"); Serial.print("LED4B : "); Serial.println(avg_blank[3]);
|
||||
}
|
||||
Serial.println("#OC");
|
||||
Serial.println("#BC");
|
||||
if((appmode==0)&&(timestamp_printer==1))
|
||||
{
|
||||
Serial.print("Process: Buffer end; Timestamp: ");Serial.println(millis());
|
||||
Reference in New Issue
Block a user