Home > Applied project-based learning: building applications for low-cost hardware - Part 1

Applied project-based learning: building applications for low-cost hardware - Part 1

Supplier News
article image Arduino open-source, single-board microcontroller

Project-based learning is a comprehensive teaching and learning approach that engages students in the investigation of authentic engineering problems. To make this approach effective, the teacher must identify a problem that is accessible but challenging enough to stimulate the learning process. Unfortunately, many hardware applications are too complex, distracting students from the real task with low-level hardware issues.

MATLAB and Simulink address this challenge by making it easy for students to implement their projects on low-cost hardware platforms. This article describes three project-based learning activities that demonstrate the range of approaches and skills that can be taught with MATLAB and Simulink.

Two Approaches to the Arduino Blink Challenge

A problem may be solved at different levels of abstraction and using different implementation strategies. Let's consider a popular example of a basic application involving hardware: the Arduino Blink Challenge. In this popular example Arduino, an open-source, single-board microcontroller, controls the blinking logic of several LEDs. Through a potentiometer and a button, the user controls the blinking mode (on, off, simultaneous, or sequential), frequency, and speed.

The problem can be solved using two very different styles: coding and modelling. The coder solves the problem by developing an algorithm, setting up decision logic, and writing code; the modeller solves it by creating a system diagram highlighting connections and information flows. MATLAB and Simulink support both approaches.

Solving the Blink Challenge Using Code

With MATLAB Support Package for Arduino, students can establish a tethered connection with the board to acquire information from sensors (a button and a potentiometer), process this information through an algorithm, and send it back to the actuators (LEDs). With this package, the user’s algorithm runs on the computer in MATLAB and Simulink, and the Arduino processes requests to read or write from its I/O pins.

Communication with the board is reduced to the following straightforward commands:

1. Establish a connection with the board:

a = arduino('COM7');

2. Define the role of each pin:

a.pinMode(3, 'INPUT');
a.pinMode(5, 'OUTPUT');

3. Read sensor input and write actuator output:

ain = a.analogRead(aPin);
curr = a.digitalRead(bPin);

This simplified communication approach enables the student to concentrate on algorithm implementation. The compact and flexible MATLAB language supports many different implementations based on classic programming constructs, such as loops and conditional statements, as well as more specialised algorithms for different projects, such as data analysis and signal processing.

Solving the Blink Challenge Using a Model

Writing code for an embedded system can be extremely complex: Students must use the proper language and take care of data types and interfaces. With Simulink they can design the system in a graphical environment and then automatically translate this representation into an executable to be deployed on the board.

They can download a set of libraries, examples, and documentation to help them deploy their models on different hardware platforms, including Arduino (UNO and MEGA 2560), LEGO MINDSTORMSNXT, BeagleBoard, and PandaBoard.

A possible Simulink implementation for solving the Blink Challenge consists of three main subsystems:

  • Inputs from Arduino. Students can add analogue and digital input blocks for acquiring information from the potentiometer and the button.
  • Modes. Thanks to the large library of blocks, students can design a scheduler that controls the operation modes.
  • LEDs. Students can use PWM Arduino blocks to control the outputs and switch the different LEDs on and off.

The students run the complete model on the board automatically by selecting Tools > Run On Target Hardware > Prepare To Run. This option lets users select the target hardware, host COM port, and other simple configuration settings. To start the executable application generation and deployment process that will transfer the model to the board, they select Tools > Run On Target Hardware > Run. The board is then programmed with their algorithm and can run autonomously, without any connection to the PC.

This one-click approach to executable generation lets the student concentrate on system modelling. Applications from different fields, such as controls, image processing, computer science, and signal processing, can be easily experienced interacting with the hardware platform. The student is immediately able to design, simulate, and test on the hardware without facing all the low-level issues related to the interaction with the board.

Continued in Part 2

Newsletter sign-up

The latest products and news delivered to your inbox