How do I read windows accelerometer?

how do I read windows accelerometer?

You should add some additional information.

• What do you mean by Windows accelerometer? (i assume the accelerometer of a windows phone)

• What Mode is your Code in? (Java, Python…)

• Maybe the specific model/version… or similar information.

We can‘t help if we don‘t know what you are looking for.

I have an application written in Processing 3.5.3 running on Windows 10 laptop Lenovo Yoga 700. I have also connected arduino pro micro. Purpose of setup to produce audible signaling for nurses and control my heated blanket, as I am stiff as cucumber because of ALS.
Problem now is that nurses often abuse my laptop. So I decided to use laptops built in accelerometer and produce beep if it’s being kicked. I found this sample from Microsoft https://code.msdn.microsoft.com/Accelerometer-Sensor-Sample-22982671. Which woks but is hugely complicated. I would like to somehow access this accelerometer in my processing app.

First of all you‘d probably need to have Access to the Main component you‘re going to use. I don‘t know if you already have this preinstalled, so if you have you don‘t need this. But just in case, this is the dll file to get access to windows.devices.sensors.accellerometer. Without this you can‘t do it.
This is basically a library like processing.core.PApplet, just that you can‘t simply add an import statement to import it like you do with a java library (since it‘s a dll file).

So to actually „import“ it to have access to it‘s classes and functions, you‘ll have to take a look at this :

This describes how to call functions from a dll file in Java (so it also works in Processing).

As for which functions to use and what they do, you can take a look at the Code section in the link you posted.

That‘s basically how it works, as far as i can tell.

Edit :
It is still pretty complicated, but if i got it right, now you should be able to import the dll file like this :

import com.sun.jna.*;

And then simply access it with :

accelerometer = Windows.Devices.Sensors.Accelerometer.getDefault();

Take note, that i don‘t know wether jna natively has access to Windows.Devices… or if you have to add the dll file to JNA‘s library folder first.

Thanks! Ibut I am not sure how to get JNA. Links have been disabled and no JNA available separately. Instead I installed Java JDK. But JNA doesn’t seem to be there.
for now I have code like this
import com.sun.jna.*;
import Windows.Devices.Sensors.dll;
accelerometer = Windows.Devices.Sensors.Accelerometer.getDefault();
void setup() {

}

to be honest I would rather give a donation for a working piece of code, since I use eyetracker to type. So my ability to play with code is very limited. essentially I need to read three numbers from accelerometer at reasonable rate.

I only have an old Laptop with Windows 8 (probably doesn‘t even have an accelerometer) , and i‘m not capable enough to write some working code without being able to test it myself…

As for the code, it should probably look something like this :

import com.sun.jna.*;

void setup() {
size(800,400);

println(Windows.Devices.Sensors.Accelerometer.getDefault().getClass()); // since i‘m not quite sure what class this is...
}

This will give you something like $*]WDSAccelerometer£^¥ or similar.

Then just rewrite the Code as :

import com.sun.jna.*;

WDSAccelerometer accelerometer;

void setup() {
   size(800,400);
   accelerometer = Windows.Devices.Sensors.Accelerometer.getDefault();
}

void draw() {
   AccelerometerReading reading = accelerometer.GetCurrentReading();

   double x = reading.AccelerationX;
   double y = reading.AccelerationY;
   double z = reading.AccelerationZ;
}

Please try out the first code, to check if it even works. Also, you have to download the JNA library from github and add it to your Processing library folder. Maybe you can also add it by opening Processing and installing it directly from the Libraries and Tools tab.

1 Like

from Github I have folder jna-master. But Processing doesn’t see it. Any hint how to install jna?

If you have problems installing the library, try taking a look at this. It describes how to add libraries to Processing.

Actually, thinking about it for a while, i think it would be a lot easier to simply add an accelerometer to your Arduino setup and have it on your Laptop.
This way you can simply access the Data via your Arduino.

Although you‘d probably have to somehow add it on your Laptop, you probably have your Arduino attached there too (doubt it‘s just hanging from the Laptop like how i have it :sweat_smile: ), since it‘s a permanent setup in your case.

But this might not be the case.

You might also want to take a look at Buttons. Buttons are small button-like products that have various functions like measuring temperature (and making sound if it‘s too hot for example).

I tried looking for an accelerometer version, but it‘s pretty difficult to find one, although i‘m sure i saw something like that some months ago…

I am looking for jna here https://github.com/java-native-access/jn. But can’t find folder structure for installation.

adding accelerometer to arduino crossed my mind also. Just I have to find someone to connect it for me. Tried to avoid this. But seems it’s an easier way…

