Thursday, August 29, 2019

global key word usage in python

"""
Created on Thu Aug 29 16:29:56 2019
@author: anil durgam
date:29-08-2019
"""
f = 101;
print(f)
# Global vs.local variables in functions
def someFunction():
  global f
  print(f)
  f = "changing global variable"
someFunction()
print(f)


output:
101
101

changing global variable

declaration and re-declaration of the variable


"""
Created on Thu Aug 29 16:29:56 2019
@author: anil durgam
date:29-08-2019
"""
# Declare a variable and initialize it
f = 0
print(f)
# re-declaring the variable works
f = 'guru99'
print(f)

output:
0
guru99





example 3:


"""
Created on Thu Aug 29 16:29:56 2019
@author: anil durgam
date:29-08-2019
"""
# Declare a variable and initialize it
f = 101
print(f)
# Global vs. local variables in functions
def someFunction():
# global f
    f = 'I am learning Python'
    print(f)
someFunction()
print(f)

output:
101
I am learning Python

101

defination in python

"""
Created on Thu Aug 29 16:29:56 2019
@author: anil durgam
date:29-08-2019
"""
def main():
    print("hello world\n");
   
if __name__ =="__main__":
    main()
   
print("testing")

Wednesday, August 28, 2019

NUMBER SERIES BASIC TESTING

/**************************************************
** written by :ANIL DURGAM
** NUMBER SERIES TESTING VER 1.0
**DATE:29-08-2019
**************************************************/



#include <stdio.h>
#include <stdlib.h>

int main()
{
    int first_num,sec_num,third_num,fourth_num,next_number;
    int first_diff,second_diff,third_diff,fourth_diff;
    printf("please enter the FOUR number after every number hit ENTER\n");
    scanf("%d%d%d%d",&first_num,&sec_num,&third_num,&fourth_num);
    printf("first number=%d,\nsecond number=%d,\nthird number=%d,\nfourth number=%d\n",first_num,sec_num,third_num,fourth_num);
    first_diff=sec_num-first_num;
    second_diff=third_num-sec_num;
    third_diff=fourth_num-third_num;
    if(first_diff==second_diff)
    {
        if(third_diff==second_diff)
        {
            next_number=first_diff+fourth_num;
            printf("next number is ==%d\n",next_number);
        }
        else
        {
            printf("third and fourth number is not matching\n");
        }
    }
    else{

        printf("number not matching\n");
    }

    return 0;
}


OUTPUT:
please enter the FOUR number after every number hit ENTER
12
24
36
48
first number=12,
second number=24,
third number=36,
fourth number=48


next number is ==60

format type in c language

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a=789,b=1234;
    printf("a=%3d, b=%4d", a, b);
    return 0;
}

output:
a=789,b=1234

input is
a=9,b=4;
a=  9, b=   4


"\r" carriage return in c programming language

#include <stdio.h>
#include <stdlib.h>

int main()
{
    printf("Hello \rworld!\n");
    return 0;
}


output :
world

because of \r in the printf statement....so after \r the statements  will be executed

HM-TRLR-D-868 WITH ARDUINO COMMUNICATION



THIS is the simple connection between usb ttl  and arduino uno




Monday, July 29, 2019

infinite times execution using functions


#include <stdio.h>

void proc_task1();
void proc_task2();
void proc_task3();


int main()
{
    printf("\r\nit is inside main\r\n\n");
    proc_task1();
   

    return 0;
}

//proc_task1
void proc_task1()
{
    printf("\r\nit is inside proc_task1\r\n\n");
    proc_task2();
}

//proc_task2
void proc_task2()
{
    printf("\r\nit is inside proc_task2\r\n\n");
    proc_task3();
   
}

//proc_task3
void proc_task3()
{
    printf("\r\nit is inside proc_task3\r\n\n");
    proc_task1();
   
}





read the data from UART in QUECTEL MC60

