Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/euler2dot7/android_things_bmp180
Android Things Bosh BMP85/BMP180 Driver Example Java
https://github.com/euler2dot7/android_things_bmp180
Last synced: 9 days ago
JSON representation
Android Things Bosh BMP85/BMP180 Driver Example Java
- Host: GitHub
- URL: https://github.com/euler2dot7/android_things_bmp180
- Owner: euler2dot7
- Created: 2017-01-05T17:08:41.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-01-06T17:33:08.000Z (almost 8 years ago)
- Last Synced: 2024-08-01T17:24:31.761Z (3 months ago)
- Language: Java
- Homepage:
- Size: 263 KB
- Stars: 8
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-android-things - Bosh BMP85/BMP180 - Bosh BMP85/BMP180 barometer (Useful links / Drivers)
- awesome-android-things - Bosh BMP85/BMP180 - Bosh BMP85/BMP180 barometer (Useful links / Drivers)
README
# android_things_bmp180
Android Things Bosh BMP85/BMP180 Driver Example##Driver for BMP85/BMP180 for Android Things
##Example how to use BMP85/BMP180 with Android Things
### BMP180 sensor connection
![Alt text](/img/BMP180.png?raw=true "I2C connection")
### One can use the sensor directly without SensorManager
```java
private Bmp180 mBmp180;
private static final String I2C_BUS = "I2C1";
private void initSensor(){
mBmp180 = new Bmp180(I2C_BUS);
}private void readData(){
try {
float temp = mBmp180.readTemperature();
float press = mBmp180.readPressure();
double alt = mBmp180.readAltitude();
Log.d(TAG, "loop: temp " + temp + " alt: " + alt + " press: " + press);
} catch (IOException e) {
Log.e(TAG, "Sensor loop error : ", e);
}
}private void closeSensor(){
try {
mBmp180.close();
} catch (IOException e) {
Log.e(TAG, "closeSensor error: ", e);
}
mBmp180 = null;
}```
### You can also use this driver with SensorManager
Registers the sensor and attach the listener
```java
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
mSensorManager.registerDynamicSensorCallback(new SensorManager.DynamicSensorCallback() {
@Override
public void onDynamicSensorConnected(Sensor sensor) {
if (sensor.getType() == Sensor.TYPE_DEVICE_PRIVATE_BASE) {
if (sensor.getStringType().equalsIgnoreCase(Bmp180SensorDriver.BAROMETER_SENSOR)) {
Log.i(TAG, "Barometer sensor connected");
mSensorManager.registerListener(mListener,
sensor, SensorManager.SENSOR_DELAY_NORMAL);
}
}
}
});try {
mSensorDriver = new Bmp180SensorDriver(I2C_PORT);
mSensorDriver.registerBarometerSensor();
} catch (IOException e) {
Log.e(TAG, "Error configuring sensor ", e);
}```
Receives data through SensorEventListener
```java
@Override
public void onSensorChanged(SensorEvent event) {
float data[] = Arrays.copyOf(event.values, 3);
Log.i(TAG, "Pressure: " + data[0]);
Log.i(TAG, "Temperature: " + data[1]);
Log.i(TAG, "Altitude: " + (Math.round(data[2] * 10) / 10.0F));
}@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
Log.i(TAG, "sensor accuracy changed: " + accuracy);
}
```### Live photo
![Alt text](/img/foto.jpg?raw=true "photo")