How to control the Longer BT100-1L pump via Python ?

How to control the Longer BT100-1L pump via Python ?

If you are looking for a precision peristaltic pump that can handle multiple channels simultaneously (up to 24), you might want to check out the Longer BT100-1L. This pump can deliver flow rates ranging from 2 µL/min to 366.7 mL/min depending on the number of rollers in the pump head. It is also a relatively cheap peristaltic pump that has a wide range of applications.

The BT100-1L can be controlled remotely from your computer which can give you more flexibility and convenience, especially if you want to run complex pumping programs with loops, pauses, and varying flow rates.

In this blog post, we will show you how to communicate with the BT100-1L using the LONGER RS485 protocol, which is a serial communication protocol that allows you to send commands and receive responses from the pump. We will also provide some examples and code snippets on how to use Python to write and send control command strings to the pump.

What do you need to communicate with the BT100-1L ?

To communicate with the BT100-1L using the LONGER RS485 protocol, you will need the following:

  • A BT100-1L pump with a pump head and a tubing of your choice
  • A RS485 control module that plugs into the DB15 port on the rear of the pump
  • A DB15 connector that is wired to the RS485 control module
  • A serial cable that connects the RS485 control module to your computer or device
  • A programming platform (Python in the case herein)
  • A basic understanding of the data format, command format, and pdu format of the LONGER RS485 protocol (explained below 👇)

How to Set Up the Communication Port ?

Before you can start sending and receiving data from the pump, you need to set up the communication port correctly. Here are the steps to follow:

  • Connect the DB15 connector to the DB15 port on the rear of the pump
  • Turn on the pump and press the adjusting knob on the pump front to enter the remote control setting interface and enable remote control mode 🕹️
  • Make sure the communication parameters on your programming platform match the ones of the BT100-1L, which are:
    • 1 start bit
    • 8 data bits
    • 1 even parity
    • 1 stop bit
    • a baud rate of 1200 bits/s

How to Write Control Command Strings to the BT100-1L ?

Once you have set up the communication port, you can start writing and sending control command strings to the pump. A control command string is a sequence of hexadecimal characters that follows a specific format, which consists of:

  • a start flag (E9H)
  • a pump address (1 to 30, or 31 for broadcast)
  • a length of the pdu (protocol data unit)
  • a pdu, which contains the command characters and the parameters for the desired application
  • a frame check sequence (fcs), which is obtained by calculating the XOR of the pump address, the length of the pdu, and the pdu itself (compute your fcs using our online frame check sequence XOR calculator)

The pdu and its length depend on the application requested from the pump. Some of the common applications are:

  • Set running parameter (rotation speed)
  • Read running parameter (rotation speed)
  • Set running parameter (flow rate) with pump head and tube
  • Read running parameter (flow rate) with pump head and tube
  • Flow calibration

For each application, there is a corresponding set of command characters and parameters that you need to include in the pdu. These parameters are detailed below.

Set running parameter (rotation speed)

This application consists of writing to the pump. The overall length of the pdu is 6 bytes where the control command string consists of (in the exact same order):

XLSet SpeedState 1State 2
2 bytes2 bytes1 byte1 byte
  • XL, control command string of 2 bytes, 58 4C
  • Set speed (2 bytes) with a speed unit of 0.1 rpm and a maximum speed of 100 rpm (03 E8)
  • State 1 (1 byte): 
    • bit 0 – start/stop bit where 1 is to start the pump and 0 is to stop it
    • bit 1 – prime bit where 1 is to prime the pump at the max speed of 100 rpm and 0 is to run the pump at a normal speed
  • State 2 (1 byte):
    • bit 0 – sets the rotation direction where 1 is for clockwise and 0 is for counter-clockwise

The pump will respond with XL and will display on its front screen the rotation speed and the direction of rotation after receiving the control command string.

Read running parameter (rotation speed)

This application consists of reading from the pump. The overall length of the pdu is 2 bytes where the control command string is DL.

The pump’s response consists of:

DLShow SpeedState 1State 2
2 bytes2 bytes1 byte1 byte
  • DL, control command string of 2 bytes, 44 4C

Set running parameter (flow rate) with pump head and tube

This application consists of writing to the pump. The overall length of the pdu is 10 bytes where the control command string consists of:

WL2 bytes
Set flow rate4 bytes
State 11 byte
State 21 byte
Pump head number1 byte
Tube number1 byte
  • WL, control command string of 2 bytes, 57 4C
  • Set flow rate (4 bytes) with a nL/min flow rate unit
  • State 1 (1 byte) and State 2 (1 byte) as already explained 
  • Pump head number (1 byte), as presented in the tables below:
Pump headCharacters
DG (6 rollers)01
DG (10 rollers)02
YZ1515/YZ251503
313D04
DG1505
  • Tube number (1 byte), as presented in the table below:
Tubing ID (mm)
01: DG (6 rollers)
02: DG (10 rollers)
05: DG15
Tube number
0.1301
0.1902
0.2503
0.3804
0.4405
0.5106
0.5707
0.6408
0.7609
0.8910
0.9511
1.0212
1.0913
1.1414
1.2215
1.3016
1.4217
1.5418
1.6519
1.7520
1.8521
2.0622
2.2923
2.5424
2.7925
3.1726
Tubing ID (mm)
3: YZ1515/YZ2515
4: 313D
Characters
0.801
1.602
2.403
3.104
4.805
6.406
7.907
9.608

The pump will respond with WL Show flow rate (4 bytes) and will display on its front screen the flow rate, the corresponding rotation speed and the direction of rotation after receiving the control command string.

Read running parameter (flow rate) with pump head and tube

This application consists of reading from the pump. The overall length of the pdu is 2 bytes where the control command string is RL.

