I'm working on a project which interfaces my Duemilanove with labview. Basically the arduino adquires several signals through the ADC, interrupts etc. and then sends them with Serialprint to the PC, where labview performs the analysis.
void loop(){
noInterrupts();
// read the analog in value:
sensorValue = analogRead(analogInPin1);
unsigned int CopiaTiempo = VariacionTiempo; //copies the value calculated during interrupt
outputValue = map(sensorValue, 0, 1023, 0, 255);
interrupts(); //enable interrupts again
int velocidad = (CopiaTiempo != 0) ? 60000/CopiaTiempo : 0;
Serial.print(outputValue);
Serial.println(velocidad);
delay(100);
}
Velocidad stays constant at 5 bytes, including the /n. However outputValue changes according to how much V is applied to the ADC, between 1-3 bytes. This is a problem, because my labview program expects a string of constant size. Any ideas? Thanks a lot
Hmm.. I don't see why OutputValue would ever change in size since you are controlling its range from 0-255. What is the data type of outputValue? (not shown in your snippet of code).
If you use an 8-bit datatype for outputValue, you may also use serial.write(outputValue) instead of .print(), this will output only one byte.
Johnny, after using an online ascii to hex converter I found out that while 0 is represented as only one byte of data, >10 and >100 are 2 and 3 bytes respectively (serial.print posts data in ascii form). So of course, Arrch's solution should work. Thank you both.
Gotcha, if you are ok with printing ascii characters. I like to send numbers as numbers, and when it comes to data communication there is far less over head compared to sending ascii (unless you are purely sending to a 'serial monitor'). Thus the serial.write() function...no ascii