Skip to content

Commit

Permalink
add BM1383AGLV, BM1422AGMV, KX122, MK71251-02
Browse files Browse the repository at this point in the history
  • Loading branch information
KokiOkada-Rohm committed Jul 16, 2018
1 parent 2951f2a commit 8fdbe96
Show file tree
Hide file tree
Showing 13 changed files with 1,049 additions and 0 deletions.
143 changes: 143 additions & 0 deletions BM1383AGLV/BM1383AGLV.cpp
@@ -0,0 +1,143 @@
/*****************************************************************************
BM1383AGLV.cpp
Copyright (c) 2018 ROHM Co.,Ltd.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
******************************************************************************/
//#include <avr/pgmspace.h>
#include <Wire.h>
#include "arduino.h"
#include "BM1383AGLV.h"

BM1383AGLV::BM1383AGLV(void)
{

}

byte BM1383AGLV::init(void)
{
byte rc;
unsigned char reg;

rc = read(BM1383AGLV_ID, &reg, sizeof(reg));
if (rc != 0) {
Serial.println("Can't access BM1383AGLV");
return (rc);
}
Serial.println("BM1383GL ID Register Value = 0x");
Serial.println(reg, HEX);

if (reg != BM1383AGLV_ID_VAL) {
Serial.println("Can't find BM1383AGLV");
return (rc);
}

reg = BM1383AGLV_POWER_DOWN_VAL;
rc = write(BM1383AGLV_POWER_DOWN, &reg, sizeof(reg));
if (rc != 0) {
Serial.println("Can't write BM1383AGLV POWER_DOWN register");
return (rc);
}

delay(1);

reg = BM1383AGLV_RESET_VAL;
rc = write(BM1383AGLV_RESET, &reg, sizeof(reg));
if (rc != 0) {
Serial.println("Can't write BM1383AGLV SLEEP register");
return (rc);
}

reg = BM1383AGLV_MODE_CONTROL_VAL;
rc = write(BM1383AGLV_MODE_CONTROL, &reg, sizeof(reg));
if (rc != 0) {
Serial.println("Can't write BM1383AGLV MODE_CONTROL register");
return (rc);
}

}

byte BM1383AGLV::get_rawval(unsigned char *data)
{
byte rc;

rc = read(BM1383AGLV_PRESSURE_MSB, data, 3);
if (rc != 0) {
Serial.println("Can't get BM1383AGLV PRESS value");
}

return (rc);
}

byte BM1383AGLV::get_val( float *press)
{
byte rc;
unsigned char val[3];
unsigned long rawpress;

rc = get_rawval(val);
if (rc != 0) {
return (rc);
}

rawpress = (((unsigned long)val[0] << 16) | ((unsigned long)val[1] << 8) | val[2]&0xFC) >> 2;

if (rawpress == 0) {
return (-1);
}

*press = (float)rawpress / 2048;

return (rc);
}

byte BM1383AGLV::write(unsigned char memory_address, unsigned char *data, unsigned char size)
{
byte rc;
unsigned int cnt;

Wire.beginTransmission(BM1383AGLV_DEVICE_ADDRESS);
Wire.write(memory_address);
Wire.write(data, size);
rc = Wire.endTransmission();
return (rc);
}

byte BM1383AGLV::read(unsigned char memory_address, unsigned char *data, int size)
{
byte rc;
unsigned char cnt;

Wire.beginTransmission(BM1383AGLV_DEVICE_ADDRESS);
Wire.write(memory_address);
rc = Wire.endTransmission(false);
if (rc != 0) {
return (rc);
}

Wire.requestFrom((int)BM1383AGLV_DEVICE_ADDRESS, (int)size, (int)true);
cnt = 0;
while(Wire.available()) {
data[cnt] = Wire.read();
cnt++;
}

return (rc);
}
58 changes: 58 additions & 0 deletions BM1383AGLV/BM1383AGLV.h
@@ -0,0 +1,58 @@
/*****************************************************************************
BM1383AGLV.h
Copyright (c) 2018 ROHM Co.,Ltd.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
******************************************************************************/
#ifndef _BM1383AGLV_H_
#define _BM1383AGLV_H_

#define BM1383AGLV_DEVICE_ADDRESS (0x5D) // 7bit Addrss
#define BM1383AGLV_ID_VAL (0x32)

#define BM1383AGLV_ID (0x10)
#define BM1383AGLV_POWER_DOWN (0x12)
#define BM1383AGLV_RESET (0x13)
#define BM1383AGLV_MODE_CONTROL (0x14)
#define BM1383AGLV_PRESSURE_MSB (0x1C)

#define BM1383AGLV_POWER_DOWN_PWR_DOWN (1 << 0)
#define BM1383AGLV_RESET_RSTB (1 << 0)
#define BM1383AGLV_MODE_CONTROL_AVE_NUM64 (6 << 5)
#define BM1383AGLV_MODE_CONTROL_T_AVE (1 << 3)
#define BM1383AGLV_MODE_CONTORL_MODE_200MS (4 << 0)


#define BM1383AGLV_POWER_DOWN_VAL (BM1383AGLV_POWER_DOWN_PWR_DOWN)
#define BM1383AGLV_RESET_VAL (BM1383AGLV_RESET_RSTB)
#define BM1383AGLV_MODE_CONTROL_VAL (BM1383AGLV_MODE_CONTROL_AVE_NUM64 | BM1383AGLV_MODE_CONTROL_T_AVE |BM1383AGLV_MODE_CONTORL_MODE_200MS)

class BM1383AGLV
{
public:
BM1383AGLV(void);
byte init(void) ;
byte get_rawval(unsigned char *data);
byte get_val(float *press);
byte write(unsigned char memory_address, unsigned char *data, unsigned char size);
byte read(unsigned char memory_address, unsigned char *data, int size);
};

#endif // _BM1383AGLV_H_
54 changes: 54 additions & 0 deletions BM1383AGLV/examples/BM1383AGLV/BM1383AGLV.ino
@@ -0,0 +1,54 @@
/*****************************************************************************
BM1383GLV.ino
Copyright (c) 2018 ROHM Co.,Ltd.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
******************************************************************************/
#include <Wire.h>
#include <BM1383AGLV.h>

BM1383AGLV bm1383;

void setup() {
byte rc;

Serial.begin(115200);
while (!Serial);

Wire.begin();

rc = bm1383.init();
}

void loop() {
byte rc;
float press;

rc = bm1383.get_val(&press);
if (rc == 0) {
Serial.write("BM1383AGLV (PRESS) = ");
Serial.print(press);
Serial.println(" [hPa]");
Serial.println();
}

delay(500);

}

0 comments on commit 8fdbe96

Please sign in to comment.