Monday, February 14, 2022

ESP 32 FreeRTOS Task Create in Dual Core

ESP 32 FreeRTOS, LED Turn On and Turn Off:

In This Artical i will explain you, how to  use FreeRTOS in ESP32 Board-

Projects 1- Create three tasks with different priority , Task 1 and Task 2 running in core 0 and task 3 running in core 1 (here we are accessing dual core at the same projects:


BaseType_t xTaskCreate(TaskFunction_t pvTaskCode
const char *constpcName
const uint32_t usStackDepth
void *constpvParameters
UBaseType_t uxPriority
TaskHandle_t *constpvCreatedTask
const BaseType_t xCoreID)

Create a new task with a specified affinity.

This function is similar to xTaskCreate, but allows setting task affinity in SMP system.

Return

pdPASS if the task was successfully created and added to a ready list, otherwise an error code defined in the file projdefs.h

Parameters
  • pvTaskCode: Pointer to the task entry function. Tasks must be implemented to never return (i.e. continuous loop), or should be terminated using vTaskDelete function.

  • pcName: A descriptive name for the task. This is mainly used to facilitate debugging. Max length defined by configMAX_TASK_NAME_LEN - default is 16.

  • usStackDepth: The size of the task stack specified as the number of bytes. Note that this differs from vanilla FreeRTOS.

  • pvParameters: Pointer that will be used as the parameter for the task being created.

  • uxPriority: The priority at which the task should run. Systems that include MPU support can optionally create tasks in a privileged (system) mode by setting bit portPRIVILEGE_BIT of the priority parameter. For example, to create a privileged task at priority 2 the uxPriority parameter should be set to ( 2 | portPRIVILEGE_BIT ).

  • pvCreatedTask: Used to pass back a handle by which the created task can be referenced.

  • xCoreID: If the value is tskNO_AFFINITY, the created task is not pinned to any CPU, and the scheduler can run it on any core available. Values 0 or 1 indicate the index number of the CPU which the task should be pinned to. Specifying values larger than (portNUM_PROCESSORS - 1) will cause the function to fail.







example:
code begin here:


TaskHandle_t Task1; TaskHandle_t Task2; TaskHandle_t Task3; const int led1 = 2;// input 1 const int led2 = 3;// input 2 const int led3 = 4;// input 3 void setup() { Serial.begin(115200); pinMode(led1, INPUT); pinMode(led2, INPUT); pinMode(led3, INPUT); xTaskCreate(led_1,"Task1",1000,NULL,1,&Task1,0); // task running in core 0 delay(300); xTaskCreate(led_2,"Task2",1000,NULL,1,&Task2,0); // task running in core 0 delay(300); xTaskCreate(led_3,"Task3",1000,NULL,1,&Task3,1); // task running in core 1 delay(300); } void led_1( void * parameter ){ Serial.print("Task1 is running on core "); Serial.println(xPortGetCoreID()); for(;;){ digitalWrite(led1, HIGH); delay(300); digitalWrite(led1, LOW); delay(300); } } void led_2( void * parameter ){ Serial.print("Task2 is running on core "); Serial.println(xPortGetCoreID()); for(;;){ digitalWrite(led2, HIGH); delay(300); digitalWrite(led2, LOW); delay(300); } } void led_3( void * parameter ){ Serial.print("Task3 is running on core "); Serial.println(xPortGetCoreID()); for(;;){ digitalWrite(led3, HIGH); delay(300); digitalWrite(led3, LOW); delay(300); } } void loop() { }




Monday, May 13, 2019

Pedometer using MIT App Inventor

       

Pedometer Using MIT App Inventor
In This Blog we discuss about how to make pedometer App using MIT App Inventor

Pedometer-pedometer is used to count the steps.and calculate the distance covered by human.It is a usually portable device  counts each step a person takes by detecting the motion of the person's hands or accerolometer sensor which is inbuilt within smartphone

Step 1st-Search on google MIT App Inventor here click for login

                        Click on Create App


Step 2nd
                    Login Using Google Account
Step 3rd
Click on Start on New Project and Write Your Project Name

Step 4th

Drag Componet Which is Required for Building this app-


  • Button
  • Pedometer Sensor in  Sensor Box
  • Accelerometer in Sensor Box
  • TinyDB used for storage
  • Labels
  • Horizontal And Vertical arrangemen
  • Rename Button,and labels according to  below image





-

Step 5th-Download Image of Start,Stop, Reset Button from Google.






















Steps -6th  Programming.

Click on Blocks-

  1. First Intialize the events-




  1. Program for Start,Stop And Reset Button.







  1. programming For Step Count-





programming For Storage-




Step 7th

Goto Designer And Click on built Button,after clicking built button you see option for Save as APK file.and install the app.

Step 8th-Open App and click on Start Button-


You are Also watch Video







Monday, March 25, 2019

Servo Motor with esp32 Electricalkida Pedometer electricalkida


The Servo moter is used to move the motor of any angle.This is Tower Pro SG-91 Micro Servoit is used for robotic,open toll gate,move the shaft of arm etc.It is very light. mounting hardware.
we can control the position the servo’s shaft in various angles from 0 to 180ยบ. Servos are controlled using a pulse width modulation (PWM) signal. This means that the PWM signal sent to the motor will determine the shaft’s position.
We control the PWM capabilities of the ESP32 by sending a 50Hz signal with the appropriate pulse width.




Wiring Of Servo Motor to ESP32

S.NO
SERVO MOTOR
ESP32
1
GND
GND
2
POWER
5V
3
SIGNAL
G4
Table 3.2.3.1: Connection of servo motor to esp32
 Programing:
#include <Servo.h>


static const int servoPin = 4;

Servo servo1;

void setup() {
    Serial.begin(115200);
    servo1.attach(servoPin);
}

void loop() {
    for(int posDegrees = 0; posDegrees <= 180; posDegrees++) {
        servo1.write(posDegrees);
        Serial.println(posDegrees);
        delay(20);
    }

    for(int posDegrees = 180; posDegrees >= 0; posDegrees--) {
        servo1.write(posDegrees);
        Serial.println(posDegrees);
        delay(20);
    }
}

We Control the Servo motor by potentimeter:
programming:
#include <Servo.h>

static const int servoPin = 4;
static const int potentiometerPin = 32;

Servo servo1;

void setup() {
    Serial.begin(115200);
    servo1.attach(servoPin);
}

void loop() {
    int servoPosition = map(analogRead(potentiometerPin), 0, 4096, 0, 180);
    servo1.write(servoPosition);
    Serial.println(servoPosition);
    delay(20);
}

Friday, March 1, 2019

ESP32 with mfr522 electricalkida

          

ESP 32 With RFID MFRC522 Electricalkida.blogspot.com

ESP32 Microcontroller

ESP32 is best module for WiFi and bluetooth .It is also capable for arduino IDE.it is single 2.4 GHz Wi-Fi-and-Bluetooth combo chip designed with the TSMC ultra-low-power 40 nm technology. IT is also provided sleep Mode .It is designed to achieve the best power and RF performance, showing robustness, versatility and reliability in a wide variety of applications and power scenarios. ESP32 is created and developed by Espressif Systems, a Shanghai-based Chinese company. ESP32 is a highly-integrated solution for Wi-Fi-and-Bluetooth IoT applications, with around 20 external components. ESP32 Has 20GPIO pins:
Pin diagram of esp32:

3.2.2 RC-522 13.56 MHz RFID Reader
RFID means radio-frequency identification. RFID uses electromagnetic fields to transfer data over short distances. RFID is useful to identify people, to make transactions, Authnetication etc.


This low cost MFRC522 based RFID Reader Module is easy to use and can be used in a wide range of applications. RC522 is a highly integrated transmission module for contactless communication at 13.56 MHz this transmission module utilizes an outstanding modulation and demodulation concept completely integrated for different kinds of contactless communication methods and protocols at 13.56 MHz.





          

            


      



             Working Of RFID Reader
An RFID system basically consists of a transceiver with a decoder and an antenna and a transponder. And how it works? These cards have a reel inside them. When you approach them from the reader, they emit a radio signal through the antennas connected to the reader. The energized tag, which is the card, modulates the information stored in its memory and sends that data to the reader. This card then enters the reading field and receives power from the reader to perform the operations. The RFID reader receives the information sent by the tag, decodes and sends the data to the server application.

Steps:1
        Wring of MFRC-522 with EP32

S.NO
MFRC522
ESP32
1
SDA
G5
2
SCK
G18
3
MISO
G19
4
MOSI
G23
5
IRQ
Not used
6
GND
GND
7
RST            
Not used
8
3.3V
3.3V
Table 3.1.1: Connection of rfid reader to esp32


Steps:2
 you download the library of mfrc-522 from Arduino or Github Down-load rc522 library here 

 programming :Copy the Following Code

#include<SPI.h>

#include <MFRC522.h>
#define SS_PIN 5
#define RST_PIN 9//not used for esp32
byte readCard[4];
MFRC522 mfrc522(SS_PIN, RST_PIN);
void setup() {
  Serial.begin(115200);
  SPI.begin();       
  mfrc522.PCD_Init();
}

void loop() {

  if ( ! mfrc522.PICC_IsNewCardPresent()) {
    return;
  }
  if ( ! mfrc522.PICC_ReadCardSerial()) { 
    return;
  }
  Serial.println(F("Scanned PICC's UID:"));
  for ( uint8_t i = 0; i < 4; i++) {
    readCard[i] = mfrc522.uid.uidByte[i];
    Serial.print(readCard[i], HEX);
  }
  Serial.println("");
  mfrc522.PICC_HaltA();

}

Note:If It Does Not Work Problem In Your ESP32 Board Serial Monitor.To Avoide This Problem we use to LCD for Print the Card Number-


Steps 3:
               LCD Connection With ESP32:
Connection:
SDA--------21
SCK--------22
GND------GND
5V---------5V
Programming:
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,20,4);  

