devinaconley / arduino-plotter

An Arduino library for easy graphing on host computer via serial communication
MIT License
186 stars 31 forks source link

Unable to get this to properly plot analogue input values #23

Closed BNNorman closed 5 years ago

BNNorman commented 5 years ago

Really excited when I found this, so much potential. Examples work fine but I cannot get a clean line plotting the analog inputs of my NANO.

The display I get clearly shows the voltages on the analogue pin, and the correct ranges, but I can't get a clean line. See attachments showing Listener.exe (Windows 10 64bit PC) window before and after auto scaling. I have changed the points to plot (500,1000,5000) - it just changes the refresh rate not the plotted line. I have tried adding delays in the loop - only the refresh rate changes..

Your examples work fine but I noticed they seem to use a 'timebase' of 5000 for their calculations. My analog input won't change rapidly - more likely to vary over a number of seconds, minutes or hours though quick reads in succession should give the same value resulting in a horizontal line.

What can I do to solve this

#include <Plotter.h>

float Vout;  // Analogue voltage
Plotter p;

#define SIG A4
#define CONTROL 10

void setup() {

  pinMode(CONTROL,OUTPUT);
  digitalWrite(CONTROL,HIGH);

  // now start the plotter

  p.Begin();

  p.AddTimeGraph( "Ion Chamber Vout", 5000, "Vout", Vout);
}

void loop() 
{
  Vout=5.0*analogRead(SIG)/1023.0;
  p.Plot();
}

plotter2 plotter1

BNNorman commented 5 years ago

After some playing around with the loop this started to make sense:-

uint32_t Step=0;

void loop() 
{
  Step++;
  if (Step==100)
    {
    Vout=5.0*analogRead(SIG)/1023.0;
    Step=0;
    }

 p.Plot();
}

However, as you can see from the attached auto adjusted plot it gets difficult to interpret without vertical lines.

![plotter slowed down](https://user-images.githubusercontent.com/15849181/49516658-05249f80-f892-11e8-9044-4abe9fcd7981.JPG)
![plotter slowed down 2](https://user-images.githubusercontent.com/15849181/49516699-21c0d780-f892-11e8-99eb-bcfc10216a39.JPG)
devinaconley commented 5 years ago

@BNNorman - based on that pattern I would guess that a float value is being multiplied against an int, resulting in lost precision between "steps".

I believe that analogRead returns an int... try casting that to a float value before multiplying against 5.0

BNNorman commented 5 years ago

Thanks for the reply. It was my understanding that the compiler would treat the entire calculation as float if any of the numbers were float. I'll give it a try tomorrow and let you know. I've tried putting a cap on vref and the analog in but no change so not sure if hdw or sw. But, i have to say that an int less than 1024 divided by 1024 would yield zero in integer math and thats not what i am getting.

BNNorman commented 5 years ago

The noise is in my electronics. If I tie a NANO ADC input to 3.3v it's almost rock steady. The circuit comprises of an Ionisation Chamber and a chip (RE46C112) designed to monitor the chamber voltage hence smoke/dust. I guess I need to add some more smoothing capacitors.