Wednesday, August 28, 2019

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:



Sunday, July 21, 2019

rs485 to hm-trp-rs485 connections and baud rate setting

hm-trp rs 485  have mainly 4 pins vdd,A,B,Gnd.
usb to rs 485 have (which one i have with me) 3 pins A,B,Gnd.

after some serious struggle i find the how to connect and how to test.
for the gui there is small gui related software.









module is set fine.
after that remove the all connection and test. download gui related software from here


Tuesday, July 16, 2019

RFM95 with arduino uno Transmitter and receiver

Before starting to  test communicate with Rfm95 with Arduino uno download radio head library

radio head library for arduino uno with rfm
https://drive.google.com/open?id=1iBQWCOm13X3bdDKEcy0czGebPDz_PqQ-

RFM95 with arduino uno connections:



ARDUINO UNO
RFM 95
Gnd
Gnd
3.3v
3.3v
D5
reset
D2
DIO 0
D3
DIO1
D13(SCK)
SCK
D12(MISO)
MISO
D11(MOSI)
MOSI
D10(SS)
NSS



NOTE:
LEVEL SHIFTER FOR BETTER OUTPUT




sender side code:

#include <SPI.h>
#include <RH_RF95.h>

RH_RF95 rf95;

int led = 9;

void setup()
{
  pinMode(led, OUTPUT);   
  Serial.begin(9600);
  while (!Serial) ; // Wait for serial port to be available
  if (!rf95.init())
    Serial.println("init failed");

}

void loop()
{
  if (rf95.available())
  {
    // Should be a message for us now 
    uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
    uint8_t len = sizeof(buf);
    if (rf95.recv(buf, &len))
    {
      digitalWrite(led, HIGH);
     // RH_RF95::printBuffer("request: ", buf, len);
      Serial.print("got request: ");
      Serial.println((char*)buf);
   
//      Serial.print("RSSI: ");
//      Serial.println(rf95.lastRssi(), DEC);
   
   
      /***************************************/
      // Send a reply
      /***************************************/
    char data[32]="";
   int availableBytes = Serial.available();
   for(int i=0; i<availableBytes; i++)
    {   
        data[i]=Serial.read();
    }
      rf95.send(data, sizeof(data));
      rf95.waitPacketSent();
      Serial.println("Sent::");
      Serial.print(data);
       digitalWrite(led, LOW);
     
    }
    else
    {
      Serial.println("recv failed");
    }
  }
  delay(100);
}


receiver side code:

// rf95_client.pde

#include <SPI.h>
#include <RH_RF95.h>

int led = 9;

RH_RF95 rf95;


void setup()
{
  pinMode(led, OUTPUT); 

  Serial.begin(9600);
  while (!Serial) ; // Wait for serial port to be available
  if (!rf95.init())
    Serial.println("init failed");
}

void loop()
{
  rfm95_uart();

}

void rfm95_uart()
{
  Serial.println("Sending to rf95_server::");


  char data[32]="";
   int availableBytes = Serial.available();
   for(int i=0; i<availableBytes; i++)
    {   
        data[i]=Serial.read();
    }
      rf95.send(data, sizeof(data));
      rf95.waitPacketSent();
      Serial.println("Sent::");
      Serial.print(data);
       digitalWrite(led, LOW);

  uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
  uint8_t len = sizeof(buf);


  if (rf95.waitAvailableTimeout(3000))
  {
    // Should be a reply message for us now 
    if (rf95.recv(buf, &len))
   {
      Serial.print("got reply: ");
      Serial.println((char*)buf);
//      Serial.print("RSSI: ");
//      Serial.println(rf95.lastRssi(), DEC); 
    }

    else
    {
      Serial.println("recv failed");
    }
  }

  else
  {
    Serial.println("No reply, is rf95_server running?");
  }
  delay(400);


  }
out put:




after some modification::
send code:
#include <SPI.h>
#include <RH_RF95.h>

RH_RF95 rf95;

int led = 9;

void setup()
{
  pinMode(led, OUTPUT);   
  Serial.begin(9600);
  while (!Serial) ; // Wait for serial port to be available
  if (!rf95.init())
    Serial.println("init failed");
}

