Difference: ImplementingTheArduinoToolbox (1 vs. 8)

Revision 82019-02-08 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="Scilab"

Implementing the Arduino toolbox

The program structure

Line: 31 to 31
  Sanp: Where "S" identifies for the stepper motor device, "a" stands for "attach" n is the GPIO pin and p is the pulse (N1 .. N4 or the stepping motor driver module) . The command also programs the GPIO pins as output. Sa21 will therefore attach GPIO pin 2 to the first stepping motor driver input (N1 on the driver card).
Changed:
<
<
Sm: moves the stepping motor by 1 step
>
>
Smfs: m: moves the stepping motor by 1 step. The parameters f and s stand for f: forward of b: backward and s is the stepping mode which can be single phase, double phase or half step. The direction and the stepping mode can be selected in the xcos block:

steppingModes.png

In the screen dump above half step mode in forward direction is selected.

  Sc: Clears all coil signals to low

Reading analog values

Line: 152 to 156
 
META FILEATTACHMENT attachment="xcosEncoder.png" attr="" comment="" date="1549551382" name="xcosEncoder.png" path="xcosEncoder.png" size="32649" user="UliRaich" version="1"
META FILEATTACHMENT attachment="encoderResult.png" attr="" comment="" date="1549551382" name="encoderResult.png" path="encoderResult.png" size="15252" user="UliRaich" version="1"
META FILEATTACHMENT attachment="arduino-linux_1.6-src-6feb.tar.gz" attr="" comment="" date="1549551606" name="arduino-linux_1.6-src-6feb.tar.gz" path="arduino-linux_1.6-src-6feb.tar.gz" size="2722718" user="UliRaich" version="1"
Added:
>
>
META FILEATTACHMENT attachment="steppingModes.png" attr="" comment="" date="1549639668" name="steppingModes.png" path="steppingModes.png" size="25119" user="UliRaich" version="1"

Revision 72019-02-07 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="Scilab"

Implementing the Arduino toolbox

The program structure

Line: 39 to 39
 The Arduino has several 10 bit ADCs on chip which can be used to read analog voltage levels. Here is the command code:

Ap: reads the voltage level from analog pin p

Added:
>
>

Interrupts

Normally interrupts can only be generated on pins 2 and 3 on an Arduino Uno or Nano. However, there are also so-called "PinChangeInterrupts" which allow to hook up an interrupt service routine when a signal level change on a GPIO pin happens. This can be "FALLING" or "RISING" for a falling or rising edge of the signal or it can be "CHANGE" for both edges.

Unfortunately there is a problem when using this with the SoftSerial library because both libraries use the same interrupt vectors. Since for our debugging port we only have to send but to not receive message I use the SendonlySoftSerial library attached to this page:

https://iotworkshop.africa/pub/Embedded_Systems/ImplementingTheArduinoToolbox/SendOnlySoftwareSerial.zip

These are the protocol codes sent to the Arduino:

Iacup: a: attach pin p for c: change mode f: falling edge: r: rising edge, u: updown: u: up-counter, d: down-counter c: clear
Idp: d: detach from interrupt on pin p
Irp: r: read no of counts from interrupt counter

Encoder

The rotary encoder also make use of interrupts. It uses 2 signals: clock and data to see when it is turned and in which direction it has been turned. The clock signal is connected to an interrupt and the interrupt service routine, by looking at the data signal, finds out if the encoder was turned clock-wise (a counter increments) of counter-clock-wise (a counter decrements).

xcosEncoder.png encoderResult.png
The above screen dumps show an xcos diagram setting up the encoder, reading it and displaying its value in a plot.
 

The multi-function board

In order to test digital read/write, analog read/write etc. we need an Arduino to which the corresponding hardware is connected, e.g. a switch to be read with digital read, a potentiometer for analog read or an LED for digital write... An easy solution is to use the multi-function board which has all these connections already done and which must simply be installed as a piggy back board onto e.g. an Arduino Uno.

Line: 56 to 72
  https://iotworkshop.africa/pub/Embedded_Systems/ImplementingTheArduinoToolbox/multiFunctionBoard.pdf
