Skip to content

Commit 17a45b2

Browse files
committed
add support for BMA150
1 parent a91a10f commit 17a45b2

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

Ports.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,15 @@ const int* GravityPlug::getAxes() {
641641
return data.w;
642642
}
643643

644+
char GravityPlug::temperature() {
645+
send();
646+
write(0x08);
647+
receive();
648+
char temp = read(1) - 60;
649+
stop();
650+
return temp;
651+
}
652+
644653
/** Select the channel on the multiplexer.
645654
* @param channel A number between 0..15.
646655
*/

Ports.h

+3
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,9 @@ class GravityPlug : public DeviceI2C {
535535
/// Get accelleration data from GravityPlug.
536536
/// @return An array with 3 integers. (x,y,z) respectively.
537537
const int* getAxes();
538+
/// Read out the temperature (only for BMA150, not the older BMA020)
539+
/// @return temp, in half deg C steps, from -30C to +50C (i.e. times 2)
540+
char temperature();
538541
};
539542

540543
/// Interface for the Input Plug - see http://jeelabs.org/ip

examples/Ports/gravity_demo/gravity_demo.ino

+24-6
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,42 @@ PortI2C myBus (1);
88
GravityPlug sensor (myBus);
99
MilliTimer measureTimer;
1010

11+
struct {
12+
int axes[3];
13+
int temp;
14+
} payload;
15+
1116
void setup () {
1217
Serial.begin(57600);
1318
Serial.println("\n[gravity_demo]");
14-
rf12_initialize(7, RF12_868MHZ, 5);
19+
20+
if (sensor.isPresent()) {
21+
Serial.print("sensor version ");
22+
sensor.send();
23+
sensor.write(0x01);
24+
sensor.receive();
25+
Serial.println(sensor.read(1), HEX);
26+
sensor.stop();
27+
}
28+
29+
rf12_initialize(7, RF12_868MHZ, 42);
1530
sensor.begin();
1631
}
1732

1833
void loop () {
1934
if (measureTimer.poll(1000)) {
20-
const int* p = sensor.getAxes();
35+
memcpy(payload.axes, sensor.getAxes(), sizeof payload.axes);
36+
payload.temp = sensor.temperature();
2137

22-
rf12_sendNow(0, p, 3 * sizeof *p);
38+
rf12_sendNow(0, &payload, sizeof payload);
2339

2440
Serial.print("GRAV ");
25-
Serial.print(p[0]);
41+
Serial.print(payload.axes[0]);
42+
Serial.print(' ');
43+
Serial.print(payload.axes[1]);
2644
Serial.print(' ');
27-
Serial.print(p[1]);
45+
Serial.print(payload.axes[2]);
2846
Serial.print(' ');
29-
Serial.println(p[2]);
47+
Serial.println(payload.temp);
3048
}
3149
}

0 commit comments

Comments
 (0)