void loop()
{
  if (rf95.available())
  {
    // Should be a message for us now 
    uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
    uint8_t len = sizeof(buf);
    if (rf95.recv(buf, &len))
    {
      digitalWrite(led, HIGH);
     // RH_RF95::printBuffer("request: ", buf, len);
      Serial.print("got request: ");
      Serial.println((char*)buf);
      /***************************************/
      // Send a reply
      /***************************************/
    char data[32]="";
   int availableBytes = Serial.available();
   for(int i=0; i<availableBytes; i++)
    {   
        data[i]=Serial.read();
    }
      rf95.send(data, sizeof(data));
      rf95.waitPacketSent();
      Serial.println("Sent::");
      Serial.print(data);
       digitalWrite(led, LOW);
    }
    else
    {
      Serial.println("recv failed");
    }
  }
  delay(100);

}

Receiver code:
// rf95_client.pde

#include <SPI.h>
#include <RH_RF95.h>

int led = 9;

RH_RF95 rf95;


void setup()
{
  pinMode(led, OUTPUT); 

  Serial.begin(9600);
  while (!Serial) ; // Wait for serial port to be available
  if (!rf95.init())
    Serial.println("init failed");
}

void loop()
{
  rfm95_uart();

}

void rfm95_uart()
{
  //Serial.println("Sending to rf95_server::");
  char data[32]="";
   int availableBytes = Serial.available();
   for(int i=0; i<availableBytes; i++)
    {   
        data[i]=Serial.read();
    }
      rf95.send(data, sizeof(data));
      rf95.waitPacketSent();
      Serial.println("Sent::");
      Serial.print(data);
       digitalWrite(led, LOW);

  uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
  uint8_t len = sizeof(buf);
  if (rf95.waitAvailableTimeout(3000))
  {
    if (rf95.recv(buf, &len))
   {
      Serial.print("got reply: ");
      Serial.println((char*)buf);
    }

    else
    {
      Serial.println("recv failed");
    }
  }
  else
  {
    Serial.println("No reply, is rf95_server running?");
  }
  delay(400);
  }



Monday, July 15, 2019

Node MCU with WIFI scanning

/*
    This sketch demonstrates how to scan WiFi networks.
    The API is almost the same as with the WiFi Shield library,
    the most obvious difference being the different file you need to include:
*/
#include "ESP8266WiFi.h"

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

  // Set WiFi to station mode and disconnect from an AP if it was previously connected
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  delay(100);

  Serial.println("Setup done");
}

void loop() {
  Serial.println("scan start");

  // WiFi.scanNetworks will return the number of networks found
  int n = WiFi.scanNetworks();
  Serial.println("scan done");
  if (n == 0) {
    Serial.println("no networks found");
  } else {
    Serial.print(n);
    Serial.println(" networks found");
    for (int i = 0; i < n; ++i) {
      // Print SSID and RSSI for each network found
      Serial.print(i + 1);
      Serial.print(": ");
      Serial.print(WiFi.SSID(i));
      Serial.print(" (");
      Serial.print(WiFi.RSSI(i));
      Serial.print(")");
      Serial.println((WiFi.encryptionType(i) == ENC_TYPE_NONE) ? " " : "*");
      delay(10);
    }
  }
  Serial.println("");

  // Wait a bit before scanning again
  delay(5000);
}

output:


Sunday, July 14, 2019

SHT31 Temparature and Humidity sensor with arduino uno


#include <Arduino.h>
#include <Wire.h>
#include "Adafruit_SHT31.h"

Adafruit_SHT31 sht31 = Adafruit_SHT31();

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

  while (!Serial)
    delay(10);     // will pause Zero, Leonardo, etc until serial console opens

  Serial.println("SHT31 test");
  if (! sht31.begin(0x44)) {   // Set to 0x45 for alternate i2c addr
    Serial.println("Couldn't find SHT31");
    while (1) delay(1);
  }
}


void loop() {
  float t = sht31.readTemperature();
  float h = sht31.readHumidity();

  if (! isnan(t)) {  // check if 'is not a number'
    Serial.print("Temp *C = "); Serial.println(t);
  } else {
    Serial.println("Failed to read temperature");
  }
 
  if (! isnan(h)) {  // check if 'is not a number'
    Serial.print("Hum. % = "); Serial.println(h);
  } else {
    Serial.println("Failed to read humidity");
  }
  Serial.println();
  delay(1000);
}

output::

python class topic video