I managed to find a Guide on how to use it with Java and i‘ll try to adapt it to processing.

This should be the file you have to add according to the instructions in the last link i Sent you.

https://github.com/java-native-access/jna/blob/master/dist/jna.jar

Afterwards you should be able to access the Classes like in these examples :

And this shows how to get access to the .dll functions.

got jna working! But windows dll still not recognised.

First of all, please have a look into your System to see if the Windows.devices.sensors exists and where it is.

it does, but at weird place.
C:\Windows\WinSxS\wow64_microsoft-windows-sensors-universal_31bf3856ad364e35_10.0.18362.1_none_392efa4544441fd8/Windows.Devices.Sensors.dll

    public interface Accelerometer extends Library { ... }

       void setup(){
          System.setProperty("jna.library.path", "C:\\Windows\\WinSxS\\wow64_microsoft-windows-sensors-universal_31bf3856ad364e35_10.0.18362.1_none_392efa4544441fd8\\Windows.Devices.Sensors.dll");
          System.setProperty("java.library.path", "C:\\Windows\\WinSxS\\wow64_microsoft-windows-sensors-universal_31bf3856ad364e35_10.0.18362.1_none_392efa4544441fd8\\Windows.Devices.Sensors.dll");

          Native.loadLibrary("C:\\Windows\\WinSxS\\wow64_microsoft-windows-sensors-universal_31bf3856ad364e35_10.0.18362.1_none_392efa4544441fd8\\Windows.Devices.Sensors.dll", PointShapeBuffer.class);
    }

This should probably do the trick… i hope…

Note that in your path, Windows.Devices.Sensors.dll was seperated with a /, not a \ how it should be, so if that is part of the actual name, and not a seperator, then please change that back accordingly, so that it‘s the right path again.

As for the Interface, i‘ll have to do that after making sure that this is actually the right path and loads properly.

sorry, I have just typed the “/” wrong, the path is right.
seems nearly there but now error
The method loadLibrary(String, Class) from the type Native refers to the missing type PointShapeBuffer

btw I have it like this

import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Platform;
//import Windows.Devices.Sensors.dll;
//WDSAccelerometer accelerometer;
public interface Accelerometer extends Library { }

   void setup(){
      System.setProperty("jna.library.path", "C:\\Windows\\WinSxS\\wow64_microsoft-windows-sensors-universal_31bf3856ad364e35_10.0.18362.1_none_392efa4544441fd8\\Windows.Devices.Sensors.dll");
      System.setProperty("java.library.path", "C:\\Windows\\WinSxS\\wow64_microsoft-windows-sensors-universal_31bf3856ad364e35_10.0.18362.1_none_392efa4544441fd8\\Windows.Devices.Sensors.dll");

      Native.loadLibrary("C:\\Windows\\WinSxS\\wow64_microsoft-windows-sensors-universal_31bf3856ad364e35_10.0.18362.1_none_392efa4544441fd8\\Windows.Devices.Sensors.dll", PointShapeBuffer.class);
}

Yes that was my mistake, i forgot to change the last class. Also, the WDSAccelerometer was just a placeholder for the actual class name (which i didn‘t know). As for how it should look like :

import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.*;

public interface Accelerometer extends Library {

}

    void setup(){
       System.setProperty("jna.library.path", "C:\\Windows\\WinSxS\\wow64_microsoft-windows-sensors-universal_31bf3856ad364e35_10.0.18362.1_none_392efa4544441fd8\\Windows.Devices.Sensors.dll");
       System.setProperty("java.library.path", "C:\\Windows\\WinSxS\\wow64_microsoft-windows-sensors-universal_31bf3856ad364e35_10.0.18362.1_none_392efa4544441fd8\\Windows.Devices.Sensors.dll");

       Native.loadLibrary("C:\\Windows\\WinSxS\\wow64_microsoft-windows-sensors-universal_31bf3856ad364e35_10.0.18362.1_none_392efa4544441fd8\\Windows.Devices.Sensors.dll", Accelerator.class);
 }

If this does not give an error message, then we‘ll just have to set the according functions in the interface (which should be relatively straight fortward, if nothing unexpected happens) and it should work.

some progress, but shows that

The method loadLibrary(String, Class<acc.Accelerometer>) from the type Native is deprecated

but runs and show this

