Skip to content

Week 4. Embedded Programming


Image description

Image Courtesy: Photo by AltumCode on Unsplash

Programming!!! I always found it fascinating, but I've never tried it. And this week's learning process focuses on real-world programming. I'm starting this week a little nervous, but a lot more excited.

This week's assignment includes understanding the data sheet for microcontrollers and programming a microcontroller development board to interact and communicate. There is also a group assignment to compare performance and development workflows for other architectures.

Learning Process

What is Programming?

I’d like to start by understanding more about programming.

Programming is the process of creating software, applications, and computer programs using various programming languages. It involves writing a set of instructions, also known as code, that a computer can understand and execute.

The goal of programming is to create efficient and effective solutions to problems. This can include anything from simple programs, such as a calculator or a game, to complex software systems used in industries like AEC, finance, healthcare, and aerospace. The process of programming involves planning, designing, coding, testing, and debugging software.

Programming is a key skill in today’s technology-driven world, and is used in a wide range of fields, from science and engineering to business and entertainment. It requires logical thinking, problem-solving skills, attention to detail, and the ability to learn and apply new concepts and technologies.

There are different programming languages that are used to develop computer programmes and software. Here are some of the most popular programming languages and their common uses:

C/C++

Python

Java/Javascript

PHP

Micropython

What is Hardware Architecture?

Hardware (Microcontroller) Architecture refers to the overall design and structure of a software system or application. It encompasses the decisions and trade-offs made by software developers to ensure that a program is organized, efficient, maintainable, and scalable.

In particular, software architecture involves defining the system’s components, their relationships and interactions, as well as their interfaces and dependencies. This can include decisions about the choice of programming languages, libraries, frameworks, and other tools. A well-designed software architecture can help ensure that a program meets its functional requirements, is easy to modify and extend, and can scale to meet future demands.

Refernce link for Microcontroller Architecture

001

What is Microcontroller?

A microcontroller is a small computer on a single integrated circuit (IC) that is designed to control a specific system or device. It is a specialized computing device that is designed to control a specific system or device. It typically includes a processor, a small amount of memory, and input/output peripherals such as timers, serial communication interfaces, and analog-to-digital converters, all of which are integrated onto a single chip. Microcontrollers are typically programmed to perform specific tasks, and run specialized software known as firmware.

Microcontrollers are used in a wide range of electronic devices, including smartphones, automotive systems, home appliances,industrial automation equipment, and more. They are also commonly used in embedded systems, which are computer systems that are integrated into other devices or products to provide specific functionality.

One of the key benefits of using microcontrollers is that they can be programmed to perform specific tasks, which can greatly enhance the functionality of a device. They are also cost-effective, consume less power than traditional computers, and can be easily integrated into electronic systems.

Microcontrollers are programmed using specialized programming languages such as C or assembly language, and are often programmed using specialized software and tools. With the increasing demand for smart and connected devices, microcontrollers have become an essential component of many electronic devices and systems.

What is IDE (Integrated Development Environment)?

It is a software application that provides a comprehensive environment for developers to write, test, and debug their code. An IDE typically includes a text editor for writing code, a compiler or interpreter for running the code, and a debugger for finding and fixing errors.

IDEs are designed to make the software development process more efficient and effective by providing a set of tools and features that help programmers write high-quality code. For example, an IDE may include features such as auto-completion, syntax highlighting, and code formatting to make it easier for developers to write clean, readable code. It may also include tools for managing version control, testing, and deployment.

Platform IO

Eclipse

Arduino

PyCharm

Microchip Studio (Atmal Studio)

What is Development Board?

A development board, also known as a prototyping board or a dev board, is a circuit board designed to provide a platform for building and testing electronic systems. Development boards typically include a microcontroller, a set of input/output pins, and a range of other components that allow developers to quickly build and test new circuits.

Some popular development boards include:

Arduino: An open-source electronics platform based on a simple microcontroller board, designed for use in a wide range of electronic projects.

Raspberry Pi: A credit card-sized computer that can be used as a standalone computer or as the brains behind an electronic project.

BeagleBone: A low-cost, high-performance development board designed for building embedded systems and IoT projects.

Adafruit Feather: A line of small, modular development boards designed for building IoT applications.


Weekly Assignment

Understanding the Data Sheet for Microcontrollers

Understanding the data sheet for microcontrollers is an essential skill for working with embedded systems. The data sheet provides detailed information about the microcontroller’s pinout, electrical characteristics, memory, clock frequency, peripherals, and programming interfaces. This information is critical for selecting the appropriate microcontroller for a project, designing the hardware to interface with the microcontroller, and programming the microcontroller to perform specific tasks.

We started with programming on ESP32.

100

115

Data Sheet for ESP32

Another one we tried is ATmega 2560.

101

116

Data Sheet for ATmega 2560


Programming a Microcontroller Development Board

Programming on NodeMCU ESP WROOM 32 Board

Programming a Microcontroller Development Board is the start of our assignment. Here we will explore how to program the ESP32 development board, including the tools and software needed to get started. We will cover the basics of microcontroller programming, including how to write and upload code to the board, how to interact with input/output pins, and how to communicate with other devices using the board’s built-in communication interfaces. We will also discuss some of the libraries and tools available for programming the ESP32.

01

NodeMCU ESP32 Board (Also Known as ESP32-DevkitC)

The ESP32 peripherals include:

18 Analog-to-Digital Converter (ADC) channels

3 SPI interfaces

3 UART interfaces