Changed:
<
<
I use GPIO pin 2 as TX line for a SoftSerial port onto which I send debugging messages. There is a problem when using this with the PinChangeInterrupt library because both libraries use the same interrupt vectors. Since for our debugging port we only have to send but to not receive message I use the SendonlySoftSerial library attached to this page:

https://iotworkshop.africa/pub/Embedded_Systems/ImplementingTheArduinoToolbox/SendOnlySoftwareSerial.zip

>
>
I use GPIO pin 2 as TX line for a SoftSerial port onto which I send debugging messages.
 

The Arduino server program and the test procedure

With this information it is possible to develop the first version of the Arduino server. Since all it needs is input from the serial line we can write a simple C program to test the server. A program asking for the server version (and printing it) as well as the Arduino server are attached to this TWiki page.

Line: 84 to 98
  A tar archive with a Xcos toolbox containing Digital Write as well as as a basic stepper motor xcos block is attached to this page:
Changed:
<
<
https://iotworkshop.africa/pub/Embedded_Systems/ImplementingTheArduinoToolbox/arduino-linux_1.5-src-v0.4.tar.gz
>
>
https://iotworkshop.africa/pub/Embedded_Systems/ImplementingTheArduinoToolbox/arduino-linux_1.6-src-6feb.tar.gz
  This is the original arduino_1.5-src archive downloaded from git which I modified to run on Linux. Only Digital Write and the stepper motor module are working. The other modules are still part of the archive but will most probably not work. In the original archive the stepper motor block was removed from the Arduino palettes. It has been put back. The original Arduino sketches have been moved into arduino.old and a new server sketch developed which you find in the arduino folder.
Line: 132 to 146
 
META FILEATTACHMENT attachment="palette.png" attr="" comment="" date="1547645846" name="palette.png" path="palette.png" size="30131" user="UliRaich" version="1"
META FILEATTACHMENT attachment="loader.png" attr="" comment="" date="1547645846" name="loader.png" path="loader.png" size="11433" user="UliRaich" version="1"
META FILEATTACHMENT attachment="builder.png" attr="" comment="" date="1547645848" name="builder.png" path="builder.png" size="159072" user="UliRaich" version="1"
Deleted:
<
<
META FILEATTACHMENT attachment="arduino-linux_1.5-src-v0.4.tar.gz" attr="" comment="" date="1547831976" name="arduino-linux_1.5-src-v0.4.tar.gz" path="arduino-linux_1.5-src-v0.4.tar.gz" size="1844077" user="UliRaich" version="1"
 
META FILEATTACHMENT attachment="multi-function.png" attr="" comment="" date="1549099775" name="multi-function.png" path="multi-function.png" size="218191" user="UliRaich" version="1"
META FILEATTACHMENT attachment="multiFunctionBoard.pdf" attr="" comment="" date="1549100057" name="multiFunctionBoard.pdf" path="multiFunctionBoard.pdf" size="23827" user="UliRaich" version="1"
META FILEATTACHMENT attachment="SendOnlySoftwareSerial.zip" attr="" comment="" date="1549100822" name="SendOnlySoftwareSerial.zip" path="SendOnlySoftwareSerial.zip" size="4452" user="UliRaich" version="1"
Added:
>
>
META FILEATTACHMENT attachment="xcosEncoder.png" attr="" comment="" date="1549551382" name="xcosEncoder.png" path="xcosEncoder.png" size="32649" user="UliRaich" version="1"
META FILEATTACHMENT attachment="encoderResult.png" attr="" comment="" date="1549551382" name="encoderResult.png" path="encoderResult.png" size="15252" user="UliRaich" version="1"
META FILEATTACHMENT attachment="arduino-linux_1.6-src-6feb.tar.gz" attr="" comment="" date="1549551606" name="arduino-linux_1.6-src-6feb.tar.gz" path="arduino-linux_1.6-src-6feb.tar.gz" size="2722718" user="UliRaich" version="1"

Revision 62019-02-02 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="Scilab"

Implementing the Arduino toolbox

The program structure

Line: 39 to 39
 The Arduino has several 10 bit ADCs on chip which can be used to read analog voltage levels. Here is the command code:

