![]() |
Arduino and LabVIEW
After searching high and low here and on the web, I still can't find a definitive answer: How do I send information (numbers) between the cRIO (using LabVIEW) and an Arduino Uno? And what are the actual hardware connections to be made at both ends? Thanks.
|
Re: Arduino and LabVIEW
You can't, I also doubt if the arduino has enough power to run vXWorks either.
|
Re: Arduino and LabVIEW
I'm not sure what David is talking about...
You can use I2C, SPI, or serial. Or, you could add an ethernet shield to the Arduino and use that. For I2C and SPI, the cRIO wants to be the master. I'm not sure if the arduino easily supports slaving in these modes, you will have to check it out. For serial, the Uno consumes its native serial port with its USB connection. Instead, you will have to use the software serial port library. |
Re: Arduino and LabVIEW
Quote:
|
Re: Arduino and LabVIEW
Quote:
There are, of course, legal issues regarding custom circuits being in the CAN bus loop. Without carefully looking I think using the bus just to pass data is ok, as long as it doesn't try to control motors. I'm not sure exactly what practical advantage it would give you over SPI or I2C, but it would be pretty neat. CAN bus shield on Sparkfun. It might be avalible elsewhere. |
Re: Arduino and LabVIEW
Custom Circuits are explicatively allowed to be on the CAN bus. They are also explicatively illegal to control any non-decorations (and I'm not sure about the rules on decorations). Unless, of course, you email FIRST and get something as an approved motor controller.
I'd most likely try to communicate using I2C, but if you can get the C-RIO to send out serial commands, that's the arduino's native protocall. |
Re: Arduino and LabVIEW
Well, we might be :cool: but not all that clever, especially when we're short on time. I'll have to check those possibilities, Eric. Where does the data wire(s) get connected? Right now I'm in the "one step back" mode (computer doesn't want to download to the Arduino), so it'll be a bit.
All I need is to send a single number to the Arduino, and it'll turn on some LEDs. Can I do it through a Digital IO (which sounds the simpliest method)? WPI_PWMSetValue.vi? Just saw Adam's post: Yeah, it's not quite decorative LEDs, so thats out. Any of the LabVIEW I2C examples are good to look at? Or the serial? |
Re: Arduino and LabVIEW
How big a number?
You can simply use the digital outputs on a sidecar to digital inputs on the Arduino to send a binary number. You don't need a communications protocol to do that. Maybe use one DIO to signal when the number has changed and should be read by the Arduino. |
Re: Arduino and LabVIEW
Do you mean (for example) 4 DIOs sending a binary signal for 16 numbers? (And no, I don't have many numbers, but I can think of ways to expand that.) Just using the signal portion of the PWM wire, right? (The Keeper of the Numbers says we have 5 DIOs free for use.) Heh -- I had thought of that too, when we originally thought of using DIOs. It seemed too obvious to be true. Could it really be that simple? Thanks, Mark!
Of course, I spent the day trying to make connections on an older robot to test all this, and now discovered (after connecting all the dots, so to speak) that LabVIEW and the Arduino programming port don't play nice together. I am making a nice collection of laptops around me just to test this. |
Re: Arduino and LabVIEW
Quote:
|
Re: Arduino and LabVIEW
Well we are talking about an Arduino. :) But no, just a signal to change lights.
Howsoever, I did see at FLR a team using an Arduino for sonar processing, but I don't know what kind of data they were sending back to the cRIO -- much more than I'm asking for, I'm sure. These little boards are fun to work with. |
Re: Arduino and LabVIEW
An update -- I have some LabVIEW code that sends a DIO true/false value depending on a button press, recieved by the Arduino on a digital pin, and blinks the light on the Arduino and also prints out the high/low value (simple test), slowed down to 1/2 second cycle. Currently I'm getting a semi-random highs/lows, even without pressing the button, which I'm guessing is LV's issue, not continually sending the true/false signal? Unfortunately, I lost my LV computer so I can't check it -- maybe I can schedule for a 3 am session? :ahh:
|
Re: Arduino and LabVIEW
If you haven't opened the IO port in your code, I think it may leave the signal pin floating. Does it work when you press the button, or does it ignore the button as well?
|
Re: Arduino and LabVIEW
I think it's opened once in the Begin.vi (the computer got grabbed so I can't look at the code at the moment), and just referenced during the button pressing, and not open/send/closed each time.
There was no discernable difference when the button got pressed. |
Re: Arduino and LabVIEW
Consider the fact that a boolean on the PPC is 4 bytes. Also consider the fact that the Arduino uses little endianness. I am not sure about the PPC on the cRio, it might be a big endian, that might bring up some troubles.
|
Re: Arduino and LabVIEW
But aren't they both using an on/off electical signal to talk between them? Not code.
(Pay Per Click?) |
Re: Arduino and LabVIEW
Quote:
So on the cRio a "true" would be represented as: 0000_0000_0000_0001B (if big endian) 0001_0000_0000_0000B (If little endian) Note: I might be wrong about the above regarding the binary on the Arduino, you need to just take the last 4 bits so it becomes: 0001B Every microprocessors have millions and billions of transistors, they all use electrical signals. Now, if there are any veterans here, feel free to rebuke me. I am a student, I make mistakes and then learn from them. |
Re: Arduino and LabVIEW
Setting a TRUE output on a DIO slot sends 5V of power down the wire. That's one bit, not 32. He's planning on using four DIO slots to send 4 bits of data to the arduino.
Just a note, you can put the PWM cable in sideways on the signal so you use two cables instead of four. Can you put a multimeter on the slots? Can you post the arduino sketch? |
Re: Arduino and LabVIEW
Quote:
|
Re: Arduino and LabVIEW
Quote:
Watch this video, note why he uses the resistor. If you get it, good, otherwise, I'll explain: Originally Posted by Roger But aren't they both using an on/off electical signal to talk between them? Not code. Yes and no. The cRIO will send out an on/off electrical signal, but the Arduino DIO pin does not "sense" "on or off." It senses 5v or Ground. If you hook it up to nothing (what you may call "off"), it will basically sense the voltage of the wire/air that it is connected to. Ever looked at a volt meter when you haven't yet hooked it up to a power source? It wanders all over the place. This is what your Arduino DIO pin is doing. It could be anything, high or low. You need to use a resistor to specifically connect the DIO pin to Ground when it isn't sensing a 5v from the cRIO DIO pin. This is called using a pull-down resistor (not to be confused with a pull-up resistor, but similar idea). Do you have a mentor who is an electrical engineer or knows electronics? You should have him help you out. This concept is a little tricky, it took me a while to figure out. Before that I was thinking the same as you. |
Re: Arduino and LabVIEW
I'm pretty sure the DIO ports on the C RIO are never left floating (at the very least not after they're initialized), so that doesn't make much sense. There's nothing in the datasheet about it, strangely enough, except that there's a 10K pullup already on it. Maybe that's not disconnected when it switches to output? That wouldn't make much sense though.
I'd say test continuity, and then go to voltage mode on your multimeter, and do one lead on ground and the other on the signal. If you get zero, put the first on 5V. If they're both zero, the pin in floating for whatever reason, if one is zero and the other is 5V, then it's something in the wiring/arduino. |
Re: Arduino and LabVIEW
(Sorry, I went home and slept a bit.) Here's the Arduino sketch:
Code:
int ledPin = 13; // LED connected to digital pin 13On the LabVIEW side there is code that if (one of 4) buttons are pressed, send a True/False to DIO Out Set (WPI_DigitalOutputSetValue.vi). I hold the button down to test, not momentarily. Currently (with the delay) the print sends "1100000111000011000001100" with or without the button presses, and there is no pattern to the length of the 1 or 0 groups. Without the delay it was all 1s. I also used the built-in LED on 13 to see if it's on or off. RoboMaster: I have the book version of that video (that's how I got my first Arduino). I'm not ashamed to say I'm not electrical-minded, but I know enough to keep me out of too much trouble. For this project originally I used the button setup to control the Arduino switching the LEDs. I've wondered about that resistor. This would be a simple test: Put the wire on a breadboard, split it with a resistor to ground, and a wire to Arduino's pin 7. I did understand David's answer (I think I did; hanging around teens I get that a lot), and I was answering more of a programming mode than electrically. WizenedEE: Maybe in the "robot world" the DIO ports aren't left floating, but when the wire is jumping into "Arduino world", would it need it's own de-floater resistor? I'm guessing at this. I do have a sensors/electrical mentor; he probably knows every wire on the robot on a first-name basis. He can test the wires to make sure they are what they ought to be. Sigh. Electricity was so much simpler when I grew up, when power went from + to - and not both ways. :) |
Re: Arduino and LabVIEW
Okay, back at the ranch... I tried with and without a resistor (10K and 1K -- that's okay? It's all I had). Signal from DIO connected to the Arduino 7 pin and also to a resistor to Arduino ground. I hope I got that right? I also took the delay out. With a resistor, it's always zero. Without, the Low/High is
Code:
11111100000000 |
Re: Arduino and LabVIEW
I think I may know the problem - your grounds are not the same. You're powering the arduino off of USB right? Try putting a wire from the arduino ground to the robot's common, and see what happens.
Warning: do not attach robot power to the arduino while the USB cable is connected - you may fry your computer's USB port Also, you may want to check with your electronics mentor before trying that.. I'm pretty sure it'll be fine though. |
Re: Arduino and LabVIEW
Quote:
I'm puzzled that when you used a resistor it the sensed value was always zero. 10K or 1K seems fine to use. Your code looks fine. The one thing I noticed was that you split the wire coming from the cRIO DIO into an Arduino Ground and DIO pin. While electrically this will still work, the objective is really to split the Arduino pin to a Ground and a possible power/voltage source (the cRIO DIO wire/pin). That way the Arduino pin either gets electricity "sucked out of it" into the ground, or electricity "pushed into it" from the voltage source. In the second case, the resistor is there to give "preference" to the voltage source pushing electricity in, because electricity follows the path of least resistance (and the voltage source path will only have a low-resistance wire). I'm not sure what WizenedEE was talking about with the difference in grounds, but he may be on to something. What is trying to be accomplished with your suggested test, WizenedEE? |
Re: Arduino and LabVIEW
Yes, the Arduino is still running off the computer's USB, though I do have a wall plug for it. But, haha, eventually we'll have to run it off of the robot's power. We have a 5V stepper thingie, a duplicate of the one the radio-thingie uses. (Can you tell I'm getting out of my area?) This will have to wait until after school tomorrow for the electronics crew to construct.
The differences in grounds, if I may guess: The robot ground is the 12V battery (except the first regional week of Lunacy, when it would be the field, and not in a good way ;) ). The Arduino ground is the USB port, or the wall power, which is not the same common ground. I don't know why this difference produces the output I've shown. Just to recap, if the Arduino is powered from the robot, that means it's grounded to the robot. So if the PWM data wire from the cRIO/sidecar gets split to Arduino pin 7 and also to a resistor and on to an Arduino ground, that ground is also grounded back to the robot, so everything is equal. Or (thinking further on this) should it be grounded back to the PWM wire back to the sidecar? And if I send 4 or 5 PWM signals to the Arduino, each signal wire gets a separate resistor and back to the PWM. And just to be sure, the cRIO's DIO sends a solid HI/LOW down that wire? That output I showed is not what I should be seeing? |
Re: Arduino and LabVIEW
Quote:
Quote:
|
Re: Arduino and LabVIEW
So far it isn't working. :confused: But we're testing other possibilities.
|
Re: Arduino and LabVIEW
Have you checked, with a multimeter, that the sidecar is actually outputting a constant 5V to the right pin?
Try disabling the serial part of your arduino code and just watching the pin 13 LED. Also, take out the wait - a half second is much too long. |
Re: Arduino and LabVIEW
Success! :confetti:
DIO White PWM goes to Arduino pin 7, and Arduino ground connects to DIO PWM ground Black. No resistors (any needed?). Next test is 4 DIOs. Solid 1s or 0s when buttons are pressed. Right now Arduino power is either the USB or the wall plug -- that gets changed soon. Yeah, I took out the delay pretty early. The 1/0 list above was with no delay. Now my lead programmer and I are arguing how to send binary numbers from LabVIEW. His method has 15 numbers -- thinking small. My method will get 256 numbers or more. Sigh -- the stars are back in alignment, world is back to normal, and programmers arguing about programming. Thanks guys for your help. Even David -- as Sherlock Holmes says "Watson, your wrong guesses sometimes gives me the truth." |
Re: Arduino and LabVIEW
Excellent, great job. May I ask what your methods are? I'm just curious. It seems that with 5 ports you could get 32 outputs, but I'm not sure about 256.
|
Re: Arduino and LabVIEW
It was this that got a train of thought starting:
Quote:
I had scribbled the Arduino and LabVIEW code in bed last night, and got half way thru it by the time I got back to the robot, but my lead programmer had different ideas (a piddly 16 numbers - pft! :) ), so we went his way. Still haven't tested that it really works, either way. |
| All times are GMT -5. The time now is 01:31. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi