Login | Register 
FEATURES
APPLICATIONS
DOWNLOADS
EDUCATION
BLOG
WIKI
FORUM
STORE

Arduino - DAT Serial In

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

Arduino - DAT Serial In

Postby xnimax » Fri May 14, 2010 12:44 pm

Download Arduino 0018 and also the ftid driver for the COM Port:
(if you buy a new Arduino from June2010 you don't need the driver annymore)

Downaload and Install FIRMATA from this link:
http://firmata.org/wiki/Download


- open from the Examples of Arduino the AnolgInSerial example

this is the script:

void setup() {
Serial.begin(9600);
}

void loop() {
// read the analog input into a variable:
int analogValue = analogRead(0)/4;
// print the result:
Serial.println(cancel ln)(analogValue,BYTE);
// wait 10 milliseconds for the analog-to-digital converter
// to settle after the last reading:
delay(10);
}

I wrote in RED what you have to change before uploading

UPLOAD ON YOUR BOARD

Now open Touch077 and place a DAT Serial In

In this jpeg you can see what you have to change in the Parameter of the Serial DAT

DAT_SerialIn_Parameter.jpg
DAT_SerialIn_Parameter.jpg (379.64 KiB) Viewed 11397 times



IT WORKS REALLY GOOD!! :) This is the value from an anaolg in attached to a light sensor...

Try it and make your own controller!

ciaaooooo! :D
User avatar
xnimax
 
Posts: 57
Joined: Wed Apr 16, 2008 11:45 pm
Location: Italy

Re: Arduino - DAT Serial In

Postby mkotlhar » Wed Jan 05, 2011 10:32 pm

Hey!

i'm new to arduino and i'm a bit confused.

why use FIRMATA? Where are you using it?

in your sketch the line:
Serial.println(cancel ln)(analogValue,BYTE);

what is (cancel ln)? it keeps coming up as an error for me.

Like i said i'm new to arduino and i've been trying to get it to talk to touch. I've got it working using a straight Serial.print command but my sensor reading comes out as a message and not a value. It seems i'm off in the wrong direction.

best,
mk
mkotlhar
 
Posts: 9
Joined: Sat Jul 04, 2009 9:10 pm

Re: Arduino - DAT Serial In

Postby rob » Thu Jan 06, 2011 1:55 pm

Hello.

What do you mean comes out as a 'message' and not 'value' ?
Can you try changing the Format in the Serial In DAT to 'per line' ?
The trick is to match the Arduino output format with the Touch Serial In DAT.

If you println(value, DEC) for example, it will output ascii bytes followed by an end of line,
as so you should set the SerialIn DAT format to 'One Row Per Line'.
You should be able to catch any values that fit in a 4-byte integer.
You could also print them as floats too for example.

If you print(value, BYTE) (print, not println) it will output individual binary 8-bit bytes,
so Touch should be set to 'One Row Per Byte'

(Using the latest experimental Touch)

Hope that helps

Cheers.
Rob
User avatar
rob
Staff
 
Posts: 1671
Joined: Tue Nov 13, 2007 1:14 am

Re: Arduino - DAT Serial In

Postby mkotlhar » Sun Jan 09, 2011 10:45 pm

Rob!

Seems like i was using the regular build and not the experimental build of touch. The serial DAT on the experimental build is a bit more comprehensive and i got it to work great!

Although I could only get multiple serial messages properly using BYTES. When using ASCII i get a blank line after each value. So to receive all my messages i need to have the double number of lines.

for examples if i do:

value = 2

Serial.println(value, DEC)
Serial.println(value*2, DEC)
Serial.println(value*4, DEC)
Serial.println(value/2, DEC)

the serial DAT reads:

2
blank line
4
blank line
8
blank line
1
blank line


Well Bytes work great for now. But it would be great to nail this thing.

thanks for the help!

best,
mk
mkotlhar
 
Posts: 9
Joined: Sat Jul 04, 2009 9:10 pm

Re: Arduino - DAT Serial In

Postby rob » Mon Jan 10, 2011 5:44 pm

Found the problem.

When you 'println' in Arduino, it actually outputs both the carriage return (13) and the line feed (10) characters.

Touch uses either one to delimit end of line, so unfortunately it sees the line feed as an empty line.

(You can always see what bytes are actually received in the DAT by turning on the 'Value Column' parameter in the last tab of parameters)

