Attach vibration sesor with RPRO

can i attach a vibration sensor with RPRO and get data.

Comments

  • yes using the gpio pins or I2C/SPI buses.
  • thanks Eric, can you also suggest any particular type sensor which can go easily with preferably smaller.
  • We have not tried any ourselves so I can't give any specific recommendations.  A typical vibration sensor should only need the gpio pins so you'll need to find one that can be powered by 3V.
  • edited March 2017
    There are no specifications listed on the store page so I can't say one way or another.  Is there a specific reason as to why you aren't using the accelerometer to detect vibrations?
  • I want to use vibration sensor for knock or impact, which i suppose difficult with accelerometer at 50hz.
    https://www.sparkfun.com/products/10293
    I have hooked the piezo element as Analog input at pin number 9 and grounded at pin number 4, have i hooked in proper pins?
    which gpio method should be used to get input value?
    not getting result with this;
    gpio.readAnalogIn(GPIO_PIN,Gpio.AnalogReadMode.ADC);

    also now the website is updated and documentation support is for version 3, can we have support of previous version, such as project.mbientlabs page is not available etc.
  • edited April 2017
    Can you clarify what you mean by saying "not getting result"?  Are you receiving invalid values or not receiving any values?  What value is the GPIO_PIN variable set to?

    Documentation for API v2 is still on the website.
  • Thanks Eric,
    The problem is solved, was using wrong value in GPIO_PIN variable. GPIO_PIN=1 solved the problem.
    If you could help me with another issue, since connection of vibration sensor to the board, the board gets disconnected rapidly within 2-3 minutes.
    below is the code:
    final RouteManager.MessageHandler dataHandler = new RouteManager.MessageHandler() {
    @Override
    public void process(Message message) {
    short rawValue = message.getData(Short.class);
    Log.i("gpio", String.valueOf(rawValue));

    }
    };
    AsyncOperation.CompletionHandler<RouteManager> gpioHandler = new AsyncOperation.CompletionHandler<RouteManager>() {
    @Override
    public void success(RouteManager result) {
    result.subscribe(VIBRATION, dataHandler);
    try {
    AsyncOperation<Timer.Controller> taskResult = mwBoard.getModule(Timer.class).scheduleTask(
    new Timer.Task() {
    @Override
    public void commands() {
    gpio.readAnalogIn(GPIO_PIN, Gpio.AnalogReadMode.ADC);
    }
    }, SCAN_INTERVAL, false);
    taskResult.onComplete(
    new AsyncOperation.CompletionHandler<Timer.Controller>() {
    @Override
    public void success(Timer.Controller result) {
    result.start();
    }
    }
    );
    } catch (UnsupportedModuleException e) {
    Log.e("Error", e.toString());
    }
    }

    };

    gpio.routeData().fromAnalogIn(GPIO_PIN,Gpio.AnalogReadMode.ADC).stream(VIBRATION).
    commit().onComplete(gpioHandler);
    Have i made the connection right as i am getting results?
    also what is the natural frequency of the metawear board?




  • What is the value of SCAN_INTERVAL?  Furthermore, is the board simply losing connection or resetting?

    I'm not exactly sure what the natural frequency of the boards are but I doubt they are bring disturbed by a knock.
  • @rajmishra

    I would start by adding a 1M ohm resistance across the piezo, as they suggest in the arduino tutorial linked by sparkfun.  Piezo elements are capacitive in nature, and may be accumulating significant charge over time.  Before taking this step, you might consider turning on the GPIO pin "pull down" on the sensor input.  This will apply a resistance in the 10k ohm range, this may or may not be too much of a load and squelch the output.

    Ideally, the sensor should have some output filtering applied to reduce the peak voltage it may output -- Piezo elements are capable of generating high voltages that could damage the MetaWear.  Here is an example of such a filter: https://en.wikipedia.org/wiki/Low-pass_filter#RC_filter.

    If I had to guess as to the reset, the piezo accumulating charge, or generating a high voltage with a particularly hard knock is causing a voltage spike or noise event resulting in a reset.
  • edited April 2017

    @Eric

    The value of START_INTERVAL= 20 initially,after your reply I changed START_INTERVAL= 50, now getting data from piezo element and the board is also not resetting at even hard knock.

    @Matt

    yes it is essential to add a 1M ohm resistance as suggested in the Arduino tutorial. so I used "pull down" on the sensor input, as you suggest without "pull down" it may damage the board, please check if I have put it correctly as there is no change in the values received form piezo:

    private final byte GPIO_PIN = 1;
    private final int SCAN_INTERVAL = 50;
    gpio.setPinPullMode(GPIO_PIN, Gpio.PullMode.PULL_DOWN);
    final RouteManager.MessageHandler dataHandler = new RouteManager.MessageHandler() {
    @Override
    public void process(Message message) {
    short rawValue = message.getData(Short.class);
    Log.i("gpio", String.valueOf(rawValue));

    }
    };
    AsyncOperation.CompletionHandler<RouteManager> gpioHandler = new AsyncOperation.CompletionHandler<RouteManager>() {
    @Override
    public void success(RouteManager result) {
    result.subscribe(VIBRATION, dataHandler);
    try {
    AsyncOperation<Timer.Controller> taskResult = mwBoard.getModule(Timer.class).scheduleTask(
    new Timer.Task() {
    @Override
    public void commands() {
    gpio.readAnalogIn(GPIO_PIN, Gpio.AnalogReadMode.ADC);
    }
    }, SCAN_INTERVAL, false);
    taskResult.onComplete(
    new AsyncOperation.CompletionHandler<Timer.Controller>() {
    @Override
    public void success(Timer.Controller result) {
    result.start();
    }
    }
    );
    } catch (UnsupportedModuleException e) {
    Log.e("Error", e.toString());
    }
    }

    };

    gpio.routeData().fromAnalogIn(GPIO_PIN,Gpio.AnalogReadMode.ADC)
    .stream(VIBRATION).
    commit().onComplete(gpioHandler);


  • By no change in data received means, that the data received is same with  PULL_DOWN and without. should there be any change ?
  • Did you add the 1Mohm resistor as described by the Arduino tutorial?

    What values are you reading so far with your sensor?  
  • edited April 2017
    No did not, instead i used PULL_DOWN function as Matt suggested.
    gpio.initiateAnalogInRead(GPIO_PIN, Gpio.AnalogReadMode.ADC).pullDownPin(GPIO_PIN).commit();

    here is the output logs, mostly after impact(on pressing the piezo surface) the value reaches maximum and fall
    falls to 1 shortly after;

    https://gist.github.com/rajkumarmishra/2f589d1b6c05d34432eb915270d840ab


  • Matt's primary suggestion is to follow the Arduino tutorial and add the 1Mohm resistor.

    You should ensure that no more resets are occurring after enabling the pull down pin and if the circuit is stable, start collecting data with your sensor.
  • Thanks Eric for all your support,

    I have attached 1 M ohm resistor, instead of my app i used to Metawear app to stream data. I am able to get data  from gpio pin continuously but after few impacts the board keep getting reset.
    I don't understand what could be the issue, it seems circuit is stable as board only resets after impacts, checked with other metawear boards as well but problem remains the same.
  • edited April 2017
    As matt said, its piezo could be accumulating charge or generating voltage spikes.  Can you try measuring the current/voltage produced by your test vibrations using a multimeter?

    The MetaWear app reads analog data at 33ms.  You should try with your previous value of 50ms which you earlier said was not causing resets.
This discussion has been closed.