/*****************************************************************************
*  Copyright Statement:
*  --------------------
*  This software is protected by Copyright and the information contained
*  herein is confidential. The software may not be copied and the information
*  contained herein may not be used or disclosed except with the written
*  permission of Quectel Co., Ltd. 2013
*
*****************************************************************************/
/*****************************************************************************
 *
 * Filename:
 * ---------
 *   example_gpio.c
 *
 * Project:
 * --------
 *   OpenCPU
 *
 * Description:
 * ------------
 *   This example demonstrates how to program a GPIO pin in OpenCPU.
 *   This example choose PINNAME_STATUS pin as GPIO.
 *
 *   All debug information will be output through DEBUG port.
 *
 *   The "Enum_PinName" enumeration defines all the GPIO pins.
 *
 * Usage:
 * ------
 *   Compile & Run:
 *
 *     Set "C_PREDEF=-D __EXAMPLE_GPIO__" in gcc_makefile file. And compile the
 *     app using "make clean/new".
 *     Download image bin to module to run.
 *
 * Author:
 * -------
 * -------
 *
 *============================================================================
 *             HISTORY
 *----------------------------------------------------------------------------
 *
 ****************************************************************************/
#ifdef __UART_TASK__
#include "ql_trace.h"
#include "ql_system.h"
#include "ql_gpio.h"
#include "ql_stdlib.h"
#include "ql_error.h"
#include "ql_uart.h"
#include "ril.h"
#include "ril_util.h"
#include "ql_type.h"
#include "ql_trace.h"
#include "ql_stdlib.h"
#include "ril_gps.h"
#include "ql_gnss.h"
#include "Nema_pro.h"



#define DEBUG_ENABLE 1
#if DEBUG_ENABLE > 0
#define DEBUG_PORT  UART_PORT1
#define DBG_BUF_LEN   512
static char DBG_BUFFER[DBG_BUF_LEN];
#define APP_DEBUG(FORMAT,...) {\
    Ql_memset(DBG_BUFFER, 0, DBG_BUF_LEN);\
    Ql_sprintf(DBG_BUFFER,FORMAT,##__VA_ARGS__); \
    if (UART_PORT2 == (DEBUG_PORT)) \
    {\
        Ql_Debug_Trace(DBG_BUFFER);\
    } else {\
        Ql_UART_Write((Enum_SerialPort)(DEBUG_PORT), (u8*)(DBG_BUFFER), Ql_strlen((const char *)(DBG_BUFFER)));\
    }\
}
#else
#define APP_DEBUG(FORMAT,...)
#endif

#define SERIAL_RX_BUFFER_LEN  2048
static u8 m_RxBuf_Uart[SERIAL_RX_BUFFER_LEN];


void proc_task1(s32 TaskId);

void proc_task2(s32 TaskId);
void proc_task3();


s32 Ql_UART_Write(Enum_SerialPort port, u8* data, u32 writeLen );


static s32 ReadSerialPort(Enum_SerialPort port, /*[out]*/u8* pBuffer, /*[in]*/u32 bufLen)
{
    s32 rdLen = 0;
    s32 rdTotalLen = 0;
    if (NULL == pBuffer || 0 == bufLen)
    {
        return -1;
    }
    Ql_memset(pBuffer, 0x0, bufLen);
    while (1)
    {
        rdLen = Ql_UART_Read(port, pBuffer + rdTotalLen, bufLen - rdTotalLen);
        if (rdLen <= 0)  // All data is read out, or Serial Port Error!
        {
            break;
        }
        rdTotalLen += rdLen;
        // Continue to read...
    }
    if (rdLen < 0) // Serial Port Error!
    {
        APP_DEBUG("<--Fail to read from port[%d]-->\r\n", port);
        return -99;
    }
    return rdTotalLen;
}


static void CallBack_UART_Hdlr(Enum_SerialPort port, Enum_UARTEventType msg, bool level, void* customizedPara)
{
s32 iRet = 0;
   //APP_DEBUG("\r\n it is inside callback_UART Handler\r\n");
   switch (msg)
   {
    case EVENT_UART_READY_TO_READ:
   {
   char* p = NULL;
   s32 totalBytes = ReadSerialPort(port, m_RxBuf_Uart, sizeof(m_RxBuf_Uart));
   if (totalBytes <= 0)
   {
APP_DEBUG("totalBytes = %d.\r\n",totalBytes);
   break;
   }

   APP_DEBUG("given i/p : %s\r\n",m_RxBuf_Uart);

 
   proc_task3();
 
   //APP_DEBUG("Invalid command...\r\n");
   }break;

   case EVENT_UART_READY_TO_WRITE:
   {
   //...
   }break;

   default:
   break;
   }
   
}


