Hi,
Im trying to increase the rate at which I can sample the analog and digitals and send to the PC.. I need to know the sampling rate accurately so Im using an interrupt. I was wondering though is there a faster way than calling serial.print so many times? Could i send all my bytes in one call at the end of the reading? Or does the serial.print handle the buffering and sending effeciently? Heres my code for read and send so far. I can send 2 analog and 6 digital in 7ms. I really nee to get faster. Maybe Im being unrealistic?
Thanks for any pointers
{
/* get analog in, for the number enabled */
for(analogPin=0; analogPin<analogInputsEnabled; ++analogPin)
{
analogData = analogRead(analogPin);
Serial.print(analogData >> 7, BYTE); // shift high bits into output byte
Serial.print(analogData % 128, BYTE); // mod by 32 for the small byte
}
Serial.print(255, BYTE); // end signifier
//digital pin checking stuff
for(n=2; n<8; ++n) {
digitalData = (byte) digitalRead(n);
if (digitalData == LOW)
{
x |= (1 << (n - 2)); // forces nth bit of x to be 1. all other bits left alone.
}
else
{
x &= ~(1 << (n - 2)); // forces nth bit of x to be 0. all other bits left alone
}
}
// if (x != lastDigital){
Serial.print(x, BYTE);
Serial.print(254, BYTE); // end signifier
}
looptime = millis() - starttime;
Serial.println(looptime);
}