Merge branch 'hemocube-qc' into 'main'
merge pyqt See merge request sminnovations/hpos-qc-desk!1
This commit is contained in:
6
.gitignore
vendored
6
.gitignore
vendored
@@ -1,2 +1,4 @@
|
||||
node_modules
|
||||
out/
|
||||
*.DS_Store
|
||||
/env
|
||||
build
|
||||
dist
|
||||
828
Hemocube_triplate.ino
Normal file
828
Hemocube_triplate.ino
Normal file
@@ -0,0 +1,828 @@
|
||||
#include "ADS1X15.h"
|
||||
#include <SPI.h>
|
||||
#include <Wire.h>
|
||||
#include <math.h>
|
||||
|
||||
const int buttonPin = 12; // Button pin
|
||||
const int PIN_CS = 10;
|
||||
const int GAIN_1 = 0x1;
|
||||
const int GAIN_2 = 0x0;
|
||||
const unsigned int steps = 512;
|
||||
unsigned int sines_of_steps[steps];
|
||||
char data; //Variable to store the data
|
||||
|
||||
ADS1115 ADS(0x48);
|
||||
|
||||
int blue_dac = {led1dac} //2220; //390 2940
|
||||
int green_dac = {led2dac} //1880; //2320 2860
|
||||
|
||||
int green_sample_size = 100;
|
||||
int blue_sample_size = 100;
|
||||
|
||||
int loopcounter = 0;
|
||||
unsigned long long intensity_storage = 0;
|
||||
int temp_counter = 0;
|
||||
|
||||
float avg_storage = 0;
|
||||
float avg_blueS = 0;
|
||||
float avg_blueS1 = 0;
|
||||
float avg_blueS2 = 0;
|
||||
float avg_blueS3 = 0;
|
||||
float avg_greenS = 0;
|
||||
float avg_greenS1 = 0;
|
||||
float avg_greenS2 = 0;
|
||||
float avg_greenS3 = 0;
|
||||
float avg_blueB = 0;
|
||||
float avg_blueB1 = 0;
|
||||
float avg_blueB2 = 0;
|
||||
float avg_blueB3 = 0;
|
||||
float avg_greenB = 0;
|
||||
float avg_greenB1 = 0;
|
||||
float avg_greenB2 = 0;
|
||||
float avg_greenB3 = 0;
|
||||
float old_blue = 0;
|
||||
float old_green = 0;
|
||||
float avg_green = 0;
|
||||
float avg_blue = 0;
|
||||
//
|
||||
bool buttonState = false; // Current button state
|
||||
bool lastButtonState = false; // Previous button state
|
||||
//int taskNumber = 1; // Current task number
|
||||
bool taskStarted = false;
|
||||
//int buttonPressCount = 0;
|
||||
int bs;
|
||||
int split_counter = 0;
|
||||
int intensity_display = 1;
|
||||
int plotter = 0;
|
||||
int blue_stable_time = 50;
|
||||
int green_stable_time = 50;
|
||||
|
||||
int blue_samples = 10;
|
||||
int green_samples = 10;
|
||||
|
||||
int moving_average_array[] = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
|
||||
int sorting_array[] = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
|
||||
int moving_average = 0;
|
||||
int j = 0;
|
||||
int temp_sort = 0;
|
||||
|
||||
void setup() {{
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println("SN HCV1001");
|
||||
pinMode(PIN_CS, OUTPUT);
|
||||
pinMode(buttonPin, INPUT_PULLUP);
|
||||
SPI.begin();
|
||||
SPI.setClockDivider(SPI_CLOCK_DIV2);
|
||||
ADS.begin();
|
||||
}}
|
||||
|
||||
void setOutput(byte channel, byte gain, byte shutdown, unsigned int val)
|
||||
{{
|
||||
byte lowByte = val & 0xff;
|
||||
byte highByte = ((val >> 8) & 0xff) | channel << 7 | gain << 5 | shutdown << 4;
|
||||
PORTB &= 0xfb;
|
||||
SPI.transfer(highByte);
|
||||
SPI.transfer(lowByte);
|
||||
PORTB |= 0x4;
|
||||
}}
|
||||
|
||||
void loop() {{
|
||||
loopcounter = 0;
|
||||
avg_storage = 0;
|
||||
split_counter = 0;
|
||||
|
||||
if (Serial.available()) {{
|
||||
char data = Serial.read();
|
||||
|
||||
if (data == 'B') {{
|
||||
taskStarted = false;
|
||||
Serial.println("#Place Buffer");
|
||||
|
||||
while (!taskStarted) {{
|
||||
buttonState = digitalRead(buttonPin);
|
||||
|
||||
if (buttonState == HIGH && lastButtonState == LOW) {{
|
||||
lastButtonState = buttonState;
|
||||
taskStarted = true;
|
||||
startTask1();
|
||||
}}
|
||||
|
||||
lastButtonState = buttonState;
|
||||
}}
|
||||
|
||||
taskStarted = false;
|
||||
while (!taskStarted) {{
|
||||
buttonState = digitalRead(buttonPin);
|
||||
|
||||
if (buttonState == HIGH && lastButtonState == LOW) {{
|
||||
lastButtonState = buttonState;
|
||||
taskStarted = true;
|
||||
startTask2();
|
||||
}}
|
||||
|
||||
lastButtonState = buttonState;
|
||||
}}
|
||||
}}
|
||||
else if (data == 'S') {{
|
||||
Serial.println("Place Sample");
|
||||
while (digitalRead(buttonPin) == LOW) {{
|
||||
delay(10);
|
||||
}}
|
||||
startTask2();
|
||||
}}
|
||||
|
||||
else if (data == 'P') {{ //Check if the received character is 1
|
||||
Serial.print("RESULT");
|
||||
Serial.print(" "); Serial.print("SN HCV1001"); Serial.print(" "); Serial.print(avg_greenB); Serial.print(" "); Serial.print(avg_blueB); Serial.print(" "); Serial.print(avg_greenS); Serial.print(" "); Serial.print(avg_blueS); Serial.print(" ");Serial.print("REND");Serial.println(" ");
|
||||
|
||||
delay(100);
|
||||
}}
|
||||
|
||||
}}
|
||||
}}
|
||||
void startTask1() {{
|
||||
Serial.println("#Buffer Started");
|
||||
setOutput(1, GAIN_1, 1, 0);
|
||||
setOutput(0, GAIN_1, 1, green_dac);
|
||||
memset (moving_average_array, 0, 10);
|
||||
temp_counter = 0;
|
||||
intensity_storage = 0;
|
||||
float f = ADS.toVoltage(1); // voltage factor
|
||||
for (int i = 0; i < green_samples + green_stable_time; i += 1)
|
||||
{{
|
||||
|
||||
int16_t val_0 = ADS.readADC(0);
|
||||
int16_t val_1 = ADS.readADC(1);
|
||||
int16_t val_2 = ADS.readADC(2);
|
||||
int16_t val_3 = ADS.readADC(3);
|
||||
moving_average_array[i % 10] = val_1;
|
||||
for (int j = 0; j < 10; j++)
|
||||
{{
|
||||
sorting_array[j] = moving_average_array[j];
|
||||
}}
|
||||
if (i >= green_stable_time)
|
||||
{{
|
||||
for (int j = 0; j < 6; j++)
|
||||
{{
|
||||
for (int k = 0; k < (9 - j); k++)
|
||||
{{
|
||||
if (sorting_array[k] > sorting_array[k + 1])
|
||||
{{
|
||||
temp_sort = sorting_array[k];
|
||||
sorting_array[k] = sorting_array[k + 1];
|
||||
sorting_array[k + 1] = temp_sort;
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
moving_average = (sorting_array[4] / 2) + (sorting_array[5] / 2);
|
||||
if ((val_1 > (moving_average * 0.9)) and (val_1 < (moving_average * 1.1)))
|
||||
{{
|
||||
intensity_storage += val_1;
|
||||
temp_counter++;
|
||||
}}
|
||||
}}
|
||||
|
||||
if (intensity_display == 1)
|
||||
{{
|
||||
// Serial.print("DAC_value : "); Serial.print(i); Serial.print('\t'); Serial.print('\t'); Serial.print("Green_Resistor_drop: "); Serial.print(val_2);
|
||||
// Serial.print('\t'); Serial.print('\t'); Serial.print("PD_output: "); Serial.print(val_1); Serial.print('\t'); Serial.print('\t'); Serial.print("PD_2X_output: "); Serial.println(val_0);
|
||||
}}
|
||||
if (plotter == 1)
|
||||
{{
|
||||
Serial.println(val_1);
|
||||
}}
|
||||
//delay(200);
|
||||
}}
|
||||
avg_greenB1 = intensity_storage / temp_counter;
|
||||
delay(500);
|
||||
|
||||
setOutput(0, GAIN_1, 1, 0);
|
||||
setOutput(1, GAIN_1, 1, blue_dac);
|
||||
memset (moving_average_array, 0, 10);
|
||||
temp_counter = 0;
|
||||
intensity_storage = 0;
|
||||
for (int i = 0; i < blue_samples + blue_stable_time; i += 1)
|
||||
{{
|
||||
|
||||
int16_t val_0 = ADS.readADC(0);
|
||||
int16_t val_1 = ADS.readADC(1);
|
||||
int16_t val_2 = ADS.readADC(2);
|
||||
int16_t val_3 = ADS.readADC(3);
|
||||
moving_average_array[i % 10] = val_1;
|
||||
//Serial.println(moving_average_array[0]);
|
||||
for (int j = 0; j < 10; j++)
|
||||
{{
|
||||
sorting_array[j] = moving_average_array[j];
|
||||
}}
|
||||
//Serial.println(sorting_array[0]);
|
||||
if (i >= blue_stable_time)
|
||||
{{
|
||||
for (int j = 0; j < 6; j++)
|
||||
{{
|
||||
for (int k = 0; k < (9 - j); k++)
|
||||
{{
|
||||
if (sorting_array[k] > sorting_array[k + 1])
|
||||
{{
|
||||
temp_sort = sorting_array[k];
|
||||
sorting_array[k] = sorting_array[k + 1];
|
||||
sorting_array[k + 1] = temp_sort;
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
moving_average = (sorting_array[4] / 2) + (sorting_array[5] / 2);
|
||||
if ((val_1 > (moving_average * 0.9)) and (val_1 < (moving_average * 1.1)))
|
||||
{{
|
||||
intensity_storage += val_1;
|
||||
|
||||
temp_counter++;
|
||||
}}
|
||||
}}
|
||||
if (intensity_display == 1)
|
||||
{{
|
||||
// Serial.print("DAC_value : "); Serial.print(i); Serial.print('\t'); Serial.print('\t'); Serial.print("Blue_Resistor_drop: "); Serial.print(val_3);
|
||||
// Serial.print('\t'); Serial.print('\t'); Serial.print("PD_output: "); Serial.print(val_1); Serial.print('\t'); Serial.print('\t'); Serial.print("PD_2X_output: "); Serial.println(val_0);
|
||||
}}
|
||||
if (plotter == 1)
|
||||
{{
|
||||
Serial.println(val_1);
|
||||
}}
|
||||
//delay(200);
|
||||
}}
|
||||
avg_blueB1 = intensity_storage / temp_counter;
|
||||
|
||||
setOutput(0, GAIN_1, 1, 0);
|
||||
setOutput(1, GAIN_1, 1, 0);
|
||||
delay (100);
|
||||
|
||||
setOutput(1, GAIN_1, 1, 0);
|
||||
setOutput(0, GAIN_1, 1, green_dac);
|
||||
memset (moving_average_array, 0, 10);
|
||||
temp_counter = 0;
|
||||
intensity_storage = 0;
|
||||
f = ADS.toVoltage(1); // voltage factor
|
||||
for (int i = 0; i < green_samples + green_stable_time; i += 1)
|
||||
{{
|
||||
|
||||
int16_t val_0 = ADS.readADC(0);
|
||||
int16_t val_1 = ADS.readADC(1);
|
||||
int16_t val_2 = ADS.readADC(2);
|
||||
int16_t val_3 = ADS.readADC(3);
|
||||
moving_average_array[i % 10] = val_1;
|
||||
for (int j = 0; j < 10; j++)
|
||||
{{
|
||||
sorting_array[j] = moving_average_array[j];
|
||||
}}
|
||||
if (i >= green_stable_time)
|
||||
{{
|
||||
for (int j = 0; j < 6; j++)
|
||||
{{
|
||||
for (int k = 0; k < (9 - j); k++)
|
||||
{{
|
||||
if (sorting_array[k] > sorting_array[k + 1])
|
||||
{{
|
||||
temp_sort = sorting_array[k];
|
||||
sorting_array[k] = sorting_array[k + 1];
|
||||
sorting_array[k + 1] = temp_sort;
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
moving_average = (sorting_array[4] / 2) + (sorting_array[5] / 2);
|
||||
if ((val_1 > (moving_average * 0.9)) and (val_1 < (moving_average * 1.1)))
|
||||
{{
|
||||
intensity_storage += val_1;
|
||||
temp_counter++;
|
||||
}}
|
||||
}}
|
||||
|
||||
if (intensity_display == 1)
|
||||
{{
|
||||
// Serial.print("DAC_value : "); Serial.print(i); Serial.print('\t'); Serial.print('\t'); Serial.print("Green_Resistor_drop: "); Serial.print(val_2);
|
||||
// Serial.print('\t'); Serial.print('\t'); Serial.print("PD_output: "); Serial.print(val_1); Serial.print('\t'); Serial.print('\t'); Serial.print("PD_2X_output: "); Serial.println(val_0);
|
||||
}}
|
||||
if (plotter == 1)
|
||||
{{
|
||||
Serial.println(val_1);
|
||||
}}
|
||||
//delay(200);
|
||||
}}
|
||||
avg_greenB2 = intensity_storage / temp_counter;
|
||||
delay(500);
|
||||
|
||||
setOutput(0, GAIN_1, 1, 0);
|
||||
setOutput(1, GAIN_1, 1, blue_dac);
|
||||
memset (moving_average_array, 0, 10);
|
||||
temp_counter = 0;
|
||||
intensity_storage = 0;
|
||||
for (int i = 0; i < blue_samples + blue_stable_time; i += 1)
|
||||
{{
|
||||
|
||||
int16_t val_0 = ADS.readADC(0);
|
||||
int16_t val_1 = ADS.readADC(1);
|
||||
int16_t val_2 = ADS.readADC(2);
|
||||
int16_t val_3 = ADS.readADC(3);
|
||||
moving_average_array[i % 10] = val_1;
|
||||
//Serial.println(moving_average_array[0]);
|
||||
for (int j = 0; j < 10; j++)
|
||||
{{
|
||||
sorting_array[j] = moving_average_array[j];
|
||||
}}
|
||||
//Serial.println(sorting_array[0]);
|
||||
if (i >= blue_stable_time)
|
||||
{{
|
||||
for (int j = 0; j < 6; j++)
|
||||
{{
|
||||
for (int k = 0; k < (9 - j); k++)
|
||||
{{
|
||||
if (sorting_array[k] > sorting_array[k + 1])
|
||||
{{
|
||||
temp_sort = sorting_array[k];
|
||||
sorting_array[k] = sorting_array[k + 1];
|
||||
sorting_array[k + 1] = temp_sort;
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
moving_average = (sorting_array[4] / 2) + (sorting_array[5] / 2);
|
||||
if ((val_1 > (moving_average * 0.9)) and (val_1 < (moving_average * 1.1)))
|
||||
{{
|
||||
intensity_storage += val_1;
|
||||
|
||||
temp_counter++;
|
||||
}}
|
||||
}}
|
||||
if (intensity_display == 1)
|
||||
{{
|
||||
// Serial.print("DAC_value : "); Serial.print(i); Serial.print('\t'); Serial.print('\t'); Serial.print("Blue_Resistor_drop: "); Serial.print(val_3);
|
||||
// Serial.print('\t'); Serial.print('\t'); Serial.print("PD_output: "); Serial.print(val_1); Serial.print('\t'); Serial.print('\t'); Serial.print("PD_2X_output: "); Serial.println(val_0);
|
||||
}}
|
||||
if (plotter == 1)
|
||||
{{
|
||||
Serial.println(val_1);
|
||||
}}
|
||||
//delay(200);
|
||||
}}
|
||||
avg_blueB2 = intensity_storage / temp_counter;
|
||||
|
||||
setOutput(0, GAIN_1, 1, 0);
|
||||
setOutput(1, GAIN_1, 1, 0);
|
||||
delay (100);
|
||||
setOutput(1, GAIN_1, 1, 0);
|
||||
setOutput(0, GAIN_1, 1, green_dac);
|
||||
memset (moving_average_array, 0, 10);
|
||||
temp_counter = 0;
|
||||
intensity_storage = 0;
|
||||
f = ADS.toVoltage(1); // voltage factor
|
||||
for (int i = 0; i < green_samples + green_stable_time; i += 1)
|
||||
{{
|
||||
|
||||
int16_t val_0 = ADS.readADC(0);
|
||||
int16_t val_1 = ADS.readADC(1);
|
||||
int16_t val_2 = ADS.readADC(2);
|
||||
int16_t val_3 = ADS.readADC(3);
|
||||
moving_average_array[i % 10] = val_1;
|
||||
for (int j = 0; j < 10; j++)
|
||||
{{
|
||||
sorting_array[j] = moving_average_array[j];
|
||||
}}
|
||||
if (i >= green_stable_time)
|
||||
{{
|
||||
for (int j = 0; j < 6; j++)
|
||||
{{
|
||||
for (int k = 0; k < (9 - j); k++)
|
||||
{{
|
||||
if (sorting_array[k] > sorting_array[k + 1])
|
||||
{{
|
||||
temp_sort = sorting_array[k];
|
||||
sorting_array[k] = sorting_array[k + 1];
|
||||
sorting_array[k + 1] = temp_sort;
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
moving_average = (sorting_array[4] / 2) + (sorting_array[5] / 2);
|
||||
if ((val_1 > (moving_average * 0.9)) and (val_1 < (moving_average * 1.1)))
|
||||
{{
|
||||
intensity_storage += val_1;
|
||||
temp_counter++;
|
||||
}}
|
||||
}}
|
||||
|
||||
if (intensity_display == 1)
|
||||
{{
|
||||
// Serial.print("DAC_value : "); Serial.print(i); Serial.print('\t'); Serial.print('\t'); Serial.print("Green_Resistor_drop: "); Serial.print(val_2);
|
||||
// Serial.print('\t'); Serial.print('\t'); Serial.print("PD_output: "); Serial.print(val_1); Serial.print('\t'); Serial.print('\t'); Serial.print("PD_2X_output: "); Serial.println(val_0);
|
||||
}}
|
||||
if (plotter == 1)
|
||||
{{
|
||||
Serial.println(val_1);
|
||||
}}
|
||||
//delay(200);
|
||||
}}
|
||||
avg_greenB3 = intensity_storage / temp_counter;
|
||||
delay(500);
|
||||
|
||||
setOutput(0, GAIN_1, 1, 0);
|
||||
setOutput(1, GAIN_1, 1, blue_dac);
|
||||
memset (moving_average_array, 0, 10);
|
||||
temp_counter = 0;
|
||||
intensity_storage = 0;
|
||||
for (int i = 0; i < blue_samples + blue_stable_time; i += 1)
|
||||
{{
|
||||
|
||||
int16_t val_0 = ADS.readADC(0);
|
||||
int16_t val_1 = ADS.readADC(1);
|
||||
int16_t val_2 = ADS.readADC(2);
|
||||
int16_t val_3 = ADS.readADC(3);
|
||||
moving_average_array[i % 10] = val_1;
|
||||
//Serial.println(moving_average_array[0]);
|
||||
for (int j = 0; j < 10; j++)
|
||||
{{
|
||||
sorting_array[j] = moving_average_array[j];
|
||||
}}
|
||||
//Serial.println(sorting_array[0]);
|
||||
if (i >= blue_stable_time)
|
||||
{{
|
||||
for (int j = 0; j < 6; j++)
|
||||
{{
|
||||
for (int k = 0; k < (9 - j); k++)
|
||||
{{
|
||||
if (sorting_array[k] > sorting_array[k + 1])
|
||||
{{
|
||||
temp_sort = sorting_array[k];
|
||||
sorting_array[k] = sorting_array[k + 1];
|
||||
sorting_array[k + 1] = temp_sort;
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
moving_average = (sorting_array[4] / 2) + (sorting_array[5] / 2);
|
||||
if ((val_1 > (moving_average * 0.9)) and (val_1 < (moving_average * 1.1)))
|
||||
{{
|
||||
intensity_storage += val_1;
|
||||
|
||||
temp_counter++;
|
||||
}}
|
||||
}}
|
||||
if (intensity_display == 1)
|
||||
{{
|
||||
// Serial.print("DAC_value : "); Serial.print(i); Serial.print('\t'); Serial.print('\t'); Serial.print("Blue_Resistor_drop: "); Serial.print(val_3);
|
||||
// Serial.print('\t'); Serial.print('\t'); Serial.print("PD_output: "); Serial.print(val_1); Serial.print('\t'); Serial.print('\t'); Serial.print("PD_2X_output: "); Serial.println(val_0);
|
||||
}}
|
||||
if (plotter == 1)
|
||||
{{
|
||||
Serial.println(val_1);
|
||||
}}
|
||||
//delay(200);
|
||||
}}
|
||||
avg_blueB3 = intensity_storage / temp_counter;
|
||||
delay(100);
|
||||
setOutput(0, GAIN_1, 1, 0);
|
||||
setOutput(1, GAIN_1, 1, 0);
|
||||
avg_blueB = (avg_blueB1 + avg_blueB2 + avg_blueB3) / 3;
|
||||
avg_greenB = (avg_greenB1 + avg_greenB2 + avg_greenB3) / 3;
|
||||
Serial.print("ok Green B Intensity: "); Serial.println(avg_greenB);
|
||||
Serial.print("ok Blue B Intensity: "); Serial.println(avg_blueB);
|
||||
Serial.println("#Buffer Completed");
|
||||
Serial.println("#Place sample");
|
||||
delay(200);
|
||||
|
||||
}}
|
||||
void startTask2() {{
|
||||
Serial.println("#Sample started");
|
||||
setOutput(1, GAIN_1, 1, 0);
|
||||
setOutput(0, GAIN_1, 1, green_dac);
|
||||
memset (moving_average_array, 0, 10);
|
||||
temp_counter = 0;
|
||||
intensity_storage = 0;
|
||||
float f = ADS.toVoltage(1); // voltage factor
|
||||
for (int i = 0; i < green_samples + green_stable_time; i += 1)
|
||||
{{
|
||||
|
||||
int16_t val_0 = ADS.readADC(0);
|
||||
int16_t val_1 = ADS.readADC(1);
|
||||
int16_t val_2 = ADS.readADC(2);
|
||||
int16_t val_3 = ADS.readADC(3);
|
||||
moving_average_array[i % 10] = val_1;
|
||||
for (int j = 0; j < 10; j++)
|
||||
{{
|
||||
sorting_array[j] = moving_average_array[j];
|
||||
}}
|
||||
if (i >= green_stable_time)
|
||||
{{
|
||||
for (int j = 0; j < 6; j++)
|
||||
{{
|
||||
for (int k = 0; k < (9 - j); k++)
|
||||
{{
|
||||
if (sorting_array[k] > sorting_array[k + 1])
|
||||
{{
|
||||
temp_sort = sorting_array[k];
|
||||
sorting_array[k] = sorting_array[k + 1];
|
||||
sorting_array[k + 1] = temp_sort;
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
moving_average = (sorting_array[4] / 2) + (sorting_array[5] / 2);
|
||||
if ((val_1 > (moving_average * 0.9)) and (val_1 < (moving_average * 1.1)))
|
||||
{{
|
||||
intensity_storage += val_1;
|
||||
temp_counter++;
|
||||
}}
|
||||
}}
|
||||
|
||||
if (intensity_display == 1)
|
||||
{{
|
||||
// Serial.print("DAC_value : "); Serial.print(i); Serial.print('\t'); Serial.print('\t'); Serial.print("Green_Resistor_drop: "); Serial.print(val_2);
|
||||
// Serial.print('\t'); Serial.print('\t'); Serial.print("PD_output: "); Serial.print(val_1); Serial.print('\t'); Serial.print('\t'); Serial.print("PD_2X_output: "); Serial.println(val_0);
|
||||
}}
|
||||
if (plotter == 1)
|
||||
{{
|
||||
Serial.println(val_1);
|
||||
}}
|
||||
//delay(200);
|
||||
}}
|
||||
avg_greenS1 = intensity_storage / temp_counter;
|
||||
delay(500);
|
||||
|
||||
setOutput(0, GAIN_1, 1, 0);
|
||||
setOutput(1, GAIN_1, 1, blue_dac);
|
||||
memset (moving_average_array, 0, 10);
|
||||
temp_counter = 0;
|
||||
intensity_storage = 0;
|
||||
for (int i = 0; i < blue_samples + blue_stable_time; i += 1)
|
||||
{{
|
||||
|
||||
int16_t val_0 = ADS.readADC(0);
|
||||
int16_t val_1 = ADS.readADC(1);
|
||||
int16_t val_2 = ADS.readADC(2);
|
||||
int16_t val_3 = ADS.readADC(3);
|
||||
moving_average_array[i % 10] = val_1;
|
||||
//Serial.println(moving_average_array[0]);
|
||||
for (int j = 0; j < 10; j++)
|
||||
{{
|
||||
sorting_array[j] = moving_average_array[j];
|
||||
}}
|
||||
//Serial.println(sorting_array[0]);
|
||||
if (i >= blue_stable_time)
|
||||
{{
|
||||
for (int j = 0; j < 6; j++)
|
||||
{{
|
||||
for (int k = 0; k < (9 - j); k++)
|
||||
{{
|
||||
if (sorting_array[k] > sorting_array[k + 1])
|
||||
{{
|
||||
temp_sort = sorting_array[k];
|
||||
sorting_array[k] = sorting_array[k + 1];
|
||||
sorting_array[k + 1] = temp_sort;
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
moving_average = (sorting_array[4] / 2) + (sorting_array[5] / 2);
|
||||
if ((val_1 > (moving_average * 0.9)) and (val_1 < (moving_average * 1.1)))
|
||||
{{
|
||||
intensity_storage += val_1;
|
||||
|
||||
temp_counter++;
|
||||
}}
|
||||
}}
|
||||
if (intensity_display == 1)
|
||||
{{
|
||||
// Serial.print("DAC_value : "); Serial.print(i); Serial.print('\t'); Serial.print('\t'); Serial.print("Blue_Resistor_drop: "); Serial.print(val_3);
|
||||
// Serial.print('\t'); Serial.print('\t'); Serial.print("PD_output: "); Serial.print(val_1); Serial.print('\t'); Serial.print('\t'); Serial.print("PD_2X_output: "); Serial.println(val_0);
|
||||
}}
|
||||
if (plotter == 1)
|
||||
{{
|
||||
Serial.println(val_1);
|
||||
}}
|
||||
//delay(200);
|
||||
}}
|
||||
avg_blueS1 = intensity_storage / temp_counter;
|
||||
|
||||
setOutput(0, GAIN_1, 1, 0);
|
||||
setOutput(1, GAIN_1, 1, 0);
|
||||
delay(100);
|
||||
setOutput(1, GAIN_1, 1, 0);
|
||||
setOutput(0, GAIN_1, 1, green_dac);
|
||||
memset (moving_average_array, 0, 10);
|
||||
temp_counter = 0;
|
||||
intensity_storage = 0;
|
||||
f = ADS.toVoltage(1); // voltage factor
|
||||
for (int i = 0; i < green_samples + green_stable_time; i += 1)
|
||||
{{
|
||||
|
||||
int16_t val_0 = ADS.readADC(0);
|
||||
int16_t val_1 = ADS.readADC(1);
|
||||
int16_t val_2 = ADS.readADC(2);
|
||||
int16_t val_3 = ADS.readADC(3);
|
||||
moving_average_array[i % 10] = val_1;
|
||||
for (int j = 0; j < 10; j++)
|
||||
{{
|
||||
sorting_array[j] = moving_average_array[j];
|
||||
}}
|
||||
if (i >= green_stable_time)
|
||||
{{
|
||||
for (int j = 0; j < 6; j++)
|
||||
{{
|
||||
for (int k = 0; k < (9 - j); k++)
|
||||
{{
|
||||
if (sorting_array[k] > sorting_array[k + 1])
|
||||
{{
|
||||
temp_sort = sorting_array[k];
|
||||
sorting_array[k] = sorting_array[k + 1];
|
||||
sorting_array[k + 1] = temp_sort;
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
moving_average = (sorting_array[4] / 2) + (sorting_array[5] / 2);
|
||||
if ((val_1 > (moving_average * 0.9)) and (val_1 < (moving_average * 1.1)))
|
||||
{{
|
||||
intensity_storage += val_1;
|
||||
temp_counter++;
|
||||
}}
|
||||
}}
|
||||
|
||||
if (intensity_display == 1)
|
||||
{{
|
||||
// Serial.print("DAC_value : "); Serial.print(i); Serial.print('\t'); Serial.print('\t'); Serial.print("Green_Resistor_drop: "); Serial.print(val_2);
|
||||
// Serial.print('\t'); Serial.print('\t'); Serial.print("PD_output: "); Serial.print(val_1); Serial.print('\t'); Serial.print('\t'); Serial.print("PD_2X_output: "); Serial.println(val_0);
|
||||
}}
|
||||
if (plotter == 1)
|
||||
{{
|
||||
Serial.println(val_1);
|
||||
}}
|
||||
//delay(200);
|
||||
}}
|
||||
avg_greenS2 = intensity_storage / temp_counter;
|
||||
delay(500);
|
||||
|
||||
setOutput(0, GAIN_1, 1, 0);
|
||||
setOutput(1, GAIN_1, 1, blue_dac);
|
||||
memset (moving_average_array, 0, 10);
|
||||
temp_counter = 0;
|
||||
intensity_storage = 0;
|
||||
for (int i = 0; i < blue_samples + blue_stable_time; i += 1)
|
||||
{{
|
||||
|
||||
int16_t val_0 = ADS.readADC(0);
|
||||
int16_t val_1 = ADS.readADC(1);
|
||||
int16_t val_2 = ADS.readADC(2);
|
||||
int16_t val_3 = ADS.readADC(3);
|
||||
moving_average_array[i % 10] = val_1;
|
||||
//Serial.println(moving_average_array[0]);
|
||||
for (int j = 0; j < 10; j++)
|
||||
{{
|
||||
sorting_array[j] = moving_average_array[j];
|
||||
}}
|
||||
//Serial.println(sorting_array[0]);
|
||||
if (i >= blue_stable_time)
|
||||
{{
|
||||
for (int j = 0; j < 6; j++)
|
||||
{{
|
||||
for (int k = 0; k < (9 - j); k++)
|
||||
{{
|
||||
if (sorting_array[k] > sorting_array[k + 1])
|
||||
{{
|
||||
temp_sort = sorting_array[k];
|
||||
sorting_array[k] = sorting_array[k + 1];
|
||||
sorting_array[k + 1] = temp_sort;
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
moving_average = (sorting_array[4] / 2) + (sorting_array[5] / 2);
|
||||
if ((val_1 > (moving_average * 0.9)) and (val_1 < (moving_average * 1.1)))
|
||||
{{
|
||||
intensity_storage += val_1;
|
||||
|
||||
temp_counter++;
|
||||
}}
|
||||
}}
|
||||
if (intensity_display == 1)
|
||||
{{
|
||||
// Serial.print("DAC_value : "); Serial.print(i); Serial.print('\t'); Serial.print('\t'); Serial.print("Blue_Resistor_drop: "); Serial.print(val_3);
|
||||
// Serial.print('\t'); Serial.print('\t'); Serial.print("PD_output: "); Serial.print(val_1); Serial.print('\t'); Serial.print('\t'); Serial.print("PD_2X_output: "); Serial.println(val_0);
|
||||
}}
|
||||
if (plotter == 1)
|
||||
{{
|
||||
Serial.println(val_1);
|
||||
}}
|
||||
//delay(200);
|
||||
}}
|
||||
avg_blueS2 = intensity_storage / temp_counter;
|
||||
|
||||
setOutput(0, GAIN_1, 1, 0);
|
||||
setOutput(1, GAIN_1, 1, 0);
|
||||
delay(100);
|
||||
setOutput(1, GAIN_1, 1, 0);
|
||||
setOutput(0, GAIN_1, 1, green_dac);
|
||||
memset (moving_average_array, 0, 10);
|
||||
temp_counter = 0;
|
||||
intensity_storage = 0;
|
||||
f = ADS.toVoltage(1); // voltage factor
|
||||
for (int i = 0; i < green_samples + green_stable_time; i += 1)
|
||||
{{
|
||||
|
||||
int16_t val_0 = ADS.readADC(0);
|
||||
int16_t val_1 = ADS.readADC(1);
|
||||
int16_t val_2 = ADS.readADC(2);
|
||||
int16_t val_3 = ADS.readADC(3);
|
||||
moving_average_array[i % 10] = val_1;
|
||||
for (int j = 0; j < 10; j++)
|
||||
{{
|
||||
sorting_array[j] = moving_average_array[j];
|
||||
}}
|
||||
if (i >= green_stable_time)
|
||||
{{
|
||||
for (int j = 0; j < 6; j++)
|
||||
{{
|
||||
for (int k = 0; k < (9 - j); k++)
|
||||
{{
|
||||
if (sorting_array[k] > sorting_array[k + 1])
|
||||
{{
|
||||
temp_sort = sorting_array[k];
|
||||
sorting_array[k] = sorting_array[k + 1];
|
||||
sorting_array[k + 1] = temp_sort;
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
moving_average = (sorting_array[4] / 2) + (sorting_array[5] / 2);
|
||||
if ((val_1 > (moving_average * 0.9)) and (val_1 < (moving_average * 1.1)))
|
||||
{{
|
||||
intensity_storage += val_1;
|
||||
temp_counter++;
|
||||
}}
|
||||
}}
|
||||
|
||||
if (intensity_display == 1)
|
||||
{{
|
||||
// Serial.print("DAC_value : "); Serial.print(i); Serial.print('\t'); Serial.print('\t'); Serial.print("Green_Resistor_drop: "); Serial.print(val_2);
|
||||
// Serial.print('\t'); Serial.print('\t'); Serial.print("PD_output: "); Serial.print(val_1); Serial.print('\t'); Serial.print('\t'); Serial.print("PD_2X_output: "); Serial.println(val_0);
|
||||
}}
|
||||
if (plotter == 1)
|
||||
{{
|
||||
Serial.println(val_1);
|
||||
}}
|
||||
//delay(200);
|
||||
}}
|
||||
avg_greenS3 = intensity_storage / temp_counter;
|
||||
delay(500);
|
||||
|
||||
setOutput(0, GAIN_1, 1, 0);
|
||||
setOutput(1, GAIN_1, 1, blue_dac);
|
||||
memset (moving_average_array, 0, 10);
|
||||
temp_counter = 0;
|
||||
intensity_storage = 0;
|
||||
for (int i = 0; i < blue_samples + blue_stable_time; i += 1)
|
||||
{{
|
||||
|
||||
int16_t val_0 = ADS.readADC(0);
|
||||
int16_t val_1 = ADS.readADC(1);
|
||||
int16_t val_2 = ADS.readADC(2);
|
||||
int16_t val_3 = ADS.readADC(3);
|
||||
moving_average_array[i % 10] = val_1;
|
||||
//Serial.println(moving_average_array[0]);
|
||||
for (int j = 0; j < 10; j++)
|
||||
{{
|
||||
sorting_array[j] = moving_average_array[j];
|
||||
}}
|
||||
//Serial.println(sorting_array[0]);
|
||||
if (i >= blue_stable_time)
|
||||
{{
|
||||
for (int j = 0; j < 6; j++)
|
||||
{{
|
||||
for (int k = 0; k < (9 - j); k++)
|
||||
{{
|
||||
if (sorting_array[k] > sorting_array[k + 1])
|
||||
{{
|
||||
temp_sort = sorting_array[k];
|
||||
sorting_array[k] = sorting_array[k + 1];
|
||||
sorting_array[k + 1] = temp_sort;
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
moving_average = (sorting_array[4] / 2) + (sorting_array[5] / 2);
|
||||
if ((val_1 > (moving_average * 0.9)) and (val_1 < (moving_average * 1.1)))
|
||||
{{
|
||||
intensity_storage += val_1;
|
||||
|
||||
temp_counter++;
|
||||
}}
|
||||
}}
|
||||
if (intensity_display == 1)
|
||||
{{
|
||||
// Serial.print("DAC_value : "); Serial.print(i); Serial.print('\t'); Serial.print('\t'); Serial.print("Blue_Resistor_drop: "); Serial.print(val_3);
|
||||
// Serial.print('\t'); Serial.print('\t'); Serial.print("PD_output: "); Serial.print(val_1); Serial.print('\t'); Serial.print('\t'); Serial.print("PD_2X_output: "); Serial.println(val_0);
|
||||
}}
|
||||
if (plotter == 1)
|
||||
{{
|
||||
Serial.println(val_1);
|
||||
}}
|
||||
//delay(200);
|
||||
}}
|
||||
avg_blueS3 = intensity_storage / temp_counter;
|
||||
|
||||
setOutput(0, GAIN_1, 1, 0);
|
||||
setOutput(1, GAIN_1, 1, 0);
|
||||
avg_greenS = (avg_greenS1 + avg_greenS2 + avg_greenS3) / 3;
|
||||
avg_blueS = (avg_blueS1 + avg_blueS2 + avg_blueS3) / 3;
|
||||
Serial.print("ok Green Intensity: "); Serial.println(avg_greenS);
|
||||
Serial.print("ok Blue Intensity: "); Serial.println(avg_blueS);
|
||||
Serial.println("#Sample Completed");
|
||||
delay(300);
|
||||
}}
|
||||
51
README.md
Normal file
51
README.md
Normal file
@@ -0,0 +1,51 @@
|
||||
### error -> FileNotFoundError: [Errno 2] No such file or directory: 'arduino-cli'
|
||||
|
||||
install arduino-cli
|
||||
|
||||
https://arduino.github.io/arduino-cli/0.33/installation/
|
||||
|
||||
|
||||
### prerequisites
|
||||
|
||||
arduino-cli
|
||||
|
||||
python
|
||||
|
||||
pyinstaller
|
||||
|
||||
### install
|
||||
|
||||
pip install -r requirements.txt
|
||||
|
||||
### run
|
||||
|
||||
python hemocube.py
|
||||
|
||||
|
||||
### build
|
||||
|
||||
pyinstaller --noconfirm --noconsole -i "smi.ico" --windowed --clean hemocube.py
|
||||
|
||||
### build error
|
||||
|
||||
>fqdn error: replace the check with nano fqdn explictly.
|
||||
In Sketch.py of everywhereml/arduino replace line 167 and 228 with:
|
||||
|
||||
|
||||
self.fqbn = 'arduino:avr:nano:cpu=atmega328old'`
|
||||
|
||||
|
||||
>arduino library not found: manually copy all required libary in the same folder
|
||||
|
||||
>Error during build: Platform 'arduino:avr' not found: platform not installed
|
||||
Try running `arduino-cli core install arduino:avr`
|
||||
|
||||
### installation after release
|
||||
|
||||
> first install the `arduino-cli.exe` and add it to path. verify it using terminal/cmd.
|
||||
|
||||
> then, connect the device and run the app exe. the port selection should have show an entry
|
||||
|
||||
> enter the values and select the port to upload the new dac values for QC
|
||||
|
||||
> the status will be show in the logging box. device will be ready, only if the upload sccuess is shown.
|
||||
11
Sample.ino
Normal file
11
Sample.ino
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
void setup() {{
|
||||
// put your setup code here, to run once:
|
||||
Serial.begin(115200);
|
||||
}}
|
||||
|
||||
void loop() {{
|
||||
// put your main code here, to run repeatedly:
|
||||
|
||||
|
||||
}}
|
||||
69
flash.py
Normal file
69
flash.py
Normal file
@@ -0,0 +1,69 @@
|
||||
from everywhereml.arduino import Sketch, Ino, H
|
||||
|
||||
"""
|
||||
Create a sketch object.
|
||||
A sketch is defined by:
|
||||
- a name (required)
|
||||
- a folder (optional)
|
||||
|
||||
If you leave the folder empty, the current working directory will be used.
|
||||
You can use the special name ':system:' to use the default Arduino sketches folder
|
||||
(as reported by the command `arduino-cli config dump`)
|
||||
"""
|
||||
|
||||
sketch = Sketch(name="PyDuino", folder=":system:")
|
||||
|
||||
"""
|
||||
Then you can add files to the project (either the .ino main file or
|
||||
C++ header files)
|
||||
"""
|
||||
sketch += Ino("""
|
||||
#include "hello.h"
|
||||
#include <SPI.h>
|
||||
#include <Wire.h>
|
||||
#include <math.h>
|
||||
#include "ADS1X15.h"
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
hello();
|
||||
delay(1000);
|
||||
}
|
||||
""")
|
||||
|
||||
sketch += H("hello.h", """
|
||||
void hello() {
|
||||
Serial.println("hello smi8");
|
||||
}
|
||||
""")
|
||||
|
||||
"""
|
||||
Compile sketch for Arduino Nano 33 BLE board.
|
||||
The board you target must appear in the `arduino-cli board listall` command.
|
||||
If you know the FQBN (Fully Qualified Board Name), you can use that too.
|
||||
"""
|
||||
if sketch.compile(board='arduino:avr:nano:cpu=atmega328old').is_successful:
|
||||
print('Log', sketch.output)
|
||||
print('Sketch stats', sketch.stats)
|
||||
else:
|
||||
print('ERROR', sketch.output)
|
||||
|
||||
|
||||
"""
|
||||
You can specify the exact port
|
||||
"""
|
||||
# sketch.upload(port='/dev/cu.usbmodem14201')
|
||||
|
||||
sketch.upload(port='/dev/cu.usbserial-1420')
|
||||
|
||||
# """
|
||||
# Or even part of it.
|
||||
# The library will look for the best match.
|
||||
# """
|
||||
# sketch.upload(port='ttyUSB')
|
||||
# sketch.upload(port='/dev/cu.usbserial-1420') #/dev/cu.usbmodem
|
||||
|
||||
print('hi', sketch.output)
|
||||
1032
hemocube.py
Normal file
1032
hemocube.py
Normal file
File diff suppressed because it is too large
Load Diff
50
hemocube.spec
Normal file
50
hemocube.spec
Normal file
@@ -0,0 +1,50 @@
|
||||
# -*- mode: python ; coding: utf-8 -*-
|
||||
|
||||
|
||||
block_cipher = None
|
||||
|
||||
|
||||
a = Analysis(
|
||||
['hemocube.py'],
|
||||
pathex=[],
|
||||
binaries=[],
|
||||
datas=[],
|
||||
hiddenimports=[],
|
||||
hookspath=[],
|
||||
hooksconfig={},
|
||||
runtime_hooks=[],
|
||||
excludes=[],
|
||||
win_no_prefer_redirects=False,
|
||||
win_private_assemblies=False,
|
||||
cipher=block_cipher,
|
||||
noarchive=False,
|
||||
)
|
||||
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
|
||||
|
||||
exe = EXE(
|
||||
pyz,
|
||||
a.scripts,
|
||||
[],
|
||||
exclude_binaries=True,
|
||||
name='hemocube',
|
||||
debug=False,
|
||||
bootloader_ignore_signals=False,
|
||||
strip=False,
|
||||
upx=True,
|
||||
console=True,
|
||||
disable_windowed_traceback=False,
|
||||
argv_emulation=False,
|
||||
target_arch=None,
|
||||
codesign_identity=None,
|
||||
entitlements_file=None,
|
||||
)
|
||||
coll = COLLECT(
|
||||
exe,
|
||||
a.binaries,
|
||||
a.zipfiles,
|
||||
a.datas,
|
||||
strip=False,
|
||||
upx=True,
|
||||
upx_exclude=[],
|
||||
name='hemocube',
|
||||
)
|
||||
56
requirements.txt
Normal file
56
requirements.txt
Normal file
@@ -0,0 +1,56 @@
|
||||
altgraph==0.17.3
|
||||
cached-property==1.5.2
|
||||
certifi==2023.5.7
|
||||
charset-normalizer==3.2.0
|
||||
contourpy==1.1.0
|
||||
cycler==0.11.0
|
||||
everywhereml==0.2.21
|
||||
fonttools==4.41.0
|
||||
hexdump==3.3
|
||||
idna==3.4
|
||||
imageio==2.31.1
|
||||
Jinja2==3.1.2
|
||||
jinja2-workarounds==0.1.0
|
||||
joblib==1.3.1
|
||||
kiwisolver==1.4.4
|
||||
lazy_loader==0.3
|
||||
llvmlite==0.40.1
|
||||
macholib==1.16.2
|
||||
MarkupSafe==2.1.3
|
||||
matplotlib==3.7.2
|
||||
networkx==3.1
|
||||
numba==0.57.1
|
||||
numpy==1.24.4
|
||||
packaging==23.1
|
||||
pandas==2.0.3
|
||||
pefile==2023.2.7
|
||||
Pillow==10.0.0
|
||||
pyinstaller==5.13.0
|
||||
pyinstaller-hooks-contrib==2023.5
|
||||
pynndescent==0.5.10
|
||||
pyparsing==3.0.9
|
||||
PyQt5==5.15.9
|
||||
PyQt5-Qt5==5.15.2
|
||||
PyQt5-sip==12.12.1
|
||||
PyQt6==6.5.1
|
||||
PyQt6-Qt6==6.5.1
|
||||
PyQt6-sip==13.5.1
|
||||
pyserial==3.5
|
||||
python-dateutil==2.8.2
|
||||
python-slugify==8.0.1
|
||||
pytz==2023.3
|
||||
pyudev==0.24.1
|
||||
PyWavelets==1.4.1
|
||||
requests==2.31.0
|
||||
scikit-image==0.21.0
|
||||
scikit-learn==1.3.0
|
||||
scipy==1.11.1
|
||||
seaborn==0.12.2
|
||||
six==1.16.0
|
||||
text-unidecode==1.3
|
||||
threadpoolctl==3.2.0
|
||||
tifffile==2023.7.10
|
||||
tqdm==4.65.0
|
||||
tzdata==2023.3
|
||||
umap-learn==0.5.3
|
||||
urllib3==2.0.3
|
||||
Reference in New Issue
Block a user