Skip to content
Snippets Groups Projects
Commit 8c737a2c authored by Karol Hennessy's avatar Karol Hennessy
Browse files

First version for lab testing based on Xavier's state diagram

parent d33e4ba6
Branches
No related merge requests found
......@@ -8,7 +8,27 @@
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:uno]
platform = atmelavr
board = uno
; [env:uno]
; platform = atmelavr
; board = uno
; framework = arduino
; [env:featheresp32]
; platform = espressif32
; framework = arduino
; board = featheresp32
; [env:mkrwifi1010]
; platform = atmelsam
; framework = arduino
; board = mkrwifi1010
[env:mkrvidor4000]
platform = atmelsam
framework = arduino
board = mkrvidor4000
; [env:nodemcu-32s]
; platform = espressif32
; framework = arduino
; board = nodemcu-32s
\ No newline at end of file
// Arduino MKR 1010 Wifi
// pwm pins
const int pin_valve_in = 2;
const int pin_valve_out = 3;
const int pin_valve_scavenge = 4;
const int pin_valve_purge = 5;
// adcs
const int pin_p_supply = A0;
const int pin_p_regulated = A1;
const int pin_p_buffer = A2;
const int pin_p_inhale = A3;
const int pin_p_patient = A4;
const int pin_temp = A5;
// leds
const int pin_led_0 = 6;
const int pin_led_1 = 7;
const int pin_led_2 = 8;
// buzzer
const int pin_buzzer = 0;
// lcd
const int pin_lcd_rs = 9;
const int pin_lcd_en = 10;
const int pin_lcd_d4 = 11;
const int pin_lcd_d5 = 12;
const int pin_lcd_d6 = 13;
const int pin_lcd_d7 = 14;
// arduino MKR 4000 Vidor
// pwm pins
const int pin_valve_in = 2;
const int pin_valve_out = 3;
const int pin_valve_scavenge = 4;
const int pin_valve_purge = 5;
// adcs
const int pin_p_supply = A0;
const int pin_p_regulated = A1;
const int pin_p_buffer = A2;
const int pin_p_inhale = A3;
const int pin_p_patient = A4;
const int pin_temp = A5;
// leds
const int pin_led_0 = 6;
const int pin_led_1 = 7;
const int pin_led_2 = 8;
// buzzer
const int pin_buzzer = 0;
// lcd
const int pin_lcd_rs = 9;
const int pin_lcd_en = 10;
const int pin_lcd_d4 = 11;
const int pin_lcd_d5 = 12;
const int pin_lcd_d6 = 13;
const int pin_lcd_d7 = 14;
// button
const int pin_button = 1;
// arduino uno
#include <LiquidCrystal.h>
//#include <LiquidCrystal.h>
// pwm pins
const int pin_valve_in = 11;
const int pin_valve_out = 6;
const int pin_valve_scavenge = 5;
const int pin_valve_purge = 3;
// adcs
const int pin_p_supply = A0;
......@@ -11,6 +12,7 @@ const int pin_p_regulated = A1;
const int pin_p_buffer = A2;
const int pin_p_inhale = A3;
const int pin_p_patient = A4;
const int pin_temp = A5;
// leds
const int pin_led_0 = 0;
......@@ -21,7 +23,7 @@ const int pin_led_2 = 2;
const int pin_buzzer = 9;
// lcd
const int pin_lcd_rs = 3;
const int pin_lcd_rs = 13;
const int pin_lcd_en = 4;
const int pin_lcd_d4 = 7;
const int pin_lcd_d5 = 8;
......
#include <Wire.h> // I2C control
#include <LiquidCrystal_I2C.h> //LCD over I2C
#include <Wire.h> // I2C control
// #include <LiquidCrystal_I2C.h> //LCD over I2C
// ESP32 HUZZAH
// pwm pins
const int pin_valve_in = 13;
const int pin_valve_out = 12;
const int pin_valve_scavenge = 27;
const int pin_valve_purge = 21;
// adcs
const int pin_p_supply = A0;
......@@ -12,6 +13,7 @@ const int pin_p_regulated = A1;
const int pin_p_buffer = A2;
const int pin_p_inhale = A3;
const int pin_p_patient = A4;
const int pin_temp = A5;
// leds
const int pin_led_0 = 33;
......@@ -21,15 +23,15 @@ const int pin_led_2 = 32;
// buzzer
const int pin_buzzer = 14;
// lcd Not enough GPIOs, we can use I2C if needed NOTE: This code was not tested through I2C
// constants needed
// by default static DO NOT UNCOMMENT SDA AND SCL LINES
// const uint8_t SDA = 23;
// static const uint8_t SCL = 22;
// lcd Not enough GPIOs, we can use I2C if needed NOTE: This code was not tested through I2C
// constants needed
// by default static DO NOT UNCOMMENT SDA AND SCL LINES
// const uint8_t SDA = 23;
// static const uint8_t SCL = 22;
const int LCD_Address = 0x27;
const int LCD_columns = 16;
const int LCD_rows = 2;
const int LCD_Address = 0x27;
const int LCD_columns = 16;
const int LCD_rows = 2;
/* In case that we want to use the LCD we must
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
......
#include <Arduino.h>
#include <LiquidCrystal.h>
// arduino uno
// pwm pins
const int pin_valve_in = 11;
const int pin_valve_out = 6;
const int pin_valve_scavenge = 5;
// adcs
const int pin_p_supply = A0;
const int pin_p_regulated = A1;
const int pin_p_buffer = A2;
const int pin_p_inhale = A3;
const int pin_p_patient = A4;
// leds
const int pin_led_0 = 0;
const int pin_led_1 = 1;
const int pin_led_2 = 2;
// buzzer
const int pin_buzzer = 9;
// lcd
const int pin_lcd_rs = 3;
const int pin_lcd_en = 4;
const int pin_lcd_d4 = 7;
const int pin_lcd_d5 = 8;
const int pin_lcd_d6 = 10;
const int pin_lcd_d7 = 12;
//#include <LiquidCrystal.h>
#if defined(ARDUINO_FEATHER_ESP32)
#define BOARD "HUZZAH32"
#include <huzzah32_pinout.h>
#elif defined(ARDUINO_NodeMCU_32S)
#define BOARD "ESP32"
#include <nodemcu_32s_pinout.h>
#elif defined(ARDUINO_AVR_UNO)
#define BOARD "UNO"
#include <Arduino_uno_pinout.h>
#elif defined(ARDUINO_SAMD_MKRVIDOR4000)
#define BOARD "VIDOR"
#include <Arduino_MKR_4000_Vidor_pinout.h>
#elif defined(ARDUINO_SAMD_MKRWIFI1010)
#define BOARD "MKR1010"
#include <Arduino_MKR_1010_WIFI_pinout.h>
#endif
//LiquidCrystal lcd(pin_lcd_rs, pin_lcd_en, pin_lcd_d4, pin_lcd_d5, pin_lcd_d6, pin_lcd_d7);
// input params
enum hev_modes : byte
{
HEV_MODE_PS,
HEV_MODE_CPAP,
HEV_MODE_PRVC,
HEV_MODE_TEST
};
enum valve_states : bool
{
V_OPEN = LOW,
V_CLOSED = HIGH
};
LiquidCrystal lcd(pin_lcd_rs, pin_lcd_en, pin_lcd_d4, pin_lcd_d5, pin_lcd_d6, pin_lcd_d7);
// input params
enum modes: byte {PS, CPAP, PRVC};
// enum modeskdjfk {PS=0, CPAP=1, PRVC=2};
int ventilation_mode = PS;
float working_pressure = 1; //?
enum lab_cycle_modes : byte
{
LAB_MODE_BREATHE = 0,
LAB_MODE_PURGE = 1,
LAB_MODE_FLUSH = 2
};
int ventilation_mode = HEV_MODE_PS;
float working_pressure = 1; //?
float inspiratory_minute_volume = 6000; // ml/min
float respiratory_rate = 15; // 10-40 +-1 ;aka breaths_per_min
float inspiratory_pressure = 10; // 10-80 cmH2O +-1
float respiratory_rate = 15; // 10-40 +-1 ;aka breaths_per_min
float inspiratory_pressure = 10; // 10-80 cmH2O +-1
//float tidal_volume = 200; // calc 200-1500ml +- 100
float inspiratory_time = 1.0; // 0.4-1.5s +-0.1
float pause_time = 1.0; // range?
float pause_time = 1.0; // range?
//float expiratory_time ; // calc
float expiratory_minute_volume; // calc?? same as inspiratory_minute_volume?
float trigger_sensitivity;
// states
enum BS_STATES : byte
{
BS_IDLE,
BS_BUFF_PREFILL,
BS_BUFF_FILL,
BS_BUFF_LOADED,
BS_BUFF_PRE_INHALE,
BS_INHALE,
BS_WAIT,
BS_EXHALE_FILL,
BS_EXHALE,
BS_BUFF_PURGE,
BS_BUFF_FLUSH
};
int bs_state = BS_IDLE;
byte lab_cycle_mode = 0;
bool start = LOW;
// calculations
float calc_tidal_volume()
{
return inspiratory_minute_volume/respiratory_rate;
return inspiratory_minute_volume / respiratory_rate;
}
float calc_expiration_time()
{
float total_respiratory_time = 60.0/respiratory_rate;
// total = expire + inspire + pause
return (total_respiratory_time - inspiratory_time - pause_time);
float total_respiratory_time = 60.0 / respiratory_rate;
// total = expire + inspire + pause
return (total_respiratory_time - inspiratory_time - pause_time);
}
float calc_expiratory_minute_volume()
{
// probably need to calculate this from readings
return 0;
// probably need to calculate this from readings
return 0;
}
// FROM OVERLEAF DOC
// Working pressure, corresponding to the manually set and monitored input pressure to the unit
// Inspiratory Minute Volume setting
// Breaths per minute setting
// Tidal volume display, based on previous two parameters
// Inspiration time setting
// Pause time setting
// expiration time display based on previous two parameters
// expired minute volume
// Airway pressure display based on the reading of $P_2$ ??? not a setting
// PEEP setting ??? external
// Trigger sensitivity to patient initiated breath
void setup()
{
pinMode(pin_valve_in, OUTPUT);
pinMode(pin_valve_out, OUTPUT);
pinMode(pin_valve_scavenge, OUTPUT);
pinMode(pin_valve_purge, OUTPUT);
// FROM OVERLEAF DOC
// Working pressure, corresponding to the manually set and monitored input pressure to the unit
// Inspiratory Minute Volume setting
// Breaths per minute setting
// Tidal volume display, based on previous two parameters
// Inspiration time setting
// Pause time setting
// expiration time display based on previous two parameters
// expired minute volume
// Airway pressure display based on the reading of $P_2$ ??? not a setting
// PEEP setting ??? external
// Trigger sensitivity to patient initiated breath
pinMode(pin_p_supply, INPUT);
pinMode(pin_p_regulated, INPUT);
pinMode(pin_p_buffer, INPUT);
pinMode(pin_p_inhale, INPUT);
pinMode(pin_p_patient, INPUT);
pinMode(pin_temp, INPUT);
void setup() {
pinMode(pin_valve_in, OUTPUT);
pinMode(pin_valve_out, OUTPUT);
pinMode(pin_valve_scavenge, OUTPUT);
pinMode(pin_valve_scavenge, OUTPUT);
pinMode(pin_led_0, OUTPUT);
pinMode(pin_led_1, OUTPUT);
pinMode(pin_led_2, OUTPUT);
pinMode(pin_p_supply, INPUT);
pinMode(pin_p_regulated, INPUT);
pinMode(pin_p_buffer, INPUT);
pinMode(pin_p_inhale, INPUT);
pinMode(pin_p_patient, INPUT);
pinMode(pin_buzzer, OUTPUT);
pinMode(pin_button, INPUT);
pinMode(pin_led_0, OUTPUT);
pinMode(pin_led_1, OUTPUT);
pinMode(pin_led_2, OUTPUT);
Serial.begin(9600);
pinMode(pin_buzzer, OUTPUT);
// lcd.begin(16, 2); // Declare number of columns and rows
}
lcd.begin(16, 2); // Declare number of columns and rows
Serial.begin(9600);
void setValves(bool vin, bool vout, bool vscav, bool vpurge)
{
digitalWrite(pin_valve_in, vin);
digitalWrite(pin_valve_out, vout);
digitalWrite(pin_valve_scavenge, vscav);
digitalWrite(pin_valve_purge, vpurge);
}
void breath_cycle()
{
// basic cycle for testing hardware
int next_state;
switch (bs_state)
{
case BS_IDLE:
start = digitalRead(pin_button);
if (start == HIGH)
{
next_state = BS_BUFF_PREFILL;
}
else
{
delay(1000);
next_state = BS_IDLE;
}
setValves(V_CLOSED, V_OPEN, V_OPEN, V_CLOSED);
break;
case BS_BUFF_PREFILL:
setValves(V_CLOSED, V_CLOSED, V_OPEN, V_CLOSED);
delay(1000);
next_state = BS_BUFF_FILL;
break;
case BS_BUFF_FILL:
setValves(V_OPEN, V_CLOSED, V_OPEN, V_CLOSED);
delay(500);
next_state = BS_BUFF_LOADED;
break;
case BS_BUFF_LOADED:
setValves(V_CLOSED, V_CLOSED, V_OPEN, V_CLOSED);
switch (lab_cycle_mode)
{
case LAB_MODE_FLUSH:
delay(500);
next_state = BS_BUFF_FLUSH;
break;
case LAB_MODE_PURGE:
delay(500);
next_state = BS_BUFF_PURGE;
break;
default:
delay(1500);
next_state = BS_BUFF_PRE_INHALE;
}
break;
case BS_BUFF_PRE_INHALE:
setValves(V_CLOSED, V_CLOSED, V_CLOSED, V_CLOSED);
delay(100);
next_state = BS_INHALE;
break;
case BS_INHALE:
setValves(V_CLOSED, V_OPEN, V_CLOSED, V_CLOSED);
delay(100);
next_state = BS_WAIT;
break;
case BS_WAIT:
setValves(V_CLOSED, V_CLOSED, V_CLOSED, V_CLOSED);
delay(1000);
next_state = BS_EXHALE_FILL;
break;
case BS_EXHALE_FILL:
setValves(V_OPEN, V_CLOSED, V_OPEN, V_CLOSED);
delay(1000);
next_state = BS_EXHALE;
break;
case BS_EXHALE:
setValves(V_CLOSED, V_CLOSED, V_OPEN, V_CLOSED);
delay(10);
next_state = BS_BUFF_LOADED;
break;
case BS_BUFF_PURGE:
setValves(V_CLOSED, V_CLOSED, V_OPEN, V_OPEN);
delay(1000);
next_state = BS_BUFF_PREFILL;
break;
case BS_BUFF_FLUSH:
setValves(V_CLOSED, V_OPEN, V_OPEN, V_CLOSED);
delay(1000);
next_state = BS_IDLE;
break;
default:
next_state = bs_state;
}
bs_state = next_state;
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("Breathing Only");
delay(5000);
// buzzer
// tone(pin, freq (Hz), duration);
}
\ No newline at end of file
void loop()
{
// put your main code here, to run repeatedly:
//Serial.println(BOARD);
// delay(1000);
// buzzer
// tone(pin, freq (Hz), duration);
breath_cycle();
Serial.println("state: " + String(bs_state));
}
#include <Wire.h> // I2C control
// #include <LiquidCrystal_I2C.h> //LCD over I2C
// Node MCU 32s
// pwm pins
const int pin_valve_in = 6;
const int pin_valve_out = 7;
const int pin_valve_scavenge = 8;
const int pin_valve_purge = 15;
// adcs
const int pin_p_supply = A0;
const int pin_p_regulated = A3;
const int pin_p_buffer = A6;
const int pin_p_inhale = A7;
const int pin_p_patient = A4;
const int pin_temp = A5;
// leds
const int pin_led_0 = 13;
const int pin_led_1 = 9;
const int pin_led_2 = 10;
// buzzer
const int pin_buzzer = 11;
// lcd Not enough GPIOs, we can use I2C if needed NOTE: This code was not tested through I2C
// constants needed
// by default static DO NOT UNCOMMENT SDA AND SCL LINES
// const uint8_t SDA = 23;
// static const uint8_t SCL = 22;
const int LCD_Address = 0x27;
const int LCD_columns = 16;
const int LCD_rows = 2;
/* In case that we want to use the LCD we must
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(LCD_Address, LCD_columns, LCD_rows);
void setup(){
// initialize LCD
lcd.init();
// turn on LCD backlight
lcd.backlight();
}
void loop(){
// set cursor to first column, first row
lcd.setCursor(0, 0);
// print message
lcd.print("Hello, World!");
delay(1000);
// clears the display to print new message
}
*/
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment