Login | Register 
FEATURES
APPLICATIONS
DOWNLOADS
EDUCATION
BLOG
WIKI
FORUM
STORE

Arduino - DAT Serial In

Helpful techniques for working with TouchDesigner. Answers only, no questions.

Re: Arduino - DAT Serial In

Postby bwheaton » Mon Dec 16, 2013 6:21 pm

Serial.print (02, HEX);
// Other data
Serial.print (03, HEX);
bwheaton
 
Posts: 329
Joined: Mon Mar 19, 2012 1:33 am

Re: Arduino - DAT Serial In

Postby rob » Sat Dec 21, 2013 1:38 pm

Hi Bruce.
Wouldn't it be just as simple to keep it delimited per line (newline or carriage return),
and wrap the contents of each message in say, square brackets.
Then the receiving end, on receiving each line could make sure the message began with [ and ended with ] ?
No special byte-by-byte parsing required.
User avatar
rob
Staff
 
Posts: 1640
Joined: Tue Nov 13, 2007 1:14 am

Re: Arduino - DAT Serial In

Postby bwheaton » Sat Dec 21, 2013 2:55 pm

Yes, but then you would be vulnerable to those characters appearing in normal text. The same could apply with a carriage return - what if you want to send a two line block of text?

Either way is better than hoping TD and the sender just happen to stay in sync.

Bruce

Edit - I should point out, I'm not making this up. This is what the STX and ETX characters are for, and using them was common when serial was the only game in town.

The other option (to do it for production quality) would be to escape certain characters, in your example, to use [, ] or return they would have to be escaped. That could be as simple as /[, /], /CR (plus you then need //).
bwheaton
 
Posts: 329
Joined: Mon Mar 19, 2012 1:33 am

Re: Arduino - DAT Serial In

Postby rob » Sat Dec 21, 2013 4:57 pm

Sure I realize the issue is that it requires reserving delimiting characters, but the vast bulk of Arduino->TD communication will be human readable ascii with a known format. (ie, labelled numeric values).
Even sending 0x2, 0x3 would make sending binary data problematic.
Most general solution would be escaping characters as you mention, or including simple checksums or other redundancies.
Cheers
Rob.
User avatar
rob
Staff
 
Posts: 1640
Joined: Tue Nov 13, 2007 1:14 am

Re: Arduino - DAT Serial In

Postby bwheaton » Sun Dec 22, 2013 3:13 pm

Well, putting aside your proposing human readable and binary formats in the same sentence... ;) you are correct that there's no perfect solution. In old serial systems, the protocol was always ascii - so STX and ETX were free, or binary, and other mechanisms are used (start headers, checksums etc.).

As discussed, formats like XML and JSON use escape sequences. But that does make binary data a rigamarole, and parsing too (more of a problem in the Arduino than in TD). Are there standard 'escape characters' and 'unescape' functions in python or an OP?

Anyway, I know you've understood my point. I'm sure what you put in the docs will be safe without being confusing. Thanks for paying attention, and Merry Christmas!

Bruce
bwheaton
 
Posts: 329
Joined: Mon Mar 19, 2012 1:33 am

Re: Arduino - DAT Serial In

Postby BenJSharman » Wed Feb 27, 2019 11:34 pm

rob wrote:Hi Bruce.
Wouldn't it be just as simple to keep it delimited per line (newline or carriage return),
and wrap the contents of each message in say, square brackets.
Then the receiving end, on receiving each line could make sure the message began with [ and ended with ] ?
No special byte-by-byte parsing required.


Hello,

I am using an Arduino with 20 or so different potentiometer, button and toggle inputs that I am controlling a visual and sound with. Most of the time the readings are stable and accurate, however occasionally it seems the SerialDAT misses a character or two, throwing the whole thing off momentarily, glitching the visual and soundtrack.

I have been reading for days trying to send the data in different ways, but it seems that this is the way to do it. My problem is I can't figure out how to set up a CallResponse/handshake type setup between Arduino and Touchdesigner. Could you point me in the right direction or explain how to code this type of communication. Thanks in advance,

Ben
BenJSharman
 
Posts: 7
Joined: Wed Feb 14, 2018 1:40 pm

Re: Arduino - DAT Serial In

Postby bwheaton » Thu Feb 28, 2019 3:38 pm

It sounds like you're a good candidate for checksums of some kind.

But first - do you have any debug (print statements, screenshots) of when the problem happens?

It's possible that the serial message/s are just being split between callbacks and you need a different approach.

PM me a touch file if you want. Don't have time to spin up an Arduino and electronics ;) but I can have a quick look.

Bruce
bwheaton
 
Posts: 329
Joined: Mon Mar 19, 2012 1:33 am

Re: Arduino - DAT Serial In

Postby BenJSharman » Thu Feb 28, 2019 5:29 pm

Hi Bruce,

Ahh interesting, checksums aren't something I had heard of! Will see if I can wrap my head around them and implement.

I have put a couple of images, the Arduino and touch files into the .zip, you might not need it but it may be handy to see them. The SerialDAT is set to receive 31 lines purely to show the error more clearly.

Ideally the process would be as speedy as possible to reduce lag from a controller being used to drive visuals etc.

Ben
Attachments
Debugging Files.zip
(962.29 KiB) Downloaded 27 times
BenJSharman
 
Posts: 7
Joined: Wed Feb 14, 2018 1:40 pm

Previous

Return to Techniques

Who is online

Users browsing this forum: No registered users and 0 guests