2 I2C interfaces

16 PWM output channels

2 Digital-to-Analog Converters (DAC)

2 I2S interfaces

10 Capacitive sensing GPIOs

Here in our board GPIO2 is assigned as the in-built LED. So while doing programming blink we can make use of that pin. ie. pin-2 can be assigned for LED Blink.

102_A

Working on Arduino IDE

First download & Install Arduino IDE 2. For Installation Tutorial Visit Link.

1.Hardwares Required

102

2.Connect ESP32 Board to system using USB cable.

103

3.Open the Arduino IDE, go to File -> Preferences and enter the following URL in the Additional Boards Manager URLs

105 106

4.Then go to Tools > Board > Boards Manager. Search for ESP32 and install the ESP32 by Espressif Systems board definition.

107 105

5.Select ESP32 Dev Module as the board.

109 110

6.Upload the Blink Program: Go to File > Examples > 01.Basics > Blink to open the Blink example program.

111

7.Code appears to be like this.

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);  
  delay(1000);                     
  digitalWrite(LED_BUILTIN, LOW);  
  delay(1000);                     
}

8.Make changes as per Board, for ESP WROOM 32, as mentioned previously, the In-built LED pin is “2”. So either define LED BUILTIN as 2 or replace the same with “2”.

112

9.The corrected code appears to be like this.

int LED = 2;
void setup() {
  pinMode(LED, OUTPUT);
}

void loop() {
  digitalWrite(LED, HIGH);  
  delay(1000);                     
  digitalWrite(LED, LOW);  
  delay(1000);                     
}

10.When the programming is finished and compiled, it must be uploaded to the board. The uploading process is demonstrated in the video below. Once the Upload button is pressed, the programme will compile the code again and show Connecting…. Now, long press the Boot button on the board and it will begin uploading the code to the board. When the uploading is finished, the LED lights begin to blink.

113 114

The Fibal Result is shown here:

11.We can experiment with the blinking time by varying the delay period. For example, we now have delay(1000), which is 1 second (1000 microseconds). We can change the number and the blinking speed will increase or decrease accordingly.

Programming on Arduino Mega 2560

Next, I tried Fading LED lights on an Arduino Mega 2560 board.

200

1.I started with a fading example from the library.

201

2.Next select the Arduino Mega board

202

3.Make changes to the code according to the board arrangements. I have connected LEDs from pin 2 to 8.

203

4.The final result.

Code Used:

int ledPin;

void setup() {

}

void loop() {
  for (ledPin = 2; ledPin < 8; ledPin++) {
  for (int fadeValue = 0; fadeValue <= 255; fadeValue += 5) {
    analogWrite(ledPin, fadeValue);
    delay(100);
  }

  for (int fadeValue = 255; fadeValue >= 0; fadeValue -= 5) {
    analogWrite(ledPin, fadeValue);
    delay(100);
  }
  }

}

Communicate ESP32 to IOT through Arduino

The ESP32 is a powerful Wi-Fi and Bluetooth enabled microcontroller designed for Internet of Things (IoT) applications. It is a dual-core processor with integrated Wi-Fi and Bluetooth connectivity, making it an ideal choice for projects that require wireless communication.

The ESP32 is compatible with the Arduino IDE, which makes it easy to use for those familiar with Arduino development. The Arduino IDE is a free, open-source software that allows you to write and upload code to the ESP32 board. The ESP32 board can be programmed using C++ language, and offers a wide range of libraries and functions to simplify programming.

The ESP32 supports multiple communication protocols such as HTTP, MQTT, and TCP/IP, and has built-in security features like SSL/TLS encryption. This makes it a great choice for IoT projects that require secure and reliable data transfer.

Overall, the ESP32 is a powerful and versatile microcontroller that offers great performance and connectivity options, making it a popular choice for IoT projects.

Install Libraries

In the Arduino IDE, navigate to Sketch -> Include Library -> Manage Libraries…

301

Search for Adafruit IO Arduino in the Library Manager, and click Install on the Adafruit IO Arduino for ESP32 library option.

302

Click Install All

303

Adafruit IO Setup

Go to Adafruit IO Website -> Create a New Account -> Then Sign In

304

Go to Dashboard

305

Create a dashboard to visualize and interact with the data being sent between ESP32-S2 board and Adafruit IO.

Click the New Dashboard button.

Name your dashboard My ESP32-S2 or depending on your board.

Your new dashboard should appear in the list.

Add New Block from the cog on top right corner

306 307

Select the Toggle block. Under My Feeds, enter “led” as a feed name. Click Create. Choose the led feed to connect it to the toggle block.

308 309 310

Under Block Settings,

Change Button On Text to 1

Change Button Off Text to 0

Click Create block

311 312

Create a New Sketch from the Adafruit IO examples.

313

Enter your network credentials next to WIFI_SSID and WIFI_PASS & Adafruit IO Credentials to IO_USERNAME and IO_KEY

314

Obtain Adafruit IO Credentials from Adafruit IO website.

315

While Uploading, the board is not connecting. Still Trying to figure out.

316



Group Assignment

Group assignment involves comparing the performance and development workflows for different microcontroller architectures. We compared the frequencies of the STM 32, ESP32, and ATmega 2560 microcontrollers. We made use of Arduino. Embedded C and Assembly languages were also used to identify differences.

Detailed report on our Group Assignment Page.

Help Taken & References

Chat GPT used for doubt clearing and content helps.

ASCII Chart.

ESP32 Pinout Reference

Back to top