Ap: reads the voltage level from analog pin p

Added:
>
>

The multi-function board

In order to test digital read/write, analog read/write etc. we need an Arduino to which the corresponding hardware is connected, e.g. a switch to be read with digital read, a potentiometer for analog read or an LED for digital write... An easy solution is to use the multi-function board which has all these connections already done and which must simply be installed as a piggy back board onto e.g. an Arduino Uno.

multi-function.png

As can be seen from the photo the multi-function board has

Device Connection
4 LEDs GPIO 10..13
2 switches A1..A3
1 potentiometer A0
1 seven segment display GPIO 4,7,8
1 buzzer GPIO 3
For further details please consult the circuit diagram:

https://iotworkshop.africa/pub/Embedded_Systems/ImplementingTheArduinoToolbox/multiFunctionBoard.pdf

I use GPIO pin 2 as TX line for a SoftSerial port onto which I send debugging messages. There is a problem when using this with the PinChangeInterrupt library because both libraries use the same interrupt vectors. Since for our debugging port we only have to send but to not receive message I use the SendonlySoftSerial library attached to this page:

https://iotworkshop.africa/pub/Embedded_Systems/ImplementingTheArduinoToolbox/SendOnlySoftwareSerial.zip

 

The Arduino server program and the test procedure

With this information it is possible to develop the first version of the Arduino server. Since all it needs is input from the serial line we can write a simple C program to test the server. A program asking for the server version (and printing it) as well as the Arduino server are attached to this TWiki page.

Line: 113 to 133
 
META FILEATTACHMENT attachment="loader.png" attr="" comment="" date="1547645846" name="loader.png" path="loader.png" size="11433" user="UliRaich" version="1"
META FILEATTACHMENT attachment="builder.png" attr="" comment="" date="1547645848" name="builder.png" path="builder.png" size="159072" user="UliRaich" version="1"
META FILEATTACHMENT attachment="arduino-linux_1.5-src-v0.4.tar.gz" attr="" comment="" date="1547831976" name="arduino-linux_1.5-src-v0.4.tar.gz" path="arduino-linux_1.5-src-v0.4.tar.gz" size="1844077" user="UliRaich" version="1"
Added:
>
>
META FILEATTACHMENT attachment="multi-function.png" attr="" comment="" date="1549099775" name="multi-function.png" path="multi-function.png" size="218191" user="UliRaich" version="1"
META FILEATTACHMENT attachment="multiFunctionBoard.pdf" attr="" comment="" date="1549100057" name="multiFunctionBoard.pdf" path="multiFunctionBoard.pdf" size="23827" user="UliRaich" version="1"
META FILEATTACHMENT attachment="SendOnlySoftwareSerial.zip" attr="" comment="" date="1549100822" name="SendOnlySoftwareSerial.zip" path="SendOnlySoftwareSerial.zip" size="4452" user="UliRaich" version="1"

Revision 52019-01-18 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="Scilab"

Implementing the Arduino toolbox

The program structure

Line: 34 to 34
 Sm: moves the stepping motor by 1 step

Sc: Clears all coil signals to low

Added:
>
>

Reading analog values

The Arduino has several 10 bit ADCs on chip which can be used to read analog voltage levels. Here is the command code:

Ap: reads the voltage level from analog pin p

 

The Arduino server program and the test procedure

With this information it is possible to develop the first version of the Arduino server. Since all it needs is input from the serial line we can write a simple C program to test the server. A program asking for the server version (and printing it) as well as the Arduino server are attached to this TWiki page.

Line: 59 to 64
  A tar archive with a Xcos toolbox containing Digital Write as well as as a basic stepper motor xcos block is attached to this page:
Changed:
<
<
https://iotworkshop.africa/pub/Embedded_Systems/ImplementingTheArduinoToolbox/arduino-linux_1.5-src.tar.gz
>
>
https://iotworkshop.africa/pub/Embedded_Systems/ImplementingTheArduinoToolbox/arduino-linux_1.5-src-v0.4.tar.gz
  This is the original arduino_1.5-src archive downloaded from git which I modified to run on Linux. Only Digital Write and the stepper motor module are working. The other modules are still part of the archive but will most probably not work. In the original archive the stepper motor block was removed from the Arduino palettes. It has been put back. The original Arduino sketches have been moved into arduino.old and a new server sketch developed which you find in the arduino folder.
