Software apps and online services
With this example, we show how to control a couple of cheap Chinese galvanometer scanners with the Pulse Train Hat to create a simple laser light show.
With the next firmware release for the PTHAT we have added a few new commands to control two spare pins that are configured as PWM outputs. This now allows Pulse Width Modulation out of the PTHAT, as well as the usual Pulse Trains.
Pulse Width Modulation can be used for a range of applications and we thought it would be fun to have as play with a laser pointer using PWM to control the position of each X and Y Galvo.The Galvanometers
These are low cost galvanometers from Ebay.
The kit comes with:
- 2 galvanometers with mirrors
- 2 Drivers
- 1 Power Supply that gives out +12/-12V
We were not expecting too much from these, but after trying servo motors and deciding we needed more speed, we were actually surprised at how well they performed, as only 20Kpps (kilo point per second) compared to more expensive ones that go up to 60Kpps or higher.How they work
The drivers control the position of each galvo and expect a input signal of 0=10V+ and 0-10V- as well a GND line from your controller.
If you imagine a grid with X going left to right and Y going from top to bottom. So you have Zero, Zero at the top left of your grid which is the position when the voltage is 0volts on both X and Y. When the voltage is 10volts the position would move to the bottom right of the grid.
So simple enough, if you wanted the position to be in the middle of the grid then you would supply 5volts to each X and Y driver.
The reason you need a Bi-Polar power supply is so you can get the full angle range of the galvos. You could just use 0-5volts but the picture would be half the size.Controlling the Drivers
The Pulse Train Hat produces very accurate, high speed pulse trains using dedicated DDS IC's for each Axis, but you cannot change the Pulse Width of these pulses, so no good for creating the variable voltage output we require.
We have spare outputs from the STM32F411 ARM processor that we can use for other things and two of these happen to have timers that can be used as PWM outputs and also come out on spare pins.
So that's cool, we now have a way of creating 0-3.3volts output with a resolution of 12 bits. This gives us a divisor of 0-4095 steps as such.
Next we put some new commands into the PTHAT's firmware to allow us to control the PWM outputs.
The PTHAT receives commands from the Raspberry Pi Serial Port which is no way fast enough to set the PWM for each point we want the laser to be positioned at, as we are looking at speeds of 125 microseconds between movements. To get around this we have added a buffer loop that can store up to 2000 commands and set the required pause between each command.
Now we have a way of setting and controlling the PWM for both the X and Y and also commands to control these at a fast speed.
The next problem is that we only have an output voltage of 3.3volts and we need 0-10volts. Oh and also we need that as a positive voltage and a negative voltage.
To get these signals we knocked up a little circuit that first takes the 3.3 volts up to 5 volts and then uses a couple of Op Amps to create our positive and negative at 10 volts.
We have a couple of pots for each axis, to adjust the gain and the offset.
Final thing we need is a way to turn off the laser when jumping to start positions of vectors that are not joined together. Lucky enough the small lasers we are using only pull a few ma and run at 5 volts. So in our firmware we added a blanking bit to be set with each movement command and connected the laser to one of the AUX outputs of the PTHAT.Software
Now with the hardware sorted, it was time to get the software working.
As usual we developed in Visual Studio 2017 and created a C# Universal Application for Windows 10 IOT that runs nicely on the Raspberry Pi.
Most laser show software will allow you to load files that are based on the International Laser Display Association (ILDA) format. http://www.ilda.com/
We first looked at the ILDA specs for the file format ILD files and wrote an import routine which loaded the files and then plotted the frame out on a canvas.
The ILD files have a lot of points and designed for high spec galvo's. To get around this we put a routine to reduce the points and this allowed us to load and test a vast amount of ILD files that are around the web.
Also we wanted to be able to import Gcode files that have been created for CNC machining. This would then allow us to simply create shapes with fewer points and also trace bitmaps to get vector points.
Once either a ILD file or Gcode file is loaded, it then gets converted to commands that the PTHAT will use to setup each of the PWM outputs.
Then finally when Start button is clicked, it will download all the commands down to the PTHAT buffer and start executing when all commands have been transferred.Results
Well here are the results.
At first we used a green laser that was super bright, but turn on/off times for blanking were not good. So we stripped down the laser pointer and removed a couple of capacitors, bingo! this sorted it out for a while, but eventually the laser burnt out. So we had to use a red laser to finish off this example.
The green laser can be seen in the video at the bottom of this project, before we then show the red laser.
It can be difficult to film the laser light show as it shows up a lot flashing and broken points, but to the human eye watching it is very smooth. Taking photo's seemed to come out better and below are a few test frames we created, along with a video.
The drivers have about 5 pots that control a number of settings such as overshoot that we have not trimmed at all. So further tweaking is needed.
Overall we were pleased with these cheap galvos and with a bit more tuning, they will produce better results.
We will be updating the PTHAT examples page in the new year, along with the firmware update and software source code.