Top
/Home


FPGA Based IoT Server and On-board LED and Switch Control

Introduction:

FPGA based IoT server & onboard LED and Switch control is a research type work based on FPGA(Field Programmable Gate Array). In this project, I used the Zybo FPGA SoC Trainer Board made by Digilent. This is a basically an FPGA based development board but it has a special feature that this board contains a hardcore processor ARM Zynq-7000 beside the FPGA block. The FPGA is used to design or test some user-defined circuit or interfaces and this hardcore processor is generally used to perform some advanced instructions. 

In this project, We are using PmodWiFi (Peripheral Module WiFi) with this board. For using this hardware we need a proper interface. This interface is made on the FPGA block. For controlling and data communicating we need the help of the Zynq processor. Here is the Zybo Reference Manual of the Zybo Board, and check the PmodWiFi Reference Manual for necessary information about the WiFi Module.

 

Hardware Requirement:

  1. Zynq-7000 ARM/FPGA SoC Trainer Board
  2. PmodWiFi Module
  3. 16 GB micro SD card
  4. Ethernet WiFi Router
  5. Micro USB cable
  6. Android mobile as the HTTP client

 

Software Requirement:

  1. Vivado 2016.3
  2. Putty
  3. Web Browser (like chrome)

 

The workflow of the System:

Here we made a very simple workflow for the system. The workflow of the system is basically divided into main three steps. First one is the connection between the Zybo and the Ethernet WiFi router through the PmodWiFi module. The second step is sending a command through HTTP (Hyper Text Transfer Protocol) and show the status of the onboard LEDs. In the third step, the system displays the onboard LEDs based on the command signal. 

  

 

Every step is just a collection of a number of sub-steps. In the First step Zybo turn-on the PmodWiFi board and searching for the available WiFi and if not found it will restart the module and start again a new search. If the desired WiFi found then it connects with the WiFi via its predefined credentials. after connecting with the network the router provides an IP address for the connected device. This IP address will be used for the communication with the Zybo.

After receiving the IP address the system inserts into a waiting state of the second step. In this step, the system waits for an incoming input command. If it receives the system check the validity of the command. For the invalid command system simply ignore it and again wait for the proper command. But if the command is valid then it will reflect the change in the web-page of the client. and finally, convey that command to the hardware manager.

In the third step, the conveyed command is received by the hardware manager and make a change on the hardware according to the command.  

 

Steps of the Project:

The entire project setup we can divide into some steps like...

 

  1. Download the IP from Github
  2. Create a new project in Vivado 16.3  
  3. Install the IPs in Vivado 16.3
  4. Make the Block design for the PmodWiFi, GPIO LEDs and Switches interface
  5. Generate the Bit File
  6. Open the SDK
  7. Setup and configure a new project for the server
  8. Copy the given web files in SD card (Edit if you want)
  9. Setup the hardware
  10. Connect the Putty software (Serial Communication)
  11. Program with the bit file and run the project file
  12. Collect the IP from Putty and test the server
  13. Control the GPIO LEDs and Switches

 

Download the IP from Github:

The very first we need the PmodWiFi IP (Intellectual Property) [Make sure that it is totally different from network IP(Internet Protocol). Intellectual Property of a module contains the interface, pin configuration and some very basic demo code for the module]. All the IPs are available in the Github. So we simply download the IPs from the link https://github.com/Digilent/vivado-library. After download, the zip file extracts the file in the C: drive or home directory of your computer.

 

Create a new project in Vivado 16.3:

For a new project first, need to open the Vivado 16.3 software and then click on the 'Create New Project' then 'Next' on the pop-up window.

Now it will ask for a project name and directory. Put the project name. Here we use "HTTP_server_with_PmodWiFi". You can use your own project name. And then select the project location where the project file will be. 

Select the "RTL Project" and click "Next". Generally "RLT Project" by default selected just you have to click "Next".  

Now its time to select the most important part of the project that is Board. First, you have to go to the "Board" tab and you have to choose the proper board from the available boards. For our case, we are using the Zybo. So select the Zybo and press "Next".

Now finally press next.

And it will take some time and the empty project will be created.

 

 

Install the IPs in Vivado 16.3:

Before starting the block design we need to install the downloaded IPs in the Vivado software. To do that we need to go to the File Navigator on the left side of the software. and then the Project Manager and click on the Project Settings. It will open a popup window like this.  

Now we have to select the IP icon from the left in that popup window.

and then select the Repository Manager tab from the upper part.

Now we have to browse the IPs by pressing the "+" icon in the middle of the window. Just click the "+" button and it will open the browse window to browse the downloaded file. After selecting the proper file we have to click Select button. 

The software will take a little bit of time to import all IPs.

After successfully Importing the IPs it looks like this. Now you have to press the Apply button and then Next button. The IP importing is now finished. Now we can move to the block design.

 

 

Block Design of the All Module with Processor Interface:

To start the block design first you need to click on the Create Block Design from the IP Integrator drop-down on the Flow Navigator. This process takes a moment to open the block design window.

