From 9b0dc692177cdc6d8fa7aad4949e5e7a0abb6399 Mon Sep 17 00:00:00 2001 From: Bernhard Tittelbach Date: Sat, 28 May 2016 02:53:04 +0200 Subject: bmp180 pressure sensor, just lacks arduino i2c-wire-lib and testing --- bmp180.mk | 42 +++++++++++++ contrib/Makefile | 10 ++- include.mk | 23 +++++++ usb-bmp180/Makefile | 53 ++++++++++++++++ usb-bmp180/usb-bmp180.c | 162 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 289 insertions(+), 1 deletion(-) create mode 100644 bmp180.mk create mode 100644 usb-bmp180/Makefile create mode 100644 usb-bmp180/usb-bmp180.c diff --git a/bmp180.mk b/bmp180.mk new file mode 100644 index 0000000..5bac3ac --- /dev/null +++ b/bmp180.mk @@ -0,0 +1,42 @@ +## +## spreadspace avr utils +## +## +## Copyright (C) 2013-2016 Christian Pointner +## Copyright (C) 2016 Bernhard Tittelbach +## +## This file is part of spreadspace avr utils. +## +## spreadspace avr utils is free software: you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## any later version. +## +## spreadspace avr utils is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with spreadspace avr utils. If not, see . +## + +include $(SPREADAVR_PATH)/defines.mk + +SRC:=$(wildcard $(BMP180_PATH)/*.cpp) + +CXXFLAGS += -I$(BMP180_PATH) +CXXFLAGS += -DARDUINO=106 +CXXFLAGS += -DNEED_CXX_BITS +CXXFLAGS += $(BMP180_OPTS) + +OBJ = $(SRC:%.cpp=%.o) + +libbmp180.a: $(OBJ) + $(AR) $@ $(OBJ) + +%.o: %.cpp + $(CXX) -c $(CXXFLAGS) $< -o $@ + +clean: + rm -f $(SRC:%.cpp=%.o) diff --git a/contrib/Makefile b/contrib/Makefile index c0e6137..be93ef2 100644 --- a/contrib/Makefile +++ b/contrib/Makefile @@ -4,6 +4,7 @@ ## ## Copyright (C) 2013-2016 Christian Pointner ## 2013-2014 Othmar Gsenger +## 2016 Bernhard Tittelbach ## ## This file is part of spreadspace avr utils. ## @@ -23,8 +24,9 @@ LUFA_VERSION := 151115 FASTLED_VERSION := v3.1.0 +BMP180_VERSION := V_1.1.2 -all: download-lufa download-fastled update-pjon update-teensy-loader +all: download-lufa download-fastled update-pjon update-teensy-loader download-bmp180 download-lufa: LUFA-${LUFA_VERSION}.zip @@ -38,6 +40,12 @@ FastLED-${FASTLED_VERSION}.zip: wget "https://github.com/FastLED/FastLED/archive/${FASTLED_VERSION}.zip" -O "$@" unzip $@ +download-bmp180: BMP180-${BMP180_VERSION}.zip + +BMP180-${BMP180_VERSION}.zip: + wget "https://github.com/sparkfun/BMP180_Breakout_Arduino_Library/archive/${BMP180_VERSION}.zip" -O "$@" + unzip -j $@ -d BMP180-${BMP180_VERSION}/ \*/src/\* + .pjon.prepared: git clone https://github.com/gioblu/PJON.git touch $@ diff --git a/include.mk b/include.mk index 7e0758a..ead19b4 100644 --- a/include.mk +++ b/include.mk @@ -123,6 +123,29 @@ clean-fastled: @echo "****************************************************" +build-bmp180: libbmp180.a + +libbmp180.a: Makefile + @echo "" + @echo "****************************************************" + @echo "building external BMP180 lib ($(BMP180_PATH))" + @echo "" + make -f $(SPREADAVR_PATH)/bmp180.mk libbmp180.a + make -f $(SPREADAVR_PATH)/bmp180.mk clean + @echo "" + @echo "****************************************************" + +clean-bmp180: + @echo "" + @echo "****************************************************" + @echo "cleaning external FastLED lib ($(BMP180_PATH))" + @echo "" + make -f $(SPREADAVR_PATH)/bmp180.mk clean + rm -f libbmp180.a + @echo "" + @echo "****************************************************" + + build-pjon: libpjon.a libpjon.a: Makefile diff --git a/usb-bmp180/Makefile b/usb-bmp180/Makefile new file mode 100644 index 0000000..94f98bc --- /dev/null +++ b/usb-bmp180/Makefile @@ -0,0 +1,53 @@ +## +## spreadspace avr utils +## +## +## Copyright (C) 2013-2016 Christian Pointner +## 2016 Bernhard Tittelbach +## +## This file is part of spreadspace avr utils. +## +## spreadspace avr utils is free software: you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## any later version. +## +## spreadspace avr utils is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with spreadspace avr utils. If not, see . +## + +NAME := usb-bmp180 +BOARD_TYPE := teensy2 +CXX_OBJ := $(NAME).o +LIBS := util led lufa-descriptor-usbserial usbio +CXX_LIBS := arduino-stub +EXTERNAL_LIBS := lufa bmp180 +SPREADAVR_PATH := .. + +BMP180_PATH := $(SPREADAVR_PATH)/contrib/BMP180-V_1.1.2 +BMP180_OPTS := + +LUFA_PATH := $(SPREADAVR_PATH)/contrib/lufa-LUFA-151115 +LUFA_OPTS = -D USB_DEVICE_ONLY +LUFA_OPTS += -D DEVICE_STATE_AS_GPIOR=0 +LUFA_OPTS += -D ORDERED_EP_CONFIG +LUFA_OPTS += -D FIXED_CONTROL_ENDPOINT_SIZE=8 +LUFA_OPTS += -D FIXED_NUM_CONFIGURATIONS=1 +LUFA_OPTS += -D USE_FLASH_DESCRIPTORS +LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)" +LUFA_OPTS += -D INTERRUPT_CONTROL_ENDPOINT + +LUFA_OPTS += -D USB_MANUFACTURER="L\"xro\"" +LUFA_OPTS += -D USB_PRODUCT="L\"spreadspace usb-bmp180 example\"" + +LUFA_COMPONENTS := USB USBCLASS + +include $(SPREADAVR_PATH)/include.mk + +RESET_FUNC := $(SPREADAVR_PATH)/tools/reset_lufa_cdc +RESET_PARAM := '!' diff --git a/usb-bmp180/usb-bmp180.c b/usb-bmp180/usb-bmp180.c new file mode 100644 index 0000000..dabca95 --- /dev/null +++ b/usb-bmp180/usb-bmp180.c @@ -0,0 +1,162 @@ +/* + * spreadspace avr utils - usb-bmp180 example + * + * + * Copyright (C) 2016 Bernhard Tittelbach + * basically this is refactored and enhanced code from: + * https://github.com/sparkfun/BMP180_Breakout_Arduino_Library + * Please buy the sparkfun people Beer when you see them!!!! + * + * This file is part of spreadspace avr utils. + * + * spreadspace avr utils is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * spreadspace avr utils is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with spreadspace avr utils. If not, see . + */ + +#include +#include +#include +#include +#include + +#include "util.h" +#include "led.h" +#include "usbio.h" + +#include "Arduino.h" +#include "SFE_BMP180.h" + + +SFE_BMP180 pressure; + +#define ALTITUDE 353.0 // Altitude of Graz in Austria + + +int main(void) +{ + MCUSR &= ~(1 << WDRF); + wdt_disable(); + + cpu_init(); + led_init(); + usbio_init(); + sei(); + + arduino_init(); + + if (pressure.begin()) + printf("BMP180 init success"); + else + { + // Oops, something went wrong, this is usually a connection problem, + // see the comments at the top of this sketch for the proper connections. + + printf("BMP180 init fail\n\n"); + while(1); // Pause forever. + } + + for(;;) { + usbio_task(); + + char status; + double T,P,p0,a; + + // Loop here getting pressure readings every 10 seconds. + + // If you want sea-level-compensated pressure, as used in weather reports, + // you will need to know the altitude at which your measurements are taken. + // We're using a constant called ALTITUDE in this sketch: + + printf("\nprovided altitude: "); + printf(ALTITUDE,0); + printf(" meters, "); + printf(ALTITUDE*3.28084,0); + printf(" feet\n"); + + // If you want to measure altitude, and not pressure, you will instead need + // to provide a known baseline pressure. This is shown at the end of the sketch. + + // You must first get a temperature measurement to perform a pressure reading. + + // Start a temperature measurement: + // If request is successful, the number of ms to wait is returned. + // If request is unsuccessful, 0 is returned. + + status = pressure.startTemperature(); + if (status != 0) + { + // Wait for the measurement to complete: + _delay_ms(status); + + // Retrieve the completed temperature measurement: + // Note that the measurement is stored in the variable T. + // Function returns 1 if successful, 0 if failure. + + status = pressure.getTemperature(T); + if (status != 0) + { + // Print out the measurement: + printf("temperature: %02d degC\n",T); + + // Start a pressure measurement: + // The parameter is the oversampling setting, from 0 to 3 (highest res, longest wait). + // If request is successful, the number of ms to wait is returned. + // If request is unsuccessful, 0 is returned. + + status = pressure.startPressure(3); + if (status != 0) + { + // Wait for the measurement to complete: + _delay_ms(status); + + // Retrieve the completed pressure measurement: + // Note that the measurement is stored in the variable P. + // Note also that the function requires the previous temperature measurement (T). + // (If temperature is stable, you can do one temperature measurement for a number of pressure measurements.) + // Function returns 1 if successful, 0 if failure. + + status = pressure.getPressure(P,T); + if (status != 0) + { + // Print out the measurement: + printf("absolute pressure: %02d mb, %02d inHg\n", P, P*0.0295333727); + + // The pressure sensor returns abolute pressure, which varies with altitude. + // To remove the effects of altitude, use the sealevel function and your current altitude. + // This number is commonly used in weather reports. + // Parameters: P = absolute pressure in mb, ALTITUDE = current altitude in m. + // Result: p0 = sea-level compensated pressure in mb + + p0 = pressure.sealevel(P,ALTITUDE); // we're at 1655 meters (Boulder, CO) + printf("relative (sea-level) pressure: %02d mb, %0d2 inHg", p0, p0*0.0295333727); + + // On the other hand, if you want to determine your altitude from the pressure reading, + // use the altitude function along with a baseline pressure (sea-level or other). + // Parameters: P = absolute pressure in mb, p0 = baseline pressure in mb. + // Result: a = altitude in m. + + a = pressure.altitude(P,p0); + printf("computed altitude: %dm\n",a); + } + else printf("error retrieving pressure measurement\n"); + } + else printf("error starting pressure measurement\n"); + } + else printf("error retrieving temperature measurement\n"); + } + else printf("error starting temperature measurement\n"); + + _delay_ms(5000); // Pause for 5 seconds. + + } +} -- cgit v1.2.3