Introduction: Adding LEDs to the Claw Game
The Claw Game is pretty cool but there is always a way to improve a project. To improve the claw game LED strips are going to be added to the base because no project is complete without excessive numbers of LEDs.
Unfortunately the project for the Basys 3 makes it difficult to add a block design for MicroBlaze which will be used to control the LED strips in this project. As such I will be using the Arty FPGA board to complete this project.
Items required to build this project:
- Arty FPGA development board
- WS2812 LED strips
- USB A to USB micro-B cable
- Jumper wires
- Vivado and Xilinx SDK
- Digilent Board Files installed (Follow this tutorial if needed)
Step 1: Creating the Project and Adding the DigiLED IP to the Project
Step 2: Adding the Blocks
The next step is to create the block design. Now click Create Block Design in the IP Integrator section of the Flow Navigator. Give the design a name without spaces. Add the Following blocks to the design:
- MicroBlaze
- DigiLED
- 4 Push Buttons from the board tab
Step 3: Running Automation
Now that the blocks have been added to the design run Block Automation from the green banner. In the window that pops up increase the Local Memory to 128KB and make the Cache Configuration 8KB. Leaving everything else alone click OK, block automation will run and make some connections between the blocks and generate a couple new blocks.
Before running Connection Automation double click on the clocking wizard that was created and set the Reset Type to Active Low. Click OK and delete the diff_clk_rtl pin that was generated and replace it with the System Clock from the board tab. Now run Connection Automation. Select the uppermost checkbox in the hierarchy to select all blocks and click OK. Run it once more to finish automation.
Step 4: Adding the Output Pin and Configuring the LED Block
The last part of the block design is to connect the output of the DigiLED block to an output pin and configure the block. To do this right click on the led_out text and select Make External. To configure the block double click on it and set the following settings:
- Color Mode: HSV
- Number of LEDs: the number of LEDs to drive (In my case 90)
Now create a new constraints file to define the output pin for the LEDs. The following line will add the led_out wire to pin IO0 on the Arty.
set_property -dict { PACKAGE_PIN V15 IOSTANDARD LVCMOS33 } [get_ports { led_out }];
Step 5: Generate the Outputs
Now that the block design is complete a wrapper can be created. To do this open the sources tab and right click on the block design selecting Create HDL Wrapper. In the pop up window make sure that the Let Vivado manage wrapper and auto-update option is selected. Now the bitstream can be generated. If Vivado asks to run synthesis and implementation say OK.
This may take a while depending on the computer used.
Step 6: Exporting the Hardware and Starting the SDK
Now that the bitstream has been generated export the hardware with File->Export->Export Hardware, check the Include Bitstream box when the dialog pops up. This will generate some files that the SDK will use to generate its binaries. Next open the SDK with File->Launch SDK.
Step 7: Program the FPGA
In order for the program to be run on the board the FPGA must be programmed with the bit file from earlier. To do this click on the Program FPGA button. This step sets up the LUTs and wire nets on the FPGA to accept the MicroBlaze program to drive the LED strips. Click the Program FPGA button in the toolbar of the SDK to program the FPGA.
Step 8: Program the Processor
Now that the SDK has opened, a new Xilinx Application Project needs to be created. Click the new button on the toolbar and select Xilinx->Application Project. Click next and give the project a name that doesn't contain any spaces or special characters. Click Finish to create the project and dependencies.
To add the needed files to the project drag and drop them onto the src folder that was generated by the New Project Wizard. A dialog will appear asking how to import the files, say copy into the project. After loading open patterns.h and change the number at the end of line 18 to the number of LEDs selected when customizing the DigiLED block.
The program can now be loaded onto the processor. Click the Run button in the toolbar and select System Debugger on Local in the dialog. The program is now loaded into the processors instruction memory. Press BTN0 on the Arty to cycle through the Patterns on the LED strip(s).
Step 9: Connect the Arty to the LED Strips
Only 3 connections need to be made on the Arty. Using jumper wires, connect the data line of the LED strip to pin IO0 of the Arty and power and ground to 3V3 and GND, respectively. Make sure that the data line is the input side of the LED strip.
Step 10: Create Your Own LED Patterns
There are 3 functions that control the LED strips, SetLEDColor, clearLEDs, and enableLEDs.
enableLEDs() - Enables the LEDs for SetLEDColor to work
clearLEDs(int) - Clears the passed number of LEDs starting from the first LED on the strip
SetLEDColor(led_number, hue, saturation, value) - Sets led_number from the first LED to the passed hue, saturation, and value.
To create a custom pattern use SetLEDColor and some loops that set each led to the desired value.