# How do I read windows accelerometer?

**URL:** <https://discourse.processing.org/t/how-do-i-read-windows-accelerometer/15318>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [November 7, 2019, 4:02pm UTC](https://discourse.processing.org/t/how-do-i-read-windows-accelerometer/15318 "2019-11-07T16:02:02Z")\
**Posts on this page:** 18\
**Page:** 2

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [November 9, 2019, 12:46pm UTC](https://discourse.processing.org/t/how-do-i-read-windows-accelerometer/15318/21 "2019-11-09T12:46:16Z")

</div>

Hmm… First of all, i made a mistake in the last Code. The last accelerator.class should be Accelerometer.class.

As for the error… maybe try replacing Native.loadLibrary() with Native.load(); Apparently loadLibrary() works only if the .dll file is in the correct path (from where libraries are loaded for JNA), while load can take any path to load the libraries…

If that doesn‘t work, we‘ll have to redefine the Systems property „jna.path.library“ with the commandline… which in turn means starting the sketch with the cmd (commandline) and that would just make it annoying to start up each time…

---

<div class="post-metadata">

**Author:** ![irmantas](https://avatars.discourse-cdn.com/v4/letter/i/53a042/32.png) [@irmantas](https://discourse.processing.org/u/irmantas)\
**Post date:** [November 9, 2019, 12:54pm UTC](https://discourse.processing.org/t/how-do-i-read-windows-accelerometer/15318/22 "2019-11-09T12:54:47Z")

</div>

yes I have fixed accelerometer and tried load. But still errors.  
would it be good idea to build.exe? Just that GetCurrentReading is not working.

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [November 9, 2019, 1:25pm UTC](https://discourse.processing.org/t/how-do-i-read-windows-accelerometer/15318/23 "2019-11-09T13:25:18Z")

</div>

The problem is that the System.setProperty() function is probably too Late to call in the Code. We‘ll have to call it before, and for that we need to call it in the cmd like this :

```auto
java -Djna.library.path=<path to your library> MainClass

```

Now the problem is, to start a Processing sketch, the Code is :

```auto
processing-java --sketch=MySketch --output=/tmp/MySketch --run

```

While a normal java class is loaded like :

```auto
java MainClass

```

As you can see, the to run a java class and running it with the new path property is pretty easy to figure out.  
The problem is that i have no idea, where (or if) we can include the -Djna.library.path= part…

The best i could think of would be to try this :

```auto
processing-java -Djna.library.path=<pathToLibrary> --sketch=Conway --output=/tmp/Conway --run

```

This is pretty much the same as saying processing-java is equal to java, -D…\> stays the same and then —sketch…—run is equal to MainClass.  
But i‘m not good with the cmd, so that might as well be nonsense…

So if that doesn‘t work, we‘ll have to export your current sketch and just call it like a normal java class (which should hopefully be easier)…

---

<div class="post-metadata">

**Author:** ![irmantas](https://avatars.discourse-cdn.com/v4/letter/i/53a042/32.png) [@irmantas](https://discourse.processing.org/u/irmantas)\
**Post date:** [November 9, 2019, 1:43pm UTC](https://discourse.processing.org/t/how-do-i-read-windows-accelerometer/15318/24 "2019-11-09T13:43:45Z")

</div>

I also thought about simplifying Microsoft sample and somehow pass numbers to processing? Does that make any sense?

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [November 9, 2019, 2:54pm UTC](https://discourse.processing.org/t/how-do-i-read-windows-accelerometer/15318/25 "2019-11-09T14:54:53Z")

</div>

Does the microsoft sample work for you? If so, you could probably do that, yes. But we’ll have to see how to inform the running processing sketch of a change (either by updating a variable constantly, or better, call a function within the running sketch).

---

<div class="post-metadata">

**Author:** ![irmantas](https://avatars.discourse-cdn.com/v4/letter/i/53a042/32.png) [@irmantas](https://discourse.processing.org/u/irmantas)\
**Post date:** [November 9, 2019, 3:12pm UTC](https://discourse.processing.org/t/how-do-i-read-windows-accelerometer/15318/26 "2019-11-09T15:12:48Z")

</div>

yes, Microsoft works. Let me play a bit on it.

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [November 9, 2019, 3:21pm UTC](https://discourse.processing.org/t/how-do-i-read-windows-accelerometer/15318/27 "2019-11-09T15:21:40Z")

</div>

I‘ve looked around a bit and most refer to JNI to do this (more complex version of JNA), but apparently there‘s also a way to do this with System.Diagnostics.Process.

As for how that works, i‘ll take a look at the Documentation. But it seems to be a lot easier.

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [November 9, 2019, 3:46pm UTC](https://discourse.processing.org/t/how-do-i-read-windows-accelerometer/15318/28 "2019-11-09T15:46:50Z")

</div>

I think another approach would be a lot easier. We could send a variable to your arduino with Serial through the Port in C# (in the sample Code) and from the arduino to processing. That would be a lot easier.

But before i try to get the Code together, please tell me if that approach would work out for you.

---

<div class="post-metadata">

**Author:** ![irmantas](https://avatars.discourse-cdn.com/v4/letter/i/53a042/32.png) [@irmantas](https://discourse.processing.org/u/irmantas)\
**Post date:** [November 10, 2019, 10:05am UTC](https://discourse.processing.org/t/how-do-i-read-windows-accelerometer/15318/29 "2019-11-10T10:05:30Z")

</div>

My app is taking to arduino via serial.  
I thought about creating file when accelerometer is kicked and in Processing I would check if file exist. If exist produce beep.  
not most elegant, but within my knowledge.

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [November 10, 2019, 10:56am UTC](https://discourse.processing.org/t/how-do-i-read-windows-accelerometer/15318/30 "2019-11-10T10:56:36Z")

</div>

It would probably be more elegant to write the first line with C# in the .txt and read that from processing. This way you could actually establish a simple two way communication.

---

<div class="post-metadata">

**Author:** ![irmantas](https://avatars.discourse-cdn.com/v4/letter/i/53a042/32.png) [@irmantas](https://discourse.processing.org/u/irmantas)\
**Post date:** [November 10, 2019, 11:28am UTC](https://discourse.processing.org/t/how-do-i-read-windows-accelerometer/15318/31 "2019-11-10T11:28:41Z")

</div>

that is right. I will play a bit and let you know.

---

<div class="post-metadata">

**Author:** ![irmantas](https://avatars.discourse-cdn.com/v4/letter/i/53a042/32.png) [@irmantas](https://discourse.processing.org/u/irmantas)\
**Post date:** [November 13, 2019, 9:07am UTC](https://discourse.processing.org/t/how-do-i-read-windows-accelerometer/15318/32 "2019-11-13T09:07:03Z")

</div>

I am stuck. Can’t get through exceptiona Access to the path ‘C:\Users\Irmantas\Documents\Processing\b.txt’ is denied.

---

<div class="post-metadata">

**Author:** ![irmantas](https://avatars.discourse-cdn.com/v4/letter/i/53a042/32.png) [@irmantas](https://discourse.processing.org/u/irmantas)\
**Post date:** [November 13, 2019, 9:11am UTC](https://discourse.processing.org/t/how-do-i-read-windows-accelerometer/15318/33 "2019-11-13T09:11:16Z")

</div>

File.Create(“C:\Users\Irmantas\Documents\Processing\b.txt”);

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [November 13, 2019, 11:49am UTC](https://discourse.processing.org/t/how-do-i-read-windows-accelerometer/15318/34 "2019-11-13T11:49:53Z")

</div>

The .txt is probably marked as a Read-only file. Just rightclick on the file and under properties uncheck the read-only box.

---

<div class="post-metadata">

**Author:** ![irmantas](https://avatars.discourse-cdn.com/v4/letter/i/53a042/32.png) [@irmantas](https://discourse.processing.org/u/irmantas)\
**Post date:** [November 13, 2019, 1:02pm UTC](https://discourse.processing.org/t/how-do-i-read-windows-accelerometer/15318/35 "2019-11-13T13:02:56Z")

</div>

I have checked and rechecked. This  
File.Exists(“C:\Users\Irmantas\Documents\Processing\b.txt”) ;  
also gives response False.

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [November 13, 2019, 8:35pm UTC](https://discourse.processing.org/t/how-do-i-read-windows-accelerometer/15318/36 "2019-11-13T20:35:21Z")

</div>

Ok, it‘s probably because the path should look like this :

```auto
“C:/Users/Irmantas/Documents/Processing/b.txt”

```

That should probably solve it.

---

<div class="post-metadata">

**Author:** ![irmantas](https://avatars.discourse-cdn.com/v4/letter/i/53a042/32.png) [@irmantas](https://discourse.processing.org/u/irmantas)\
**Post date:** [November 14, 2019, 7:53am UTC](https://discourse.processing.org/t/how-do-i-read-windows-accelerometer/15318/37 "2019-11-14T07:53:17Z")

</div>

no, no luck. Microsoft is so secure it can’t write to its own disc.

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [November 14, 2019, 1:24pm UTC](https://discourse.processing.org/t/how-do-i-read-windows-accelerometer/15318/38 "2019-11-14T13:24:12Z")

</div>

Maybe try this :

```auto
File file = new File(“C:\\Users\\Irmantas\\Documents\\Processing\\b.txt”);
println(file.exists());

```

And try replacing the \ \ with \ or /… i think i used \ \ some time ago on a project, but online one says \ \ another says / and apparently both work…

[Previous page](https://discourse.processing.org/t/how-do-i-read-windows-accelerometer/15318.md?page=1)
