androidthings / weatherstation

Sensor-based peripheral sample using Android Things
Apache License 2.0
213 stars 78 forks source link

Need to throttle updates? #1

Open joreilly opened 7 years ago

joreilly commented 7 years ago

I'm using this with Raspberry Pi and Rainbow HAT. If I leave it running the temperature shown steadily increases. It might be case that I need to add heatsink to the processor but wondering if perhaps the code should throttle number of updates it does. Not a big issue in the scheme of things (realise this is just a demo).

proppy commented 7 years ago

@joreilly I think this is coming from the apa102 RGB LED that are just above the temperature sensor.

You could try to dim them off and see if it affect the temperature.

joreilly commented 7 years ago

I commented out code to set LEDs but still seeing temperature steadily going up. I also tried passing in my longer delay (1000000 microseconds for example) to mSensorManager.registerListener() but it didn't seem to take effect.

proppy commented 7 years ago

Pimoroni recently added the following note to the product page

Temperature readings are affected by heat radiated from your Pi’s CPU and the onboard LEDs; calibration can help to correct temperature readings. bstrobl, on the Raspberry Pi forums, suggests to use the formula: corrected temp. = measured temp. - (CPU temp. - measured temp.) / 2. Using a Mini Black HAT Hack3r can also help.

Maybe we could implement that as an helper function in the Rainbow Hat driver

/cc @gguuss

Emeritus-DarranKelinske commented 7 years ago

Here is something to keep the display from flickering with each change. It also converts to Fahrenheit:

private SensorEventListener mTemperatureListener = new SensorEventListener() {
    @Override
    public void onSensorChanged(SensorEvent event) {
        float newTemperature = event.values[0];
        if (Math.abs(newTemperature - mLastTemperature) > 1) {
            mLastTemperature = event.values[0];
            Log.d(TAG, "sensor changed: " + mLastTemperature);
            if (mDisplayMode == DisplayMode.TEMPERATURE) {
                float fahrenheit = 32 + (mLastTemperature * 9 / 5);
                updateDisplay(fahrenheit);
            }
        }
    }

    @Override
    public void onAccuracyChanged(Sensor sensor, int accuracy) {
        Log.d(TAG, "accuracy changed: " + accuracy);
    }
};
Emeritus-DarranKelinske commented 7 years ago

did anyone try the pimoroni suggestion? what were the results?

msagi commented 5 years ago

Pimoroni recently added the following note to the product page

Temperature readings are affected by heat radiated from your Pi’s CPU and the onboard LEDs; calibration can help to correct temperature readings. bstrobl, on the Raspberry Pi forums, suggests to use the formula: corrected temp. = measured temp. - (CPU temp. - measured temp.) / 2. Using a Mini Black HAT Hack3r can also help.

Maybe we could implement that as an helper function in the Rainbow Hat driver

/cc @gguuss

You cannot read the CPU temp on Android Things but even if you could this would not work. I have tried to move the Rainbow Hat away from the Android Things board via a 20cm long 2x20 GPIO cable. The temp sensor still measures data from another reality, e.g. 30C+ at normal room temp. This is a design flaw in the Rainbow Hat itself.