Serial connection (realtime)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Serial connection (realtime)

GuiCintraAlves
Hi I need do a connection real time,

between arduino and Octave

. I searched very much but i didn't find good exemples for do that.

I finded exemple for matlab. please somebody helpme.

sorry for my English.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Serial connection (realtime)

Juan Pablo Carbajal-2
On Wed, Mar 1, 2017 at 4:41 AM, GuiCintraAlves
<[hidden email]> wrote:

> HiI need do a connection real time,
> between arduino and Octave
> . I searched very much but i didn't  find good exemples for do that.
> I finded exemple for matlab. please somebody helpme.
> sorry for my English.
>
>
>
>
> --
> View this message in context: http://octave.1599824.n4.nabble.com/Serial-connection-realtime-tp4682072.html
> Sent from the Octave - General mailing list archive at Nabble.com.
>
> _______________________________________________
> Help-octave mailing list
> [hidden email]
> https://lists.gnu.org/mailman/listinfo/help-octave

see if you can use the instrumnet-contorl package
https://octave.sourceforge.io/instrument-control/
it worked with arduino leonardo, no prob, and with PIC ucontroler
http://shop.dwengo.org/node/486

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Serial connection (realtime)

GuiCintraAlves
I'm making the arduino connection using potentiometer (for testing) and I get random values ​​... can you tell me why?

pkg load instrument-control

s1 = serial("/dev/ttyACM0",9600)
data = srl_read(s1,100)
.............................................
Serial Port Object
    open:     1
    port:     /dev/ttyACM0
    baudrate: 9600
    parity:   None
    bytesize: 8
    stopbits: 1
    timeout:  -1


data =

 Columns 1 through 18:

  13  10  53  53  50  13  10  53  53  49  13  10  53  53  50  13  10  53

 Columns 19 through 36:

  53  49  13  10  53  53  51  13  10  53  53  48  13  10  53  53  50  13

 Columns 37 through 54:

  10  53  53  49  13  10  53  53  49  13  10  53  53  49  13  10  53
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Serial connection (realtime)

Juan Pablo Carbajal-2
On Wed, Mar 1, 2017 at 2:24 PM, GuiCintraAlves
<[hidden email]> wrote:

> I'm making the arduino connection using potentiometer (for testing) and I get
> random values ... can you tell me why?
>
> pkg load instrument-control
>
> s1 = serial("/dev/ttyACM0",9600)
> data = srl_read(s1,100)
> .............................................
> Serial Port Object
>     open:     1
>     port:     /dev/ttyACM0
>     baudrate: 9600
>     parity:   None
>     bytesize: 8
>     stopbits: 1
>     timeout:  -1
>
>
> data =
>
>  Columns 1 through 18:
>
>   13  10  53  53  50  13  10  53  53  49  13  10  53  53  50  13  10  53
>
>  Columns 19 through 36:
>
>   53  49  13  10  53  53  51  13  10  53  53  48  13  10  53  53  50  13
>
>  Columns 37 through 54:
>
>   10  53  53  49  13  10  53  53  49  13  10  53  53  49  13  10  53
>
>
>
> --
> View this message in context: http://octave.1599824.n4.nabble.com/Serial-connection-realtime-tp4682072p4682078.html
> Sent from the Octave - General mailing list archive at Nabble.com.
>
> _______________________________________________
> Help-octave mailing list
> [hidden email]
> https://lists.gnu.org/mailman/listinfo/help-octave

what is the size of the datatype you are sending? you need to take
care of long ints properly. See code in previous mail.

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Serial connection (realtime)

GuiCintraAlves
In reply to this post by GuiCintraAlves
The point is that even by varying the potentiometer the values ​​do not change, and the "led tx" of the arduino does not show that this communication is actually being performed.

Example:
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Serial connection (realtime)

Juan Pablo Carbajal-2
On Wed, Mar 1, 2017 at 3:06 PM, GuiCintraAlves
<[hidden email]> wrote:

> The point is that even by varying the potentiometer the values do not
> change, and the "led tx" of the arduino does not show that this
> communication is actually being performed.
>
> Example:
> <http://octave.1599824.n4.nabble.com/file/n4682080/arduinooctave.png>
>
>
>
> --
> View this message in context: http://octave.1599824.n4.nabble.com/Serial-connection-realtime-tp4682072p4682080.html
> Sent from the Octave - General mailing list archive at Nabble.com.
>
> _______________________________________________
> Help-octave mailing list
> [hidden email]
> https://lists.gnu.org/mailman/listinfo/help-octave

have you checked the level of noise in the channel?

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Serial connection (realtime)

GuiCintraAlves
No... but went i use
#!/bin/bash
 cu -l /dev/ttyACM0 -s 9600
 $SHELL

It works just like the arduino's serial monitor. I hope it's something octave ...
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Serial connection (realtime)

Juan Pablo Carbajal-2
On Wed, Mar 1, 2017 at 6:25 PM, GuiCintraAlves
<[hidden email]> wrote:

> No... but went i use
> #!/bin/bash
>  cu -l /dev/ttyACM0 -s 9600
>  $SHELL
>
> It works just like the arduino's serial monitor. I hope it's something
> octave ...
>
>
>
> --
> View this message in context: http://octave.1599824.n4.nabble.com/Serial-connection-realtime-tp4682072p4682088.html
> Sent from the Octave - General mailing list archive at Nabble.com.
>
> _______________________________________________
> Help-octave mailing list
> [hidden email]
> https://lists.gnu.org/mailman/listinfo/help-octave