Now the most reliable way of sending numeric values to the DAT would be to leave its Table Format to 'One Row Per Line' but change the Arduino script to only output a carriage return.

Heres a brief example.
Note you're free to use values greater than 1 byte, including floating points:

Hope that helps,
Rob.


Code: Select all
void setup()
{
  // start serial port at 9600 bps:
  Serial.begin(9600);
}

void loop()
{
  delay(1000);
   
  int  i = 1234;
  Serial.print(i, DEC);
  Serial.print('\n');
 
  float f = 321.7;
  Serial.print(f);
  Serial.print('\n');
}
User avatar
rob
Staff
 
Posts: 1671
Joined: Tue Nov 13, 2007 1:14 am

Re: Arduino - DAT Serial In

Postby rob » Mon Jan 10, 2011 7:31 pm

Ive encapsulated the above in a new wiki page:

http://www.derivative.ca/wiki/index.php?title=Arduino


-Rob
User avatar
rob
Staff
 
Posts: 1671
Joined: Tue Nov 13, 2007 1:14 am

Re: Arduino - DAT Serial In

Postby DG2011 » Fri May 04, 2012 6:00 pm

Hey Rob!

Is it possible to have the toe file from your video?

THANKS!
DG2011
 
Posts: 31
Joined: Mon Nov 28, 2011 7:00 pm

Re: Arduino - DAT Serial In

Postby bwheaton » Thu Dec 05, 2013 12:19 pm

As I'm reading those examples, and the one on the wiki, it seems to me that the sender and receiver can fall out of sync. Unlike TCP/IP packet based protocols, there's no clear 'start' and 'end', so any byte or part of a byte could be construed as any part of the package. One missed piece of data (pretty certain to happen) would flip the order of what is coming in.

The example should probably have, at least, different delimiters between data chunks and the end of the whole data. It would probably better to wrap the whole data into some sort of delimiter, such as putting a '[' at the start, and a ']' at the end. That helps make sure you only update if all the data is received (i.e. not updating b unless the corresponding r and g were also correctly received.

Historically, the STX and ETX characters should be used, since they can't accidentally arise in a readable or typed piece of data. Easy enough to send in the Arduino side, maybe the wiki could cover how to split based on them? That would make the wiki entry more useful for learning to parse other serial protocols.

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

Re: Arduino - DAT Serial In

Postby rob » Mon Dec 16, 2013 4:28 pm

DG2011 wrote:Hey Rob!

Is it possible to have the toe file from your video?

THANKS!


Sorry, I somehow missed this direct question last year :(
Is this the component you're referring to?

http://www.derivative.ca/wiki/index.php?title=Arduino
http://www.derivative.ca/wiki088/images ... sample.tox
User avatar
rob
Staff
 
Posts: 1671
Joined: Tue Nov 13, 2007 1:14 am

Re: Arduino - DAT Serial In

Postby rob » Mon Dec 16, 2013 4:32 pm

bwheaton wrote:As I'm reading those examples, and the one on the wiki, it seems to me that the sender and receiver can fall out of sync. Unlike TCP/IP packet based protocols, there's no clear 'start' and 'end', so any byte or part of a byte could be construed as any part of the package. One missed piece of data (pretty certain to happen) would flip the order of what is coming in.

The example should probably have, at least, different delimiters between data chunks and the end of the whole data. It would probably better to wrap the whole data into some sort of delimiter, such as putting a '[' at the start, and a ']' at the end. That helps make sure you only update if all the data is received (i.e. not updating b unless the corresponding r and g were also correctly received.

Historically, the STX and ETX characters should be used, since they can't accidentally arise in a readable or typed piece of data. Easy enough to send in the Arduino side, maybe the wiki could cover how to split based on them? That would make the wiki entry more useful for learning to parse other serial protocols.

Bruce


Hi Bruce.
Those are good suggestions.
Ive never heard of STX and ETX to be honest (ascii characters 2 and 3?)
We've found in our Arduino dealings, that the serial communication is reliable enough for most peoples usage, but we'll add your RFE to the list for parsing between known characters.
I like your suggestion of '[' and ']' better as those are easier for Arduino coders to include.
Cheers,
Rob
User avatar
rob
Staff
 
Posts: 1671
Joined: Tue Nov 13, 2007 1:14 am

Next

Return to Techniques

Who is online

Users browsing this forum: No registered users and 2 guests