Firmware Code

Here you will be able to download the Firmware code for the PTHAT controller and the code for the Nextion Touch Screen.

Pulse Train HAT (PTHAT) firmware

We have a developed a custom version of the PTHAT firmware to work with the automated BVM and this will need to be programmed into the PTHAT before you can use it.

You can download the firmware from this link
http://www.automatedbvm.net/ABVM-Firmware-V1.zip

For instructions on how to upgrade the firmware, please look at this page
http://pthat.com/index.php/firmware/

We are using the small Eeprom on the PTHAT mainboard for storing variables that are used by the Nextion display and you will need to add a couple of jumpers leads as shown below. Also make sure you add a jumper to allow Eeprom write.

The PTHAT sits on top of the USB>Serial Board and the jumpers should be configured as shown in the picture below



Nextion NX4832T035 Touch Screen Code.

Below you can download the HMI file that can be loaded into the Nextion Editor.
http://www.automatedbvm.net/ABVM-Software-V1.zip

The Nextion Editor is free and can be downloaded from this link
https://nextion.tech/nextion-editor/

If you do not want to use the editor to check out the code and also compile then we have a compiled .tft file in the Output folder. So you can copy to a SD card, place this in the Nextion display and program it.

Here are some details from the Nextion FAQ page with regards programming the TFT file.

Nextion’s microSD slot is primarily used to upload a TFT project file.

Not all microSD cards are made for use with embedded devices.
– especially newer microSD cards made for cameras, etc.
Class 10 HC 8GB to 32GB cards have had good success. Others too.

Ensure
– microSD card formatted as FAT32 under Windows
– microSD card is less than 32 GB
– only 1 TFT project file exists on the microSD card
– Nextion device is powered off before inserting microSD card
– insert the microSD card containing TFT project file
– power on Nextion with recommended clean power as per Datasheets
– Nextion device is undisturbed while uploading
– after upload “successed” indication power off Nextion
– after Nextion device is powered off then remove microSD card
– power on Nextion with recommended clean power as per Datasheets
– if new version of Nextion Editor, allow time for firmware to update
– wait for uploaded project to begin running on Nextion device

If microSD upload is unsuccessful
– Reformat the microSD card – ensuring FAT32 under Windows, and try.
– use a different microSD card (HC, Class 10, under 32GB), and try.
– compile a blank HMI project and try again.
– microSD card is not the only method to upload project – try via USB to TTL.

Using the above steps, the Nextion device will always run firmware upload
when an inserted microSD is detected at power on (power off before insert/remove)

Setting the Baud Rate

The Nextion is defaulted to use 9600 Baud for serial communications when new. This will need to be changed to 115200 Baud.

In the ABVM-Software zip file that can be downloaded above. There is a folder named “Baudrate Setup”, in there is two .HMI files to be used with the editor to check out the code.

Then we have two compiled .tft files in the Output folder, so you can set the baud rate without having to compile your own version.

Follow the Steps below to set the baudrate on your Nextion TFT display.


1) First copy the “Set Baudrate.tft” file onto an SD card and insert into the TFT SD card slot.
2) Power on and wait until the upload is complete, then turn off the display and remove the SD card.
3) Now power the TFT Display back on until you see the text “Baud set” on the screen.

After the baud rate is set we repeat steps 1 and 2 with the “Check Baudrate.tft” file. Then power the TFT display back on and tap the button “Check Baud”, you should now see the value “115200” below the button.

Now that we’ve set the baud rate and checked that it’s definitely set at 115200 we can now upload the Automated BVM file to the TFT Display.

Overview of the TFT control screens.

Here we go through each of the control screens

Loading screen

The first screen in our application is the loading screen. We have our logos, a progress bar and a hidden button that will become visible if there is an error when loading.

In the background we have a timer that polls the PTHAT memory for the following list of settings.

  • Homing pulses – 6 Bytes; Pulses to move to the home position.
  • Pulses per mm – 6 Bytes; Pulses per 1mm movement.
  • Pulses per compression – 6 Bytes; Pulses from edge of BVM to the centre.
  • Volume% – 3 Bytes; Percentage of bag compression, should never exceed 100.
  • Jog distance – 2 Bytes; Movement distance in mm for jog controls.
  • Respiratory rate – 2 Bytes; The amount of breaths per minute.
  • IE Ratio – 1 Byte; Inhale to Exhale ratio

