In this build, we'll explore how to configure the CodeCell's onboard motion sensor to try and guess the personal activate you're doing, and display it on an OLED screen. Its meant to track different states such as walking, running, cycling, climbing stairs and driving!
The CodeCell's motion sensor is capable of categorizing various personal activities based on movement patterns. Based on these patterns the BNO085 sensor will try to guess which activity is being performed. These activities include walking, running, cycling, driving and more.
The CodeCell library makes it easy for you to directly read the activity without any complex code.
In this example, the CodeCell continuously monitors the BNO085's personal activity guess. The activity with the highest chance is then displayed on an OLED screen using the Adafruit SSD1306 library. This setup is ideal for creating wearable activity monitors or fitness trackers that provide real-time feedback on physical activities.
Note that some activities might take between 10-30 seconds to start getting recognized, as it will mainly depend on orientation of the CodeCell and where it is mounted.
Below is the example code to get you started. Make sure your CodeCell is connected via USB-C and your OLED display is wired correctly to the CodeCell’s lower side, using its ground, 3V3, and I2C pins (SDA and SCL).
Follow the comments in the code to understand each step.
#include <CodeCell.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
CodeCell myCodeCell;
/* Configure the OLED Display */
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C // Address of the OLED display
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
int read_timer = 0;
void setup() {
Serial.begin(115200); // Set Serial baud rate to 115200. Ensure Tools/USB_CDC_On_Boot is enabled if using Serial.
myCodeCell.Init(MOTION_ACTIVITY); // Initializes activity sensing.
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
}
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.display();
delay(2000);
}
void loop() {
if (myCodeCell.Run()) {
if (read_timer < 10) {
read_timer++;
} else {
// Update every 1 sec
read_timer = 0;
display.clearDisplay();
display.setCursor(32, 16);
display.print(F("Activity: "));
display.setCursor(32, 24);
switch (myCodeCell.Motion_ActivityRead()) {
case 1:
display.print("Driving");
break;
case 2:
display.print("Cycling");
break;
case 3:
case 6:
display.print("Walking");
break;
case 4:
display.print("Still");
break;
case 5:
display.print("Tilting");
break;
case 7:
display.print("Running");
break;
case 8:
display.print("Stairs");
break;
default:
display.print("Reading..");
break;
}
display.display();
}
}
}
This project demonstrates how to use the CodeCell’s motion sensor to monitor personal activities and display the results on an OLED screen. This basic setup provides a foundation for developing more advanced activity monitoring systems.
Experiment with the code and settings to create your own personalized wearable!
Be the first to know about new projects and get exciting deals!
© 2024 Microbots.