A library relies on native code that’s not available.
Or only works properly when the sketch is run as a 32-bit application.
UnsatisfiedLinkError: Unable to load library ‘C:\Windows\WinSxS\wow64_microsoft-windows-sensors-universal_31bf3856ad364e35_10.0.18362.1_none_392efa4544441fd8\Windows.Devices.Sensors.dll’: Native library (win32-x86-64/C:\Windows\WinSxS\wow64_microsoft-windows-sensors-universal_31bf3856ad364e35_10.0.18362.1_none_392efa4544441fd8\Windows.Devices.Sensors.dll) not found in resource path ([file:/C:/Users/Irmantas/AppData/Local/Temp/acc4339148863374097872temp/, file:/C:/Users/Irmantas/Downloads/processing-3.5.3-windows64%20(1)/processing-3.5.3/, file:/C:/Users/Irmantas/Documents/Processing/acc/code/jna-4.5.0.jar, file:/C:/Users/Irmantas/Documents/Processing/acc/code/jna-platform-4.5.0.jar, file:/C:/Users/Irmantas/Documents/Processing/acc/code/jna.jar, file:/C:/Users/Irmantas/Downloads/processing-3.5.3-windows64%20(1)/processing-3.5.3/core/library/core.jar, file:/C:/Users/Irmantas/Downloads/processing-3.5.3-windows64%20(1)/processing-3.5.3/core/library/gluegen-rt-natives-linux-aarch64.jar, file:/C:/Users/Irmantas/Downloads/processing-3.5.3-windows64%20(1)/processing-3.5.3/core/library/gluegen-rt-natives-linux-amd64.jar, file:/C:/Users/Irmantas/Downloads/processing-3.5.3-windows64%20(1)/processing-3.5.3/core/library/gluegen-rt-natives-linux-armv6hf.jar, file:/C:/Users/Irmantas/Downloads/processing-3.5.3-windows64%20(1)/processing-3.5.3/core/library/gluegen-rt-natives-linux-i586.jar, file:/C:/Users/Irmantas/Downloads/processing-3.5.3-windows64%20(1)/processing-3.5.3/core/library/gluegen-rt-natives-macosx-universal.jar, file:/C:/Users/Irmantas/Downloads/processing-3.5.3-windows64%20(1)/processing-3.5.3/core/library/gluegen-rt-natives-windows-amd64.jar, file:/C:/Users/Irmantas/Downloads/processing-3.5.3-windows64%20(1)/processing-3.5.3/core/library/gluegen-rt-natives-windows-i586.jar, file:/C:/Users/Irmantas/Downloads/processing-3.5.3-windows64%20(1)/processing-3.5.3/core/library/gluegen-rt.jar, file:/C:/Users/Irmantas/Downloads/processing-3.5.3-windows64%20(1)/processing-3.5.3/core/library/jogl-all-natives-linux-aarch64.jar, file:/C:/Users/Irmantas/Downloads/processing-3.5.3-windows64%20(1)/processing-3.5.3/core/library/jogl-all-natives-linux-amd64.jar, file:/C:/Users/Irmantas/Downloads/processing-3.5.3-windows64%20(1)/processing-3.5.3/core/library/jogl-all-natives-linux-armv6hf.jar, file:/C:/Users/Irmantas/Downloads/processing-3.5.3-windows64%20(1)/processing-3.5.3/core/library/jogl-all-natives-linux-i586.jar, file:/C:/Users/Irmantas/Downloads/processing-3.5.3-windows64%20(1)/processing-3.5.3/core/library/jogl-all-natives-macosx-universal.jar, file:/C:/Users/Irmantas/Downloads/processing-3.5.3-windows64%20(1)/processing-3.5.3/core/library/jogl-all-natives-windows-amd64.jar, file:/C:/Users/Irmantas/Downloads/processing-3.5.3-windows64%20(1)/processing-3.5.3/core/library/jogl-all-natives-windows-i586.jar, file:/C:/Users/Irmantas/Downloads/processing-3.5.3-windows64%20(1)/processing-3.5.3/core/library/jogl-all.jar, file:/C:/Users/Irmantas/Documents/Processing/libraries/jna/library/aix-ppc.jar, file:/C:/Users/Irmantas/Documents/Processing/libraries/jna/library/aix-ppc64.jar, file:/C:/Users/Irmantas/Documents/Processing/libraries/jna/library/android-aarch64.jar, file:/C:/Users/Irmantas/Documents/Processing/libraries/jna/library/android-arm.jar, file:/C:/Users/Irmantas/Documents/Processing/libraries/jna/library/android-armv7.jar, file:/C:/Users/Irmantas/Documents/Processing/libraries/jna/library/android-mips.jar, file:/C:/Users/Irmantas/Documents/Processing/libraries/jna/library/android-mips64.jar, file:/C:/Users/Irmantas/Documents/Processing/libraries/jna/library/android-x86-64.jar, file:/C:/Users/Irmantas/Documents/Processing/libraries/jna/library/android-x86.jar, file:/C:/Users/Irmantas/Documents/Processing/libraries/jna/library/darwin.jar, file:/C:/Users/Irmantas/Documents/Processing/libraries/jna/library/doc.zip, file:/C:/Users/Irmantas/Documents/Processing/libraries/jna/library/freebsd-x86-64.jar, file:/C:/Users/Irmantas/Documents/Processing/libraries/jna/library/freebsd-x86.jar, file:/C:/Users/Irmantas/Documents/Processing/libraries/jna/library/jna-min.jar, file:/C:/Users/Irmantas/Documents/Processing/libraries/jna/library/jna-platform.jar, file:/C:/Users/Irmantas/Documents/Processing/libraries/jna/library/jna.jar, file:/C:/Users/Irmantas/Documents/Processing/libraries/jna/library/linux-aarch64.jar, file:/C:/Users/Irmantas/Documents/Processing/libraries/jna/library/linux-arm.jar, file:/C:/Users/Irmantas/Documents/Processing/libraries/jna/library/linux-armel.jar, file:/C:/Users/Irmantas/Documents/Processing/libraries/jna/library/linux-ia64.jar, file:/C:/Users/Irmantas/Documents/Processing/libraries/jna/library/linux-mips64el.jar, file:/C:/Users/Irmantas/Documents/Processing/libraries/jna/library/linux-ppc.jar, file:/C:/Users/Irmantas/Documents/Processing/libraries/jna/library/linux-ppc64.jar, file:/C:/Users/Irmantas/Documents/Processing/libraries/jna/library/linux-ppc64le.jar, file:/C:/Users/Irmantas/Documents/Processing/libraries/jna/library/linux-s390x.jar, file:/C:/Users/Irmantas/Documents/Processing/libraries/jna/library/linux-sparcv9.jar, file:/C:/Users/Irmantas/Documents/Processing/libraries/jna/library/linux-x86-64.jar, file:/C:/Users/Irmantas/Documents/Processing/libraries/jna/library/linux-x86.jar, file:/C:/Users/Irmantas/Documents/Processing/libraries/jna/library/openbsd-x86-64.jar, file:/C:/Users/Irmantas/Documents/Processing/libraries/jna/library/openbsd-x86.jar, file:/C:/Users/Irmantas/Documents/Processing/libraries/jna/library/src-full.zip, file:/C:/Users/Irmantas/Documents/Processing/libraries/jna/library/src.zip, file:/C:/Users/Irmantas/Documents/Processing/libraries/jna/library/sunos-sparc.jar, file:/C:/Users/Irmantas/Documents/Processing/libraries/jna/library/sunos-sparcv9.jar, file:/C:/Users/Irmantas/Documents/Processing/libraries/jna/library/sunos-x86-64.jar, file:/C:/Users/Irmantas/Documents/Processing/libraries/jna/library/sunos-x86.jar, file:/C:/Users/Irmantas/Documents/Processing/libraries/jna/library/w32ce-arm.jar, file:/C:/Users/Irmantas/Documents/Processing/libraries/jna/library/win32-x86-64.jar, file:/C:/Users/Irmantas/Documents/Processing/libraries/jna/library/win32-x86.jar, file:/C:/Users/Irmantas/Downloads/processing-3.5.3-windows64%20(1)/processing-3.5.3/lib/, file:/C:/Users/Irmantas/Downloads/processing-3.5.3-windows64%20(1)/processing-3.5.3/lib/pde.jar, file:/C:/Users/Irmantas/Downloads/processing-3.5.3-windows64%20(1)/processing-3.5.3/core/library/core.jar, file:/C:/Users/Irmantas/Downloads/processing-3.5.3-windows64%20(1)/processing-3.5.3/lib/jna.jar, file:/C:/Users/Irmantas/Downloads/processing-3.5.3-windows64%20(1)/processing-3.5.3/lib/jna-platform.jar, file:/C:/Users/Irmantas/Downloads/processing-3.5.3-windows64%20(1)/processing-3.5.3/lib/antlr.jar, file:/C:/Users/Irmantas/Downloads/processing-3.5.3-windows64%20(1)/processing-3.5.3/lib/ant.jar, file:/C:/Users/Irmantas/Downloads/processing-3.5.3-windows64%20(1)/processing-3.5.3/lib/ant-launcher.jar])