Serial String read & write

934 views
Skip to first unread message

Paolo Botta

unread,
Feb 20, 2018, 10:48:09 AM2/20/18
to Bonsai Users
Hi Goncalo,

The BONSAI code attached is able to read values from an arduino output. The output value is expressed in speed.
Is there a way to trigger another arduino when the speed exceed a certain threshold?

Thanks,
Paolo




Wheel.bonsai

Gonçalo Lopes

unread,
Feb 20, 2018, 8:10:38 PM2/20/18
to Paolo Botta, Bonsai Users
Hi Paolo,

What do you mean by "trigger another arduino"? Do you want to just send the data to another serial port? It looks like this workflow can do this just fine already.

Do you want to change the state of pins in the Arduino when the value exceeds the threshold? If this is the case, you need to first read the value as a numerical value. You may be interested in the recent discussion about the Parse operator:
https://groups.google.com/forum/#!topic/bonsai-users/cV2aUowMmzE

There are many posts in the forum about triggering the pins of the Arduino in all kinds of ways. Can you elaborate on what exactly do you want to do?


--
You received this message because you are subscribed to the Google Groups "Bonsai Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bonsai-users+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/bonsai-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/bonsai-users/7c236537-849c-48e4-8788-4ac19bbc29a9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Paolo Botta

unread,
Feb 21, 2018, 9:49:05 AM2/21/18
to Gonçalo Lopes, Bonsai Users
Sorry for not explain better.

Yesterday I read all the posts on parse and included. However, the value is still in string and I did not find a single post showing how to convert it to a numeric value.
As you wrote, I want to convert this value in a numerical value, use a threshold (I was using the node GreaterThan), change the state of pins in the Arduino when the value exceeds the threshold.
I guess the only step is missing so far is how to convert the string value to a numeric value.

I am attaching the BONSAI code. I have used parse to divide the two items (item 1: speed; item 2: time; for simplicity I have included only the item 1 in the code). I would like to convert the speed from the Source.item1 into a numerical value, set a threshold and change the pin state of an arduino.
Here it is the error when I include GreaterThan after the Source.Item1 (obtained from the Parse node output).

Inline image 1

Hope that I was more clear. Thanks for the help!
Paolo



Paolo Botta
Postdoctoral fellow, Costa lab
Zuckerman Institute
Columbia University
Tel. +1 3475253666 | Skype paolo...@gmail.comLinkedIn
Wheeltest.bonsai

Gonçalo Lopes

unread,
Feb 21, 2018, 9:53:54 AM2/21/18
to Paolo Botta, Bonsai Users
Hi Bogdan,

Can you tell me which Pattern you are using for the Parse node?

Paolo Botta

unread,
Feb 21, 2018, 10:11:55 AM2/21/18
to Gonçalo Lopes, Bonsai Users
I am using: %s;%s

I have also tried %i;%i but it is not working because values are strings.

Paolo Botta
Postdoctoral fellow, Costa lab
Zuckerman Institute
Columbia University
Tel. +1 3475253666 | Skype paolo...@gmail.comLinkedIn

Gonçalo Lopes

unread,
Feb 21, 2018, 10:34:28 AM2/21/18
to Paolo Botta, Bonsai Users
What do you mean "values are strings"? The input to Parse is always a string, the whole point is to convert text into numbers.

Can you show me an example of what a line from the serial port looks like?

Paolo Botta

unread,
Feb 21, 2018, 12:19:15 PM2/21/18
to Gonçalo Lopes, Bonsai Users
Sure. You can find it here.
Sometimes there is a slo a weird character (with question points: ????) after 5 or 6 frames..

Paolo Botta
Postdoctoral fellow, Costa lab
Zuckerman Institute
Columbia University
Tel. +1 3475253666 | Skype paolo...@gmail.comLinkedIn

testParse2018-02-21T12_16_55.txt

Paolo Botta

unread,
Feb 21, 2018, 12:29:00 PM2/21/18
to Gonçalo Lopes, Bonsai Users
I have managed to get rid of the first line using skip.
Subsequently, we wrote a small script using PythonTransform:

@returns(float)
def process(value):
  num = float(value)
  return num

Finally, I have set a threshold using GreaterThan to trigger the change the pin state of an arduino board.

Inline image 1

I am also attaching the code in case there is a simpler solution.

Paolo Botta
Postdoctoral fellow, Costa lab
Zuckerman Institute
Columbia University
Tel. +1 3475253666 | Skype paolo...@gmail.comLinkedIn

Wheeltest.bonsai

Gonçalo Lopes

unread,
Feb 21, 2018, 12:53:09 PM2/21/18
to Paolo Botta, Bonsai Users
Hi Paolo,

The Pattern property needs to match the input string, in your case:

(%i, %i)

If it matches, Parse will extract the right input numbers.

Paolo Botta

unread,
Feb 21, 2018, 3:10:04 PM2/21/18
to Gonçalo Lopes, Bonsai Users
I tried it yesterday and it was not working. Parse was working only using “%s, %s”.
I can give it another try and let you know. Thanks,
Paolo

To unsubscribe from this group and stop receiving emails from it, send an email to bonsai-users...@googlegroups.com.








--
Reply all
Reply to author
Forward
0 new messages