Line: 87 to 92
  loader.png
Changed:
<
<
Now you can start xcos either by typing xcos in the command window orr by clicking the Xcos icon (the one looking a bit like an oscilloscope). In the palettes box coming up you should see an Arduino entry:
>
>
Start xcos either by typing xcos in the command window or by clicking the Xcos icon (the one looking a bit like an oscilloscope). In the palettes box coming up you should see an Arduino entry:
  palette.png
Changed:
<
<
Now you can create a diagram using your new Arduino blocks and run it. The LED should blink or the stepper motor move.
>
>
Now you can create a diagram using your new Arduino blocks and run it. You can blink LEDs with the digital output block, read switches with the digital input block, read analog values or make a stepper motor move.
  -- Uli Raich - 2019-01-07
Line: 104 to 109
 
META FILEATTACHMENT attachment="serialLib.png" attr="" comment="" date="1547562536" name="serialLib.png" path="serialLib.png" size="23041" user="UliRaich" version="1"
META FILEATTACHMENT attachment="stepper.png" attr="" comment="" date="1547562537" name="stepper.png" path="stepper.png" size="15446" user="UliRaich" version="1"
META FILEATTACHMENT attachment="blink2.png" attr="" comment="" date="1547563216" name="blink2.png" path="blink2.png" size="63326" user="UliRaich" version="1"
Deleted:
<
<
META FILEATTACHMENT attachment="arduino-linux_1.5-src.tar.gz" attr="" comment="" date="1547645323" name="arduino-linux_1.5-src.tar.gz" path="arduino-linux_1.5-src.tar.gz" size="1841722" user="UliRaich" version="1"
 
META FILEATTACHMENT attachment="palette.png" attr="" comment="" date="1547645846" name="palette.png" path="palette.png" size="30131" user="UliRaich" version="1"
META FILEATTACHMENT attachment="loader.png" attr="" comment="" date="1547645846" name="loader.png" path="loader.png" size="11433" user="UliRaich" version="1"
META FILEATTACHMENT attachment="builder.png" attr="" comment="" date="1547645848" name="builder.png" path="builder.png" size="159072" user="UliRaich" version="1"
Added:
>
>
META FILEATTACHMENT attachment="arduino-linux_1.5-src-v0.4.tar.gz" attr="" comment="" date="1547831976" name="arduino-linux_1.5-src-v0.4.tar.gz" path="arduino-linux_1.5-src-v0.4.tar.gz" size="1844077" user="UliRaich" version="1"

Revision 42019-01-16 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="Scilab"

Implementing the Arduino toolbox

The program structure

Line: 32 to 32
 Sanp: Where "S" identifies for the stepper motor device, "a" stands for "attach" n is the GPIO pin and p is the pulse (N1 .. N4 or the stepping motor driver module) . The command also programs the GPIO pins as output. Sa21 will therefore attach GPIO pin 2 to the first stepping motor driver input (N1 on the driver card).

Sm: moves the stepping motor by 1 step

Added:
>
>
Sc: Clears all coil signals to low
 

The Arduino server program and the test procedure

With this information it is possible to develop the first version of the Arduino server. Since all it needs is input from the serial line we can write a simple C program to test the server. A program asking for the server version (and printing it) as well as the Arduino server are attached to this TWiki page.

Line: 53 to 55
 stepper.png

And in fact you see the motor turn when it receives the Sm commands.

Added:
>
>

How to bring the demo system up

A tar archive with a Xcos toolbox containing Digital Write as well as as a basic stepper motor xcos block is attached to this page:

https://iotworkshop.africa/pub/Embedded_Systems/ImplementingTheArduinoToolbox/arduino-linux_1.5-src.tar.gz

This is the original arduino_1.5-src archive downloaded from git which I modified to run on Linux. Only Digital Write and the stepper motor module are working. The other modules are still part of the archive but will most probably not work. In the original archive the stepper motor block was removed from the Arduino palettes. It has been put back. The original Arduino sketches have been moved into arduino.old and a new server sketch developed which you find in the arduino folder.

