Tags:
view all tags
---+ 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 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<br /><b>R1:</b> sets the analogue reference to internal<br /><b>R2</b>: sets the analogue reference to external<br /><b>R3</b>: 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.<br /><b>Drn</b>: Read the state of GPIO line n<br /><b>Dwn0</b> or <b>Dwn1 </b>sets the GPIO line n to 0 or 1 respectively. <img alt="ascii.png" height="294" src="%ATTACHURL%/ascii.png" title="ascii.png" width="637" /> 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: <img alt="blink.png" height="433" src="%ATTACHURL%/blink.png" title="blink.png" width="312" /> -- %USERSIG{UliRaich - 2019-01-07}% ---++ Comments %COMMENT%
Attachments
Attachments
Topic attachments
I
Attachment
History
Action
Size
Date
Who
Comment
png
ascii.png
r1
manage
70.1 K
2019-01-07 - 16:49
UliRaich
png
blink.png
r1
manage
38.5 K
2019-01-07 - 16:49
UliRaich
Edit
|
Attach
|
Watch
|
P
rint version
|
H
istory
:
r8
|
r4
<
r3
<
r2
<
r1
|
B
acklinks
|
V
iew topic
|
Raw edit
|
More topic actions...
Topic revision: r2 - 2019-01-07
-
UliRaich
Home
Site map
AFNOG web
Embedded_Systems web
IoT_Course_English web
IoT_Course_French web
Main web
Sandbox web
TWiki web
Embedded_Systems Web
Create New Topic
Index
Search
Changes
Notifications
RSS Feed
Statistics
Preferences
P
View
Raw View
Print version
Find backlinks
History
More topic actions
Edit
Raw edit
Attach file or image
Edit topic preference settings
Set new parent
More topic actions
Account
Log In
Register User
Edit
Attach
Copyright © 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