I am using an Arduino Uno with a BMP183 barometric pressure/altitude sensor, and a Thermistor.
The output of the devices will be displayed on a 20x4 LCD. The default MOSI, MISO, SCK, and SS pins (11, 12, 13, 10 on the Arduino) are being used by the LCD, and I want to use any remaining pins on the Arduino for the BMP183 using SPI. I am having trouble writing the code correctly. I wanted to use pins 2-5 for the BMP183 using SPI.
Currently the Thermistor integration works fine, but the BMP183 is not showing reading on the LCD. I presume that I don't have the setup correct for the BMP183. Any help or feedback would be greatly appreciated.
This is what I have so far:
// which analog pin to connect
#define THERMISTORPIN A0
// resistance at 25 degrees C
#define THERMISTORNOMINAL 10000
// temp. for nominal resistance (almost always 25 C)
#define TEMPERATURENOMINAL 25
// how many samples to take and average, more takes longer
// but is more 'smooth'
#define NUMSAMPLES 5
// The beta coefficient of the thermistor (usually 3000-4000)
#define BCOEFFICIENT 3950
// the value of the 'other' resistor
#define SERIESRESISTOR 10000
#define ANEMOMETER A1
#include <LiquidCrystal.h>
#include <SPI.h>
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE3);
SPI.setClockDivider(SPI_CLOCK_DIV4);
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP183.h>
#define BMP183_CLK 5
#define BMP183_SDO 4 // AKA MISO
#define BMP183_SDI 3 // AKA MOSI
#define BMP183_CS 2
Adafruit_BMP183 bmp = Adafruit_BMP183(BMP183_CLK, BMP183_SDO, BMP183_SDI, BMP183_CS);
// BS E D4 D5 D6 D7
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
//Thermistor-------------------------------------------------------------
int samples[NUMSAMPLES];
void setup(void) {
Serial.begin(9600);
analogReference(EXTERNAL);
lcd.begin(20, 4);
bmp.begin();
}
void loop(void) {
uint8_t i;
float average;
// take N samples in a row, with a slight delay
for (i=0; i< NUMSAMPLES; i++) {
samples = analogRead(THERMISTORPIN);
-
delay(10);*
-
}*
-
// average all the samples out*
-
average = 0;*
-
for (i=0; i< NUMSAMPLES; i++) {*
_ average += samples*;_
_ }_
_ average /= NUMSAMPLES;*_
* Serial.print("Average analog reading ");*
* Serial.println(average);*
* // convert the value to resistance*
* average = 1023 / average - 1;*
* average = SERIESRESISTOR / average;*
* Serial.print("Thermistor resistance ");*
* Serial.println(average);*
* float steinhart;*
* steinhart = average / THERMISTORNOMINAL; // (R/Ro)*
* steinhart = log(steinhart); // ln(R/Ro)*
_ steinhart /= BCOEFFICIENT; // 1/B * ln(R/Ro)
* steinhart += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To)*
* steinhart = 1.0 / steinhart; // Invert*
* steinhart -= 273.15; // convert to C*
steinhart = steinhart*9.0/5.0 + 32.0; // convert to F_
* lcd.setCursor(0, 0);*
* lcd.print("Temp: ");*
* lcd.print(steinhart);*
* lcd.print(" F");*
* //BMP183-----------------------------------------------------------------------------*
* lcd.setCursor(0, 1);*
* lcd.print("Pressure: ");*
* lcd.print( bmp.getPressure() );*
* lcd.print(" Pa");*
* //lcd.setCursor(0, 2);*
* //lcd.print("Temp: ");*
* //lcd.print( bmp.getTemperature() );*
* //lcd.print(" C");*
* float seaLevelPressure = 1013.25;*
* lcd.setCursor(0, 2);*
* lcd.print("Altitude: ");*
* lcd.print(bmp.getAltitude(seaLevelPressure));*
* lcd.print(" m");*
* delay(1000);*
}