Data acquisition and device control with Scilab.

Dependencies:   Servo MPU6050

Desciription

Scilab is a freeware alternative to MATLAB. For low-cost data acquisition and device control a nice Arduino toolbox is available.

https://os.mbed.com/media/uploads/hudakz/scilab.png

This site presents a Mbed port which allows to use Mbed boards (equipped with Arduino header) rather than Arduino to import real time data into Scilab and to control real equipment witch Scilab.

https://os.mbed.com/media/uploads/hudakz/arduino-temp-read_imagelarge_1.jpeg

Installation
  • Install Scilab to your PC, if not done yet.
  • Launch Scilab and install the Arduino toolbox by executing the following command from the Scilab console:

--> atomsInstall("arduino")
Controlling Mbed's digital output from Scilab
  • In Xcos open examples/Arduino1.zcos

/media/uploads/hudakz/scilab_arduino1.png

  • Double click on the Board setup block and replace the serial port number with mbed's actual virtual serial port number.
  • Double click on the Digital WRITE block and set Digital Pin to 13 (D13 is connected to LED1).
  • Start simulation and LED1 on the Mbed board should start blinking.
Reading and displaying Mbed's analog input
  • In Xcos open examples/Arduino2.zcos

/media/uploads/hudakz/scilab_arduino2.png

  • Double click on the Board setup block and replace the serial port number with mbed's actual virtual serial port number.
  • Double click on the Analog READ block and set Analog Pin to 2.
  • Start simulation and a graph should appear showing the analog signal measured on Mbed's pin A2.

NOTE: Currently, there is bug in the toolbox ARDUINO_ANALOG_READ_sim function (I have reported to Scilab) so the analog readings are not correct.

/media/uploads/hudakz/scilab_graph.png

PID controller
  • In Xcos open examples/Arduino9.zcos

/media/uploads/hudakz/scilab_arduino9.png

Committer:
hudakz
Date:
Mon Jan 18 19:51:22 2021 +0000
Revision:
0:295b7e1c12f3
Data acquisition and device control with Scilab.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hudakz 0:295b7e1c12f3 1 #include "Encoder.h"
hudakz 0:295b7e1c12f3 2
hudakz 0:295b7e1c12f3 3 /**
hudakz 0:295b7e1c12f3 4 * @brief The Encoder class
hudakz 0:295b7e1c12f3 5 * @note Rotary encoder with three operating modes
hudakz 0:295b7e1c12f3 6 */
hudakz 0:295b7e1c12f3 7 Encoder::Encoder(PinName pinA, PinName pinB, int mode) : _position(0)
hudakz 0:295b7e1c12f3 8 {
hudakz 0:295b7e1c12f3 9 switch (mode) {
hudakz 0:295b7e1c12f3 10 case 1:
hudakz 0:295b7e1c12f3 11 _chanA = new InterruptIn(pinA);
hudakz 0:295b7e1c12f3 12 _chanA->rise(callback(this, &Encoder::onRiseMode1));
hudakz 0:295b7e1c12f3 13 _chanB = new InterruptIn(pinB);
hudakz 0:295b7e1c12f3 14 break;
hudakz 0:295b7e1c12f3 15
hudakz 0:295b7e1c12f3 16 case 2:
hudakz 0:295b7e1c12f3 17 _chanA = new InterruptIn(pinA);
hudakz 0:295b7e1c12f3 18 _chanA->rise(callback(this, &Encoder::onChangeMode2));
hudakz 0:295b7e1c12f3 19 _chanA->fall(callback(this, &Encoder::onChangeMode2));
hudakz 0:295b7e1c12f3 20 _chanB = new InterruptIn(pinB);
hudakz 0:295b7e1c12f3 21 break;
hudakz 0:295b7e1c12f3 22
hudakz 0:295b7e1c12f3 23 case 4:
hudakz 0:295b7e1c12f3 24 _chanA = new InterruptIn(pinA);
hudakz 0:295b7e1c12f3 25 _chanA->rise(callback(this, &Encoder::onChangeMode2));
hudakz 0:295b7e1c12f3 26 _chanA->fall(callback(this, &Encoder::onChangeMode2));
hudakz 0:295b7e1c12f3 27 _chanB = new InterruptIn(pinB);
hudakz 0:295b7e1c12f3 28 _chanB->rise(callback(this, &Encoder::onChangeMode2));
hudakz 0:295b7e1c12f3 29 _chanB->fall(callback(this, &Encoder::onChangeMode2));
hudakz 0:295b7e1c12f3 30 break;
hudakz 0:295b7e1c12f3 31 }
hudakz 0:295b7e1c12f3 32 }
hudakz 0:295b7e1c12f3 33
hudakz 0:295b7e1c12f3 34 Encoder::~Encoder()
hudakz 0:295b7e1c12f3 35 {
hudakz 0:295b7e1c12f3 36 delete _chanA;
hudakz 0:295b7e1c12f3 37 delete _chanB;
hudakz 0:295b7e1c12f3 38 }
hudakz 0:295b7e1c12f3 39
hudakz 0:295b7e1c12f3 40 void Encoder::onRiseMode1()
hudakz 0:295b7e1c12f3 41 {
hudakz 0:295b7e1c12f3 42 int b = _chanB->read();
hudakz 0:295b7e1c12f3 43 if (b)
hudakz 0:295b7e1c12f3 44 _position--;
hudakz 0:295b7e1c12f3 45 else
hudakz 0:295b7e1c12f3 46 _position++;
hudakz 0:295b7e1c12f3 47 }
hudakz 0:295b7e1c12f3 48 void Encoder::onChangeMode2()
hudakz 0:295b7e1c12f3 49 {
hudakz 0:295b7e1c12f3 50 int a = _chanA->read();
hudakz 0:295b7e1c12f3 51 int b = _chanB->read();
hudakz 0:295b7e1c12f3 52 if ((a && !b) || (!a && b))
hudakz 0:295b7e1c12f3 53 _position++;
hudakz 0:295b7e1c12f3 54 else
hudakz 0:295b7e1c12f3 55 _position--;
hudakz 0:295b7e1c12f3 56 }
hudakz 0:295b7e1c12f3 57 void Encoder::onChangeMode4()
hudakz 0:295b7e1c12f3 58 {
hudakz 0:295b7e1c12f3 59 int a = _chanA->read();
hudakz 0:295b7e1c12f3 60 int b = _chanB->read();
hudakz 0:295b7e1c12f3 61 if ((a && !b) || (!a && b))
hudakz 0:295b7e1c12f3 62 _position++;
hudakz 0:295b7e1c12f3 63 else
hudakz 0:295b7e1c12f3 64 _position--;
hudakz 0:295b7e1c12f3 65 }