I use a raspberry pi3 sensor and DHT11 to monitor the temperature. I have the following contact positions
VCC for output: 2 Ground for output: 6 Output in GPIO: BCM22, i.e. No 15
The code I used:
public class WeatherStationActivity extends Activity { private Handler mHandler = new Handler(); private TextView mTxtStatus; private PeripheralManagerService service = new PeripheralManagerService(); private Gpio tempGpio; private int i = 0; int[] dht11_dat = {0, 0, 0, 0, 0}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d("Weather station", "Started Weather Station"); setContentView(R.layout.activity_main); mTxtStatus = (TextView) findViewById(R.id.txtStatus); try { tempGpio = service.openGpio("BCM22"); Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { if (i == 10) { handler.removeCallbacks(this); } else { getTemp(); handler.postDelayed(this, 5000); } i++; } }, 5000); } catch (Exception e) { e.printStackTrace(); } } private void getTemp() { boolean laststate = false; try { laststate = tempGpio.getValue(); } catch (IOException e) { e.printStackTrace(); } int j = 0; final int MAXTIMINGS = 85; dht11_dat[0] = dht11_dat[1] = dht11_dat[2] = dht11_dat[3] = dht11_dat[4] = 0; try { tempGpio.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
The above code gives me "Nothing working" as the output.
Any suggestion where I could be wrong?
android android-things sensor raspberry-pi3
Manoj
source share