/************************************************************************/
/* The entrance for this example application                            */
/************************************************************************/
void proc_main_task(s32 taskId)
{
    s32 ret;
    ST_MSG msg;

    // Register & open UART port
    ret = Ql_UART_Register(UART_PORT1, CallBack_UART_Hdlr, NULL);
    if (ret < QL_RET_OK)
    {
        Ql_Debug_Trace("Fail to register serial port[%d], ret=%d\r\n", UART_PORT1, ret);
    }
    ret = Ql_UART_Open(UART_PORT1, 115200, FC_NONE);
    if (ret < QL_RET_OK)
    {
        Ql_Debug_Trace("Fail to open serial port[%d], ret=%d\r\n", UART_PORT1, ret);
    }
   
    APP_DEBUG("\r\n<-- OpenCPU: UART TASK EXECUTION-->\r\n");

   
     proc_task1(taskId);

    // Start message loop of this task
    while (TRUE)
    {
        Ql_OS_GetMessage(&msg);
        switch(msg.message)
        {
        case MSG_ID_USER_START:
            break;
        default:
            break;
        }
    }
}



//SUB TASK 1
void proc_task1(s32 TaskId)
{

APP_DEBUG("\r\n<-- IT IS INSIDE PROC_TASK1-->\r\n");
Ql_UART_Write(UART_PORT1, m_RxBuf_Uart, sizeof(m_RxBuf_Uart));
proc_task2(TaskId);

}

//SUBTASK2
void proc_task2(s32 TaskId)
{

APP_DEBUG("\r\n<-- IT IS INSIDE PROC_TASK2-->\r\n");
Ql_UART_Write(UART_PORT1, m_RxBuf_Uart, sizeof(m_RxBuf_Uart));

}

void proc_task3()
{

APP_DEBUG("\r\n<-- IT IS INSIDE PROC_TASK3-->\r\n");
Ql_UART_Write(UART_PORT1, m_RxBuf_Uart, sizeof(m_RxBuf_Uart));

}




#endif //__EXAMPLE_GPIO__



Saturday, July 27, 2019

variable declaration in makefiles



printing variable in makefile

@echo the program for compilation is $(C_PREDEF)
@echo $(C_PREDEF)


printing symbols in makefiles
@echo ----------------------------------------------------
@echo ***********************************

Thursday, July 25, 2019

esp32 wrover kit lcd test

/***************************************************
  This is our GFX example for the Adafruit ILI9341 Breakout and Shield
  ----> http://www.adafruit.com/products/1651

  Check out the links above for our tutorials and wiring diagrams
  These displays use SPI to communicate, 4 or 5 pins are required to
  interface (RST is optional)
  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.
  MIT license, all text above must be included in any redistribution
 ****************************************************/


#include "SPI.h"
#include "Adafruit_GFX.h"
#include "WROVER_KIT_LCD.h"

#define min(X, Y) (((X) < (Y)) ? (X) : (Y))

WROVER_KIT_LCD tft;

