Thursday, 16 December 2021

nrf24L01 data receive and compare with string

 #include <SPI.h>

#include <nRF24L01.h>

#include <RF24.h>


//create an RF24 object

RF24 radio(14, 33);  // CE, CSN


String out, chk="welcome" , red="red" , yellow="yellow";

//address through which two modules communicate.

const byte address[6] = "00001";

const char text2[] = "Hello World";

void setup()

{

  while (!Serial);

    Serial.begin(9600);

  

  radio.begin();

  

  //set the address

  radio.openReadingPipe(0, address);

  

  //Set module as receiver

  radio.startListening();

}


void loop()

{

  //Read the data if available in buffer

  if (radio.available())

  {

    char text[32] = {0};

    radio.read(&text, sizeof(text));

   

    Serial.println(text);

    out=String(text);

    if(out==chk){Serial.println("equal");}

    if(out==red){Serial.println("red colour");}

    if(out==yellow){Serial.println("yellow");}

  }

}

string and char array compare

 String my = "this is red light i need space" , si, read1 , tem="t";

char text, tm="t";

int len;

void setup() {

  // put your setup code here, to run once:

  Serial.begin(9600);

  Serial.println();

  char buf[32] = "this is red light i need space";


  Serial.print("Char array: ");

  Serial.println(buf);

  String s = String(buf);

  Serial.print("String: ");

  Serial.println(s);

  if (my == s) {

    Serial.println("equal ");

  }

}

void loop() {

  if (Serial.available() > 0) {

    read1 = Serial.readString();

    text = read1.charAt(2);

      Serial.println(text);

     if(text==tm){Serial.println("temp");}

    len = read1.toInt();


    Serial.println(len);

    if (len == 25000) {

      Serial.println("equal");

    }

  }

}

Monday, 13 December 2021

store the double and Float value in I2C eeprom using arduino

 


#include <Wire.h>

#define address 0x50

char va="as";

int val = 100;

byte data;

double lati1 =32.45678;

String lati = String(lati1);  

String myString = "Hello World";


unsigned int len = myString.length() + 1;



void setup()

 Wire.begin();

 Serial.begin(9600);

 delay(1000); 

byte buff[len];

 //WRITE!!!!*******************************

 Wire.beginTransmission(address);

 Wire.write(0x00);      //First Word Address

 Wire.write(0x00);      //Second Word Address


myString.getBytes(buff, len);


for (int i = 0; i < len; i++)

{  Wire.write(buff[i]);      //Write an 'A'

  Serial.println(buff[i]);

}



 delay(10);


 Wire.endTransmission();

 delay(10);


 //READ!!!!*********************************

 Wire.beginTransmission(address);

 Wire.write(0x00);      //First Word Address

 Wire.write(0x00);      //Second Word Address

 Wire.endTransmission();

 delay(10);


 Wire.requestFrom(address, 1);

 delay(10);

 data = Wire.read();

 Serial.write(data);      //Read the data and print to Serial port

 Serial.println();

 delay(10);

}


void loop()

{

}

string to byte

 String myString = "arduino this was very difficult problem i just solved that ";

 unsigned int len = myString.length() + 1;

 


void setup() {

 Serial.begin(9600);

 char buff[len];

 myString.getBytes(buff, len);

  for (int i = 0; i < len; i++)

{      

  Serial.println(buff[i]);

}

 

}


void loop() {


}


Storing the long number(16bits / 32bits) in external flash of arduino or STM32 .

 #include <Wire.h> #define flashaddress 0x50 int liters = 10058 , add1=10 , add2,time1=55; // value of liters save in flash byte data ...