11/*
22 SCP1000 Barometric Pressure Sensor Display
3-
3+
44 Shows the output of a Barometric Pressure Sensor on a
55 Uses the SPI library. For details on the sensor, see:
66 http://www.sparkfun.com/commerce/product_info.php?products_id=8161
77 http://www.vti.fi/en/support/obsolete_products/pressure_sensors/
8-
8+
99 This sketch adapted from Nathan Seidle's SCP1000 example for PIC:
1010 http://www.sparkfun.com/datasheets/Sensors/SCP1000-Testing.zip
11-
11+
1212 Circuit:
1313 SCP1000 sensor attached to pins 6, 7, 10 - 13:
1414 DRDY: pin 6
1515 CSB: pin 7
1616 MOSI: pin 11
1717 MISO: pin 12
1818 SCK: pin 13
19-
19+
2020 created 31 July 2010
2121 modified 14 August 2010
2222 by Tom Igoe
@@ -33,7 +33,7 @@ cont byte READ = 0b00000000; // SCP1000's read command
3333const byte WRITE = 0b00000010 ; // SCP1000's write command
3434// pins used for the connection with the sensor
3535// the other you need are controlled by the SPI library):
36- const int dataReadyPin = 6 ;
36+ const int dataReadyPin = 6 ;
3737const int chipSelectPin = 7 ;
3838
3939void setup () {
@@ -70,13 +70,13 @@ void loop() {
7070
7171
7272 // Read the pressure data highest 3 bits:
73- byte pressure_data_high = readRegister (0x1F , 1 );
73+ byte pressure_data_high = readRegister (0x1F , 1 );
7474 pressure_data_high &= 0b00000111 ; // you only needs bits 2 to 0
7575
7676 // Read the pressure data lower 16 bits:
77- unsigned int pressure_data_low = readRegister (0x20 , 2 );
77+ unsigned int pressure_data_low = readRegister (0x20 , 2 );
7878 // combine the two parts into one 19-bit number:
79- long pressure = ((pressure_data_high << 16 ) | pressure_data_low)/ 4 ;
79+ long pressure = ((pressure_data_high << 16 ) | pressure_data_low) / 4 ;
8080
8181 // display the temperature:
8282 Serial.println (" \t Pressure [Pa]=" + String (pressure));
@@ -86,7 +86,7 @@ void loop() {
8686// Read from or write to register from the SCP1000:
8787unsigned int readRegister (byte thisRegister, int bytesToRead ) {
8888 byte inByte = 0 ; // incoming byte from the SPI
89- unsigned int result = 0 ; // result to return
89+ unsigned int result = 0 ; // result to return
9090
9191 // SCP1000 expects the register name in the upper 6 bits
9292 // of the byte. So shift the bits left by two bits:
@@ -95,25 +95,25 @@ unsigned int readRegister(byte thisRegister, int bytesToRead ) {
9595 dataToSend = thisRegister & READ;
9696
9797 // take the chip select low to select the device:
98- digitalWrite (chipSelectPin, LOW);
98+ digitalWrite (chipSelectPin, LOW);
9999 // send the device the register you want to read:
100- SPI.transfer (dataToSend);
100+ SPI.transfer (dataToSend);
101101 // send a value of 0 to read the first byte returned:
102- result = SPI.transfer (0x00 );
102+ result = SPI.transfer (0x00 );
103103 // decrement the number of bytes left to read:
104104 bytesToRead--;
105105 // if you still have another byte to read:
106106 if (bytesToRead > 0 ) {
107- // shift the first byte left, then get the second byte:
107+ // shift the first byte left, then get the second byte:
108108 result = result << 8 ;
109- inByte = SPI.transfer (0x00 );
109+ inByte = SPI.transfer (0x00 );
110110 // combine the byte you just got with the previous one:
111111 result = result | inByte;
112112 // decrement the number of bytes left to read:
113113 bytesToRead--;
114114 }
115115 // take the chip select high to de-select:
116- digitalWrite (chipSelectPin, HIGH);
116+ digitalWrite (chipSelectPin, HIGH);
117117 // return the result:
118118 return (result);
119119}
@@ -130,13 +130,13 @@ void writeRegister(byte thisRegister, byte thisValue) {
130130 dataToSend = thisRegister | WRITE;
131131
132132 // take the chip select low to select the device:
133- digitalWrite (chipSelectPin, LOW);
133+ digitalWrite (chipSelectPin, LOW);
134134
135135 SPI.transfer (dataToSend); // Send register location
136136 SPI.transfer (thisValue); // Send value to record into register
137137
138138 // take the chip select high to de-select:
139- digitalWrite (chipSelectPin, HIGH);
139+ digitalWrite (chipSelectPin, HIGH);
140140}
141141
142142
0 commit comments