more information would be needed to detect what the problem is.
Ideally you could report a bug in the bug tracker.
It seems the serial connection is not being established by the
instrument-control package (I can't reproduce here).

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Serial connection (realtime)

Kire Pudsje
Looking at the data, I see 13 and 10. These are the ascii values of carriage return and line feed.
So the data is just a list of ascii values representing characters.
To convert to a string, just do:
s =  char(data);
Then (after making sure, you do proper aligning of strings, to prevent cuts between digits), use
val = str2num(s);

untested code, processing chunks of 100 bytes at once
dataacc = [];
while true
  % read data
  data=srl_read(s1,100);
  % append to accumulation buffer
  datacc = [datacc, data];
  % find last line feed
  idx = find(dataacc == 10);
  % if something found
  if ~isempty(idx)
    % process data until last linefeed character
    val = str2num(char(dataacc(1:idx(end))));
    % do something useful with the data
    disp(val);
    % remove processed part from accumulation buffer
    dataacc(1:idx) = [];
  end
end


On Wed, Mar 1, 2017 at 11:15 PM, Juan Pablo Carbajal <[hidden email]> wrote:
On Wed, Mar 1, 2017 at 6:25 PM, GuiCintraAlves
<[hidden email]> wrote:
> No... but went i use
> #!/bin/bash
>  cu -l /dev/ttyACM0 -s 9600
>  $SHELL
>
> It works just like the arduino's serial monitor. I hope it's something
> octave ...
>
>
>
> --
> View this message in context: http://octave.1599824.n4.nabble.com/Serial-connection-realtime-tp4682072p4682088.html
> Sent from the Octave - General mailing list archive at Nabble.com.
>
> _______________________________________________
> Help-octave mailing list
> [hidden email]
> https://lists.gnu.org/mailman/listinfo/help-octave

more information would be needed to detect what the problem is.
Ideally you could report a bug in the bug tracker.
It seems the serial connection is not being established by the
instrument-control package (I can't reproduce here).

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Serial connection (realtime)

Kire Pudsje
Sorry, one of the last lines should have been
    dataacc(1:idx(end)) = [];

On Thu, Mar 2, 2017 at 3:29 AM, Kire Pudsje <[hidden email]> wrote:
Looking at the data, I see 13 and 10. These are the ascii values of carriage return and line feed.
So the data is just a list of ascii values representing characters.
To convert to a string, just do:
s =  char(data);
Then (after making sure, you do proper aligning of strings, to prevent cuts between digits), use
val = str2num(s);

untested code, processing chunks of 100 bytes at once
dataacc = [];
while true
  % read data
  data=srl_read(s1,100);
  % append to accumulation buffer
  datacc = [datacc, data];
  % find last line feed
  idx = find(dataacc == 10);
  % if something found
  if ~isempty(idx)
    % process data until last linefeed character
    val = str2num(char(dataacc(1:idx(end))));
    % do something useful with the data
    disp(val);
    % remove processed part from accumulation buffer
    dataacc(1:idx) = [];
  end
end


On Wed, Mar 1, 2017 at 11:15 PM, Juan Pablo Carbajal <[hidden email]> wrote:
On Wed, Mar 1, 2017 at 6:25 PM, GuiCintraAlves
<[hidden email]> wrote:
> No... but went i use
> #!/bin/bash
>  cu -l /dev/ttyACM0 -s 9600
>  $SHELL
>
> It works just like the arduino's serial monitor. I hope it's something
> octave ...
>
>
>
> --
> View this message in context: http://octave.1599824.n4.nabble.com/Serial-connection-realtime-tp4682072p4682088.html
> Sent from the Octave - General mailing list archive at Nabble.com.
>
> _______________________________________________
> Help-octave mailing list
> [hidden email]
> https://lists.gnu.org/mailman/listinfo/help-octave

more information would be needed to detect what the problem is.
Ideally you could report a bug in the bug tracker.
It seems the serial connection is not being established by the
instrument-control package (I can't reproduce here).

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave



_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Serial connection (realtime)

GuiCintraAlves
The conversion worked. But the code, no. After all what is the real purpose of this code? Write the data ?? I cony analyze more than one example signal detect 2 different potentiometers on the same serial?

pkg load instrument-control

 s1 = serial("/dev/ttyACM0",9600)
 data = srl_read(s1,100);
 s1 = char(data);
 val = str2num(s1)

..............................................

s1 =

  Serial Port Object
    open:     1
    port:     /dev/ttyACM0
    baudrate: 9600
    parity:   None
    bytesize: 8
    stopbits: 1
    timeout:  -1


val =

     5
   558
   558
   558
   558
   558
   558
   558
..............................................
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Serial connection (realtime)

Kire Pudsje


On Tue, Mar 7, 2017 at 12:44 PM, GuiCintraAlves <[hidden email]> wrote:
The conversion worked. But the code, no. After all what is the real purpose
of this code? Write the data ?? I cony analyze more than one example signal
detect 2 different potentiometers on the same serial?

If the code works, then you are OK.

The code was intended for cases where the microcontroller keeps on spitting out data.
Suppose you read in 10 byte chunks and the following data is being output
1 23 456 78910 111213 141516

in chunks of 10 bytes this is
"1 23 456 7"
"8910 11121"
"3 141516"

processing with str2num would result in
1
23
456
7
8910
11121
3
141516

instead of
1
23
456
78910
111213
141516

So some protection of values crossing chunk borders should be there.
If you do not care about dropping values, you can throw away the first and last value of a chunk.

For outputting 2 values, you could eg do: v1[space]v2[crlf].
But there are lots of ways to (de)serialize data, but that is another topic.
Anyway you have the serial port working.


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Loading...