The pump’s response consists of:

RL2 bytes
Show flow rate4 bytes
State 11 byte
State 21 byte
Pump head number1 byte
Tube number1 byte
  • RL, control command string of 2 bytes, 52 4C

Flow calibration

This application consists of writing to the pump. The overall length of the pdu is 6 bytes where the control command string consists of:

CLTest flow rate
2 bytes4 bytes
  • CL, control command string of 2 bytes, 43 4C
  • Test flow rate (4 bytes) with a nL/min flow rate unit

Examples of control command strings

  • Set the BT100-1L to run clockwise at a rotating speed of 20 rpm

Control command string: E9 01 06 58 4C 00 C8 01 01 DB

  • E9 as the flag
  • 01 as the address 1 of the pump
  • 06 as the length of the pdu (58 4C 00 C8 01 01)
  • 58 4C as command characters XL
  • 00 C8 refers to the rotation speed, 00 C8(hex) = 200(dec); the speed unit being 0.1 rpm ⇒ the rotation speed = 20 rpm (check our online base conversion tool)
  • 01 to start the pump at normal speed
  • 01 to run the pump clockwise
  • DB as the XOR result of 01 (pump address), 06 (pdu length) and 58 4C 00 C8 01 01 (pdu) 
  • Set the BT100-1L to run counter-clockwise at a flow rate of 3 mL/min with a pump head DG (10 rollers) and a tubing ID of 0.25 mm

Control command string: E9 01 0A 57 4C 00 2D C6 C0 01 00 02 03 3B

  • E9 as the flag
  • 01 as the address 1 of the pump
  • 0A as the length of the pdu (57 4C 00 2D C6 C0 01 00 02 03)
  • 57 4C as command characters WL
  • 00 2D C6 C0 refers to the flow rate, 00 2D C6 C0(hex) = 3000000(dec); the flow rate unit being nL/min ⇒ the flow rate = 3000000 nL/min = 3 mL/min
  • 01 to start the pump at normal speed
  • 00 to run the pump counter-clockwise
  • 02 for the DG (10 rollers) pump head
  • 03 for the tubing ID of 0.25 mm
  • 3B as the XOR result of 01 (pump address), 0A (pdu length) and 57 4C 00 2D C6 C0 01 00 02 03 (pdu) 

🚨Do not hesitate to use our user-friendly online command string generator to effortlessly generate precise control command strings for your BT100-1L.

How to communicate with the BT100-1L using Python ?

Python code snippets showing how to open the serial port, write and send control command strings to the pump and write a simple pumping program are presented below.

From the first example just presented above, the following Python code snippet makes the BT100-1L run clockwise at a rotational speed of 20 rpm.

				
					### RUN PUMP 1, CLOCKWISE, AT A ROTATING SPEED OF 20 RPM

# To use the pySerial package
import serial

# Open the serial port with the data format corresponding to the BT100-1L
ser = serial.Serial('COM6', 1200, parity=serial.PARITY_EVEN, bytesize=8, stopbits=1, timeout=None, xonxoff=0, rtscts=0)

# Write the corresponding control command string in hexadecimal
Data = bytearray(b'\xE9\x01\x06\x58\x4C\x00\xC8\x01\x01\xDB')

# Write the Data to the pump
ser.write(Data)

				
			
  • In a second code snippet, let’s make the pump run clockwise at a rotating speed of 10 rpm for 10s, then make it run counter-clockwise at a rotating speed of 5 rpm for 30s before stopping it.
				
					### RUN PUMP 1 CLOCKWISE AT A ROTATING SPEED OF 10 RPM FOR 10s, THEN COUNTER−CLOCKWISE AT A ROTATING SPEED OF 5 RPM FOR 30s BEFORE STOPPING IT

# To use the pySerial package
import serial

# To use the time package
import time

# Open the serial port with the data format corresponding to the BT100-1L
ser = serial.Serial('COM6', 1200, parity=serial.PARITY_EVEN, bytesize=8, stopbits=1, timeout=None, xonxoff=0, rtscts=0)

# Run pump 1 clockwise at a rotating speed of 10 rpm for 10s
Data = bytearray(b'\xE9\x01\x06\x58\x4C\x00\x64\x01\x01\x77') # corresponding control command string in hexadecimal
ser.write(Data) # write the Data to the pump

Pumping_time = 10;
while Pumping_time > 0:
    print(Pumping_time)
    time.sleep(1)
    Pumping_time = Pumping_time − 1
end # 10s delay with a visible timer

# Run pump 1 counter-clockwise at a rotating speed of 5 rpm for 30s
Data = bytearray(b'\xE9\x01\x06\x58\x4C\x00\x32\x01\x00\x20') 
ser.write(Data) # write the Data to the pump

Pumping_time = 30;
while Pumping_time > 0:
    print(Pumping_time)
    time.sleep(1)
    Pumping_time = Pumping_time − 1
end # 30s delay with a visible timer


# Stop the pump
Data = bytearray(b'\xE9\x01\x06\x58\x4C\x00\x32\x00\x00\x21') # corresponding control command string in hexadecimal: we took the previous command string and changed the State 1 byte from 01 (start the pump) to 00 (stop the pump) and of course computed the new fcs
ser.write(Data) # write the Data to the pump

				
			

Conclusion

We hope this blog post has helped you understand how to control the Longer BT100-1L multichannel peristaltic pump remotely via Python using the LONGER RS485 protocol. You can also use other programming platforms such as Matlab to write and send control command strings to the pump and read and interpret the responses from the pump. For more details about this topic, check our blog post “How to Control the Longer BT100-1L Pump via Matlab ?”.

If you have any questions or feedback, please feel free to contact us at contact@darwin-microfluidics.com.