Introduction: BLE Target Tracker
This project combines wireless communication techniques and video image processing in order to create a device capable of tracking and filming a specific target. The target will be paired with the Zybo board via Bluetooth Low Energy (BLE). The target will transmit accelerometer data via BLE to the Zybo board. The board will then analyze the received data, and control a servo with a camera mounted on it to track, follow, and film the target. The video output of the camera could be viewed live on an attached monitor.
Zybo Zynq 7000 Development board
Parallax Standard Servo (#900-00005)
Micro HDMI - HDMI cable
RedBearLab BLE Peripheral Module
BLE Central Module
Xilinx Vivado Design Suite 2015.4
Adept 2.16.1 System, 32/64-bit Windows
You can see the overall setup/design of the system from the Block Diagram.
In this example, we will be using an iPhone as the BLE Central Module to transmit accelerometer data via BLE. The iPhone is running a custom iPhone app. You can find the Xcode files to develop the app with in the zipped folder.
Step 1: Vivado Procedure
Open up Vivado and create a new project. Give your project a name. Declare it as an RTL project and select not to specify sources. Next, select “parts” and search for xc7z010clg400-1. You can also do this later on as well (Tools ⇒ Project Settings ⇒ General). Click Create Block design and give it a name. Next, press the green plus icon to Add IP. Search for ZYNQ and choose the ZYNQ7 Processing System.
Now double click the new block and wait for a window to open. Download the attached file. In the window, click “Import XPS Settings” and select “zybo_zynq_def.xml” from the unzipped “Zybo def” folder. Additionally, to implement UART 0, go to MIO Configuration and check UART 0. Additionally, Enable the GPIO MIO under GPIO as well as the ENET Reset for GPIO.
Apply these changes and go back to the block design. Finally, click “Run Block Automation.” Say Ok to the questions that pop open.
Click “Add IP” again and search for “gpio.” Create an instance of GPIO and double click on the box. Select “All Outputs” and create a width of 1. Apply these settings. Next, click “Run Block Automation.” More blocks will appear. These bigger blocks manage the AXI system.
Find the AXI GPIO block and right click on the two bars next to the GPIO+. Click “Make External.” Select the GPIO output and the properties section will appear to the left of the block diagram. Rename this GPIO to SERVO.
Finally, go to the sources window and right click on design_1.bd. Select the Create an HDL wrapper option. Select to “Copy generated wrapper to allow user edits.”
Next, download the attached file the ZYBO_MASTER.xdc file, which contains constraints. Then, click on the Constraints in the Sources box in Vivado. Select Add sources, then Add or Create Constraints. Click Next and select Add Files. Find the ZYBO_Master.xdc file. Open up the file in Vivado and find the comment ##Pmod Header JE. Go to the comment ##IO_L4P_T0_34 directly below. Uncomment this this pin and rename the instances of je to servo_tri_o.
Download the attached ZIP file. Follow the HDMI tutorial to add the block design for HDMI-VGA compatibility.
Finally, Generate the bitstream. This will go through synthesis and implementation. Once completed, you can open the Implemented Design and see the “used” portions of the Zynq. In the File/Edit bar, there is a drop down with the Default Layout option selected. Turn that into IO Planning. The image shows the physical pinouts for the Zynq processor. You can find the SERVO pin output here.
Step 6: Vivado Procedure Complete!
Go to File ⇒ Export ⇒ Hardware and then Launch SDK.
Step 7: SDK Procedure
The SDK is a thinly veiled version of Eclipse. A platform is shown on the left corresponding to the Vivado project.
Create a BSP to wrap the platform (File ⇒ New Board Support Package). Select your platform for the Hardware Platform. Use the _0 CPU. Click Finish and a window containing drivers will open. Check off lwip141 for inclusion with the bsp and then click Ok.
Step 9: Breaking Down the Code
Download the latest FreeRTOS release. In the SDK select File ⇒ Import. Click General ⇒ From an Existing Workspace and then navigate to where FreeRTOS is downloaded. The demo is located in FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702. Three projects will pop up. Import them all into the current workspace. It will build the projects in the SDK. Blue folders contain the actual code of the projects. Right click on the folder and select “Change Referenced BSP.” Change the BSP to the one you just created for your Zybo. Go to main.c and find the #define for mainSELECTED_APPLICATION. Set this to 0. This will set the program to run main_blinky.c
Go to ParTest.c in the RTOSDemo. Download a new version of the attached ParTest.c Copy the code and paste from this tutorial over the one from RTOS Demo. This code contains UART and GPIO compatibility. This code reads from the UART which contains accelerometer data transmitted via BLE. ParTest than analyzes the inputted data and adjust the Servo via GPIO outputs.
These are necessary in order to allow GPIO and UART compatibility. The defines setup the signal directions and the channeles. partst_RX and partst_TX refer specifically to the MIO pins. They are connected directly and, therefore, the UART signals do not depend on GPIO pins.
These are the various instance variables required for the program. xUart and xServo variables are created for both the UART communication and the servo controller. Some of the other variables are for the logic that reads the received UART information and controls the servo controller.
These are some declarations for variables required in the initialization method.
This method consists of initializations for the GPIO driver and the UART driver. It sets the directions for the signals and enables the outputs. It also checks the signals status and makes sure they are present.
The vParTestToggleLed method contains the logic that controls the servo controller. The servo controller datasheet can be examined to learn more about its functionality. The XUartPs_Recv method receives the information from the BLE module. It then uses this to output varying pulses to the servo controller. This will adjust the positioning of the servo and track the user’s movement.
Additionally, download the board drivers from the Digilent website. Download Adept 2.16.1 System, 32/64-bit Windows.” Plug in the board and let the drivers run.
Step 14: SDK Procedure Complete!
In the SDK, select “Debug Configurations” from the “Run” menu. Create a new System Debugger run. In the “Target Setup” tab, select “Reset Entire System” so that both that and ps7_init are selected. Select the Application tab. Set the cortexa9_0 core to stop at program entry. A core 0 is made to run the RTOSDemo.elf. Click Apply and Debug.
Step 15: Hardware Setup Procedure
Connect the servo accordingly. The black wire should connect to ground. The red wire should connect to the positive end of the 5V battery. The white wire should connect to the servo GPIO in the Standard Pmod header marked 11. (JE, pin 1). Connect the GND pin of the JE header to ground as well.
The UART MIO pins are found in the MIO Pmod header marked 6. If you're using the RedBear Mini like this tutorial uses, follow the pin diagram pictured. Vin to 5V, GND to GND, the receiver pin corresponds to MIO 9 (JA, pin 8), and the transmitter pin corresponds to MIO 10 (JA, pin 2).
Step 17: Hardware Setup Complete!
Connect your GoPro via the micro HDMI adapter to the HDMI connector marked 26. Then connect a monitor using the VGA cable to the VGA connector marked 24.
Mount your GoPro onto the mount. We took the mount of a selfie stick and screwed it onto the servo controller. The mount could then hold the camera.
Connect the USB port marked 3 to your laptop containing the project. Flip the switch marked 1 to turn on the board. Now, you can run the program.
Step 18: Using the Custom BLE IPhone App
Once all the previous steps are completely and the system is ready to run, power on the system.
Develop, debug, and install the provided custom BLE Select iOS app from the beginning of this tutorial.
Open the app. You should see the pictured home screen. Press Scan All.
You should now see this screen with a list containing surrounding RedBear BLE Peripheral Modules within range. Click on the one you're using.
You should now see the pictured screen! Click Transmit and your iPhone should start transmitting accelerometer data via BLE to the connected system. The screen will stay the same though.
Press Disconnect to disconnect and restart the app from the beginning.
Step 21: Congratulations!
You're all done! Hopefully everything works properly and you completed this instructable tutorial without any problems!
As you can see in the video of our demo version, the servo is not super responsive and accurate. This is due to the noisiness of the accelerometer data from our iPhone. Better filtering and accelerometer analyzation can be applied to smooth out the motion and tracking. This instructable was more focused on the overall implementation of the entire system.