How do I read windows accelerometer?

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…

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.

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 :

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

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

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

While a normal java class is loaded like :

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 :

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)…

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

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).

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

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.

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.

1 Like

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.

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.

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

1 Like

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

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

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

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

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

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

That should probably solve it.

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

Maybe try this :

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…