Showing posts with label stateflow. Show all posts
Showing posts with label stateflow. Show all posts

Saturday, December 19, 2020

Reading Potentiometer value using Arduino - Software creation using Simulink and MATLAB

 In our previous article we have seen to control three LED's together using the Arduino and the software is developed using Stateflow as a state machine. In this article we will look at generating the software from the Simulink blocks to read the potentiometer value and showing that as a binary value using three LED's.

Required components

  • Three LEDs
  • Arduino
  • Connecting Wires
  • Three Resistors
  • Matlab or Arduino IDE
  • Potentiometer

The idea is to read the potentiometer reading using Arduino and converting the read value from 0 to 1023 scale to 1 to 4 scale. So all the potentiometer values from 0 to 256 are represented using 1 and 257 to 512 are represented using 2 and so on.

Software creation for Arduino using Simulink

In our earlier posts we have seen using the stateflow, in this article we see the Simulink in action all of the software is developed using Simulink graphically. At the end the Simulink model is deployed to the Arduino using Simulink embedded coder.

Following video explains the software creation to read and process the analog value using Arduino and Simulink.


In the next article we will explore the code generation and deployment to the hardware along with demo.

LEDs Sequential lighting - Software Loading into Arduino and Demo

 In the previous post we have seen the developing of the software for the LED's sequential lighting using Stateflow. In this article we will explore the circuit diagram for the LED's sequential lighting and software deployment parts.

Schematic for Arduino and LED's Sequential Lighting

Following is the circuit diagram for the LED's sequential lighting using Arduino.

Arduino digital pin 3 is connected to the Red LED anode, digital pin 4 is connected to the Green LED anode and digital pin 5 is connected to the Yellow LED's anode. All the LED's cathodes are connected to the ground via a resistor. This resistor is used as current limiting resistor to limit the current draw from Arduino and saving the micro-controller from frying up.

Software deployment to Arduino from Simulink

Following video presents the steps required to prepare the Simulink model for code generation for the Arduino board. The steps for the code generation are same as the steps explained in this article

Demo for the LED's Sequential Lighting using Arduino

The following video shows the demo of the article on the Arduino Mega hardware, you can see the working of software created in earlier article


I hope you enjoyed the LED's sequential lighting demo in this article and in our next article we will explore the potentiometer interfacing with Arduino.

You can checkout how the LED's Sequential Lighting can be implemented using C programming language and Arduino IDE in this article.


LEDs Sequential lighting - Software creation using Simulink and Stateflow for Arduino

 In the previous article we have seen how to blink the single LED using Arduino and the software is developed using Simulink and Stateflow charts. In this article we learn about how to light three different LEDs in sequential manner. 

Required components

  • Three LEDs (Red, Green, Yellow)
  • Arduino
  • Connecting Wires
  • Three Resistors
  • Matlab or Arduino IDE

The idea is to turn only one LED at any time. The sequence is Green LED turns on first and then Yellow LED and finally Red LED and this sequence continues. Green LED will be on for 2 seconds, Yellow LED for 1 second and Red LED for 2 seconds.

Software creation for Arduino using Stateflow

All this is implemented as a stateflow and temporal logic as a transition condition. In earlier article we just used entry condition in the state and this article introduces one more condition called exit condition.

The details of creating the stateflow chart for sequential control of three LEDs is explained in the following video.


 In our next article we will deploy the code generated from the model to the Arduino board and test our logic on the actual hardware.

Sunday, December 13, 2020

LED Blinking using Arduino and Matlab - Software Loading into Arduino and Demo

 In previous post we have seen the steps to create the Simulink model for the LED Blinking. In this post we will learn about configuring and preparing the model for code generation and deployment to the Arduino board.

Steps for preparing the Simulink model for deployment to Arduino

 The following steps help you to prepare the model for the deployment to the hardware in our case Arduino board.

  • Open the model configuration parameters from the Simulation window or select the little triangle icon beside gear icon in the tool bar and select "Model Configuration Parameters"
  • Select the "Hardware Implementation" option from the right options pane
  • Next choose the "Hardware board" from the drop down list available in our case we will select the Arduino. It can be either Arduino UNO or Arduino Mega 2560 based on your board.
  • Click save for the model configuration parameters.
  • Select the C/C++ Code from the Code menu and then click on Deploy to Hardware option or you can simply press Ctrl+B to deploy the software to the hardware board.
  • After successful code generation the code generation report will be opened automatically and you can browse the code from the simple HTML window popped up. 
  • MATLAB automatically generated the hex file for the Arduino board and deploys it using the connected USB cable.

All the above listed steps are explained in the following video.


 Schematic

 The Arduino schematic is developed using Fritzing software and is as follows, Arduino digital pin 9 is connected to the anode of the LED and the cathode of the LED is connected to the ground via current limiting resistor.

LED Blinking Demo using Arduino

You can check the following video for the LED Blinking demo, as you can see in the video the LED blinks with 0.5sec cycle.


 I hope you enjoyed the LED Blinking project using Arduino, Simulink and Stateflow.

Friday, December 11, 2020

LED Blinking using Arduino and Matlab - Software Creation using Stateflow and Simulink

 In this article we will work on LED blinking program using Arduino. The software required for the LED blinking is developed using MATLAB/Simulink and Stateflow charts. 

The required components

  • One LED
  • Arduino
  • Connecting Wires
  • Resistor
  • Matlab or Arduino IDE

In this article we will use the MATLAB, Simulink and Stateflow to create the required software to blink the LED. In next article we will explore the same using Arduino IDE and C programming language.

Matlab has support for Arduino development and we can use the blocks from  "Simulink Support Package for Arduino". You can follow the below Matlab support article to get the blocks for Arduino

https://in.mathworks.com/hardware-support/arduino-simulink.html

Steps for creating the Simulink model for LED blinking

  • Create an empty model
  • Open the Simulink Library browser
  • Drag and Drop the Digital Output block from "Simulink Support Package for Arduino Hardware"
  • Drag and Drop the Stateflow chart to the model
  • The following video shows the step by step process


     
  •  Now we have seen how to create the software using Simulink and Stateflow and the next step is preparing the Simulink model for the code generation.
  • In our next post we will see how to prepare our LED blinking model for the embedded code generation and how to load the generated executable into Arduino Board.

Stateflow

  • Stateflow is MATLAB is used to create the state machines.
  • In above video we have seen how to use state and entry criteria to control the LED on and off.
  • entry condition in the Stateflow is used to set the state of the signals at start of the state and they will stay remained at the assigned values.

Reading Potentiometer value using Arduino - Software creation using Ardino IDE and C Programming Language

 In previous article we have seen the steps in creating the software for the reading Potentiometer value using Simulink for Arduino board. ...