Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Arduino, VISA, Serial Communication

Hello to all the users,

I'm new here. What I'm trying to achieve is to graph in real time data from two accelerometers connected to an arduino uno. The problem is that I am not receiving anything if I connect the sensors, but it works if I leave the analog inputs of my Uno floating. This is the code:


float Sensore1, Sensore2;     // Variabili che contengono i campioni da inviare a LabVIEW

void setup() {
 Serial.begin(115200);    // Imposto il baudrate a 115200
  while( !Serial.available() ) ;   // Inizia il loop quando LabVIEW invia una lettera per avviare la lettura dei sensori 
 }

void loop() {
  

//Dati da inviare a LabVIEW
    
    Sensore1 = (analogRead(A0) ) * 5.0 / 1024;     // Dati rilevati dal primo sensore
    Sensore2 =   (analogRead(A1) ) * 5.0 / 1024;   // Dati rilevati dal secondo sensore  
    Serial.print("a");                          // Stringa appesa al valore del primo sensore per effettuare il riconoscimento da LabVIEW
    Serial.println(Sensore1);                   // Scrivi sul monitor seriale i campioni relativi al primo sensore
    delay(3);
    Serial.print("b");                          // Stringa appesa al valore del secondo sensore per effettuare il riconoscimento da LabVIEW
    Serial.println(Sensore2);                   // Scrivi sul monitor seriale i campioni relativi al secondo sensore
    delay(3);

    
}

0 Kudos
Message 1 of 4
(4,369 Views)

If arduino is giving data when nothing is connected, then code is fine, look at connections.

"Not receiving anything" - does it mean com port communication fails or it is giving the same data as without sensors?

Does ADC work?  check with 1.5 V battery.

Is it bipolar adc (can it measure both positive and negative voltage)?

 

0 Kudos
Message 2 of 4
(4,355 Views)

"not receiving anything" means that in LabVIEW I'm getting loads of zeros for both sensors, while if I check the serial monitor from the Arduino IDE I can see that it's correctly sending data.

 

The ADC can convert only positive values from 0 to +5 V, but I am not giving any negative voltage to it.

0 Kudos
Message 3 of 4
(4,340 Views)

@Andrew92 wrote:

while if I check the serial monitor from the Arduino IDE I can see that it's correctly sending data.


Could you give us a screen shot or something to show what the stream looks like?  My guess is that you need to format your data into a human readable string first.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 4
(4,329 Views)