To install everything please

  • create a folder /opt/ucc/scilab
  • unpack the above tar archive into this folder.
Have a look in the arduino folder where you should find the server sketch called toolbox_arduino_v0.2.ino. This sketch must be uploaded onto an Arduino. I used an Arduino Nano but an Uno or Mega should work as well. For debugging I use a Softserial port. Connect your PC via a USB to serial converter to the Arduino. GPIO pin 10 on the Arduino corresponds to the Arduino Tx line (Rx of the USB to serial adapter) and pin 11 corresponds to Arduino Rx (see also the definitions in the sketch).

In arduino/serverTest you will find test programs for the server sketch as well as interface functions in serialLib which interface the XCos block Scilab code to the serial driver. The test program,running on the PC, (have a look at blink2.c) passes through these functions and calls the driver in exactly the same way that Scilab will use. For the moment only 2 such test programs are available:

  • blink2.c reading out the server version and blinking the Arduino builtin LED on GPIO pin 13
  • stepper.c which make the stepper motor move. The coil pins on the stepping motor controller (N1 .. N4) must be connected to Arduino GPIO pins 2..5
Try to make the Arduino server sketch work with these programs first.

Then start Scilab. Load the macros

  • builder.sce
  • loader.sce
  • unloader.sce
Execute the builder.sce script.

You should see something similar to this:

builder.png

If the builder exits successfully then you can start the loader adding the Arduino features into the Scilab system. This is what you should see:

loader.png

Now you can start xcos either by typing xcos in the command window orr by clicking the Xcos icon (the one looking a bit like an oscilloscope). In the palettes box coming up you should see an Arduino entry:

palette.png

Now you can create a diagram using your new Arduino blocks and run it. The LED should blink or the stepper motor move.

  -- Uli Raich - 2019-01-07
Line: 65 to 104
 
META FILEATTACHMENT attachment="serialLib.png" attr="" comment="" date="1547562536" name="serialLib.png" path="serialLib.png" size="23041" user="UliRaich" version="1"
META FILEATTACHMENT attachment="stepper.png" attr="" comment="" date="1547562537" name="stepper.png" path="stepper.png" size="15446" user="UliRaich" version="1"
META FILEATTACHMENT attachment="blink2.png" attr="" comment="" date="1547563216" name="blink2.png" path="blink2.png" size="63326" user="UliRaich" version="1"
Added:
>
>
META FILEATTACHMENT attachment="arduino-linux_1.5-src.tar.gz" attr="" comment="" date="1547645323" name="arduino-linux_1.5-src.tar.gz" path="arduino-linux_1.5-src.tar.gz" size="1841722" user="UliRaich" version="1"
META FILEATTACHMENT attachment="palette.png" attr="" comment="" date="1547645846" name="palette.png" path="palette.png" size="30131" user="UliRaich" version="1"
META FILEATTACHMENT attachment="loader.png" attr="" comment="" date="1547645846" name="loader.png" path="loader.png" size="11433" user="UliRaich" version="1"
META FILEATTACHMENT attachment="builder.png" attr="" comment="" date="1547645848" name="builder.png" path="builder.png" size="159072" user="UliRaich" version="1"

Revision 32019-01-15 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="Scilab"

Implementing the Arduino toolbox

The program structure

Line: 10 to 10
 There is already an Xcos system reading out several sensors and controlling several actuators, mainly motors. Unfortunately this Scilab toolbox works on Windows exclusively. It is however a good starting point for our Linux version. Using the same communication protocol and only changing the OS dependent calls to the serial driver will make both toolboxes largely compatible with each other.

I decided however to re-implement the Arduino server including better debugging features.

Added:
>
>

The communication protocol

 
Changed:
<
<
The communication protocol must be as simple and short as possible in order to increase the speed and therefore the maximum possible sampling rate. Here is the basic protocol description:

Setting the analogue reference and getting the server version

