fab-lab.euSascha Wolter
Published © CC BY-NC-SA

Blended - retrofit for home appliances 

Hack the House

Work in progress4,045
Blended - retrofit for home appliances 

Things used in this project

Hardware components

WunderBar
Relayr WunderBar
×1
Platinchen (Arduino compatible board plus integrated BLE)
×1
Relayr - WunderBar Bridge
×1
Gesture Sensor APDS-9960 - for hands free operation of blender
×1
Proximity Sensor VCNL4000 - for level / volume detection in blender
×1
Eclipse SmartHome supported switch (e.g. Belkin WeMo Switch)
×1

Story

Read more

Code

blender.ino

C/C++
Platinchen the tiny Arduino compatible board is using following code, receiving sensor data and streaming the data via the Wunderbar Bridge to the Open Cloud
/* 

This code was created during the #HackTheHouse in Berlin
by the blended team - http://www.hackster.io/smarthome/blended
Includes code libraries provided by Sparkfun.com
Code is as it is  - might be changed and comes with no warranty
Download and install latest UART firmware and Arduino Libs from 
relayr gibthub

 */

#include <SoftwareSerial.h>
#include <WunderbarBridge.h>

#include <Wire.h>
#define VCNL4000_ADDRESS 0x13  //I2C Address of the board

#define BRIDGE_DEBUG true

// SoftwareSerial mySerial(8, 10); // RX, TX
const int DEBUG_TX = 10;
const int DEBUG_RX = 8;

/*  Config the bridge module, the 3rd parameter is the baudrate,
    which has to be the same used in the PC serial monitor application*/
Bridge bridge = Bridge(DEBUG_RX, DEBUG_TX, 115200); 

const int led = 2;
const int button = 5;

void setup() {
	pinMode(led, OUTPUT);
	pinMode(button, INPUT);
      
        Wire.begin();  // initialize I2C stuff
        initVCNL4000(); //initilize and setup the board
  	  
	bridge.begin();
}


static char dataOut[18];
/* Main Loop */
void loop() {
	 
	static bridge_payload_t rxPayload;

	if (bridge.newData == true){
		
	rxPayload = bridge.getData();
    
        // no action here
	}

  unsigned int ambientValue = readAmbient(); //can a tiny bit slow
  unsigned int proximityValue = readProximity();

  int length = snprintf(dataOut, 18, "%d", proximityValue );
  bridge.sendData((uint8_t*) dataOut, length);
}

/* the serialEvent() handler is called on every received data 
from the serial port. */
void serialEvent(){
	bridge.processSerial();
}



void initVCNL4000(){
  byte temp = readVCNLByte(0x81);

  if (temp != 0x11){  // Product ID Should be 0x11
    //Serial.print("initVCNL4000 failed to initialize");
    //Serial.println(temp, HEX);
  }else{
    //Serial.println("VNCL4000 Online...");
  } 

  /*VNCL400 init params
   Feel free to play with any of these values, but check the datasheet first!*/
  writeVCNLByte(0x84, 0x0F);  // Configures ambient light measures - Single conversion mode, 128 averages
  writeVCNLByte(0x83, 15);  // sets IR current in steps of 10mA 0-200mA --> 200mA
  writeVCNLByte(0x89, 2);  // Proximity IR test signal freq, 0-3 - 781.25 kHz
  writeVCNLByte(0x8A, 0x81);  // proximity modulator timing - 129, recommended by Vishay 
}


unsigned int readProximity(){
  // readProximity() returns a 16-bit value from the VCNL4000's proximity data registers
  byte temp = readVCNLByte(0x80);
  writeVCNLByte(0x80, temp | 0x08);  // command the sensor to perform a proximity measure

  while(!(readVCNLByte(0x80)&0x20));  // Wait for the proximity data ready bit to be set
  unsigned int data = readVCNLByte(0x87) << 8;
  data |= readVCNLByte(0x88);

  return data;
}


unsigned int readAmbient(){
  // readAmbient() returns a 16-bit value from the VCNL4000's ambient light data registers
  byte temp = readVCNLByte(0x80);
  writeVCNLByte(0x80, temp | 0x10);  // command the sensor to perform ambient measure

  while(!(readVCNLByte(0x80)&0x40));  // wait for the proximity data ready bit to be set
  unsigned int data = readVCNLByte(0x85) << 8;
  data |= readVCNLByte(0x86);

  return data;
}


void writeVCNLByte(byte address, byte data){
  // writeVCNLByte(address, data) writes a single byte of data to address
  Wire.beginTransmission(VCNL4000_ADDRESS);
  Wire.write(address);
  Wire.write(data);
  Wire.endTransmission();
}


byte readVCNLByte(byte address){
  // readByte(address) reads a single byte of data from address
  Wire.beginTransmission(VCNL4000_ADDRESS);
  Wire.write(address);
  Wire.endTransmission();
  Wire.requestFrom(VCNL4000_ADDRESS, 1);
  while(!Wire.available());
  byte data = Wire.read();

  return data;
}

Credits

fab-lab.eu

fab-lab.eu

22 projects • 275 followers
Maker!
Sascha Wolter

Sascha Wolter

2 projects • 4 followers
Sascha is a Developer, Innovation Manager, and Keynote Speaker with Passion for IoT, Rich Applications and Mobile Apps in all flavors.

Comments