このことには複雑なスタートアップがあると考えてフラストレーションを感じた後、私は別のチップを試すことにしました.以下は、温度をCで、圧力をmbarで取得します(SPIを使用)。
#include <SPI.h> //add arduino SPI library;
//list of all registers binary addresses;
byte REF_P_XL = 0B00001000;
byte REF_P_L = 0B00001001;
byte REF_P_H = 0B00001010;
byte WHO_AM_I = 0B00001111;
byte RES_CONF = 0B00010000;
byte CTRL_REG1 = 0B00100000;
byte CTRL_REG2 = 0B00100001;
byte CTRL_REG3 = 0B00100010;
byte INT_CFG_REG = 0B00100011;
byte INT_SOURCE_REG = 0B00100100;
byte THS_P_LOW_REG = 0B00100101;
byte THS_P_HIGH_REG = 0B00100110;
byte STATUS_REG = 0B00100111;
byte PRESS_POUT_XL_REH = 0B00101000;
byte PRESS_OUT_L = 0B00101001;
byte PRESS_OUT_H = 0B00101010;
byte TEMP_OUT_L = 0B00101011;
byte TEMP_OUT_H = 0B00101100;
byte AMP_CTRL = 0B00110000;
byte Read = 0B10000000;
byte Write = 0B00000000;
//chip select pin on arduino;
const int CS = 10;
/*
SPI.h sets these for us in arduino
const int SDI = 11;
const int SDO = 12;
const int SCL = 13;
*/
void setup() {
Serial.begin(9600);
//start the SPI library;
SPI.begin();
//initalize the chip select pins;
pinMode(CS, OUTPUT);
//activate borometer at 12.5Hz
WriteRegister(CTRL_REG1,0B11100000);
delay(100);
}
void loop() {
byte Temp_H = ReadRegister(TEMP_OUT_H);
byte Temp_L = ReadRegister(TEMP_OUT_L);
byte Pressure_H = ReadRegister(PRESS_OUT_H);
byte Pressure_L = ReadRegister(PRESS_OUT_L);
byte Pressure_XL = ReadRegister(PRESS_POUT_XL_REH);
int Temperature = Temp_H <<8 | Temp_L;
long int Pressurei = Pressure_H <<8 | Pressure_L;
long int Pressure = Pressurei <<8 | Pressure_XL;
Serial.print("Pressure_H: ");
Serial.println(Pressure_H, BIN);
Serial.print("Pressure_L: ");
Serial.println(Pressure_L, BIN);
Serial.print("Pressure_XL: ");
Serial.println(Pressure_XL, BIN);
Serial.print("Pressure: ");
Serial.println(Pressure/4096, DEC);
Serial.print("Temperature: ");
Serial.println(42.5 + (Temperature/480), DEC);
delay(1000);
}
byte ReadRegister(byte Address){
byte result = 0;
digitalWrite(CS, LOW);
SPI.transfer(Read | Address);
result = SPI.transfer(0x00);
/* Serial.print(Address, BIN);
Serial.print(" : ");
Serial.println(result, BIN); */
digitalWrite(CS, HIGH);
return(result);
}
void WriteRegister(byte Address, byte Value){
digitalWrite(CS, LOW);
SPI.transfer(Write | Address);
SPI.transfer(Value);
digitalWrite(CS, HIGH);
}