void setup()
{
  lcd.init();                     
  lcd.backlight();
  lcd.setCursor(0,0);
  lcd.print("Hello, world!");
  delay(699);
  lcd.clear();

}


void loop()
{
FINAL Programming Code

#include <SPI.h>

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,20,4);

#include <MFRC522.h>

#define SS_PIN 5

#define RST_PIN 9

byte readCard[4];

MFRC522 mfrc522(SS_PIN, RST_PIN);

void setup() 

{

  Serial.begin(115200);  

  SPI.begin();          

  mfrc522.PCD_Init();

 lcd.init();                      

 lcd.backlight();   

 lcd.setCursor(0,0);

 lcd.print("Hello, world!");
  delay(699);
  lcd.clear();

}

void loop()

 {  if ( ! mfrc522.PICC_IsNewCardPresent()) {

return;

  }

  if ( ! mfrc522.PICC_ReadCardSerial()) {   

return;

  }

 Serial.println("Scanned PICC's UID:");

  for ( uint8_t i = 0; i < 4; i++) { 

    readCard[i] = mfrc522.uid.uidByte[i];

Serial.print(readCard[i], HEX);

  lcd.setCursor(0,0);

  lcd.print(readcard[i]);

/*  lcd.print(readcard); try it's, if above code is not run

  lcd.print(readcard[i],HEX);// try it's, if above code is not run */

 delay(2000);

 lcd.clear();

  }






















ESP 32 FreeRTOS Task Create in Dual Core

ESP 32 FreeRTOS, LED Turn On and Turn Off: In This Artical i will explain you, how to  use FreeRTOS in ESP32 Board- Projects 1- Create three...