0% found this document useful (0 votes)
3 views

ESI Arduino IDE Examples

The document outlines a series of experiments involving the STM32 microcontroller and Arduino, focusing on various interfacing techniques such as LED control, ADC reading, UART over USB, I2C LCD control, motor driver interfacing, and HC-05 Bluetooth module control. Each experiment includes objectives, required materials, procedures, and sample code for implementation. The experiments aim to provide practical knowledge on using STM32 for different applications.

Uploaded by

DURONTO
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

ESI Arduino IDE Examples

The document outlines a series of experiments involving the STM32 microcontroller and Arduino, focusing on various interfacing techniques such as LED control, ADC reading, UART over USB, I2C LCD control, motor driver interfacing, and HC-05 Bluetooth module control. Each experiment includes objectives, required materials, procedures, and sample code for implementation. The experiments aim to provide practical knowledge on using STM32 for different applications.

Uploaded by

DURONTO
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Experiment No.

Title: LED Interfacing with STM32 and Arduino.

Objective:

The objective of this experiment is to learn how to control LED with an STM32 microcontroller. This
experiment aims to demonstrate the basic setup and usage of controlling a LED with STM32.

Materials Required:

1. STM32 Microcontroller (STM32F103C8T6 Blue).

2. ST-LINK

3. Arduino IDE.

4. Micro USB cable for Serial.

Procedure:

1. Connect the STM32 microcontroller to a computer using ST-LINK.

2. Set up the Arduino IDE with the appropriate board support and create a new Sketch File.

 Set Board : Generic STM32F103C series


 Set Upload Method : STLink

3. Write program to perform the controlling of a LED.

4. Compile and Upload the code onto the STM32 microcontroller.

5. Open a COM Test Serial with the correct baud rate (9600 in this case) to observe the transmitted
message.

Code:

void setup()

pinMode(PC13, OUTPUT);
}

void loop()

digitalWrite(PC13, HIGH);

delay(500);

digitalWrite(PC13, LOW);

delay(500);

}
Conclusion:
Experiment No.

Title: ADC Interfacing with STM32 and Arduino.

Objective:

The objective of this experiment is to learn how to get ADC values with an STM32 microcontroller.
This experiment aims to demonstrate the basic setup and usage of internal ADC of STM32.

Materials Required:

1. STM32 Microcontroller (STM32F103C8T6 Blue).

2. ST-LINK

3. Arduino IDE.

4. Micro USB cable for Serial.

Procedure:

1. Connect the STM32 microcontroller to a computer using ST-LINK.

2. Set up the Arduino IDE with the appropriate board support and create a new Sketch File.

 Set Board : Generic STM32F103C series


 Set Upload Method : STLink

3. Write program to perform the ADC Experiment.

4. Compile and Upload the code onto the STM32 microcontroller.

5. Open a COM Test Serial with the correct baud rate (9600 in this case) to observe the transmitted
message.

Code:

void setup()

pinMode(PA0, INPUT);

Serial.begin(9600);
}

void loop()

float adcVal = analogRead(PA0);

Serial.println(“\nADC Value: ”);

Serial.println(adcVal);

delay(50);
}

Conclusion:
Experiment No.

Title: UART VIA USB Interfacing with STM32 and Arduino.

Objective:

The objective of this experiment is to learn how to implement UART over USB with an STM32
microcontroller. This experiment aims to demonstrate the basic setup and usage of controlling UART
with STM32.

Materials Required:

1. STM32 Microcontroller (STM32F103C8T6 Blue).

2. ST-LINK

6. Arduino IDE.

7. Micro USB cable for Serial.

Procedure:

1. Connect the STM32 microcontroller to a computer using ST-LINK.

2. Set up the Arduino IDE with the appropriate board support and create a new Sketch File.

 Set Board : Generic STM32F103C series


 Set Upload Method : STLink

3. Write program to perform the controlling of a LED.

4. Compile and Upload the code onto the STM32 microcontroller.

5. Open a COM Test Serial with the correct baud rate (9600 in this case) to observe the transmitted
message.

Code:

void setup()

Serial.begin(9600);
}

void loop()

Serial.println(“Hello This is STM32 UART Over USB !!”);

Delay(1000);

}
Conclusion
Experiment No.

Title: I2C LCD Interfacing with STM32 and Arduino.

Objective:

The objective of this experiment is to learn how to control I2C LCD with an STM32 microcontroller.

