Jump to content

VerticalFarmingStudent

Members
  • Posts

    6
  • Joined

  • Last visited

Posts posted by VerticalFarmingStudent

  1. Hi, 

    I am figuring out how implement artificial intelligence into the zybo board. The artificial intelligence is about studying different types of ill plant and determine if the plant is sick or healthy. As the starter of FPGA and no idea of AI, I do not know how to start research. 

    Here are what I have found out so far:

    I searched the Zybo AI, but there is no relevent information except for "Under Construction"

    image.thumb.png.8195b9d7125bbc992e8a24f555fa1380.png

     

    Later, I found that Zybo Z720 can support reVISION SDSoC Platform, which "make it possible to do FPGA accelerated video processing using openCV functions in an all C/C++ development environment". I think that will be the direction for my AI project.

    But I do not see some useful tutorial, and I dont know how to start as well. 

    Is there any tutorial on how the Zybo AI and reVISION SDSoC Platform? So I can try and learn

     

    Thanks

     

     

     

  2. Here is the code for Vitis. For Vivado  just add pmod esp32 into your block design.

    #include "xparameters.h"
    #include "xil_printf.h"
    #include "sleep.h"
    #include "stdio.h"
    #include "xtime_l.h"
    #include "stdlib.h"
    #include "string.h"
    #include "xgpiops.h"
    
    
    extern "C"{
    
    
    #include "PmodESP32.h"
    }
    /******************************************************************************/
    /*                                                                            */
    /* Defines  																  */
    /*                                                                            */
    /******************************************************************************/
    
    
    #ifdef __MICROBLAZE__
    #define HOST_UART_DEVICE_ID XPAR_AXI_UARTLITE_0_BASEADDR
    #define HostUart XUartLite
    #define HostUart_Config XUartLite_Config
    #define HostUart_CfgInitialize XUartLite_CfgInitialize
    #define HostUart_LookupConfig XUartLite_LookupConfig
    #define HostUart_Recv XUartLite_Recv
    #define HostUartConfig_GetBaseAddr(CfgPtr) (CfgPtr->RegBaseAddr)
    #include "xuartlite.h"
    #include "xil_cache.h"
    #else
    #define HOST_UART_DEVICE_ID XPAR_PS7_UART_1_DEVICE_ID
    #define HostUart XUartPs
    #define HostUart_Config XUartPs_Config
    #define HostUart_CfgInitialize XUartPs_CfgInitialize
    #define HostUart_LookupConfig XUartPs_LookupConfig
    #define HostUart_Recv XUartPs_Recv
    #define HostUartConfig_GetBaseAddr(CfgPtr) (CfgPtr->BaseAddress)
    #include "xuartps.h"
    #endif
    
    #define PMODESP32_UART_BASEADDR XPAR_PMODESP32_0_AXI_LITE_UART_BASEADDR
    #define PMODESP32_GPIO_BASEADDR XPAR_PMODESP32_0_AXI_LITE_GPIO_BASEADDR
    #define BLOCK_SIZE 40
    /******************************************************************************/
    /*																			  */
    /* Function Declarations         											  */
    /*                                                                            */
    /******************************************************************************/
    void EnableCaches();
    void DisableCaches();
    void startup();
    void receiveData(XTime time);
    void receiveData2(XTime time);
    void setWifiMode(void);
    void connectWifi(void);
    void establishConnection(void);
    void cipsend(void);
    /******************************************************************************/
    /*                                                                            */
    /* Variables 																  */
    /*                                                                            */
    /******************************************************************************/
    
    HostUart myHostUart;
    
    XTime TimeStart;
    XTime TimeEnd;
    PmodESP32 ESP32;
    XGpioPs_Config *ConfigPtr;
    XGpioPs output;
    
    
    
    
    int countdown =60;
    
    
    
    int main() {
       EnableCaches();
       startup();
    
       setWifiMode(); // Set Mode
       xil_printf("Init Started\n\r");
       connectWifi();
       xil_printf("Wifi Done\n\r");
    
      // sleep(2);
    
       XTime_GetTime(&TimeStart);
       TimeEnd = TimeStart + ((XTime)COUNTS_PER_SECOND);
    
       while (true){
    
       establishConnection();
    
       cipsend();
       }
    
       DisableCaches();
       return 0;
    }
    
    void startup(){
    
    	   //Init ESP32
    	   HostUart_Config *CfgPtr;
    	   ESP32_Initialize(&ESP32, PMODESP32_UART_BASEADDR, PMODESP32_GPIO_BASEADDR);
    	   CfgPtr = HostUart_LookupConfig(HOST_UART_DEVICE_ID);
    	   HostUart_CfgInitialize(&myHostUart, CfgPtr, HostUartConfig_GetBaseAddr(CfgPtr));
      
      	   // Init GPIO
    	   ConfigPtr = XGpioPs_LookupConfig(XPAR_PS7_GPIO_0_DEVICE_ID);
    	   XGpioPs_CfgInitialize(&output, ConfigPtr, ConfigPtr->BaseAddr);
    	   XGpioPs_SetDirectionPin(&output, 13, 1); //Pin 1 output
    	   XGpioPs_SetOutputEnablePin(&output, 13,1);
    	   XGpioPs_SetDirectionPin(&output, 10, 1); //Pin 2 output
    	   XGpioPs_SetOutputEnablePin(&output, 10, 1);
    
    /* 
    Write your code here to initialise GPIO
    */ 
    
    }
    
    void receiveData(XTime time){
    	XTime tEnd, tCur;
    	u8 recv_buffer=0;
    	u32 num_received=0;
    
    
    	XTime_GetTime(&tCur);
    	tEnd  = tCur + (time * COUNTS_PER_SECOND);
    	do
        {
    		num_received = ESP32_Recv(&ESP32, &recv_buffer,1);
    				if(num_received >0){
    					num_received = ESP32_Recv(&ESP32, &recv_buffer,1);
    					xil_printf("%c", recv_buffer);
    				}
    		if(tCur == tCur + COUNTS_PER_SECOND){
    			countdown = countdown -1;
    		}
    		else
    			XTime_GetTime(&tCur);
        } while (tCur < tEnd);
    
    }
    
    
    
    
    void receiveData2(XTime time){
        XTime tEnd, tCur;
        u8 recv_buffer=0;
        u32 num_received=0;
    
        int i=0;
        int max_index = BLOCK_SIZE-1;
    
    
        int *ptr= (int *) malloc(sizeof(int)*BLOCK_SIZE);
      
    
        if(ptr==NULL)
        {
            perror("some error");
            //return 1;
        }
    
        XTime_GetTime(&tCur);
        tEnd  = tCur + (time * COUNTS_PER_SECOND);
        do
        {
            num_received = ESP32_Recv(&ESP32, &recv_buffer,1);
                    if(num_received >0){
                        num_received = ESP32_Recv(&ESP32, &recv_buffer,1);
    
                            if(i > max_index)
                            {
                                ptr=(int *)realloc(ptr, (max_index+1 + BLOCK_SIZE)*sizeof(int));
                                
                                if(ptr == NULL)
                                {
                                    perror("insufficient memory!");
                                    break;
                                }
                                printf("\nReallocated!");
                                max_index += BLOCK_SIZE;
                            }
                            ptr[i]=recv_buffer;
                            i++;
    
                        
    
                    }
            if(tCur == tCur + COUNTS_PER_SECOND){
               countdown = countdown -1;
            }
            else
                XTime_GetTime(&tCur);
        } while (tCur < tEnd);
    
    
        xil_printf("Data %d: %c",i ,ptr[45]);
    
    
        if (ptr[45]=='1'){
        	xil_printf("LED On");
        	XGpioPs_WritePin(&output, 13, 0);
        }else if (ptr[45]=='0')
        {
        	xil_printf("LED Off");
        	XGpioPs_WritePin(&output, 13, 1);
        } else {
        	xil_printf("LED On");
        	XGpioPs_WritePin(&output, 13, 0);
        }
    
    
        free(ptr); // Clear the memory to prevent "ptr==null"
    
    }
    
    void setWifiMode(void){
    	u8 tx[]="AT+CWMODE=3\r\n";// buffer
    	u32 num = strlen((char *) tx);// convert buffer to length
    	xil_printf((char *) tx); // Display AT+CWMODE Function
    	ESP32_SendBuffer(&ESP32, tx, num);// Send AT+CWMODE Function
    	usleep(100);
    	receiveData(3); // Response from server
    }
    
    void connectWifi(void){
    
    	
    	u8 tx[] = "AT+CWJAP=\"<Wifi SSID>\",\"<Password>\"\r\n";
    	
    	u32 num = strlen((char *) tx); // convert buffer to length
    	xil_printf((char *) tx); // Display AT+CWJAP Function
    	ESP32_SendBuffer(&ESP32, tx, num);// Send AT+CWJAP Function
    	usleep(100);
    	receiveData(30); // Response from server
    }
    
    void establishConnection(void){
    	u8 tx[] = "AT+CIPSTART=\"TCP\",\"api.thingspeak.com\",80\r\n"; //buffer
    	u32 num = strlen((char *) tx); // convert buffer to length
    	xil_printf((char *) tx); // Display AT+CIPSTART Function
    	ESP32_SendBuffer(&ESP32, tx, num); // Send AT+CIPSTART Function
    	receiveData(10); // Receive information from server
    }
    
    void cipsend(void){
    	u8 command[150]; //GET Function
    	u8 finalcmd[50]; //AT+CIPSEND
    
    
    
    
    	sprintf((char*)command, "GET https://api.thingspeak.com/channels/<channels id> /fields/1/last?key=<channel's key>\r\n"); // convert the GET Function to char form
           // From here, you can acquire the latest Thingspeak's entry data in the +IPD format. 
    
    
    	u32 length = strlen((char*)command); // count how many bits  for GET function
    
    		sprintf((char*)finalcmd, "AT+CIPSEND=%d\r\n", (int)length); // convert the AT+CIPSEND Command to char form
    		u32 cmdlength =strlen((char*)finalcmd); // count how many bits  for AT+CIPSEND function
    
    
    	xil_printf("Length %d\r\n", length); // Display how many bits does the length have
    	xil_printf((char *)finalcmd); // Display AT+CIPSEND= "finalcmd"
    	ESP32_SendBuffer(&ESP32, finalcmd, cmdlength); // Send AT+CIPSEND command to server
    	sleep(1);
    	xil_printf((char *)command); // Display GET+"update link"
    	ESP32_SendBuffer(&ESP32, command, length); // Send GET+"update link" to server
    
    
    	receiveData2(10); // Receive the Json parsed data and control the relay...
    
    
    }
    
    void EnableCaches() {
    #ifdef __MICROBLAZE__
    #ifdef XPAR_MICROBLAZE_USE_ICACHE
       Xil_ICacheEnable();
    #endif
    #ifdef XPAR_MICROBLAZE_USE_DCACHE
       Xil_DCacheEnable();
    #endif
    #endif
    }
    
    void DisableCaches() {
    #ifdef __MICROBLAZE__
    #ifdef XPAR_MICROBLAZE_USE_ICACHE
       Xil_ICacheDisable();
    #endif
    #ifdef XPAR_MICROBLAZE_USE_DCACHE
       Xil_DCacheDisable();
    #endif
    #endif
    }

     

  3. Hi, 

    I am using Zybo Z720 and Pmod ESP32 to explore on IoT control.

    I used several AT commands like "AT+CWMODE", "AT+CWJAP", "AT+CIPSTART", "AT+CIPSEND" and "GET <links>" to receive the last entry data from the Thingspeak. Here is the response I received from the Vitis Serial Terminal: 

    image.png.c535a7439c3b9252117e02fbe29f8e2d.png

    Now, I want to make use of this data from +IPD response and control the GPIO and relay (relay connected to the GPIO pin). 

    I know Arduino has sth like Serial.find() function and help me with extracting serial terminal's IPD response. I just wonder Xilinx Vitis has the same thing as Arduino. 

    The Arduino used the code as following:

    if(Serial.available()>1)
    
    { String response = Serial.read();
     Serial.println(response); }

    The Vitis code is attached below

    Thanks in advance

     

     

    IoTControl_New.txt

×
×
  • Create New...