void setup() {
  Serial.begin(115200);

  tft.begin();
  tft.setRotation(1);

  uint8_t x = 0;
  uint32_t id = tft.readId();
  if(id){
      Serial.println("======= WROVER ST7789V Display Test ========");
  } else {
      Serial.println("======= WROVER ILI9341 Display Test ========");
  }
  Serial.println("============================================");
  Serial.printf("Display ID:      0x%06X\n", id);

  x = tft.readcommand8(WROVER_RDDST);
  Serial.print("Status:          0x"); Serial.println(x, HEX);
  x = tft.readcommand8(WROVER_RDDPM);
  Serial.print("Power Mode:      0x"); Serial.println(x, HEX);
  x = tft.readcommand8(WROVER_RDDMADCTL);
  Serial.print("MADCTL Mode:     0x"); Serial.println(x, HEX);
  x = tft.readcommand8(WROVER_RDDCOLMOD);
  Serial.print("Pixel Format:    0x"); Serial.println(x, HEX);
  x = tft.readcommand8(WROVER_RDDIM);
  Serial.print("Image Format:    0x"); Serial.println(x, HEX);
  x = tft.readcommand8(WROVER_RDDSDR);
  Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX);
 
  Serial.println(F("Benchmark                Time (microseconds)"));
  delay(10);
  Serial.print(F("Screen fill              "));
  Serial.println(testFillScreen());
  delay(500);

  Serial.print(F("Text                     "));
  Serial.println(testText());
  delay(3000);

  Serial.print(F("Lines                    "));
  Serial.println(testLines(WROVER_CYAN));
  delay(500);

  Serial.print(F("Horiz/Vert Lines         "));
  Serial.println(testFastLines(WROVER_RED, WROVER_BLUE));
  delay(500);

  Serial.print(F("Rectangles (outline)     "));
  Serial.println(testRects(WROVER_GREEN));
  delay(500);

  Serial.print(F("Rectangles (filled)      "));
  Serial.println(testFilledRects(WROVER_YELLOW, WROVER_MAGENTA));
  delay(500);

  Serial.print(F("Circles (filled)         "));
  Serial.println(testFilledCircles(10, WROVER_MAGENTA));

  Serial.print(F("Circles (outline)        "));
  Serial.println(testCircles(10, WROVER_WHITE));
  delay(500);

  Serial.print(F("Triangles (outline)      "));
  Serial.println(testTriangles());
  delay(500);

  Serial.print(F("Triangles (filled)       "));
  Serial.println(testFilledTriangles());
  delay(500);

  Serial.print(F("Rounded rects (outline)  "));
  Serial.println(testRoundRects());
  delay(500);

  Serial.print(F("Rounded rects (filled)   "));
  Serial.println(testFilledRoundRects());
  delay(500);

  Serial.println(F("Done!"));

}


void loop(void) {
  for(uint8_t rotation=0; rotation<4; rotation++) {
    tft.setRotation(rotation);
    testText();
    delay(1000);
  }
}

unsigned long testFillScreen() {
  unsigned long start = micros();
  tft.fillScreen(WROVER_BLACK);
  yield();
  tft.fillScreen(WROVER_RED);
  yield();
  tft.fillScreen(WROVER_GREEN);
  yield();
  tft.fillScreen(WROVER_BLUE);
  yield();
  tft.fillScreen(WROVER_BLACK);
  yield();
  return micros() - start;
}

unsigned long testText() {
  tft.fillScreen(WROVER_BLACK);
  unsigned long start = micros();
  tft.setCursor(0, 0);
  tft.setTextColor(WROVER_WHITE);  tft.setTextSize(1);
  tft.println("Hello World!");
  tft.setTextColor(WROVER_YELLOW); tft.setTextSize(2);
  tft.println(1234.56);
  tft.setTextColor(WROVER_RED);    tft.setTextSize(3);
  tft.println(0xDEADBEEF, HEX);
  tft.println();
  tft.setTextColor(WROVER_GREEN);
  tft.setTextSize(5);
  tft.println("ANIL.DURGAM");
  tft.setTextSize(2);
  tft.println("Embedded systems");
  tft.setTextSize(1);
  tft.println("programming is easy");
  tft.println("once you start working");
  tft.println("you will understand");
  tft.println("start with basics");
  tft.println("of the arduino");
  tft.println("become thopu");
  tft.println("durgam.anil1@gmail.com");
  return micros() - start;
}

unsigned long testLines(uint16_t color) {
  unsigned long start, t;
  int           x1, y1, x2, y2,
                w = tft.width(),
                h = tft.height();

  tft.fillScreen(WROVER_BLACK);
  yield();
 
  x1 = y1 = 0;
  y2    = h - 1;
  start = micros();
  for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  x2    = w - 1;
  for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  t     = micros() - start; // fillScreen doesn't count against timing

  yield();
  tft.fillScreen(WROVER_BLACK);
  yield();

  x1    = w - 1;
  y1    = 0;
  y2    = h - 1;
  start = micros();
  for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  x2    = 0;
  for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  t    += micros() - start;

  yield();
  tft.fillScreen(WROVER_BLACK);
  yield();

  x1    = 0;
  y1    = h - 1;
  y2    = 0;
  start = micros();
  for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  x2    = w - 1;
  for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  t    += micros() - start;

  yield();
  tft.fillScreen(WROVER_BLACK);
  yield();

  x1    = w - 1;
  y1    = h - 1;
  y2    = 0;
  start = micros();
  for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  x2    = 0;
  for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);

  yield();
  return micros() - start;
}

