0

I have trying to connect an ultrasonic sensor in scilab and I'am utilizing the Arduino toolbox for it. Unfortunately I cannot connect the ultrasonic sensor directly to scilab unlike the temperature sensor that outputs voltage depending on the temperature so that it can be read by the arduino toolbox using ANALOG_READ block. My solution is using two arduino-nos.

A. Arduino 1

This is Where I programmed the ultrasonic sensor and mapped the sensed distance to output a certain PWM value.

B. Arduino 2

This arduino has the Arduino toolbox.ino uploaded so that it would work on scilab. I tried editing the Arduino toolbox.ino but any change to that ino file would not work in scilab it gives an error saying this is not the Arduino toolbox.ino even though it is and I just inserted a function for the ultrasonic sensor.

Bascially I can now output PWM values with respect to distance so that it can be read in scilab using the DIGITAL_READ block.But I dont know how to interpret the waveform. I want to output it as 0%-100% not just a waveform shown in the Scope.

  • take a look at [Scilab Serial Communication Toolbox](https://github.com/Foadsf/Scilab-Serial) or the new version which I'm working on [here](https://gist.github.com/Foadsf/44fe9b5e2bcb02b22392adf6d8f7a871) – Foad S. Farimani Mar 06 '19 at 11:17
  • 1
    Thanks ! this is really help full! Is it possible that the serial data read can be used as an XCOS block ? using "From workspace block" or any alternative I need the serial data as a feedback to a PID –  Mar 06 '19 at 21:59
  • yes there is `writeserial` [here](https://github.com/Foadsf/Scilab-Serial/blob/master/macros/writeserial.sci). It is not ideal but should work. – Foad S. Farimani Mar 06 '19 at 22:10
  • and lastly Can I use the serial write in XCOS for example using a sinewave block that oscillates from -5 to 5 can I serial write it to an arduino ? I have not really tried it because I dont know how to approach this. I programmed my arduino to receive values from the serial port. –  Mar 06 '19 at 22:25
  • My only solution is utilizing "to workspace block"that exports the sine wave data to workspace then serial writes it but the problem with the "to workspace block is it only exports XCOS data after the simulation . I really want it in real time –  Mar 06 '19 at 22:32
  • There is already an Arduino ToolBox for xcos [here](https://atoms.scilab.org/toolboxes/arduino). but if you wish to have more control, it is possible to have Scilab function blocks inside xcos as I have explained [here](https://stackoverflow.com/a/54816664/4999991) – Foad S. Farimani Mar 06 '19 at 22:34
  • Is it possible to simultaneously use the Arduino Toolbox + Serial Communication Toolbox . I 'am aware that the Arduino Toolbox utilizes the serial communication toolbox and Iam planning to create a function that also utilizes the serial communication in scilab to be used as an XCOS block . Would it interfere with the Arduino toolbox ? –  Mar 06 '19 at 22:49
  • I haven't used the Arduino Toolbox but it seema to be just a wrapper around the serial toolbox AFIK. and they both are relying on Tcl for handing serial ports I think. variables are globally persistent on Tcl too. So I guess there shouldn't be a problem if you know what you are doing. – Foad S. Farimani Mar 06 '19 at 22:51
  • 1
    Thank you so much, really appreciate it for answering my questions ! –  Mar 06 '19 at 23:01
  • happy to help. [This post](https://stackoverflow.com/a/54960839/4999991) also might help. – Foad S. Farimani Mar 06 '19 at 23:03
  • @Foad i was trying to install the toolbox form your github in Scilab 5.5.2 using the zip file –  Mar 07 '19 at 03:36
  • -->atomsInstall('C:\Users\Desktop\5th year\scilabbFinal\Scilab-Serial-master.zip') !--error 10000 atomsDESCRIPTIONread: The file "C:\PROGRA~1\SCILAB~1.2\.atoms\tmp_1551929622\Scilab-Serial-master\DESCRIPTION" does not exist. at line 46 of function atomsDESCRIPTIONread called by : at line 160 of function atomsInstall called by : atomsInstall('C:\Users\Desktop\5th year\scilabbFinal\Scilab-Serial-master.zip') –  Mar 07 '19 at 03:36
  • ok I have managed to get it working installing serial coms in atoms then finding its file location deleting old files basically everything and copy pasting your files. –  Mar 07 '19 at 03:55
  • @Foad is it possible to read two COM ports at the same time using the toolbox ? –  Mar 07 '19 at 04:12
  • well, scilab is not the best platform for real time io, neither is MATLAB or Python. you can read/feed multiple ports consecutively, however there will be some delays. if you want true real time go for lower level languages like C and you need a real time operating system. – Foad S. Farimani Mar 07 '19 at 06:01
  • ohh even MATLAB ! ok thank you so much for the tips and answering my questions again. –  Mar 07 '19 at 07:12
  • MATLAB is actually a bloated platform. In some cases even Python is faster. FYI Octave has also serial communication capabilities if you do not need the Scilab GUI building and xcos / scicos platform. It is even more MATLAB compliant. – Foad S. Farimani Mar 07 '19 at 07:51
  • Yeah I've tried octave but i really need the GUI building of xcos which is why i choose xcos. I tried to create a function so that the serial read can be displayed on the xcos scope but failed. Asked I question here https://stackoverflow.com/questions/55040779/scilab-function-as-a-block-in-xcos-variable-returned-by-scilab-argument-functi I think i cannot directly put serialread as a function in xcos why is that and my implementation of this is wrong ? I was hoping you could give insight on this –  Mar 07 '19 at 10:03

0 Answers0