add second accelerometer for comparison
Some checks failed
Some checks failed
This commit is contained in:
@ -84,7 +84,7 @@ int main(void)
|
||||
|
||||
cfb_set_kerning(dev, 3);
|
||||
|
||||
const struct device *ina, *bmp, *bmx, *hdc;
|
||||
const struct device *ina, *bmp, *bmx, *lis, *hdc;
|
||||
|
||||
ina = DEVICE_DT_GET(DT_NODELABEL(ina231));
|
||||
if (!device_is_ready(ina))
|
||||
@ -108,6 +108,14 @@ int main(void)
|
||||
}
|
||||
LOG_INF("Initialized %s\n", bmx->name);
|
||||
|
||||
lis = DEVICE_DT_GET(DT_NODELABEL(lis2dh));
|
||||
if (!device_is_ready(lis))
|
||||
{
|
||||
LOG_ERR("Device %s not ready\n", lis->name);
|
||||
return 0;
|
||||
}
|
||||
LOG_INF("Initialized %s\n", lis->name);
|
||||
|
||||
// hdc = DEVICE_DT_GET(DT_NODELABEL(hdc1080));
|
||||
// if (!device_is_ready(dev))
|
||||
// {
|
||||
@ -118,12 +126,13 @@ int main(void)
|
||||
while (1)
|
||||
{
|
||||
int ret;
|
||||
struct sensor_value voltage, current, pressure, temperature, accel_x, humidity;
|
||||
struct sensor_value voltage, current, pressure, temperature, accel_z, accel_z_ref, humidity;
|
||||
char str_v[15] = {0};
|
||||
char str_i[15] = {0};
|
||||
char str_p[16] = {0};
|
||||
char str_t[16] = {0};
|
||||
char str_ax[16] = {0};
|
||||
char str_az[16] = {0};
|
||||
char str_az_ref[16] = {0};
|
||||
char str_h[16] = {0};
|
||||
|
||||
ret = sensor_sample_fetch(ina);
|
||||
@ -176,7 +185,20 @@ int main(void)
|
||||
LOG_ERR("Could not get temperature (%d)", ret);
|
||||
return 0;
|
||||
}
|
||||
ret = sensor_channel_get(bmx, SENSOR_CHAN_ACCEL_X, &accel_x);
|
||||
ret = sensor_channel_get(bmx, SENSOR_CHAN_ACCEL_Z, &accel_z);
|
||||
if (ret < 0)
|
||||
{
|
||||
LOG_ERR("Could not get acceleration (%d)", ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = sensor_sample_fetch(lis);
|
||||
if (ret < 0)
|
||||
{
|
||||
LOG_ERR("Could not fetch sample (%d)", ret);
|
||||
return 0;
|
||||
}
|
||||
ret = sensor_channel_get(lis, SENSOR_CHAN_ACCEL_Z, &accel_z_ref);
|
||||
if (ret < 0)
|
||||
{
|
||||
LOG_ERR("Could not get acceleration (%d)", ret);
|
||||
@ -200,7 +222,8 @@ int main(void)
|
||||
sprintf(str_i, "I:%01d.%06d", current.val1, current.val2);
|
||||
sprintf(str_p, "P:%03d.%04d", pressure.val1, pressure.val2 / 100);
|
||||
sprintf(str_t, "T:%03d.%04d", temperature.val1, temperature.val2 / 100);
|
||||
sprintf(str_ax, "X:%03d.%04d", accel_x.val1, accel_x.val2 / 100);
|
||||
sprintf(str_az, "Z:%03d.%04d", accel_z.val1, accel_z.val2 / 100);
|
||||
sprintf(str_az_ref, "Z:%03d.%04d", accel_z_ref.val1, accel_z_ref.val2 / 100);
|
||||
sprintf(str_h, "H:%05d.%06d", humidity.val1, humidity.val2);
|
||||
|
||||
// printf("%s\t%s\t%s\t%s\n", str_v, str_i, str_p, str_t);
|
||||
@ -216,12 +239,12 @@ int main(void)
|
||||
printf("Failed to print a string\n");
|
||||
continue;
|
||||
}
|
||||
if (cfb_print(dev, str_ax, 0, 16 * 2))
|
||||
if (cfb_print(dev, str_az, 0, 16 * 2))
|
||||
{
|
||||
printf("Failed to print a string\n");
|
||||
continue;
|
||||
}
|
||||
if (cfb_print(dev, str_t, 0, 16 * 3))
|
||||
if (cfb_print(dev, str_az_ref, 0, 16 * 3))
|
||||
{
|
||||
printf("Failed to print a string\n");
|
||||
continue;
|
||||
|
@ -173,6 +173,12 @@
|
||||
compatible = "bosch,bmx055";
|
||||
reg = <0x18>;
|
||||
};
|
||||
|
||||
lis2dh: lis2dh@19 {
|
||||
// This is built into the DWM1001 module
|
||||
compatible = "st,lis2dh";
|
||||
reg = <0x19>;
|
||||
};
|
||||
};
|
||||
|
||||
&spi1 {
|
||||
|
@ -154,19 +154,19 @@ static int bmx055_channel_get(const struct device *dev,
|
||||
val->val2 = 0; // TODO: don't throw out LSB
|
||||
break;
|
||||
case SENSOR_CHAN_ACCEL_X:
|
||||
case SENSOR_CHAN_ACCEL_Y:
|
||||
return -ENOTSUP;
|
||||
case SENSOR_CHAN_ACCEL_Z:
|
||||
// For now assume 2g since that's the default value
|
||||
// 2g 0.98mg/LSB
|
||||
// 4g 1.95mg/LSB
|
||||
// 8g 3.91mg/LSB
|
||||
// 16g 7.81mg/LSB
|
||||
// 1 g = 9.80665 m/s^2
|
||||
float accel = data->accel_x * 0.00098 * 9.80665; // to gees, to m/s^2
|
||||
float accel = data->accel_z * 0.00098 * 9.80665; // to gees, to m/s^2
|
||||
val->val1 = accel;
|
||||
val->val2 = (accel - val->val1) * 1000000;
|
||||
break;
|
||||
case SENSOR_CHAN_ACCEL_Y:
|
||||
case SENSOR_CHAN_ACCEL_Z:
|
||||
return -ENOTSUP;
|
||||
case SENSOR_CHAN_GYRO_X:
|
||||
case SENSOR_CHAN_GYRO_Y:
|
||||
case SENSOR_CHAN_GYRO_Z:
|
||||
|
Reference in New Issue
Block a user