In my project, I have to read the input pin number(send by RPi), where 8 sensors are attached to Arduino Nano, after reading Arduino Nano send the real-time values of all sensors through serial USB communication. All is fine, but my problem is that I need to speed up the sending of data since it takes to long to read from Rasberry pi. I put the delay of 70 milliseconds but if I try to reduce more than that, I encounter a problem i.e data overwrites. My baud rate is 115200. Kindly help me with the code to make it fast.
int analogInputPin;
float voltage;
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(115200);
}
void loop() {
// if any data on the serial port are available
// read it and try to update the analogInputPin
// based on the number that was read on the serial
if (Serial.available() > 0) {
analogInputPin = Serial.parseInt();
}
// read the analog value:
int analogInputPinValue = analogRead(analogInputPin);
voltage=(5./1023.)*analogInputPinValue;
// print the results to the serial port:
// the output should have the following form: INPUTPIN:VALUE
// followed by a newline character
Serial.print(analogInputPin);
Serial.print(":");
Serial.print(voltage);
Serial.println("");
// wait 50 milliseconds before the next loop
delay(50);
}
parseInt
. Ever. It's rancid. Read serial properly : majenko.co.uk/blog/reading-serial-arduino – Majenko♦ Aug 18 at 11:51