analogRead basic (but strange) question

Status
Not open for further replies.
Hi there,

this is my first post so please forgive my lack of knowledge here. I use to program a lot with Arduino and Teensy for various projects but in some way I miss some basics. Recently I came back to a project where I use Piezo sensor to detect the position of impacts on a floor. I started back from the very beginning and came across a very strange behavior with a Teensy 3.1 and the analogRead() function.

For now I'm just trying to get the sensor value here is the schematics

piezo_schematics.jpg

and the code :

Code:
#include <Metro.h>

#define INPIN A0       
int sensorValue = 0;
Metro myMetro = Metro(1000);

void setup() {
  Serial.begin(115200);
  }

void loop() {
  int tmp = analogRead(INPIN);
  if ( tmp > sensorValue) sensorValue = tmp; 
  if (myMetro.check()) {
    Serial.println(sensorValue);
    sensorValue = 0;
    }
  }

The problem is that I never get a value of 0. Dispite it works well with an Arduinon Uno, I got values around 15 instead with the Teensy board.
Even with the A0 pin connected directy to the ground I got a value of 1 with the Teensy board...

I don't understand why so any help will be welcome.

Thanks, Sylvain
 
That and you should also put a 0.01 uF cap in parallel to the resistor per the recommendations of the chip maker.

Lastly, the reaistance at 10k is on the high side, depending on what you're measuring, how quickly the signal is changing, and so on. Ideally, you want to stay below 2-5k for the input impedance.

You can help smooth signals further through the use of averaging or decimation. It's also important to know what resolution you need - the teensy can realistically deliver about 12 bits in single-ended mode and 13 on the two differential channels.
 
@sumotoy :
yep I tried AGND and the result is the same, actually if I refer to the Teensy Schematics they are both linked anyway.

@constantin :
I don't really understand the need of a cap but it worst the try. I'll do it right as soon as possible.
I don't understand what you mean about the resistance : high side ? 2-5k below for the input impedance ?
I think I will use a 8bit resolution in my final application. I'll aslo use an analogic filter for each piezo : capacitor + bridge rectifier + zener clipper circuit to clean and smooth the signal (so no decimation or averaging needed here). It should be 100+ sensor at one point so everything will go thru multiplexers. The output of the multiplexers will then pass thru PGA amplifier (to increase the general sensibility of the device) to the analog input of the Teensy.

But for now I just want to know why I never get 0 on the analog input despite it's directly connected to ground. It like a basic step which I believed to be always true and which seems not on my Teensy boards. I got 0 on other board (I've tried Arduino Uno, Mega and Due) or with external ADC (I've tried de ADS1015 break board from Adafruit) but those very strange value with the Teensy 3.1.
 
Status
Not open for further replies.
Back
Top