OlivierLD / raspberry-coffee

JVM related (Java, Groovy, Scala, Kotlin, etc) samples for the Raspberry PI, relying on PI4J. IoT and friends.
http://raspberrypi.lediouris.net/
111 stars 38 forks source link

Bug in BMP180 readS16() #1

Closed wilsmatic closed 8 years ago

wilsmatic commented 8 years ago

Hi Olivier,

Firstly, thanks for sharing! I took a copy of your BMP180.java and adapted it for the BME280 by taking logic from Adafruit's bme280.py. This device includes a humidity sensor and appears to be little-endian. When readS16() forms a little-endian result it reads the hi byte as unsigned and the lo byte as signed whereas it should be the other way around. This bug doesn't affect the BMP180 as that device is presumably big-endian.

BTW I also have a BMP180 and your code works as-is with this device.

ttfn, Aidan.

OlivierLD commented 8 years ago

Thank Aidan for the hint. Sounds like the BME180 is exactly what I need for this project, much better than a BMP180 plus an HTU21D-F. I'll get one of those, this way I could make the tests, and update the code. I'll leave a note here when done. Thanks again for your feedback.

wilsmatic commented 8 years ago

Hi Olivier, The BME280 was only released mid-2015 hence I also bought a BMP180 first together with a DHT22 for my boat project but the latter isn't great. I got my BME280 from Hong Kong via eBay for 4 pounds and it arrived last week. I've been studying the datasheet today and realised that I need to enhance my Java implementation a little to fully utilise this little marvel. I'm happy to share the working example I have.

Now I look at your profile picture again I realise I should have guessed that you're a sailor! Your project page is great and far more advanced than my fledgling project which runs along similar lines. I inherited an LM27 a couple of years ago, got my Day Skipper and started upgrading the equipment as most of it was ancient and/or non-functional. I quickly recognised that NMEA 0183 is pretty cool and easy to interface to hence I bought an NMEA anemometer and an ActiSense DST-2. But I also recognised that sail-boat power is very limited hence I'm going the Android route. Although wifi is the obvious option I came across the IOIO-OTG which is a really cool little board consisting of a PIC (with loads of I/O) and a USB OTG so it can be plugged into an Android device or a PC (which is great for prototyping). The IOIO's PIC i/o includes ADC (notable omission from RPi), 3 I2C and 4 bidirectional UARTs hence I've used the latter for my NMEA instruments. Multiplexing the NMEA is just a bit of Java multithreading. To opto-isolate the NMEA devices I chose the HCPL 2731 because its inputs can be driven at just 1mA and hence I connect without a driver. 4 UARTs is not that restrictive because of course a lot of devices either talk or listen, hence I could connect 4 talkers and 4 listeners which is enough for me. But then I got to thinking about all those other lovely i/o pins which led me to the BME280. A temperature probe for monitoring engine cooling water is next and maybe a bilge level sensor of some sort as my pump is manual. Two other cool things about the IOIO-OTG: it provides charging current to your Android device, you can plug a little Bluetooth dongle into its USB port and connect wirelessly using less power than wifi. All the best, Aidan.

OlivierLD commented 8 years ago

Fixed! Kudos to Aidan for spotting it. The fix is available in BMP180, and in the new BME280,recently implemented.