Materials Required:

1. STM32 Microcontroller (STM32F103C8T6 Blue).

2. ST-LINK

3. 16x2 LCD

4. I2C MODULE (PCF8574)

5. Power Supply.

6. Arduino IDE.

7. Micro USB cable for Serial.

Procedure:

1. Connect the STM32 microcontroller to a computer using ST-LINK.

2. Set up the Arduino IDE with the appropriate board support and create a new Sketch File.

 Set Board : Generic STM32F103C series


 Set Upload Method : STLink

3. Write program to perform the controlling of a motor with help of a motor driver.

4. Compile and Upload the code onto the STM32 microcontroller.

5. Open a COM Test Serial with the correct baud rate (9600 in this case) to observe the transmitted
message.

Code:

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// Set the LCD address to 0x3F for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup()
{
lcd.init();
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("STM32 I2C ");
lcd.setCursor(0,1);
lcd.print("LCD DEMO");
}

void loop()
{
// Do nothing here…
}

Conclusion:
Experiment No.

Title: Motor Driver Interfacing with STM32 and Arduino.

Objective:

The objective of this experiment is to learn how to control DC motors using a Motor Driver with an
STM32 microcontroller. This experiment aims to demonstrate the basic setup and usage of
controlling a motor driver such as an L293 / L298D driver with STM32.

Materials Required:

1. STM32 Microcontroller (STM32F103C8T6 Blue).

2. ST-LINK

3. Motor Driver. (L293D / L298D)

4. DC Motor.

5. Power Supply.

6. Arduino IDE.

7. Micro USB cable for Serial.

Procedure:

1. Connect the STM32 microcontroller to a computer using ST-LINK.

2. Set up the Arduino IDE with the appropriate board support and create a new Sketch File.

 Set Board : Generic STM32F103C series


 Set Upload Method : STLink

3. Write program to perform the controlling of a motor with help of a motor driver.

4. Compile and Upload the code onto the STM32 microcontroller.

5. Open a COM Test Serial with the correct baud rate (9600 in this case) to observe the transmitted
message.

Code:

#define motor1R PB8


#define motor1L PB9
#define inputPin PA1

int motorA;
bool motorDir;
void setup() {

Serial.begin(9600);
pinMode(inputPin, INPUT_PULLUP);
pinMode(motor1R, OUTPUT);
pinMode(motor1L, OUTPUT);

void loop() {

motorA = digitalRead(inputPin);
if(motorA == HIGH)
{
digitalWrite(motor1R, HIGH);
digitalWrite(motor1L, LOW);
motorDir = true;
}

else if(motorA == LOW)


{
digitalWrite(motor1R, LOW);
digitalWrite(motor1L, HIGH);
motorDir = false;
}

Serial.print("Switch State = ");


Serial.print(motorA);

switch(motorDir)
{
case true:
Serial.print(" Clockwise");
break;

case false:
Serial.print(" Anti-Clockwise");
break;
}
Serial.print("\n");
delay(100);

Conclusion:
Experiment No.

Title: HC-05 Bluetooth Module Interfacing with STM32 and Arduino.

Objective:

The objective of this experiment is to learn how to control HC-05 Bluetooth Module with an STM32
microcontroller.

Materials Required:

1. STM32 Microcontroller (STM32F103C8T6 Blue).

2. ST-LINK

3. HC-05 Bluetooth Module

4. Power Supply.

5. Arduino IDE.

6. Micro USB cable for Serial.

Procedure:

1. Connect the STM32 microcontroller to a computer using ST-LINK.

2. Set up the Arduino IDE with the appropriate board support and create a new Sketch File.

 Set Board : Generic STM32F103C series


 Set Upload Method : STLink

3. Write program to perform the controlling of a motor with help of a motor driver.

4. Compile and Upload the code onto the STM32 microcontroller.

5. Open a COM Test Serial with the correct baud rate (9600 in this case) to observe the transmitted
message.

Code:

#define LED PC13

char data = 0;

void setup() {

Serial1.begin(9600);

pinMode(LED,OUTPUT);
}

void loop() {

if(Serial1.available()> 0)

data = Serial1.read();

if(data == 'A')

digitalWrite(LED, HIGH);

Serial1.print("LED ON\n");

if(data == 'a')

digitalWrite(LED, LOW);

Serial1.print("LED OFF\n");

Conclusion:

You might also like