After the opening of the Block Design window, you have to right click on the window and select the Add IP option and browser the required IPs. 

Here is the list of all available IPs. from them we need to use the proper IPs. 

First of all, we need the IP of the Zynq Processor. Here the IP is ZYNQ7 Processing System. We need to select that IP. 

The Processor IP looks like this.

Now we have to add the Pmod(Peripheral Module) IPs. To do this we have click on one of the Pmod Connector of JB, JC, JD, JE. (JA is not used for Pmod, JA is reserve for the XADC). Click on the connector and select the proper Pmod from the popup window. Here we are choosing PmodWiFi_v1_0. Then click on OK.

It will show like this. Make sure that the output of the PmodWiFi is connected with the Pmod connector. Here the PmodWiFi is connected with JC port.

Now we have to add the GPIOs. In this project, we are using the 4 onboard LEDs and 4 Slide Switch. So the 4 LEDs are drag and drop from the left pallet's GPIO drop-down.

Now Select the 4 Switch and drag down on the same GPIO block of the block diagram. It will show this kind of green color.

If it is successfully imported then it looks like this. Now basic blocks are imported. now its time for connection.

For connection, the Vivado software gives an automotive connection facility. To use this we need to first run "Run Block Automation" from the top panel of the software. It will open a popup like this. Simply click on OK. It will automatically execute. 

Now we have to click on the Run Connection Automation. It will again open a popup.

In that popup, you have to select the blocks which we want to connect automatically. It's better to select all the blocks and click OK.

Its automatically add the extra blocks which are needed to run the main blocks. And also connect the required connections for the blocks.  

But after automatic connection system left one connection that is the interrupts for the PmodWiFi. So we need to do it manually. To do this first we need to add one interrupt pin in the Zynq processor. So first we need to double click on processor block to customize. It will open a popup. from the popup, we need open Interrupts option from the left panel. Then expand the Fabric Interrupts option. Then expand PL-PS Interrupt Ports. 

Now select the IRQ_F2P[15:0] option and click on OK.

Now we can find a new interrupt pin income in the processor. It will use to connect the interrupt pin of the PmodWiFi.

Now simply click on the interrupt pin of the PmodWiFi and drag-drop up-to-the interrupt pin of the processor. It will make a connection between the two interrupt.  

Now click on the Regenerate Layout option in the left panel of the design window. It will regenerate the circuit and rearrange the circuit. (This is an optional step, you can skip it)

After regenerating the layout it will show like this. 

Now we have to make the wrapper for the layout. This will internally make a new file and call the instance of all blocks from a single main function. This is a very very important step. To do it we need to go to the source window from the left panel. And right click on the design file and select the Create HDL Wrapper...  

It will open another popup window and ask for an option selection. Select the option Let Vivado manage wrapper and auto-update and click on OK

 

 

Generate the Bit File:

Now its times to generate a Bit file. This bit file is basically the compiled binary executable file which will be used to program the FPGA farther. To generate this bit file we have to click on the Generate Bitstream form the bottom left of the window. It will ask for permission. Just ignore it and click on Yes

The bit file generation will take 10 to 15 minutes (depends upon the processing speed of your computer). So take a nap and wait for the completion of the process.

After completion of the process, one popup will be open to asking for run the implementation design, reports and like this. This thing is not needed. so simply you click on the Cancel button.  

 

 

Open the SDK:

After a bit of file generation, the next step is the open SDK(Software Development Kit). Up to this whatever we did that was block design. this was nothing but the interface for the Pmod and GPIOs. But now we have to program the processor. That's why we need this SDK. In this SDK we will use the C++ language to program the processor. Before open the SDK another important step is to export the design as hardware. So to do this we have to go to the top left corner and select the File then click on the Export, and Export Hardware...

In the newly opened popup, you need to press OK. But before that make sure that the option Include bitstream is checked. If it is not then checked it and press OK.

Now it is time to launch the SDK. So again go the File and click on the Launch SDK.

The launching SDK will ask for the Exported Location and the Workspace location. Leave it as default and press OK

Now it will start to launch the SDK.

This is the interface of the SDK. So next to all the work we will do here only. 

 

 

Setup and configure a new project for the server:

Now we have made a new project in this SDK. To do that we need to go to the File and then Application Project.

Now in the newly opened popup window, we have to put the new project name. Here we use the same name which we gave in the Vivado. And make sure that the language C++ is selected in the window. Then press Next.

Now select the Empty Application option (some time it is by default selected) and press Finish button.

Now in the Project Explorer panel, you have to go to design_1_wrapper_hw_platfoem_0 folder. Then drivers folder. Then examples. Finally HTTPServer. This folder contains the all required files.  

Now you have to copy all the files and folders inside the HTTPServer folder, except the CopyTheseToYourSDCard folder. 

Now go to the project folder that you made just some time ago. Go to the inside of that folder and find the src folder in it. 

Now paste the copied file and folders in that src folder.

It will ask for permission. Give permission to overwrite the existing files. Click Yes To All.

