fab-lab.eu
Published

The SENSable THING

The (most likely) smallest Arduino-compatible sewable pico-Platinchen #SENSableTHING

IntermediateFull instructions provided7,786
The SENSable THING

Things used in this project

Hardware components

pico-Platinchen
×1
NeoPixel Ring - 12 x WS2812
×1
LilyPad Coin Cell Battery Holder - Switched
×1

Software apps and online services

Fusion
Autodesk Fusion

Story

Read more

Custom parts and enclosures

SENSable Thing aka The Ring

Autodesk Fusion 360

the base .STL

part 1 of the ring

the ring .STL

part 2 of the ring

Code

SENSable

C/C++
Requires the Bosch Sensortec NAxisMotion library provided as part of the Arduino IDE 1.0.7 and Adafruit Neopixel library you do need to download from the Adafruit github.
#include "NAxisMotion.h"        //Contains the bridge code between the API and the Arduino Environment
#include <Wire.h>

// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
// released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library
#include <Adafruit_NeoPixel.h>

// Which pin on the Arduino is connected to the NeoPixels?
#define PIN            2

// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS      12

// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
// example for more information on possible values.
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);


NAxisMotion mySensor;         //Object that for the sensor 
unsigned long lastStreamTime = 0;     //To store the last streamed time stamp
const int streamPeriod = 20;          //To stream at 50Hz without using additional timers (time period(ms) =1000/frequency(Hz))

int north = 0;
int north_old = 0;
  
void setup() //This code is executed once
{    
  //Peripheral Initialization
  Serial.begin(115200);           //Initialize the Serial Port to view information on the Serial Monitor
  I2C.begin();                    //Initialize I2C communication to the let the library communicate with the sensor.
  //Sensor Initialization
  mySensor.initSensor();          //The I2C Address can be changed here inside this function in the library
  mySensor.setOperationMode(OPERATION_MODE_NDOF);   //Can be configured to other operation modes as desired
  mySensor.setUpdateMode(MANUAL);	//The default is AUTO. Changing to MANUAL requires calling the relevant update functions prior to calling the read functions
  //Setting to MANUAL requires fewer reads to the sensor  
  
//  pixels.begin(); // This initializes the NeoPixel library.

  strip.begin();
  strip.show(); // Initialize all pixels to 'off'

  init(50);

}

void loop() //This code is looped forever
{
  if ((millis() - lastStreamTime) >= streamPeriod)
  {
    lastStreamTime = millis();    
    mySensor.updateEuler();        //Update the Euler data into the structure of the object
    mySensor.updateCalibStatus();  //Update the Calibration Status

    Serial.print("Time: ");
    Serial.print(lastStreamTime);
    Serial.print("ms ");

    Serial.print(" H: ");
    Serial.print(mySensor.readEulerHeading()); //Heading data
    Serial.print("deg ");

    Serial.print(" R: ");
    Serial.print(mySensor.readEulerRoll()); //Roll data
    Serial.print("deg");

    Serial.print(" P: ");
    Serial.print(mySensor.readEulerPitch()); //Pitch data
    Serial.print("deg ");
    
    Serial.print(" A: ");
    Serial.print(mySensor.readAccelCalibStatus());  //Accelerometer Calibration Status (0 - 3)
	
    Serial.print(" M: ");
    Serial.print(mySensor.readMagCalibStatus());    //Magnetometer Calibration Status (0 - 3)
	
    Serial.print(" G: ");
    Serial.print(mySensor.readGyroCalibStatus());   //Gyroscope Calibration Status (0 - 3)
	
    Serial.print(" S: ");
    Serial.print(mySensor.readSystemCalibStatus());   //System Calibration Status (0 - 3)

    Serial.println();
    

    north = (360-mySensor.readEulerHeading())/30;
    
    
    if (mySensor.readEulerPitch() > -90) {
   
     
      
    if (north == 0) {strip.setPixelColor(9, 55, 0, 0);strip.show(); delay(100); strip.setPixelColor(9, 0, 0, 0); strip.show();}
    if (north == 1) {strip.setPixelColor(10, 55, 0, 0);strip.show(); delay(100); strip.setPixelColor(10, 0, 0, 0); strip.show();}
    if (north == 2) {strip.setPixelColor(11, 55, 0, 0);strip.show(); delay(100); strip.setPixelColor(11, 0, 0, 0); strip.show();}
    if (north == 3) {strip.setPixelColor(0, 55, 0, 0);strip.show(); delay(100); strip.setPixelColor(0, 0, 0, 0); strip.show();}
    if (north == 4) {strip.setPixelColor(1, 55, 0, 0);strip.show(); delay(100); strip.setPixelColor(1, 0, 0, 0); strip.show();}
    if (north == 5) {strip.setPixelColor(2, 55, 0, 0);strip.show(); delay(100); strip.setPixelColor(2, 0, 0, 0); strip.show();}
    if (north == 6) {strip.setPixelColor(3, 55, 0, 0);strip.show(); delay(100); strip.setPixelColor(3, 0, 0, 0); strip.show();}
    if (north == 7) {strip.setPixelColor(4, 55, 0, 0);strip.show(); delay(100); strip.setPixelColor(4, 0, 0, 0); strip.show();}
    if (north == 8) {strip.setPixelColor(5, 55, 0, 0);strip.show(); delay(100); strip.setPixelColor(5, 0, 0, 0); strip.show();}
    if (north == 9) {strip.setPixelColor(6, 55, 0, 0);strip.show(); delay(100); strip.setPixelColor(6, 0, 0, 0); strip.show();}
    if (north == 10) {strip.setPixelColor(7, 55, 0, 0);strip.show(); delay(100); strip.setPixelColor(7, 0, 0, 0); strip.show();}
    if (north == 11) {strip.setPixelColor(8, 55, 0, 0);strip.show(); delay(100); strip.setPixelColor(8, 0, 0, 0); strip.show();}
    
    
   
      
    
      
    //strip.setPixelColor(north, 255, 0, 0); // Moderately bright green color.
    //strip.show();
    //strip.setPixelColor(north-1, 0, 80, 0); // Moderately bright green color.
    //strip.setPixelColor(north+1, 0, 80, 0); // Moderately bright green color.
    strip.show();
    } else
    {
      strip.setPixelColor(north, 0, 0, 0); // Moderately bright green color.
      strip.show();
    }
   
   
   if (north != north_old)
   {
   delay(10); 
   strip.setPixelColor(north-1, 0, 0, 0); // Moderately bright green color.
   //strip.setPixelColor(north, 0, 0, 0); // Moderately bright green color.
   strip.setPixelColor(north+1, 0, 0, 0); // Moderately bright green color.
   strip.show();
   }
    
    north_old = north;
   
   if (north == 0)
   {
    init(5);
    rainbow(10);
    init(5);
   }
   
    
  }
}



void init(uint8_t wait) {
  uint16_t i;

    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, 0, 0, 255);
      strip.show();
      delay(wait);
    }
    
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, 0, 0, 0);
      strip.show();
      delay(wait);
    }
    
}

void rainbow(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256; j++) {
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i+j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85) {
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else if(WheelPos < 170) {
    WheelPos -= 85;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  } else {
   WheelPos -= 170;
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  }
}

Adafruit NeoPixel Library

Credits

fab-lab.eu

fab-lab.eu

22 projects • 276 followers
Maker!

Comments