Stopping Y axis autoscaling

Please help. I tried all the forums, no luck.
I am reading A(0) 0 to 5 volts. Y scale auto ranges where 5V at A(0) becomes middle of scale. And where 0V at A(0) becomes middle of scale.

/*
  ReadAnalogVoltage
  Center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
 modified by yours truly, Dr. G
*/
// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = sensorValue * (5.0 / 1050.0);
  // print out the value of the potentiometer as an interger only:
//Trying to force Y not autoscale
Serial.print("0, "); //lower range sent to plotter
Serial.print("5, "); //lower range sent to plotter
float pi = 3.14;
int value = (int)pi;
Serial.print("voltage:");
Serial.println(voltage,0);
  delay(200);  // delay in between reads for stability
}


Is this the goal or the unexpected/undesired results (both 5v and 0v are mid scale) ?

int value = map(analogRead(A0), 0, 1023, 0, 5);

can you also plot constants at the limits you want?

1 Like

If you remove the line:

Serial.print("voltage:");

then your code does what you want.

Here, I've commented it out:

2 Likes

...or modify these lines to have their own labels:

such as:

Serial.print("low:0, "); //lower range sent to plotter
Serial.print("high:5, "); //lower range sent to plotter
2 Likes

Yes, DaveX, that's a better solution.

2 Likes
void serialPlotter() {
  int Data1 = analogRead(A0);
  int Data2 = 0;
  int Data3 = 1023;

  Serial.print("Trace1:");
  Serial.print(Data1);
  Serial.print(",");
  Serial.print("Trace2:");
  Serial.print(Data2);
  Serial.print(",");
  Serial.print("Trace3:");
  Serial.println(Data3);
}
1 Like

Hello DaveX,

Thank you. Now I can't get any readings, i.e., no change in the plot.

I am sorry about my ignorance and I thank you for your patience.

/*
  ReadAnalogVoltage
  Center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
 modified by yours truly, Dr. G
*/
// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
int sensorValue = analogRead(A0);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1050.0);
  // print out the value of the potentiometer as an interger only:
Serial.print("voltage:");
//Trying to force Y not autoscale
Serial.print("low:0, "); //lower range sent to plotter
Serial.print("high:5, "); //high range sent to plotter
Serial.println(voltage,0);
  delay(200);  // delay in between reads for stability
}

Thank you. I tired it and I am getting this error, and due to my ignorance dont know how to fix it.

This is the error message:

C:\Users\Acer_new\AppData\Local\Temp\ccqUf37O.ltrans0.ltrans.o: In function main': C:\Users\Acer_new\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino/main.cpp:46: undefined reference to loop'
collect2.exe: error: ld returned 1 exit status

exit status 1

Compilation error: exit status 1

This is the sketch

/*
  ReadAnalogVoltage
  Center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
 modified by yours truly, Dr. G
*/
// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void serialPlotter() {
  int Data1 = analogRead(A0);
  int Data2 = 0;
  int Data3 = 1023;

  Serial.print("Trace1:");
  Serial.print(Data1);
  Serial.print(",");
  Serial.print("Trace2:");
  Serial.print(Data2);
  Serial.print(",");
  Serial.print("Trace3:");
  Serial.println(Data3);
}

JohnLincoln

Thank you. Thank you. Thank you. Thank you. e infinity

Please one more question, how do I change the labels on the plot from Value 1, Value 2, Value 3 to Lower Voltage Threshold, Output Voltage and Upper Voltage Threshold?

Thank you

I am assuming

Serial.print("voltage:");

is what printed voltage?

/*
  ReadAnalogVoltage
  Center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
 modified by yours truly, Dr. G
*/
// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = sensorValue * (5.0 / 1050.0);
  // print out the value of the potentiometer as an interger only:
//Serial.print("voltage:");
//Trying to force Y not autoscale
Serial.print("0, "); //lower range sent to plotter

Serial.print("5, "); //upper range sent to plotter
Serial.println(voltage,0);


  delay(200);  // delay in between reads for stability
}

I've done some testing.
It seems as though you can't have the label 'Lower Voltage Threshold' as three words.

The closest I could get was:

/*
  ReadAnalogVoltage
  Center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
  modified by yours truly, Dr. G
*/
// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = sensorValue * (5.0 / 1050.0);
  // print out the value of the potentiometer as an interger only:
  //Serial.print("voltage:");
  //Trying to force Y not autoscale
  Serial.print("Lower_Voltage_Threshold:0, ");  //lower range sent to plotter
  Serial.print("Upper_Voltage_Threshold:5, ");  //upper range sent to plotter
  Serial.print("Voltage:");
  Serial.println(voltage);
  delay(200);  // delay in between reads for stability
}


(I changed back to the default number of decimal places - I like a sine wave to look like a sine wave and not a staircase.)

2 Likes

You need the function loop() to call the function SerialPlotter()

1 Like

JohnLincoln: You are the best. Without divulging details, this project will save lives. Again, thank you. I know I cannot pay you $$$; the lessons I learnt will help me teach others. Your giving will be multiplied. This Y axis autoscaling "problem" has been going on for about twelve years. Ditto making single digits.

Again, thank you.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.