Alex GlowMoheeb Zara
Published © GPL3+

Prometheus Lamp

This little lightbulb turns on when you have a EUREKA moment! Ft. the new TinyCircuits accelerometer and NeoPixel-compatible LED.

IntermediateFull instructions provided1.5 hours2,178
Prometheus Lamp

Things used in this project

Hardware components

TinyLily Mini Processor
TinyCircuits TinyLily Mini Processor
×1
TinyCircuits TinyLily RGB LED
×1
TinyCircuits TinyLily Accelerometer
×1
Slide Switch
Slide Switch
×1
Glass lightbulb container
From the Neon Museum in Las Vegas!
×1
Coin Cell Battery CR2032
Coin Cell Battery CR2032
×1
Battery Holder, Lithium CR2032
Battery Holder, Lithium CR2032
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Code

TinyIdea.ino (final sketch)

Arduino
The final sketch: flickers low while upside-down; burns bright when held high!
/*
TinyDuino Accelerometer Demo
  
Updated 15 August 2016 to use the correct serial monitor interface for
TinyDuino or TinyScreen+
This example code is in the public domain.
http://www.tinycircuits.com
*/

#include <Wire.h>
#include "BMA250.h"
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif


#if defined(ARDUINO_ARCH_SAMD)
#define SerialMonitorInterface SerialUSB
#else
#define SerialMonitorInterface Serial
#endif

BMA250 accel;

#define PIN 3  // tinylily pwm pin 3
Adafruit_NeoPixel strip = Adafruit_NeoPixel(1, PIN, NEO_GRB + NEO_KHZ800);
int magni = 0;
int tude = 0;
int grn = 0;

void setup()
{
  SerialMonitorInterface.begin(9600);
  Wire.begin();
  accel.begin(BMA250_range_2g, BMA250_update_time_64ms); //This sets up the BMA250 accelerometer
  strip.begin();
  strip.show(); 
}

void loop()
{
  accel.read();//This function gets new data from the accelerometer
  SerialMonitorInterface.print("X = ");
  SerialMonitorInterface.print(accel.X);
  SerialMonitorInterface.print("  Y = ");
  SerialMonitorInterface.print(accel.Y);
  SerialMonitorInterface.print("  Z = ");
  SerialMonitorInterface.print(accel.Z);
//  SerialMonitorInterface.print("  Temperature(C) = ");
//  SerialMonitorInterface.println((accel.rawTemp*0.5)+24.0,1);
  delay(150);//We'll make sure we're over the 64ms update time set on the BMA250
  
// Find the absolute magnitude of the vector of motion (shake detect)
  magni = (sq(accel.X) + sq(accel.Y) + sq(accel.Z));
  tude = sqrt(magni);
  magni = map(tude,0,180,5,60);
  if (accel.X > 190) {
    magni = accel.X;
  }
  SerialMonitorInterface.print("  Brightness = ");
  SerialMonitorInterface.println(magni);
  colorWipe(strip.Color(magni, magni, 0), 10);
}

void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    delay(wait);
  }
}

BMA250.cpp

C/C++
C++ library file
#include "BMA250.h"
#include <inttypes.h>
#include "Arduino.h"
#include <Wire.h>

BMA250::BMA250()
{
}

void BMA250::begin(uint8_t range, uint8_t bw)
{
  //Setup the range measurement setting
  Wire.beginTransmission(BMA250_I2CADDR);
  Wire.write(0x0F); 
  Wire.write(range);
  Wire.endTransmission();
  //Setup the bandwidth
  Wire.beginTransmission(BMA250_I2CADDR);
  Wire.write(0x10);
  Wire.write(bw);
  Wire.endTransmission();
}


void BMA250::read()
{
  //Set register index
  Wire.beginTransmission(BMA250_I2CADDR);
  Wire.write(0x02);
  Wire.endTransmission();
  //Request seven data bytes
  Wire.requestFrom(BMA250_I2CADDR,7);
  //Receive acceleration measurements as 16 bit integers
  X = (int16_t)Wire.read();
  X |= (int16_t)Wire.read()<<8;
  Y = (int16_t)Wire.read();
  Y |= (int16_t)Wire.read()<<8;
  Z = (int16_t)Wire.read();
  Z |= (int16_t)Wire.read()<<8;
  //Only use the 10 significant bits
  X >>= 6; Y >>= 6; Z >>= 6;
  //Receive temperature measurement
  rawTemp = Wire.read();
}

BMA250.h

C Header File
Library header file
#ifndef BMA250_h
#define BMA250_h

