Command Set Examples

Here we shall list some quick and easy examples to help people get up and running.

You can find a fully comprehensive breakdown of all the commands in the Command Set Page for more of a detailed view.

When you first get your PTHAT you can test it by manually sending commands via a Terminal program such as Putty, Hyper Terminal etc.

Also before placing it onto the Raspberry pi you might want to do some testing using your PC using the USB>Serial Adapter Board as shown in the Stand Alone Page.

While testing we would recommend the Standard Speed with a Baud rate of 115200, so make sure the link on the PTHAT mainboard is removed as shown below:

Standard Speed High Speed
BaudRate = 115200
Parity = None
StopBits = One
DataBits = 8
Handshake = None
BaudRate = 806400
Parity = None
StopBits = One
DataBits = 8
Handshake = None

Now you have your board rate set, simply open up your preferred Terminal Program, select the COM port that is connected to the PTHAT and open the port.

The first Test we would do is to send a Request Firmware Version Command.
So type in:


You should now get a reply back of

CNC Design Ltd Pulse Train Hat V5.1 2017*

This now shows that you have the correct communications setup and the PTHAT is listening to you.

So lets now jump straight in and get a motor running. First make sure that your motor is connected and powered up to the X-Axis. Also for this example we are presuming the Micro Stepper Driver is set to 1600 pulses per revolution.

We are first going to set the X-Axis telling it the speed and that we want it to rotate 10 revolutions.

The pulses we know are 1600 that we need to send for 1 revolution so for 10 revolutions it would be 16000 pulses.

The speed will depend on the Frequency we send and most of the time you will want to use RPM and a calculation will be needed to convert this to Hz. There are online calculators that will do this for you, but  you have to take into consideration the number of pulses per revolution that your motor driver is set to.

In our case it is 1600 pulses per revolution, so to get our base frequency of 1RPM we can use the following 1600 * 0.0166666666666667 which equals 26.666Hz.
Now that is slow, so lets do 200RPM for this test, which would be 200*26.666Hz=5333.200Hz

We set this using the Set Axis Command and so we send it out.


We should now get two replies back.



Timing is very important and you must wait for both replies to come back before sending any other commands.

Now to start the motor send a Start X-Axis Command.


You will receive a reply back


The motor should now ramp up until it reaches 200 RPM and rotate 10 times with a ramp down.
After all the pulses have completed you will now get a X Count Pulse completed reply back


And that is it ! your first test movement complete.

To double check that it did actually stop on 16000 pulses you could send the following command


The reply should come back with


As you can see you get the command received back, followed by the pulse count and then a completed command. You will notice the 1 after the XP which is the direction the motor is turning. You can also send this command at anytime while the motor is running to get the current pulse back and use it to update a counter in your software.

Now for another example lets do the same again but with two motors. We will set two motors, one on the X-Axis and one on Y-Axis and start them off at the same time.


Wait for replies before sending any other commands.


Send Set command


Wait for replies before sending any other commands.


Now send a Start All command.


Again we will get a reply telling us that the command was received


And when both motors reach their pulse count we will get two more replies back


Both motors should of completed 10 revolutions each (16000 Pulses).
You can repeat the above for all 4 motors if you want by setting X.Y,Z and E Axis and using the Start All command.

Please feel free to contact us if you want other examples placed on this page.






Closer look at the PCB's

Share This