LabVIEW for LEGO MINDSTORMS and LabVIEW for Education

Showing results for 
Search instead for 
Did you mean: 

reading an analog voltage using LabVIEW and an EV3

 Hi, I'm a physics professor, familiar with LabVIEW for experimental control and data acquisition for around 20 years.

We have been using Lego Mindstorms robots for over 10 years to have a fun team project at the end of our Electronics course.  Students are supposed to design some sort of new sensor, and then have the robot respond to that sensor in some way.  In the past, we were using the NXT bricks, and it was simple to read an analog voltage into the brick, and then proceed with programming in LabVIEW.

This year, we are using the EV3 robots for the first time, and I have gotten completely stuck at reading an analog voltage in using the EV3 bricks and LabVIEW.  I know the pinouts of the cables connecting the brick to the sensors.  I've tested the system with something simple like a voltage from a potentiometer going into the analog input pin -- this works immediately and easily in the Lego EV3 software.  I can read either the raw or the scaled value.

However, I cannot figure out anyway in LabVIEW to do this same task.  


I investigated the subVIs for the various forms of the polymorphic, and mostly they seemed to use "Setup Sensor Port" coupled with "Read Generic Sensor".  So I've set up a test vi just combining those two subVIs, but I don't get any reading.  I thought that my problem must be that somehow I was not setting up the sensor port correctly, but I've tried all the options that I can see, and still I don't see any meaningful values coming out of the Read Generic Sensor vi.  The raw value typically reads 0, but sometimes will flicker between 3 and 4, but with no apparent relationship to the voltage that I'm applying to the AI pin, so I think this is just noise of some sort.


Thanks for any suggestions.

0 Kudos
Message 1 of 12

Hi syl89,


First of all, my familiarity with the Lego platform is fairly low (perhaps some experts could chime in!). But it seems to me that if you are able to see noise, then the code is trying to read on some port. Have you tried connecting to a different AI pin to see if it is reading on a different pin / port? 

0 Kudos
Message 2 of 12

Hi Jordans,


Thanks for your reply.  I realized when I read your suggestion, that what I had written in the first place didn't make sense.  I had written my post from memory, so I went back and checked my lab notebook.  

I was getting occasional values of 3 and 4 for the raw values before I figured out how to actually connect to all of the pins correctly, and I think (bad notebook!) that I was using the EV3 software at that point.  


After getting totally stuck and having no luck reading any meaningful signal on any of the pins, I fortunately found an informative YouTube video with a circuit shown to connect an analog voltage into the EV3, and even with a saved program in the EV3 software.  This program works perfectly -- the analog voltage (controlled by a potentiometer) reads in (via pin 6)  and displays on the front panel of the robot.

Changing absolutely nothing electronically, but just closing the EV3 software and opening LabVIEW instead, gives me no readings at all.  Regardless of what settings I choose for the sensor setup, I get values of 0 from the raw and scaled outputs from the Read Generic Sensor vi.

Given that the analog voltage is easily read in using the EV3 software makes me believe that I have the pins correctly connected at this point.  I just can't figure out how to make LabVIEW get that information from the sensor.  


0 Kudos
Message 3 of 12

Good Morning syl89,


That makes sense. One thing I noticed in the code was that you are using the Setup Sensor Port VI in the while loop. This might be an issue because it would be trying to configure the port on each loop iteration. You could try setting up the sensor outside the loop and only having your read in the loop.


Have you run into this issues with other types of sensor bricks? 

0 Kudos
Message 4 of 12

I'm having the same problem getting simple analog signals into the EV3 using LabVIEW. Has anyone had any luck with this?

0 Kudos
Message 5 of 12

I still have not figured it out, but I haven't been working on it since last Christmas.  


I'm not glad you're having the problem, but I'm glad I'm not the only one! I wish the NI developers were paying attention to this issue -- it seems so basic.  Why give the ability to read a voltage in the EV3 proprietary software which in general is less powerful, and not in LabVIEW, which seems to me where more people might like to use it.


Do you have any new info to add from your testing? 



0 Kudos
Message 6 of 12

Nothing really noteworthy to add. I was scrambling before a lab I was teaching and made several attempts. I had written some curriculum that worked on the NXT but this is my first time running it with the EV3.


I tried wiring the inputs so that the EV3 brick thought the sensor was actually a different known sensor (emulating the sensor ID signal) - but that didn't work. Even as a simulated touch sensor I couldn't get it to detect a high vs. low signal. I also tried digging into the base LV functions but to no avail. I'll likely pick this back up next summer when I have more time to write up some custom code. Keep me posted if you make any progress!

0 Kudos
Message 7 of 12

Sorry - I just saw this - if you look at the hardware documentation for the EV3 page 6 (from LEGO website) - pin 1 is only analog in if you set it properly with resistors to be IDed as such.  However, pin 6 almost always just works straight out.  You can make pin 1 work with a resistor setup, but pin 6 is a lot easier.

0 Kudos
Message 8 of 12

Hi -- thanks!  I haven't been working on this since I posted, but your response is timely since I'm teaching this material again this semester and was about to try these connections again next month!


I don't remember exactly what I was doing, but I think I was using pin 6 (not pin 1).  But I'll test out what you say, and get back to you.  

0 Kudos
Message 9 of 12

I contacted Chris Rogers about a year ago and he connected me with Steve Cogger, an awesome STEM educator, who solved the problem. So thank you, Steve! All the credit goes to him. Steve made a change to the "type" and "mode" of the Read Generic Sensor VI to get it working. I was hoping Steve would post this so he would get the credit for the fix but since it's been awhile, I'll go ahead and share it.


I'm attaching a VI that should work as a generic analog read on the EV3. It should work with the input on Pin 6. 


We did have some issues with the settings reverting to defaults during the save process - I think I fixed that but if the VI doesn't work for you, please let me know and I can post instructions on how to make the update in the default version of the file included with the LabVIEW Mindstorms toolkit. 

0 Kudos
Message 10 of 12