Once we’ve received our serial buffer full of the above settings we then store these settings in the application and proceed to the Main screen. If the PTHAT memory has never been written to then there is a built function which will write default values.

When any of the above settings change in the software then we’ll upload the new settings to the PTHAT memory.

Main screen

Our Main screen consists of three settings; Volume, Respiratory rate and IE Ratio.
We then have a column of buttons Setup, Monitoring, Start and Stop.
And at the bottom of the screen there is a status indication for monitoring purposes.

Three settings

Volume
This will determine the amount of volume to express from the BVM based on a percentage that will vary from different bag sizes. In the future we will look at introducing a flow sensor and we’ll change this from a percentage of the bag size to a measurement such as l/min.

Respiratory rate
The amount of breaths per minute.

IE Ratio
The inhale and exhale ratio, if for example we had a respiratory rate of 12 b/min then 1 breath will always take 5 seconds.

IE Ratio of 1:1, The inhale would take 2.5 seconds and the exhale would take 2.5 seconds.
IE Ratio of 1:3, The inhale would take 1.25 seconds and the exhale would take 3.75 seconds.

Side buttons

At the top we have the Setup button, this will take you to the Setup screen where we’ll calibrate the machine to the BVM that will be used with it.

Next is the Monitoring button, this will take you to the Monitoring screen where you can track various statistics of the machine.

We now have the Start button, when tapped the start button will first take all of our settings and calculate the inhale and exhale set commands that are sent to the PTHAT Controller, next it will disable all controls and start the homing routine.

Once the homing routine is finished the stop and monitor buttons will re-enable and then the machine will loop through the two commands until stop is pressed.

Last is the Stop button, the machine will continue to run unless the stop button is pressed or the machine is powered down. When the button is tapped it will send a stop command to the PTHAT which will then send the nextion a command signalling the machine has stopped, nextion will then re-enable all controls.

Status indication

Here we display the current incoming replies from the PTHAT.

Setup screen

In the Setup screen there are two panels, one of the panels has two input boxes and the other has jog buttons and a calibration routine.

Input Boxes

Pulses Per mm Movement
This is the amount of pulses per mm movement, to obtain this figure we take the motor pulses per revolution and divide by the ballscrew pitch.

We’ve suggested setting the motors to 1600 pulses per revolution. We are also using ballscrews with a pitch of 4 mm, so we know our pulses per mm movement will be 1600/4=400 Pulses Per mm.

Jog Travel Per Click
This is the distance to travel in mm when one of the jog buttons are pressed.

Jog Controls and Calibration

Jog Controls
The jog controls consist of two buttons, In and Out. When tapped this will send a set and start command to the PTHAT, The set command is set at a fixed frequency and the pulses are the two input boxes multiplied together, the direction is determined by which button was tapped.

Calibration
There are two buttons, Set and Done. The Done button will be disabled until the calibration is complete.

There are four steps to completing the calibration:

  • First use the Jog control buttons to align the paddles of the machine to the outside edges of the BVM.
  • Next press the Set button, this will start a homing routine where the paddles will move outwards until they trigger the proximity sensor and record the amount of pulses it travelled. The machine then moves back to the edge of the BVM.
  • Now use the Jog control buttons to fully compress the bag.
  • Once fully compressed tap the Set button, the machine will now move back to the edge of the BVM and write the values to the PTHAT memory.

When the process is finished the Set button will disable and the Done button will enable allowing the user to return to the Main screen.

Keypad screen

This screen is used to input values for all the settings, Once the OK button is pressed the values will be written to the PTHAT memory and you’ll be returned to your previous page.

Monitor screen

**Still In Development**

This is the Monitoring screen from here we will monitor the alarm systems of each motor and other various sensors. These will be Flow sensors, Regulators etc…

Nextion also has a built in waveform that we can use outputting frequencies from the PTHAT.