Skip to content

Commit 737ce34

Browse files
authored
Merge pull request #131 from Pi4J/bmeSpi_device_driver_updates
update BMESPI device for recent Driver updates. Basically remove the …
2 parents 113b4c3 + 2ee87a0 commit 737ce34

3 files changed

Lines changed: 10 additions & 46 deletions

File tree

pom.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,11 @@
110110
<artifactId>pi4j-plugin-gpiod</artifactId>
111111
<version>${pi4j.version}</version>
112112
</dependency>
113-
<!-- requires driver verification >
114-
<dependency>
113+
<dependency>
115114
<groupId>com.pi4j</groupId>
116115
<artifactId>pi4j-plugin-ffm</artifactId>
117116
<version>${pi4j.version}</version>
118117
</dependency>
119-
<-->
120118
<dependency>
121119
<groupId>com.pi4j</groupId>
122120
<artifactId>pi4j-plugin-linuxfs</artifactId>

src/main/java/com/pi4j/devices/bme280/BME280DeviceSPI.java

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
import com.pi4j.drivers.sensor.environment.bmx280.Bmx280Driver;
4141
import com.pi4j.drivers.sensor.environment.bmx280.Bmx280Driver.Measurement;
4242
import com.pi4j.drivers.sensor.environment.bmx280.Bmx280Driver.Model;
43-
import com.pi4j.io.gpio.digital.DigitalOutput;
44-
import com.pi4j.io.gpio.digital.DigitalState;
4543
import com.pi4j.io.spi.Spi;
4644
import com.pi4j.io.spi.SpiBus;
4745
import com.pi4j.io.spi.SpiMode;
@@ -81,7 +79,6 @@ public class BME280DeviceSPI {
8179

8280
private static final int chipSelect = 0;
8381
private static final SpiBus spiBus = SpiBus.BUS_0;
84-
private static DigitalOutput csGpio;
8582
private static Spi spi;
8683

8784
public static void main(String[] args) throws Exception {
@@ -91,31 +88,13 @@ public static void main(String[] args) throws Exception {
9188
// Initialize SPI
9289
console.println("Initializing the sensor via SPI");
9390

94-
String helpString = " parms: -csp chipSelectGPIO \n ";
91+
String helpString = " parms: NONE \n ";
9592
for (int i = 0; i < args.length; i++) {
9693
String o = args[i];
97-
if (o.contentEquals("-csp")) { // device address
98-
String a = args[i + 1];
99-
i++;
100-
csPin = Integer.parseInt(a);
101-
} else if (o.contentEquals("-h")) {
102-
console.println(helpString);
103-
System.exit(39);
104-
} else {
105-
console.println(" !!! Invalid Parm " + args);
106-
console.println(helpString);
107-
System.exit(42);
108-
}
94+
console.println(helpString);
95+
System.exit(39);
10996
}
11097

111-
var csGpioConfig = DigitalOutput.newConfigBuilder(pi4j)
112-
.id("CS_pin")
113-
.name("CS")
114-
.bcm(csPin)
115-
.shutdown(DigitalState.HIGH)
116-
.initial(DigitalState.HIGH);
117-
csGpio = pi4j.create(csGpioConfig);
118-
11998
var spiConfig = Spi.newConfigBuilder(pi4j)
12099
.id(SPI_PROVIDER_ID)
121100
.name(SPI_PROVIDER_NAME)
@@ -126,7 +105,7 @@ public static void main(String[] args) throws Exception {
126105
.build();
127106
spi = pi4j.create(spiConfig);
128107

129-
Bmx280Driver bmx280Driver = new Bmx280Driver(spi, csGpio);
108+
Bmx280Driver bmx280Driver = new Bmx280Driver(spi);
130109

131110
console.println("Device model detected: " + bmx280Driver.getModel());
132111

src/main/java/com/pi4j/devices/bmp280/README.md

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,25 @@ class documentation to understand its various logging options.
1515

1616
The I2C connection functions as written in the Phillips spec.
1717

18-
I2C connection path.
1918

19+
I2C
2020
1. ./mvnw clean package
2121
2. cd target/distribution
2222
3. sudo ./runBMP280I2C.sh
2323
Args if bus and or address must be set
2424
-b 0x01 -a 0x77
2525

26-
The SPI connection per the Datasheet supports MODE0 or MODE3. The spec shows reading a register consists of:
27-
28-
1. Chip select driven low
29-
2. Eight clocks pulses to write the register address via the Pi MOSI
30-
3. Multiple eight clock pulses for each byte of data returned thru the Pi MISO
31-
4. Chip select driven high
32-
33-
In either Mode0 or Mode3 the read data bytes are miss-read and the clock pulses are not signaled for the expected reads.
34-
The SPI open flags support configuration of writing a determined number of bytes before continuing the clock pulses
35-
for the expected read data . This however requires the BMP280 chip connect using the 3-wire configuration and
36-
the chips config register be modified. As most chips use 4-wire configuration I use 4-wire, and use a configurable
37-
GPIO as the CS (chip select)
38-
39-
SPI connection path.
26+
The SPI connection per the Datasheet supports MODE0 or MODE3.
4027

28+
SPI
4129
1. ./mvnw clean package
4230
2. cd target/distribution
4331
3. sudo ./runBMP280SPI.sh
4432

45-
Use of different bus or device address, use the applicable values in the following command.
46-
sudo ./runBMP280I2C.sh -b 0x01 -a 0x77
33+
4734

4835
Will create the BMP280 device to create a BMP280Device instance Call the various temperature and pressure methods
49-
defined in the interface. The device defaults to Pi Bus 1 and device address 0X77
36+
defined in the interface.
5037

5138
No parameters are required. However, if 'any' parameter value is to be supplied:
5239
parms: -b hex value bus -a hex value address -t trace

0 commit comments

Comments
 (0)