Getting Started with MethodSCRIPT
This example serves as a guide in how to start developing standalone methods for the Sensit Wearable. In this example a series of measurement methods are made which can be triggered using a button press or by tapping the device. The data of the measurements are put into a file which can later be accessed using PSTrace.
First the type of measurements will be defined. Since we want a standalone operation of the Sensit Wearable the base of the MethodSCRIPT code for these measurements will be pulled from PSTrace. Afterwards the MethodSCRIPT will be extended so the measurements start on waking the Sensit Wearable and such that the data of the measurements will be saved to the device. The MethodSCRIPT will be uploaded using PSTrace or the serial port and finally reading out the measurement data will be shown.
We start by looking at which measurements we want to perform. For this example it will be a CA and an EIS measurement. This combination of measurements could for example be the case if you want to get an indication of the oxygen concentration and the impedance of the analyte in PBS by just using Ag/AgCl RE and Pt CE/WE electrodes. To get the MethodSCRIPT for these measurements first the Sensit Wearable is connected to the computer via USB. In PSTrace a connection is established with the device. The CA measurement is selected and the parameters for the measurement are put in. E dc is -0.7V, t interval on 0.1s and t run 4s. In the bottom left the button 'show MethodSCRIPT' will give the MethodSCRIPT for this measurement. The text can be copied and put in a text document. Now EIS measurement is selected with a default scan type, E dc of 0V, E ac of 0.01V, 7 frequencies per decade, maximum frequency at 200kHz and the minimum frequency at 10Hz. Again the 'Show MethodSCRIPT' button in the bottom left can be clicked and the code can be copied and pasted below the previous piece of code. This will look like the code below.
e
var i
var e
set_pgstat_chan 1
set_pgstat_mode 0
set_pgstat_chan 0
set_pgstat_mode 2
set_max_bandwidth 58505m
set_range_minmax da -700m -700m
set_range ba 470u
set_autoranging ba 47n 2350u
set_e -700m
cell_on
meas_loop_ca e i -700m 100m 4100m
pck_start
pck_add e
pck_add i
pck_end
endloop
on_finished:
cell_off
e
var f
var z_r
var z_i
set_pgstat_chan 1
set_pgstat_mode 0
set_pgstat_chan 0
set_pgstat_mode 3
set_max_bandwidth 2M
set_range_minmax da 0 0
set_range ba 2350u
set_autoranging ba 47n 2350u
set_range ab 4200m
set_autoranging ab 4200m 4200m
set_e 0
cell_on
meas_loop_eis f z_r z_i 10m 200k 10 31 0
pck_start
pck_add f
pck_add z_r
pck_add z_i
pck_end
endloop
on_finished:
cell_off
This code can now be combined to perform two measurements after each other. First the declarations of all the variables will be put to the top, the duplicate commands and all empty lines are removed. The MethodSCRIPT will now look like shown below. This piece of MethodSCRIPT can be tested by opening the MethodSCRIPT sandbox in PSTrace and running this code.
e
# defining the variables for the measurements
var i
var e
var f
var z_r
var z_i
# setting the potentiostat settings for CA
set_pgstat_chan 1
set_pgstat_mode 0
set_pgstat_chan 0
set_pgstat_mode 2
set_max_bandwidth 58505m
set_range_minmax da -700m -700m
set_range ba 470u
set_autoranging ba 47n 2350u
set_e -700m
cell_on
# performing the CA measurement for 4 seconds
meas_loop_ca e i -700m 100m 4100m
pck_start
pck_add e
pck_add i
pck_end
endloop
cell_off
# turning the cell off to set different settings for EIS
set_pgstat_mode 3
set_max_bandwidth 2M
set_range_minmax da 0 0
set_range ba 2350u
set_range ab 4200m
set_autoranging ab 4200m 4200m
set_e 0
cell_on
# performing the EIS measurement
meas_loop_eis f z_r z_i 10m 200k 10 31 0
pck_start
pck_add f
pck_add z_r
pck_add z_i
pck_end
endloop
cell_off
Using the MethodSCRIPT manual we can now look at the commands to use for putting the Sensit Wearable to sleep and to wake it back up by tapping or pressing the button. A small example piece of code is put below.
e
set_pgstat_mode 0 # the device can only go to sleep in mode 0, 2 or 5
loop 1i == 1i # put the Sensit Wearable in a loop to go to hibernation after doing its thing
hibernate 14i 600 # The hibernate command setting to wake on double-tap, button press or after 10 minutes
notify_led 7 # quickly flashing the LED while awake
wait 10 # Timer for 10 seconds
notify_led 0 # turn off the LED
endloop
Now we can put this piece of code around the code we made earlier.
# defining the variables for the measurements
var i
var e
var f
var z_r
var z_i
set_pgstat_mode 0 # the device can only go to sleep in mode 0, 2 or 5
loop 1i == 1i # put the Sensit Wearable in a loop to go to hibernation after doing its thing
hibernate 14i 600 # The hibernate command setting to wake on double-tap, button press or after 10 minutes
notify_led 7 # quickly flashing the LED while awake
# setting the potentiostat settings for CA
set_pgstat_chan 1
set_pgstat_mode 0
set_pgstat_chan 0
set_pgstat_mode 2
set_max_bandwidth 58505m
set_range_minmax da -700m -700m
set_range ba 470u
set_autoranging ba 47n 2350u
set_e -700m
cell_on
# performing the CA measurement for 4 seconds
meas_loop_ca e i -700m 100m 4100m
pck_start
pck_add e
pck_add i
pck_end
endloop
cell_off
# turning the cell off to set different settings for EIS
set_pgstat_mode 3
set_max_bandwidth 2M
set_range_minmax da 0 0
set_range ba 2350u
set_range ab 4200m
set_autoranging ab 4200m 4200m
set_e 0
cell_on
# performing the EIS measurement
meas_loop_eis f z_r z_i 10m 200k 10 31 0
pck_start
pck_add f
pck_add z_r
pck_add z_i
pck_end
endloop
cell_off
set_pgstat_mode 0 # the device can only go to sleep in mode 0, 2 or 5
notify_led 0 # turn off the LED
endloop
This piece of code can again be tested with the MethodSCRIPT sandbox of PSTrace. Now the data should be shown in the plot when the device is tapped, the top is pressed or when 10 minutes pass.
To really use the device standalone the data should be stored in a file that can be accessed later. By defining the output for the data packages and opening a file for every measurement we can accomplish our goal of having a standalone device that can be read out later. Most of these commands are described in the 'Script output' section of the MethodSCRIPT manual. Below is an example, adapted from the MethodSCRIPT example on GitHub, of how to use these commands to save the data to a file.
e
file_open "output_&i.txt" 2 # Open a new file. If a file with the same name exists, &i will be incremented until a unique name is found.
set_script_output 3 # Use serial output and output to a file
var p # Applied potential during CA
var c # Measured current during CA
var t
set_pgstat_mode 4
set_range_minmax da 50m 150m
set_autoranging ba 0 1
cell_on
# Perform a 1 second CA measurement
timer_start
meas_loop_ca p c 100m 20m 1
timer_get t
pck_start
pck_add t
pck_add c
pck_end
endloop
on_finished:
# Files are automatically closed when MethodScript ends, but this is more explicit!
file_close
cell_off
Now we can take this piece of code, removing the CA measurement and only taking the relevant commands, and combine it with the previous code to have a standalone Sensit Wearable that saves the data to multiple files that can be accessed later.
# defining the variables for the measurements
var i
var e
var f
var z_r
var z_i
set_pgstat_mode 0 # the device can only go to sleep in mode 0, 2 or 5
loop 1i == 1i # put the Sensit Wearable in a loop to go to hibernation after doing its thing
hibernate 14i 600 # The hibernate command setting to wake on double-tap, button press or after 10 minutes
notify_led 7 # quickly flashing the LED while awake
file_open "output_&i.txt" 2 # Open a new file. If a file with the same name exists, &i will be incremented until a unique name is found.
set_script_output 3 # Use serial output and output to a file
# setting the potentiostat settings for CA
set_pgstat_chan 1
set_pgstat_mode 0
set_pgstat_chan 0
set_pgstat_mode 2
set_max_bandwidth 58505m
set_range_minmax da -700m -700m
set_range ba 470u
set_autoranging ba 47n 2350u
set_e -700m
cell_on
# performing the CA measurement for 4 seconds
meas_loop_ca e i -700m 100m 4100m
pck_start
pck_add e
pck_add i
pck_end
endloop
cell_off
# turning the cell off to set different settings for EIS
set_pgstat_mode 3
set_max_bandwidth 2M
set_range_minmax da 0 0
set_range ba 2350u
set_range ab 4200m
set_autoranging ab 4200m 4200m
set_e 0
cell_on
# performing the EIS measurement
meas_loop_eis f z_r z_i 10m 200k 10 31 0
pck_start
pck_add f
pck_add z_r
pck_add z_i
pck_end
endloop
cell_off
file_close # close the file after the measurements are done
set_pgstat_mode 0 # the device can only go to sleep in mode 0, 2 or 5
notify_led 0 # turn off the LED
endloop
on_finished:
file_close
cell_off
Now you have a Sensit Wearable that can perform measurements standalone. The device can be triggered by tapping, pressing the button or after 10 minutes. The data of the measurements will be saved to a file on the device which can be accessed later. The files are named output_1.txt, output_2.txt etc. depending on how many measurements have been performed. The data in these files can be read out using PSTrace by connecting the device to the computer via USB and going to 'Data' and 'Load data from internal storage'.