Hi every One :-)
Let make a vibrate detection with HDX Vibration Sensor and Esp32 and NanoFramework!
HDX Vibration Sensor is little sensor for vibrate detection
You should put that in true direction. Otherwise it will not work properly! (its direction is vertical)
You can find its direction with multimeter. Set voltmeter on diode mode then put multimeter wire on HDX pins after that you must shake HDX. Now you must hear Disconnect and reconnect sequence sound.
Ok now we must connect HDX to board (esp32).
Here I connect HDX to GPIO 21.
You must install nanoframework on your device
NanoFramework Esp32 - Hackster.io
Ok everything is ready to develop ;-)
I develop a package for vibration sensor. currently my package only support HDX sensor.
(maybe I will add another sensor to this package)
you can get it from github (github/alirezap)
Unfortunately, I couldn’t Publish this package as nugget package (it has exception when is try to publush it as nugget package) so you should download source from github and add that to your project.
Ok now let developing
Open Gpio (here is 21)
Set it as input
Set gpio eventhandler
_shockDetection = s_GpioController.OpenPin(_pinNumberShockDetection);
_shockDetection.SetDriveMode(GpioPinDriveMode.Input);
_shockDetection.ValueChanged += _shockDetection_ValueChanged;
private static void VibrationObject_InvokeEvent(object sender, EventArgs e)
{
Debug.WriteLine("Vibrate!!!!!!");
}
Add package to your project
Create instance from package
vibrationObject = newAP.NanoFrameWork.Vibration.HDX();
set Threshold. (default is 15)
vibrationObject.Threshold = 20;
Threshold is count of Pin status change in second.
set event handler
vibrationObject.InvokeEvent += VibrationObject_InvokeEvent;
now in gpio valuechange event handler pass gpio status to package
private static void _shockDetection_ValueChanged(object sender, GpioPinValueChangedEventArgs e)
{
vibrationObject.AnalyseSignal(e.Edge);
}
Full code:
run project and enjoy
Thank you Microsoft
Thank you Nanoframework team. This is future of chip development
Comments
Please log in or sign up to comment.