please help??

Hi

i am new in arduino and labview and i want to read from labview vi and send this reading serially by arduino by PWM .

for example want to write 2.4 in the vi and view this value as voltage in arduio PWM
How i can do that??

please help me in the arduino code and how to convert the signal came from labview vi to arduino (send any number from 0-5 and view as PWM in same value)

Regards

view this value as voltage in arduio PWM

Without a filter on the output, PWM voltages are only ever 5V or 0V.

any help about that!! :blush:

up
up

No, up AND down.

Ok. As an 'ok' programmer at each Labview and Arduino i will attempt to at least shine a little light on your issue to help you understand what's happening.

The 0 to 5 volts you are referring to is not a PWM Output in the way you are describing it. It is an Analog Input. Labview will not output those analog inputs the way you expect and give you fine control of the LED unless you use a floating point variable and the use the map command to limit that number into the 0 to 255 range which makes it make it a bit more of a pain than it needs to be.

Labview, without seperate external digital to analog conversion hardware, cannot output an analog 0 to 5 volts directly. You will be wanting Labview to output a Serial string containing the PWM value you wish to output. You then set up your arduino to take the number provided by this serial string and set it to a variable, that variable will then be written as an analog.write to the pin controlling your LED.

so if your VI has a slider you want to be set to adjust the brightness of an LED. You set the slider min to 0 and max to 255 (Range of an 8 bit PWM signal). The set point of that slider then get output via serial string on the proper comm port.

I have a bit of code i was playing with while in a labview class a few years ago, It need a little tweaking for proper reading of the serial string but you may be able to get a general idea of whats happening. (This VI has 3 sliders Red, Green, and Blue. The output serial string is in the format "Rxxx,Gxxx,Bxxx" where xxx is the color value 000 to 255.

int red = 5; // Set pins for output
int green = 7;
int blue = 6;

char testVal = 0;

int buf1 = 0; // Buffer spaces for 000 to 255
int buf2 = 0;
int buf3 = 0;

int redVal = 0; // To hold LED value
int blueVal = 0;
int greenVal = 0;

void setup (){
  
  pinMode (red, OUTPUT);
  pinMode (blue, OUTPUT);
  pinMode (green, OUTPUT);
  
  digitalWrite (red, LOW); //LED's all off
  digitalWrite (blue, LOW);
  digitalWrite (green, LOW);
  
  Serial.begin(9600);
}

void loop () {
  
  if (Serial.available () > 0 ){ // Any chars wating to be read?
    testVal = Serial.read ();
    
 if (testVal == 'r'){
        
        buf1 = Serial.read(); // the Serial.read command brings the characters in as their ASCII equivilant so is stores as an intiger
        buf1 = buf1 - 48;     // 1 becomes 49, 2 becomes 50, 7 becomes 55, etc. this line subtracts 48 to give the digit it's numeric value
        redVal = buf1;
        
        buf2 = Serial.read(); 
        buf2 = buf2 - 48;
        redVal = (buf1 * 10) + buf2; // Converts two individual numbers into a two digit value. For example 2 then 5 would become 25

        buf3 = Serial.read();
        buf3 = buf3 - 48;
        redVal = ((buf1*10) + buf2)*10 + buf3; // Converts two individual numbers into a three digit value. For example 25 then 3 would become 253
       }
       
       Serial.print("Red:"); // Serial Print for DEBUG and as feedback to Labview VI Display box
       Serial.println(redVal);
      
    if (testVal == 'b'){
        
        buf1 = Serial.read(); 
        buf1 = buf1 - 48;     
        blueVal = buf1;
        
        buf2 = Serial.read();
        buf2 = buf2 - 48;
        blueVal = (buf1 * 10) + buf2;

        buf3 = Serial.read();
        buf3 = buf3 - 48;
        blueVal = ((buf1*10) + buf2)*10 + buf3;
       }
       
       Serial.print("Blue:");
       Serial.println(blueVal);
       
     if (testVal == 'g'){
        
        buf1 = Serial.read(); 
        buf1 = buf1 - 48;     
        greenVal = buf1;
        
        buf2 = Serial.read();
        buf2 = buf2 - 48;
        greenVal = (buf1 * 10) + buf2;

        buf3 = Serial.read();
        buf3 = buf3 - 48;
        greenVal = ((buf1*10) + buf2)*10 + buf3;
       }
       
       Serial.print("Green:");
       Serial.println(greenVal);
       
  }
      
      
   analogWrite (red , redVal); // Ouput color value to pins
   analogWrite (blue , blueVal);
   analogWrite (green , greenVal); 
   
   delay(50); // Delay 50ms
   
}