Then You Want To Take Care Of The CO2 Curve, Focusing On Scan Synchronization.
The 3 curves of this project, chart view2 is for the SpO2 blood oxygen sensor and chart view3 is for CO2 respiration.
Chart view2, chart view3 X axis are set min = 0, max = 100, and ECG chart view1 the same, curve sweep to keep synchronized, chart view2 Y axis2 max = 100, so the preparation of the program Y-axis value is given to 95 maximum, the algorithm is shown in the following program code.
First, define 3 variables as follows.
Int num19_3 = 0;
Int num19_4 = 0;
Int num19_5 = 0;
The CO2 curve is then generally depicted in the main loop, main.c, by the following code.
num19_3 += 1;
if(num19_3 >= 4){ //one point every 40ms
num19_3 = 0;
num19_4 += 1;
if(num19_4 <= 10){
num19_5 = num19_4*9; //the first 10 points increase linearly
Serial.print(“ST<{\”cmd_code\”:\”set_value\”,\”type\”:\”line_series\”,\”widget\”:\”line_series3\”,\”mode\”:\”push\”,\”value\”:” );
Serial.print(num19_5);
Serial.println(“}>ET”);
}else if(num19_4 <= 40){ // the last 30 points decrease linearly
num19_5 = 95 – (num19_4 – 10)*3;
Serial.print(“ST<{\”cmd_code\”:\”set_value\”,\”type\”:\”line_series\”,\”widget\”:\”line_series3\”,\”mode\”:\”push\”,\”value\”:” );
Serial.print(num19_5);
Serial.println(“}>ET”);
}else{
num19_4 = 0;
Serial.println(“ST<{\”cmd_code\”:\”set_value\”,\”type\”:\”line_series\”,\”widget\”:\”line_series3\”,\”mode\”:\”push\”,\”value\” :5}>ET”);
} }
Figure (8) shows the ECG waveform at the top and the CO2 waveform at the bottom (symbol round radius = 4)
Figure (9) shows the ECG waveform at the top and the CO2 waveform at the bottom (symbol round radius = 30)
The following CO2 waveform in Figure (8) is the effect of the above program when the attribute symbol round radius = 4 for line series3. We try to modify symbol round radius = 30, hoping that the curve transition is more rounded, but the test result is no different from Figure (8), see Figure (9), which shows that when the points are denser, the rounding effect is not obvious. This can only be achieved by changing the point coordinates.
Figure (10) with coordinates separating axes
Let’s take a look at the properties of the X axis in Figure (3) by using Figure (10). In Figure (3), when show = true for split line, the long vertical bar (separator bar) will be displayed; when show = true for line, the horizontal line of X-axis will be displayed (such as the horizontal line at the bottom of the top chart view); when show = true for tick, the thin line of the scale below the horizontal line of X-axis will be displayed; when show = true for label, the number below the horizontal line of X-axis (the value filled in data) will be displayed. = true, it will show the number below the horizontal line of the X-axis (the value filled in the data). That’s all.
Now It Was Down To The SpO2 Curve And Decided To Use AD Conversion.
Curve simulation using ESP32 ADC, it is 12-bit, full scale 4096. chart view2 Y axis max = 255, the ADC read-in value divided by 20, can meet the curve display. The full-scale SPO2 display is 100%, so the ADC read in value divided by 20 and then divided by 2.55 can be displayed in label2, the program because it is an integer number operation, the algorithm is corrected, please see the actual test ok program code. Use the function analogRead(32) in Arduino to read the AD conversion value of GPIO32 (also ADC-CH4) of ESP32 directly. The test can be done by a potentiometer, but also simply connect the ADC-CH4 pin to GND, to +3.3V, to +5V, or overhang to see the interference waveform, see video effect (shown at low when grounded, connected to +3.3V, +5V is the same high full amplitude, the overhang is a spurious curve), the right label2 control timely display ADC voltage changes. The code and algorithm code is as follows.
//——–ADC——-
int adcPin = 32; // GPIO32, also ADC-CH4
int adcValue = 0;
int num19_6 = 0;
delay(10);
adcValue = analogRead(adcPin); // Read in the value of the AD conversion
adcValue = adcValue/20;
//—–SPO2 curve plotting ——
num19_6 += 1;
if(num19_6 >= 4){ // one point every 40ms
num19_6 = 0;
Serial.print(“ST<{\”cmd_code\”:\”set_value\”,\”type\”:\”line_series\”,\”widget\”:\”line_series2\”,\”mode\”:\”push\”,\”value\”:” );
Serial.print(adcValue);
Serial.println(“}>ET”);
adcValue = (adcValue*10)/21;
Serial.print(“ST<{\”cmd_code\”:\”set_value\”,\”type\”:\”label\”,\”widget\”:\”label2\”,\”value\”:”);
Serial.print(adcValue);
Serial.println(“}>ET”);
}

Fig. (11) The actual completed 3 groups of curves partially
See Figure (11) for a partial shot of the actual picture, and Figure (12) for the design interface in the computer. As in Figure (3), when the show = false of the split line of the X axis2 of the chart view2, the separator bar of the yellow SPO2 area in the middle of Figure (12) will turn off the display (like the real picture); the smooth waveform of the video display can be done completely as a real-time oscilloscope.
Figure (12) 3 sets of curves completed by computer
Reference Points
The structure of the STONE designer platform chart view control is shown in Figure (13). There is a detailed description in the official User’s Manual 8.1, including the explanation of each property and parameter; the instruction set 4.24 gives the method of data pushing, see Figure (14), and there are examples of instructions used in the program here.

Figure (13) Structure of the chart view of the curve control

Figure (14) Instructions for using the chart view of the curve control
2. Arduino’s analogRead() read function for analog AD conversion. In the Arduino version 1.8.13 menu “Help”—“Reference” —- “learning —– “Analog I/O”, you can see the description of the analogRead() function As follows.
AnalogRead()
Description
The Arduino board contains a 6-channel (8 channels on the Mini and Nano, 16 on the Mega), 10-bit analog-to-digital converter. This means that it will map input voltages between 0 and 5 volts into integer values between 0 and 1023. This yields a resolution between readings of 5 volts / 1024 units or, .0049 volts (4.9 mV) per unit. analogReference ().
It takes about 100 microseconds (0.0001 s) to read an analog input, so the maximum reading rate is about 10,000 times a second.
Syntax
analogRead(pin)
Parameters
pin: the number of the analog input pins to read from (0 to 5 on most boards, 0 to 7 on the Mini and Nano, 0 to 15 on the Mega)
Returns
int (0 to 1023)