#define BMA250_I2CADDR 0x18
#define BMA250_update_time_64ms 0x08
#define BMA250_update_time_32ms 0x09
#define BMA250_update_time_16ms 0x0A
#define BMA250_update_time_8ms 0x0B
#define BMA250_update_time_4ms 0x0C
#define BMA250_update_time_2ms 0x0D
#define BMA250_update_time_1ms 0x0E
#define BMA250_update_time_05ms 0xF
#define BMA250_range_2g 0x03
#define BMA250_range_4g 0x05
#define BMA250_range_8g 0x08
#define BMA250_range_16g 0x0C

#include <inttypes.h>

class BMA250 {
public:
BMA250();
void begin(uint8_t, uint8_t);
void read();
int16_t X,Y,Z,rawTemp;
};
#endif

TinyShield_Accel.ino

Arduino
Arduino sketch
/*
TinyDuino Accelerometer Demo
  
Updated 15 August 2016 to use the correct serial monitor interface for
TinyDuino or TinyScreen+
This example code is in the public domain.
http://www.tinycircuits.com
*/

#include <Wire.h>
#include "BMA250.h"


#if defined(ARDUINO_ARCH_SAMD)
#define SerialMonitorInterface SerialUSB
#else
#define SerialMonitorInterface Serial
#endif

BMA250 accel;


void setup()
{
  SerialMonitorInterface.begin(9600);
  Wire.begin();
  accel.begin(BMA250_range_2g, BMA250_update_time_64ms); //This sets up the BMA250 accelerometer
}

void loop()
{
  accel.read();//This function gets new data from the accelerometer
  SerialMonitorInterface.print("X = ");
  SerialMonitorInterface.print(accel.X);
  SerialMonitorInterface.print("  ");
  SerialMonitorInterface.print("Y = ");
  SerialMonitorInterface.print(accel.Y);
  SerialMonitorInterface.print("  ");
  SerialMonitorInterface.print("Z = ");
  SerialMonitorInterface.print(accel.Z);
  SerialMonitorInterface.print("  Temperature(C) = ");
  SerialMonitorInterface.println((accel.rawTemp*0.5)+24.0,1);
  delay(250);//We'll make sure we're over the 64ms update time set on the BMA250
}

TinyFirefly.ino

Arduino
Firefly code! Glows dimly unless shaken with vigor. Uses "absolute magnitude of vector" of acceleration (h/t Nick Pisarro!).
/*
TinyDuino Accelerometer Demo
  
Updated 15 August 2016 to use the correct serial monitor interface for
TinyDuino or TinyScreen+
This example code is in the public domain.
http://www.tinycircuits.com
*/

#include <Wire.h>
#include "BMA250.h"
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif


#if defined(ARDUINO_ARCH_SAMD)
#define SerialMonitorInterface SerialUSB
#else
#define SerialMonitorInterface Serial
#endif

BMA250 accel;

#define PIN 3  // tinylily pwm pin 3
Adafruit_NeoPixel strip = Adafruit_NeoPixel(1, PIN, NEO_GRB + NEO_KHZ800);
int magni = 0;
int tude = 0;
int grn = 0;

void setup()
{
  SerialMonitorInterface.begin(9600);
  Wire.begin();
  accel.begin(BMA250_range_2g, BMA250_update_time_64ms); //This sets up the BMA250 accelerometer
  strip.begin();
  strip.show(); 
}

void loop()
{
  accel.read();//This function gets new data from the accelerometer
  SerialMonitorInterface.print("X = ");
  SerialMonitorInterface.print(accel.X);
  SerialMonitorInterface.print("  Y = ");
  SerialMonitorInterface.print(accel.Y);
  SerialMonitorInterface.print("  Z = ");
  SerialMonitorInterface.print(accel.Z);
//  SerialMonitorInterface.print("  Temperature(C) = ");
//  SerialMonitorInterface.println((accel.rawTemp*0.5)+24.0,1);
  delay(250);//We'll make sure we're over the 64ms update time set on the BMA250
  magni = sq(accel.X) + sq(accel.Y) + sq(accel.Z);
  tude = sqrt(magni);
  magni = map(tude,0,180,25,255);
  grn = magni * 0.75;
  SerialMonitorInterface.print("  Brightness = ");
  SerialMonitorInterface.println(magni);
  colorWipe(strip.Color(magni, grn, 0), 10);
}

void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    delay(wait);
  }
}

Credits

Alex Glow

Alex Glow

149 projects • 1584 followers
The Hackster team's resident Hardware Nerd. I love robots, music, EEG, wearables, and languages. FIRST Robotics kid.
Moheeb Zara

Moheeb Zara

39 projects • 136 followers
Developer Advocate at EMQ Technologies - . Co-founder - South West Maker Festival. Hardware hacker, artist, robots, HeatSync Labs

Comments