unsigned long testFastLines(uint16_t color1, uint16_t color2) {
  unsigned long start;
  int           x, y, w = tft.width(), h = tft.height();

  tft.fillScreen(WROVER_BLACK);
  start = micros();
  for(y=0; y<h; y+=5) tft.drawFastHLine(0, y, w, color1);
  for(x=0; x<w; x+=5) tft.drawFastVLine(x, 0, h, color2);

  return micros() - start;
}

unsigned long testRects(uint16_t color) {
  unsigned long start;
  int           n, i, i2,
                cx = tft.width()  / 2,
                cy = tft.height() / 2;

  tft.fillScreen(WROVER_BLACK);
  n     = min(tft.width(), tft.height());
  start = micros();
  for(i=2; i<n; i+=6) {
    i2 = i / 2;
    tft.drawRect(cx-i2, cy-i2, i, i, color);
  }

  return micros() - start;
}

unsigned long testFilledRects(uint16_t color1, uint16_t color2) {
  unsigned long start, t = 0;
  int           n, i, i2,
                cx = tft.width()  / 2 - 1,
                cy = tft.height() / 2 - 1;

  tft.fillScreen(WROVER_BLACK);
  n = min(tft.width(), tft.height());
  for(i=n; i>0; i-=6) {
    i2    = i / 2;
    start = micros();
    tft.fillRect(cx-i2, cy-i2, i, i, color1);
    t    += micros() - start;
    // Outlines are not included in timing results
    tft.drawRect(cx-i2, cy-i2, i, i, color2);
    yield();
  }

  return t;
}

unsigned long testFilledCircles(uint8_t radius, uint16_t color) {
  unsigned long start;
  int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2;

  tft.fillScreen(WROVER_BLACK);
  start = micros();
  for(x=radius; x<w; x+=r2) {
    for(y=radius; y<h; y+=r2) {
      tft.fillCircle(x, y, radius, color);
    }
  }

  return micros() - start;
}

unsigned long testCircles(uint8_t radius, uint16_t color) {
  unsigned long start;
  int           x, y, r2 = radius * 2,
                w = tft.width()  + radius,
                h = tft.height() + radius;

  // Screen is not cleared for this one -- this is
  // intentional and does not affect the reported time.
  start = micros();
  for(x=0; x<w; x+=r2) {
    for(y=0; y<h; y+=r2) {
      tft.drawCircle(x, y, radius, color);
    }
  }

  return micros() - start;
}

unsigned long testTriangles() {
  unsigned long start;
  int           n, i, cx = tft.width()  / 2 - 1,
                      cy = tft.height() / 2 - 1;

  tft.fillScreen(WROVER_BLACK);
  n     = min(cx, cy);
  start = micros();
  for(i=0; i<n; i+=5) {
    tft.drawTriangle(
      cx    , cy - i, // peak
      cx - i, cy + i, // bottom left
      cx + i, cy + i, // bottom right
      tft.color565(i, i, i));
  }

  return micros() - start;
}

unsigned long testFilledTriangles() {
  unsigned long start, t = 0;
  int           i, cx = tft.width()  / 2 - 1,
                   cy = tft.height() / 2 - 1;

  tft.fillScreen(WROVER_BLACK);
  start = micros();
  for(i=min(cx,cy); i>10; i-=5) {
    start = micros();
    tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
      tft.color565(0, i*10, i*10));
    t += micros() - start;
    tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
      tft.color565(i*10, i*10, 0));
    yield();
  }

  return t;
}

unsigned long testRoundRects() {
  unsigned long start;
  int           w, i, i2,
                cx = tft.width()  / 2 - 1,
                cy = tft.height() / 2 - 1;

  tft.fillScreen(WROVER_BLACK);
  w     = min(tft.width(), tft.height());
  start = micros();
  for(i=0; i<w; i+=6) {
    i2 = i / 2;
    tft.drawRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(i, 0, 0));
  }

  return micros() - start;
}

unsigned long testFilledRoundRects() {
  unsigned long start;
  int           i, i2,
                cx = tft.width()  / 2 - 1,
                cy = tft.height() / 2 - 1;

  tft.fillScreen(WROVER_BLACK);
  start = micros();
  for(i=min(tft.width(), tft.height()); i>20; i-=6) {
    i2 = i / 2;
    tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(0, i, 0));
    yield();
  }

  return micros() - start;
}

output:



python class topic video