Connect piezo element with MetawearC

I am trying to interface piezo element through gpio pins, and read ADC values on Metawear App. But the problem of disconnect
when trying to stream gyro/accel after reading frm GPIO. Streaming of gyro/accel works fine without gpio.
After reading datasheets and other materials, i have added 1m resistor in series but results are same.

for reference: 
 
I have also tried solutions discussed above.
 

Comments

  • edited February 2018
    • How fast are you sampling the sensors + gpio pin?
    • Please post the code you are using and the specs of your board (model, firmware rev, hardware rev)
  • - gyro at 50hz  gpio at 33hz
    -Metawear C, firmware revision 1.3.6 , Hardware revision 0.3

    gpio.pin(gpioPin).analogAdc().addRouteAsync(source -> source.stream(gpioSubscriber));
    timer.scheduleAsync(GPIO_SAMPLE_PERIOD, false, () -> {
    gpio.pin(gpioPin).analogAdc().read();

    }).continueWith(task -> {
    scheduledTask = task.getResult();
    scheduledTask.start();

    return null;
    });
    mwBoard.onUnexpectedDisconnect(new MetaWearBoard.UnexpectedDisconnectHandler() {
    @Override
    public void disconnected(int status) {
    Log.i("GpioActivity", "Unexpectedly lost connection: " + status);
    String discon = "Disconnected "+status;
    Toast.makeText(getActivity().getApplicationContext(),"Gpio "+discon,Toast.LENGTH_LONG).show();
    }
    });
    private final Subscriber gpioSubscriber = (data, env) -> {
    final Short gpioValue = data.value(Short.class);
    Log.i("Gpio",""+gpioValue);
    getActivity().runOnUiThread(new Runnable() {
    @Override
    public void run() {
    gpioData.setText(""+gpioValue);
    }
    });

    };
  • edited February 2018
    Where's the gyro and acc code?

    Are you streaming acc, gyro, and gpio data simultaneously?  It is unclear from your initial post if you are.
  • yes i need to stream gyro and gpio data simultaneously. 
    Gyro stream code :

  • Gyro code looks fine.  

    I'm wondering if perhaps the piezo is the cause of the disconnect issue.  What happens if you only streaming from the gpio?

    Another user had also attached a piezo to the board, perhaps some of the suggestions from this post can help you.
  • If only streaming from gpio then sensor work fine but when i streaming gpio and gyro simultaneously then disconnect issue happen.
    • How long does it take before connection is lost?
    • Is it simply the connection being lost or is the board resetting?
    • How exactly are you executing your code from your app?
      • The code snippets you provided make it seem like the gyro and gpio code exist in separate classes.

    Another two things to test:
    • Remove the piezo and retry gyro + gpio sampling
    • Decrease the gpio sampling frequency
  • - sometimes it happens soon after connecting, other times it happens within 5 mins
    - I suppose it's connection lost because app tries to reconnect itself, sometimes app remains connected but stop sending data from gyro/accel
    -  code for streaming gyro and piezo is in the same class(Activity), as i am trying to stream simultaneously 

    Test results as suggested
    - removed piezo, no disconnect streaming gyro+gpio 
    - decreased sample rate @25hz, disconnect/gyro streaming stops after some time.
  • Piezo elements generate very high voltages when subject to mechanical impulses -- as much as several kilo volts.

    A high voltage spike like this on a pin will definitely reset a MetaWearC, if it does not destroy the pin circuitry, the chip or both.

    We would advise at least using a flyback diode, voltage divider to drop current and voltage, and a zener diode (3V) to make sure absolutely no high voltage spikes hit the MetaWearC.  This is the same recommendation and circuit as in the first answer on your stack exchange page (but without the amplifier).
  • I have also used with clipper circuit. where i used the silicon diode that clip the signal at 0.7V.
  • I have used the clipper circuit with piezo. And output of that clipper circuit connected with the gpio of metawear C. In which i have used two silicon diode , one is in forward connection which has clip the forward voltage and another one connected in reverse direction which has clip the negative voltage .
    So, according to clipper circuit which i have used , output will not generate more then 0.7v.
    But, still at the impact  on piezo sensor will get reset.
This discussion has been closed.