>
>
The communication protocol must be as simple and short as possible in order to increase the speed and therefore the maximum possible sampling rate.The server itself is an Arduino sketch consisting essentially of a big switch statement. The first specifies the type of action to be taken or the device to talk to. For the moment only 2 devices are implemented:
  • version: returns the version number of the protocol server on the Arduino
  • digital read or write
    This allows to read the state of a GPIO line defined in the xcos block or to write a high or low state to this GPIO line. Before the xcos simuation (the scilab program on the PC) is started (pre-simulation) the mode of the GPIO line is set.
  • stepping motor
    Here we set the GPIO pins associated to the stepping motor pulse to output in the pre-simulation step. The a "do one step" command is sent to the server.
Here is the basic protocol description:

Getting the server version

 
Changed:
<
<
R0: sets the analogue reference to default
R1: sets the analogue reference to internal
R2: sets the analogue reference to external
R3: gets the server version code. The server answers with Vx where x is the version number e.g. V4 for version 4
>
>
V: gets the server version code. The server answers with Vab where a is the major and b the minor version number e.g. V13 for version 1.3
 

Reading or writing a digital GPIO line

Changed:
<
<
Dan0 or Dan1: attaches GPIO line n. The last character defines if the line in input (0) or output (1). n is the GPIO pin number which can be '1' (0x31) up to '9' (0x39). For higher pin numbers just take the next ASCII characters. Having a look at the ASCII table tells us the pin number 10 will correspond to the ASCII characters with code (0x3A) which is ':', 11 corresponds to ';' and so on.
Drn: Read the state of GPIO line n
Dwn0 or Dwn1 sets the GPIO line n to 0 or 1 respectively.
>
>
Dan0 or Dan1: attaches GPIO line n. The last character defines if the line is input (0) or output (1). n is the GPIO pin number which can be '1' (0x31) up to '9' (0x39). For higher pin numbers just take the next ASCII characters. Having a look at the ASCII table tells us the pin number 10 will correspond to the ASCII characters with code (0x3A) which is ':', 11 corresponds to ';' and so on.
Drn: Read the state of GPIO line n
Dwn0 or Dwn1 sets the GPIO line n to 0 or 1 respectively.
  ascii.png
Added:
>
>

Controlling a stepper motor

In case of the stepper motor we need a means to define which GPIO pin is connected to which stepper motor coil. This is done with a command:

Sanp: Where "S" identifies for the stepper motor device, "a" stands for "attach" n is the GPIO pin and p is the pulse (N1 .. N4 or the stepping motor driver module) . The command also programs the GPIO pins as output. Sa21 will therefore attach GPIO pin 2 to the first stepping motor driver input (N1 on the driver card).

Sm: moves the stepping motor by 1 step

The Arduino server program and the test procedure

  With this information it is possible to develop the first version of the Arduino server. Since all it needs is input from the serial line we can write a simple C program to test the server. A program asking for the server version (and printing it) as well as the Arduino server are attached to this TWiki page.

The Arduino server uses debugging code which prints each character received as well as the interpretation in makes out of it to a Softserial port with Rx connected to GPIO pin 11 and Tx connected to pin 10. This Softserial port can be attached to a USB to serial adapter and the output observed with a serial emulator program like minicom. The communication between Scilab and the Arduino happens on /dev/ttyUSB0, the debugging port should therefore be connected to /dev/ttyUSB1 (minicom -D /dev/ttyUSB1).

Changed:
<
<
Here is a screen dump of the server output when we first read the server version and then blink the builtin LED 5 times:
>
>
Both, the test programs as well as the xcos toolbox, pass through the same serial library with the following calls:

serialLib.png

Since the test programs and the xcos toolbox use the same communication code we can be sure that once the server is tested with the test programs it will also work on the toolbox.

Here is a screen dump of the server output when we first read the server version and then blink the builtin LED (on GPIO pin 13) 5 times:

blink2.png

And this is the output from the Arduino server onto /dev/ttyUSB1 when running the stepper motor test:

stepper.png

 
Changed:
<
<
blink.png
>
>
And in fact you see the motor turn when it receives the Sm commands.
  -- Uli Raich - 2019-01-07
Line: 37 to 62
 
