DPS3005 PSU Module and MODBUS RTU Python & Arduino
I recently came across a DPS3005 PSU Module with PC control option , i have used similar modules before in a bench power supply and was impressed with the results . With the launch of a new version that included PC control i decided to order one ! (Banggood.com)
A few weeks later it arrived …
in the box was a
- DPS3005 Module
- Usb serial Adaptor
- Bluetooth Module
- link lead (not pictured)
The PC / bluetooth was not mentioned in the supplied instructions and the pc software (windows 7+ only) was available from the sellers listing and also Manufacturers Youtube Channel. I decided not to install and see if i was able to control from a MCU such as an Arduino
Investigating The Interface
I started by investigating the interface by first connecting the Bluetooth and USB serial adapter to the unit and simply seeing if there was any data flowing on the com ports. This did not prove very successfully at all and wasn’t even able to pair the Bluetooth adapter with any device i tried. Though without a button on the bluetooth module i couldnt see a way of even putting it in pair mode !
Without giving up and i decided to look on the manufacture’s download link and found a interface datasheet, all in Chinese . Using google translate i was able to see the command set and the interface was basically listed as Modbus Rtu, rs232,9600 baud and slave address 1.
I have no experience with modbus at all and had to do a bit of research to understand this very basics .
The following functions were listed as supported in the datasheet:
0x03 – Read data from one or more registers
0x06 – Write a single register
0x10 – Write multiple registers
basic Functions extacted from datasheet , needed for examples below
Voltage set – Register 0x00
Current set – Register 0x01
Voltage measured – Register 0x02
Current measured – Register 0x03
power on – Register 0x04
Loads more see manufactures datasheet for more info…
Luckly there are a wide range of software libraries available for different platforms to help communicate with Modbus Rtu devices. So i didn’t need to deal with the raw data on the serial port .
Rather than jumping straight in and connecting to an arduino i decided to use the supplied USB serial adaptor and python to see if i could work out the basics using the infomation exactracted above.
Below is a very simple example how i was able read the units measured voltage. One issue i did notice i had to increase the default timeout for it to work !
# DPS3005 MODBUS Example By Luke (www.ls-homeprojects.co.uk)
# Free to use this code how you like but please link my site
# Requires minimalmodbus library from: https://github.com/pyhys/minimalmodbus
instrument = minimalmodbus.Instrument('COM4', 1) # port name, slave address (in decimal)
instrument.serial.port # this is the serial port name
instrument.serial.baudrate = 9600 # Baud rate 9600 as listed in doc
instrument.serial.bytesize = 8
instrument.serial.timeout = 0.5 # This had to be increased from the default setting else it did not work !
instrument.mode = minimalmodbus.MODE_RTU #RTU mode
print instrument.read_register(2, 2) #read a range of 16-bit registers starting at register 2 to 3 (measured voltage and current)
After confirming it worked using python and the measured voltage was successfully displayed i decided to move onto arduino. I noticed that it used a 3.3v logic level and rather than using level shifter i opted just to try and use a ESP82266 running arduino. This made it really easy to hook up just three wires gnd, TX and RX. A software serial port was used to talk to the dps3005 psu module allowing the native (USB) serial port free to monitoring everything.
Note , the supplied link lead wire colours did not match the PCB marking on my unit and was completely reversed . I may have just had a defect cable in my case but can confirm the PCB Marking were correct.
// DPS3005 MODBUS Example By Luke (www.ls-homeprojects.co.uk)
// Free to use this code how you like but please link my site
// Credit to Doc Walker of ModbusMaster for making a great Arduino Library https://github.com/4-20ma/ModbusMaster
#define SERIAL_RX D5 // PIN Mapping for ESP8266 NODE MCU Only! pin for SoftwareSerial RX
#define SERIAL_TX D6 // PIN Mapping for ESP8266 NODE MCU Only! pin for SoftwareSerial TX
SoftwareSerial mySerial(SERIAL_RX, SERIAL_TX);
ModbusMaster node; // instantiate ModbusMaster object
float voltage = 0.0;
float current = 0.0;
mySerial.begin(9600); //start software serial connected to dps3005
// communicate with Modbus slave ID 1 over Serial (port 0)
uint8_t j, result;
//********Example of sending cmds***********
node.writeSingleRegister(0, 0x96); //set 1.5v
node.writeSingleRegister(1, 0x1F4); //set 500ma
node.writeSingleRegister(9, 1); //set power on !
//*******Example of reading data*****************
result = node.readHoldingRegisters(2, 2); // slave: read a range of 16-bit registers starting at register 2 to 3 (measured voltage and current)
if (result == node.ku8MBSuccess) // only do something with data if read is successful
voltage = ((float)node.getResponseBuffer(0) / 100 ); // get voltage from response buffer and convert to float
current = ((float)node.getResponseBuffer(1) / 100 ); // get current from response buffer and convert to float
Serial.print ("Voltage: ");
Serial.println ("V ");
Serial.print ("Current: : ");
Serial.println ("A ");
Im very pleased how easy it was to get control of these great psu modules. Next.. im planning to making a new bench psu with a web interface using a esp8266.