It should be copied successfully. But if you face any problem due to copy then maybe the files are not loaded perfectly. Go to the HTTPServer folder and open every file and press F5 to refresh. And again try to copy and paste the file. Hope this time you will be successful. After a successful copy, the folders look like this.

Now its time to configure the code for our router. So we have to go to the src folder of our new-made project and open the file HTTPServerConfig.h 

Here we have to find out the line where the SSID and the Password are defined. The lines are looks like this.

After finding out the likes, we have to replace the predefined SSID and Password with our router's SSID and Password. and save the file with pressing Ctrl + S.

 

 

Copy the given web files in SD card (Edit if you want):

After successfully configuring the program files, now it's time to work with the left folder named as CopyTheseToYourSDCard. Go to that folder from the example of HTTPSever. Then right click on the folder and go to the properties option. 

Now you have to copy the location of the folder from the properties window.

Now go to your computer and paste the location on the URL bar of the window like this and press enter.

It will open the content of that folder. Now select all the files and copy the file in the 16 GB micro SD card.

 

 

Setup the hardware:

For Hardware we need the Zybo FPGA board. The Micro SD card has to be inserted into the memory slot in the backside of the Zybo board.

Then we have to connect the PmodWiFi module with the JC port. (If you use a different port in the block diagram then use that port). and add the power cable with the USB port of your computer.

 

 

Connect the Putty software (Serial Communication):

Now our entire setup is complete. So its time to run the codes on the hardware. To do that first that we need is the software call putty. This tiny software supports the Serial, SSH, Rlogin, Telnet, Raw type of communication. In our project, we are going to use the Serial communication. So for the Serial Communication, we need the COM port number where the Zybo is connected. So you have to go to Computer Manager by the right click on the computer.  

This is the Computer Manager. Now we have to go Device Manager from the left panel of the window.

Then open the Ports(COM & LPT) option. It will show the connected COM ports. In my case, only one is here that is COM16. But if you find multiple then once open your Zybo from the USB  and replug it. Now you can find the new device. 

Now open the Putty software and select the Serial option.

Now put the COM16 (whatever in your case) and change the speed to 115200. This speed is fixed. the is the baud rate of the communication. And press the Open button.

It will open a black window like this. Don't do anything with this window.

 

 

Program with the bit file and run the project file:

Now we have to program the FPGA with the bit file which we generated in the Vivado software. To do this we have to click on the icon. The name of the icon is Program FPGA.

It will open a new popup window. Just click Program on that window.

It will take some time to upload the bit file on the FPGA. Wait until successfully upload the file. If it is successfully uploaded then the green LED on the Zybo will glow up.   

Now we have to program the Processor. The Bit file made the hardware interface between the processor Pmod and GPIOs. But now this Processor programming decides the working of the processor with that interface. So to that, we need to go to the project folder which is previously made by us. Then right click and go the tor Run As and then Launch on Hardware(System Debugger) option.  

 

 

Collect the IP from Putty and test the server:

With this run on hardware, the system will start to work. Now we have to move to the putty. Now you can find something is printing on the black window of the putty. This all things are written by the processor only. The processor returns the data to the computer via UART  serial communication. 

After a moment the processor returns the IP of the PmodWiFi that is given by the router. In our case that is 192.168.43.151.

Now its time to check the server is working or not. So we need to connect any computer or mobile device with the same router that we are using. And after connecting we have to open the browser. Here we are using the chrome. Finally, type the IP address that we got from the putty, and press enter. If you find this kind of page open that means your project is working. (This is the default landing page. In the Video You will find some different page. That is a customized one. you can edit the page but it is totally optional. If you want to edit the file and then copy to the Micro SD card)

 

 

Control the GPIO LEDs and Switches:

Now our server is working fine so its time to check the GPIOs are working or not. So click on the Read and Modify Board Pins link on the default landing page. and it will take you the GPIO control page, that looks like this.

By default the LEDs are LOW and the Switches are HIGH. If you want to toggle the Switch then change the switch status in hardware and press Refresh button on this page. it will show the latest switch status. if you can to control the LEDs then toggle them in the webpage from LOW to HIGH or HIGH to LOW and press Refresh button. It will turn on or off the LED on hardware.

 

 

Video Demonstration of the Project:

This the Screen Recording of the entire project from starting to end. Please check it out if you faced any problem in the entire project.

 

Conclusion:

This project is based on the basic interface of the FPGA and Processor. Here we made the interface in the FPGA and the processor is working on that interface. As if the interface is basically hardware dependent so the speed of the system is far far better than any other total software base system. Another thing is that the interface is made on the FPGA so we can change the entire interface or part of the interface with the change of the Verilog code or block design which we are using here. After testing if the design provides the satisfactory output then we can develop the design to an ASIC (Application Specific Integrated Circuit). This is the best feature of this FPGA based design.     

 

 

 

If this small effort can help in your any project then my effort will be successful. Please put feedback On our contact page.

If you faced any problem please send an email to admin@arghyabiswas.com. Thanks for being with us.

 

 




Thank You

Leave a Comment







View Previous Comment

No comment is available