Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

21BLC1151LAB4

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

School of Electronics Engineering (SENSE)

B. Tech – Electronics & Computer Engineering

BECE403E – EMBEDDED SYSTEM DESIGN


LAB RECORD
(lab slot L31+L32)

Submitted By
21BLC1151 –Aditya Kumar Jha

DATE: 29/01/2024

[Reg.No] BECE403E- Embedded Systems Design Lab Page No: 1


Slot: L31+L32

Date: 29-01-24

LAB – 04: Working with Serial Port


AIM:
To understand the working of Nucleo64-STM32L152RE Board and to perform the following
tasks:
Lab Task-1: Controlling o board LED using USB Serial port
Lab Task-2: Increasing/decreasing brightness using serial port
Lab Task-3: Increasing/decreasing brightness using potentiometer
Lab Task-4: Battery level indicator using potentiometer

Software Required: ARM Keil Studio (Mbed Online Compiler)

Hardware Required: Micro USB cable, NUCLEO64-STM32L152 Board, LEDs, Jumper Wires (M-F and M-
M), Breadboard, Buzzer
Procedure:
1. Go to ARM Keil Studio (https://studio.keil.arm.com) and log in
2. Select File → New → Mbed Project
3. Click the Example project drop-down list and select “mbed2-example-blinky”
4. In Project name field, provide the name of the new project and click Add project
5. Double click on the “main.cpp” file from the newly created project folder
6. Open Tera-term app and connect to Port.
7. Modify the code in the editor window as per the logic of your application
8. Check for any errors in the program under the “Problems” tab of the panels window
9. If no errors, connect the Nucleo Board to the computer using Micro USB Cable
10. Click Play icon (Run project) to upload and start the code execution on the board.

PROGRAM:
Lab Task-1: Controlling o board LED using USB Serial port

#include "mbed.h"
Serial pc(USBTX,USBRX);
DigitalOut myled(LED1);
int main(){
printf("Press a character:");
while(1)

21BLC1151 BECE403E- Embedded Systems Design Lab Page No: 2


{
int y=pc.getc();
printf("%c\n",y);
if(y=='H'){
myled=1;
wait(0.2);
}
else{
myled=0;
}
}
}

Output:

21BLC1151 BECE403E- Embedded Systems Design Lab Page No: 3


21BLC1151 BECE403E- Embedded Systems Design Lab Page No: 4
Lab Task-2: Increasing/decreasing brightness using serial port

#include "mbed.h"
Serial pc(USBTX,USBRX);
PwmOut led(PC_8);
float brightness=0.0;
int main() {
while(1) {
pc.printf("Enter the command to increase or decrease the brightness(I/D) :\r\n");
char c=pc.getc();
if((c=='i')){
pc.printf("Increasing the brightness by 10% : \r\n");
brightness+=0.1;
led=brightness;
}
if((c=='d')&&(brightness>0.0)){
pc.printf("Decreasing the brightness by 10% : \r\n");
brightness-=0.1;
led=brightness;
}
}
}

Output:

21BLC1151 BECE403E- Embedded Systems Design Lab Page No: 5


Lab Task 3: Increasing/decreasing brightness using potentiometer
#include "mbed.h"

Serial pc(USBTX,USBRX);
AnalogIn ain(PC_3);
PwmOut PWM1(PC_8);
int main()
{
while(1)
{
float value = ain*5;
pc.printf("The reading of pot:%f",value);
wait(1);
PWM1.period(0.01);
PWM1 = ain;
}
}

21BLC1151 BECE403E- Embedded Systems Design Lab Page No: 6


Output:

21BLC1151 BECE403E- Embedded Systems Design Lab Page No: 7


Lab Task-4: Battery level indicator using potentiometer

#include "mbed.h"

Serial pc(USBTX,USBRX);
AnalogIn ain(PC_3);
DigitalOut LED1(PC_8);
DigitalOut LED2(PB_13);
DigitalOut LED3(PB_14);
DigitalOut LED4(PB_15);
DigitalOut LED5(PB_1);
int main()
{
while(1)
{ float value = ain*5;
if(value>=0 && value<1){
pc.printf("The reading of 0 to 1");
LED1 = 1;
LED2 = 0;
LED3 = 0;
LED4 = 0;
LED5 = 0;
wait(1);
}
if(value>=1 && value<2){
pc.printf("The reading of 1 to 2");
LED1 = 1;
LED2 = 1;
LED3 = 0;
LED4 = 0;
LED5 = 0;
wait(1);
}
if(value>=2 && value<3){
pc.printf("The reading of 2 to 3");
LED1 = 1;
LED2 = 1;
LED3 = 1;
LED4 = 0;
LED5 = 0;
wait(1);
}
if(value>=3 && value<4){
pc.printf("The reading of 3 to 4");
LED1 = 1;
LED2 = 1;
LED3 = 1;
LED4 = 1;
LED5 = 0;
wait(1);
}
if(value>=4 && value<5){}
pc.printf("The reading of 4 to 5");
LED1 = 1;

21BLC1151 BECE403E- Embedded Systems Design Lab Page No: 8


LED2 = 1;
LED3 = 1;
LED4 = 1;
LED5 = 1;
wait(1);
}
}
}
}
}

21BLC1151 BECE403E- Embedded Systems Design Lab Page No: 9


Output:

Fig.4: Battery level indicator using


potentiometer

21BLC1151 BECE403E- Embedded Systems Design Lab Page No: 10


Output Verification:

21BLC1151 BECE403E- Embedded Systems Design Lab Page No: 11


21BLC1151 BECE403E- Embedded Systems Design Lab Page No: 12
21BLC1151 BECE403E- Embedded Systems Design Lab Page No: 13
INFERENCE:
As we can see we have programmed the LED’s and the Buzzer to perform certain simple
operations which are commanded via the keil software using tera term UI for user input and output
and the smt board.

RESULT:
The LED glowing using user Input via tera term and also giving Instructions to LED via
potentiometer experiment is performed successfully.

21BLC1151 BECE403E- Embedded Systems Design Lab Page No: 14

You might also like