# Smartwatch, Compass value does not change

**URL:** <https://discourse.processing.org/t/smartwatch-compass-value-does-not-change/17640>\
**Category:** Processing for Android\
**Created:** [February 8, 2020, 2:21pm UTC](https://discourse.processing.org/t/smartwatch-compass-value-does-not-change/17640 "2020-02-08T14:21:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon68884268](https://avatars.discourse-cdn.com/v4/letter/a/59ef9b/32.png) [@anon68884268](https://discourse.processing.org/u/anon68884268)\
**Post date:** [February 8, 2020, 2:21pm UTC](https://discourse.processing.org/t/smartwatch-compass-value-does-not-change/17640/1 "2020-02-08T14:21:40Z")

</div>

Hello,  
I’ve written a little smartwatch watchface (with the Ketai Libary), and the compass value isn’t changing. I tried it with getting the Sensor manually, but then it said me, `The field Sensor.TYPE_ORIENTATION is deprecated.`.  
So i searched and found [this (Android Developers)](https://developer.android.com/reference/android/hardware/Sensor.html#TYPE_ORIENTATION).  
There stands the new thing for accessing the orientation is [this (`SensorManager.getOrientation()`)](https://developer.android.com/reference/android/hardware/SensorManager.html#getOrientation(float%5B%5D,%20float%5B%5D))  
But it expects parameters, from where should I get them?

OS: Windows 10  
Mobile: Galaxy S7 edge Android 9  
Watch: Fossil Sport

> **Code (Ketai Libary)**
>
> ```auto
> void setup() {
> fullScreen();
> //size(390, 390);
> frameRate(60);
> smooth(2);
>   
> sensor = new KetaiSensor(this);
> }
> 
> void draw() {
> background(0);
> displayCompass();
> }
> 
> void displayCompass() {
> stroke(204, 0, 0);
> noFill();
> strokeWeight(width*0.08);
> strokeCap(SQUARE);
> ellipseMode(CENTER);
>   
> println(compass);
> arc(0, 0, (width-width*0.56), (width-width*0.56), radians(-5 + compass), radians(5 + compass), OPEN);
> }
> 
> void onOrientationEvent(float x, float y, float z, long time, int accuracy) {
> compass = x;
> }
> 
> ```

Thanks.

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [February 11, 2020, 5:59pm UTC](https://discourse.processing.org/t/smartwatch-compass-value-does-not-change/17640/2 "2020-02-11T17:59:24Z")

</div>

@anon68884268 ===

- I am supposing that you get only the warning “deprecated” and that your code compile without any error.
- “Deprecated” does not mean that a field will not work, only that there is a better one now.
- Sensor.Type\_ORIENTATION works with Android MM and Nougat (tested) and you can forget the warning (“deprecated”)
- Yet if you want to use getOrientation() you have to create two sensors, accelerometer && magneticField (the same way that for the “deprecated” one!) wich will return 3 values (X,Y,Z) that you store in arrays; then you have to call getRotationMatrix()with parameters (arrayR=float[9], null, yourArray1, values, your array2 values; finally create another array arrayOr=float[3] and call getOrientation(arrayR, arrayOr): it will return the values you are looking for but in radians.
- Now if you want to use this way i am quite sure that you have to leave Ketai for android direct coding…

---

<div class="post-metadata">

**Author:** ![anon68884268](https://avatars.discourse-cdn.com/v4/letter/a/59ef9b/32.png) [@anon68884268](https://discourse.processing.org/u/anon68884268)\
**Post date:** [February 16, 2020, 4:25pm UTC](https://discourse.processing.org/t/smartwatch-compass-value-does-not-change/17640/3 "2020-02-16T16:25:36Z")

</div>

Well, I’ve done the coding with acceleration and magnet field with no result. Whyever it didn’t work either on the mobile as on the watch, but with the deprecated orientation it worked on mobile, but not on the watch. It works on mobile with a wallpaper, too, so it can’t depend on the difference with `getActivity()` and `getContext()`. But I know the watch has got a compass, because another app from the Play Store works ([here](https://play.google.com/store/apps/details?id=apps.r.compass&hl=de)).

---

<div class="post-metadata">

**Author:** ![anon68884268](https://avatars.discourse-cdn.com/v4/letter/a/59ef9b/32.png) [@anon68884268](https://discourse.processing.org/u/anon68884268)\
**Post date:** [February 20, 2020, 6:16pm UTC](https://discourse.processing.org/t/smartwatch-compass-value-does-not-change/17640/4 "2020-02-20T18:16:14Z")

</div>

I found another thing. When I install the sketch on the watch as an app and not as a watchface, it works! It seems like you can’t access all sensors as a watchface, whyever.