META FILEATTACHMENT attachment="blink.png" attr="" comment="" date="1546879763" name="blink.png" path="blink.png" size="39450" user="UliRaich" version="1"
META FILEATTACHMENT attachment="ascii.png" attr="" comment="" date="1546879775" name="ascii.png" path="ascii.png" size="71780" user="UliRaich" version="1"
Added:
>
>
META FILEATTACHMENT attachment="serialLib.png" attr="" comment="" date="1547562536" name="serialLib.png" path="serialLib.png" size="23041" user="UliRaich" version="1"
META FILEATTACHMENT attachment="stepper.png" attr="" comment="" date="1547562537" name="stepper.png" path="stepper.png" size="15446" user="UliRaich" version="1"
META FILEATTACHMENT attachment="blink2.png" attr="" comment="" date="1547563216" name="blink2.png" path="blink2.png" size="63326" user="UliRaich" version="1"

Revision 22019-01-07 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="Scilab"

Implementing the Arduino toolbox

The program structure

Line: 7 to 7
 
  • a server running on the Arduino taking commands from Xcos and accessing the GPIO hardware
  • an Xcos client implementing the Xcos blocks
  • a protocol defining the communication between client and server
Added:
>
>
There is already an Xcos system reading out several sensors and controlling several actuators, mainly motors. Unfortunately this Scilab toolbox works on Windows exclusively. It is however a good starting point for our Linux version. Using the same communication protocol and only changing the OS dependent calls to the serial driver will make both toolboxes largely compatible with each other.

I decided however to re-implement the Arduino server including better debugging features.

The communication protocol must be as simple and short as possible in order to increase the speed and therefore the maximum possible sampling rate. Here is the basic protocol description:

Setting the analogue reference and getting the server version

R0: sets the analogue reference to default
R1: sets the analogue reference to internal
R2: sets the analogue reference to external
R3: gets the server version code. The server answers with Vx where x is the version number e.g. V4 for version 4

Reading or writing a digital GPIO line

Dan0 or Dan1: attaches GPIO line n. The last character defines if the line in input (0) or output (1). n is the GPIO pin number which can be '1' (0x31) up to '9' (0x39). For higher pin numbers just take the next ASCII characters. Having a look at the ASCII table tells us the pin number 10 will correspond to the ASCII characters with code (0x3A) which is ':', 11 corresponds to ';' and so on.
Drn: Read the state of GPIO line n
Dwn0 or Dwn1 sets the GPIO line n to 0 or 1 respectively.

ascii.png

With this information it is possible to develop the first version of the Arduino server. Since all it needs is input from the serial line we can write a simple C program to test the server. A program asking for the server version (and printing it) as well as the Arduino server are attached to this TWiki page.

The Arduino server uses debugging code which prints each character received as well as the interpretation in makes out of it to a Softserial port with Rx connected to GPIO pin 11 and Tx connected to pin 10. This Softserial port can be attached to a USB to serial adapter and the output observed with a serial emulator program like minicom. The communication between Scilab and the Arduino happens on /dev/ttyUSB0, the debugging port should therefore be connected to /dev/ttyUSB1 (minicom -D /dev/ttyUSB1).

Here is a screen dump of the server output when we first read the server version and then blink the builtin LED 5 times:

blink.png

  -- Uli Raich - 2019-01-07

Comments

<--/commentPlugin-->
Added:
>
>
META FILEATTACHMENT attachment="blink.png" attr="" comment="" date="1546879763" name="blink.png" path="blink.png" size="39450" user="UliRaich" version="1"
META FILEATTACHMENT attachment="ascii.png" attr="" comment="" date="1546879775" name="ascii.png" path="ascii.png" size="71780" user="UliRaich" version="1"

Revision 12019-01-07 - UliRaich

Line: 1 to 1
Added:
>
>
META TOPICPARENT name="Scilab"

Implementing the Arduino toolbox

The program structure

As you would probably expect, the program will consist of three parts

  • a server running on the Arduino taking commands from Xcos and accessing the GPIO hardware
  • an Xcos client implementing the Xcos blocks
  • a protocol defining the communication between client and server

-- Uli Raich - 2019-01-07

Comments

<--/commentPlugin-->
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback