Johan Sebastian MaciasRAKwireless
Published © GPL3+

Send Your Motion Data From WisBlock to Edge Impulse

Collect the data from the accelerometer for your motion projects with the WisBlock and send it to Edge Impulse.

BeginnerProtip826
Send Your Motion Data From WisBlock to Edge Impulse

Things used in this project

Story

Read more

Code

Defines

C/C++
#define CONVERT_G_TO_MS2    9.80665f
#define FREQUENCY_HZ        50
#define INTERVAL_MS         (1000 / (FREQUENCY_HZ + 1))

void loop()

C/C++
void loop()
{
  lis3dh_get();
  delay((1000 / (50 + 1)));
}

void lis3dh_get()

C/C++
void lis3dh_get()
{

  float x, y, z;
  x = SensorTwo.readFloatAccelX();
  y = SensorTwo.readFloatAccelY();
  z = SensorTwo.readFloatAccelZ();
    
  Serial.print(x * CONVERT_G_TO_MS2);
  Serial.print(',');
  Serial.print(y * CONVERT_G_TO_MS2);
  Serial.print(',');
  Serial.println(z * CONVERT_G_TO_MS2);
  
}

Full code

C/C++
#include "SparkFunLIS3DH.h" //http://librarymanager/All#SparkFun-LIS3DH
#include <Wire.h>

#define CONVERT_G_TO_MS2    9.80665f
#define FREQUENCY_HZ        50
#define INTERVAL_MS         (1000 / (FREQUENCY_HZ + 1))

LIS3DH SensorTwo(I2C_MODE, 0x18);

void setup()
{
	// Setup usb
	Serial.begin(115200);
	while (!Serial);

	if (SensorTwo.begin() != 0)
	{
		Serial.println("Problem starting the sensor at 0x18.");
	}
	else
	{
		Serial.println("Sensor at 0x18 started.");
	}
	Serial.println("enter !");
}

void loop()
{
	lis3dh_get();
	delay(INTERVAL_MS);
}

void lis3dh_get()
{
	// read the sensor value
  float x, y, z;
  x = SensorTwo.readFloatAccelX() * CONVERT_G_TO_MS2;
  y = SensorTwo.readFloatAccelY() * CONVERT_G_TO_MS2;
  z = SensorTwo.readFloatAccelZ() * CONVERT_G_TO_MS2;

	Serial.print(x);
  Serial.print(',');
  Serial.print(y);
  Serial.print(',');
	Serial.println(z);
}

Credits

Johan Sebastian Macias

Johan Sebastian Macias

7 projects • 23 followers
Electronics Engineer helping to make IoT easy as a Developer Advocate @ RAKwireless (until January 13th, 2023).
RAKwireless

RAKwireless

27 projects • 53 followers
A pioneer in providing innovated and diverse LPWA connectivity solutions for IoT edge devices.

Comments