Go to Post The ChiefDelphi forums are more than just a place for people to kill time and engage in some chit chat. - Karthik [more]
Home
Go Back   Chief Delphi > Technical > Programming > NI LabVIEW
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 25-08-2012, 19:19
apples000's Avatar
apples000 apples000 is offline
Registered User
no team
 
Join Date: Mar 2012
Rookie Year: 2012
Location: United States
Posts: 222
apples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant future
Sending ASCII characters through cRio serial port

I've been having tons of trouble getting the cRio to communicate to my arduino board through serial. My goal is to send three comma separated values in an ASCII string. Then the arduino will wait for a new line (ASCII decimal 10) and it will use the parseint function to find the three values. I know that the program on the arduino is working because i can use a basic stamp 2 to generate an ASCII string of 1,2,3 then a new line/line feed and the arduino will send me a confirmation message and read back the values on another serial port controlled by the software serial library. I am using a max232 ic to change the rs-232 voltage to ttl. I can see on my oscilloscope that the max232 is doing the right thing when it is connected to the crio and that the serial connection idles in the high state. Whenever I try to send data from the crio to the arduino the data sent cannot be read as an ASCII string of comma separated values. I am using the serial vi's in labview. My labview code uses a vi (I forget what it's called-it looks like two cylinders with a plate in between), which converts decimals into ASCII characters. I can probe the data and see that the output of the string concatenate vi has a 1,2,3 like I wanted. I originally thought that labview was properly sending the the numbers but not the new line ASCII code, but the problem shows up on the oscilloscope. The working output from the basic stamp is about ten times shorter than the output from labview. Does anybody know a way to get the crio serial port to output ASCII characters or another easy way to have the arduino and crio communicate?

Last edited by apples000 : 25-08-2012 at 19:23. Reason: Typo
Reply With Quote
  #2   Spotlight this post!  
Unread 25-08-2012, 21:57
FrankJ's Avatar
FrankJ FrankJ is offline
Robot Mentor
FRC #2974 (WALT)
Team Role: Mentor
 
Join Date: Feb 2011
Rookie Year: 2009
Location: Marietta GA
Posts: 1,933
FrankJ has a reputation beyond reputeFrankJ has a reputation beyond reputeFrankJ has a reputation beyond reputeFrankJ has a reputation beyond reputeFrankJ has a reputation beyond reputeFrankJ has a reputation beyond reputeFrankJ has a reputation beyond reputeFrankJ has a reputation beyond reputeFrankJ has a reputation beyond reputeFrankJ has a reputation beyond reputeFrankJ has a reputation beyond repute
Re: Sending ASCII characters through cRio serial port

Maybe plug your computer into the serial port of the crio. Use hyperterminal or something similar to be sure the crio is sending what you think & the com parameters are right. You could to the same to the arduino.
Reply With Quote
  #3   Spotlight this post!  
Unread 25-08-2012, 23:49
Greg McKaskle Greg McKaskle is offline
Registered User
FRC #2468 (Team NI & Appreciate)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 4,752
Greg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond repute
Re: Sending ASCII characters through cRio serial port

It sounds like you may be casting the numbers to string when you intended to format them to a string.

Look in the string palette for the format to string or to decimal string.

Greg McKaskle
Reply With Quote
  #4   Spotlight this post!  
Unread 26-08-2012, 07:16
apples000's Avatar
apples000 apples000 is offline
Registered User
no team
 
Join Date: Mar 2012
Rookie Year: 2012
Location: United States
Posts: 222
apples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant future
Re: Sending ASCII characters through cRio serial port

Thank for the quick replies! I haven't had time to try them out, but I think that the format into string vi is what I want. It seems that it will let me format he inputs and add a line feed at the end. It also seems to be able to stop adding spaces between strings if I input a format string such as %s%s%s. I would connect the crio to the computer to see if it was working, but I do not have the proper serial cable to make this happen. The only cable I have with me at home is one with a USB to serial converter on one end, and the other connector has been cut off and the wires have been broken off to program my basic stamp. For now, i am just looking at the output on an oscilloscope although it is not quite triggering properly on the signal.
Reply With Quote
  #5   Spotlight this post!  
Unread 26-08-2012, 13:28
apples000's Avatar
apples000 apples000 is offline
Registered User
no team
 
Join Date: Mar 2012
Rookie Year: 2012
Location: United States
Posts: 222
apples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant future
Re: Sending ASCII characters through cRio serial port

I've just tried it with the format string vi and it works perfectly! The serial connection is great because it can easily update 12 ascii characters several times per second operating at a pretty slow 9600 baud.
Reply With Quote
  #6   Spotlight this post!  
Unread 12-12-2012, 19:00
stingray27's Avatar
stingray27 stingray27 is offline
Registered User
AKA: Michael Ray
FRC #0027 (Team RUSH)
Team Role: Alumni
 
Join Date: Mar 2011
Rookie Year: 2010
Location: Clarkston, MI
Posts: 209
stingray27 is a name known to allstingray27 is a name known to allstingray27 is a name known to allstingray27 is a name known to allstingray27 is a name known to allstingray27 is a name known to all
Re: Sending ASCII characters through cRio serial port

Few months old but our team is now trying to do the same thing. Would you mind taking screen shots of your labview code and copy/pasting your arduino code so we can compare and see where things have gone wrong? Thanks!
__________________
Michael Ray
Team RUSH 27

Driving Record: 93-64-0 Best Finish: Finalist (x4 FiM Districts)
Coaching Record: 16-7-0 Best Finish: Winner (Kettering Invitationa)l

Reply With Quote
  #7   Spotlight this post!  
Unread 12-12-2012, 20:47
apples000's Avatar
apples000 apples000 is offline
Registered User
no team
 
Join Date: Mar 2012
Rookie Year: 2012
Location: United States
Posts: 222
apples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant futureapples000 has a brilliant future
Re: Sending ASCII characters through cRio serial port

For the arduino code, we switched to using a demo project that worked a little better than what we wrote.
Code:
/*
  Reading a serial ASCII-encoded string.
 
 This sketch demonstrates the Serial parseInt() function.
 It looks for an ASCII string of comma-separated values.
 It parses them into ints, and uses those to fade an RGB LED.
 
 Circuit: Common-anode RGB LED wired like so:
 * Red cathode: digital pin 3
 * Green cathode: digital pin 5
 * blue cathode: digital pin 6
 * anode: +5V
 
 created 13 Apr 2012
 by Tom Igoe
 
 This example code is in the public domain.
 */

// pins for the LEDs:
const int redPin = 3;
const int greenPin = 5;
const int bluePin = 6;

void setup() {
  // initialize serial:
  Serial.begin(9600);
  // make the pins outputs:
  pinMode(redPin, OUTPUT); 
  pinMode(greenPin, OUTPUT); 
  pinMode(bluePin, OUTPUT); 

}

void loop() {
  // if there's any serial available, read it:
  while (Serial.available() > 0) {

    // look for the next valid integer in the incoming serial stream:
    int red = Serial.parseInt(); 
    // do it again:
    int green = Serial.parseInt(); 
    // do it again:
    int blue = Serial.parseInt(); 

    // look for the newline. That's the end of your
    // sentence:
    if (Serial.read() == '\n') {
      // constrain the values to 0 - 255 and invert
      // if you're using a common-cathode LED, just use "constrain(color, 0, 255);"
      red = 255 - constrain(red, 0, 255);
      green = 255 - constrain(green, 0, 255);
      blue = 255 - constrain(blue, 0, 255);

      // fade the red, green, and blue legs of the LED: 
      analogWrite(redPin, red);
      analogWrite(greenPin, green);
      analogWrite(bluePin, blue);

      // print the three numbers in one string as hexadecimal:
      Serial.print(red, HEX);
      Serial.print(green, HEX);
      Serial.println(blue, HEX);
    }
  }
}
As for the labview, I can't get to that right now, it was just a while loop with a 100ms wait in it. We opened a serial port with all the default settings outside the loop, then in the loop we used the serial write vi. For the buffer input, we used format into string vi. You can drag the vi so it gets bigger and you can have three inputs. These are your red/green/blue values. Leave the initial string blank and for the format string use

%g,%g,%g\n

Make sure that you put the commas and that the slash goes the right way. Then you can connect the resulting string into the buffer input of the serial write. I would recommend starting by wiring constants of 127 into the inputs of the format into string so that it doesn't matter if 0 or 255 is on or off. Also, we had some issues with having both the arduino's usb connection and the serial connection running at the same time, so if it doesn't work you may also have to disconnect the arduino from the computer. Also, I don't know how much you've already done, but it helps to make sure that your arduino board can actually control the lights. We used TIP-120 transistors with ours and it worked well.
I'll be at the computer with the LV code on friday, so I can post that.

Last edited by apples000 : 12-12-2012 at 20:49.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 21:54.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi