Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Shahariar
Published © GPL3+

Warranty Void Only If Product Cover Removed

Low power active tampering & warranty void detection system based on TLE493D 3D magnetic sensor for smart protection of sensitive products.

IntermediateFull instructions provided2 hours986

Things used in this project

Hardware components

XMC2GO - industrial microcontroller kit
Infineon XMC2GO - industrial microcontroller kit
×1
3D Magnetic Sensor 2Go
Infineon 3D Magnetic Sensor 2Go
×1
1.54 inch 200x200 E-Ink Display
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Connection diagram

wiring

Code

main.c

C/C++
Arduino IDE : 1.8.5
Library and Board support must be added
See References (above) for details
//////// Libraries ///////////////

#include <SPI.h>
#include "EPD_drive.h"
#include "EPD_drive_gpio.h"
#include "Display_Lib.h"
#include <Tle493d_w2b6.h>
#include <DeviceControlXMC.h>

//////// Class Obj/Type //////////

XMCClass xmc2go;
WaveShare_EPD EPD = WaveShare_EPD();
Tle493d_w2b6 Tle493dMagnetic3DSensor = Tle493d_w2b6();

///////// Variables //////////////
float Xm = 0.0;
float Ym = 0.0;
float Zm = 0.0;

float Xm_Old = 0.0;
float Ym_Old = 0.0;
float Zm_Old = 0.0;

float dXm = 0.0;
float dYm = 0.0;
float dZm = 0.0;

  char VAL_Xm[4];
  char VAL_Ym[4];
  char VAL_Zm[4];
 
int change_tracker = 0;
int warranty_void = 0;
 

void setup() 

{

// debug LED (thread heartbeat)
   pinMode(14,OUTPUT);
   digitalWrite(14,1);
// additional control pins for Eink display   
   pinMode(CS,OUTPUT);  //  pin 3
   pinMode(DC,OUTPUT);  //  pin 4
   pinMode(RST,OUTPUT); //  pin 5
   pinMode(BUSY,INPUT); //  pin 9
///////////////////////////////////////////   
// hardwired SPI pins, MISO pin not needed   
// MOSI/DIN is          //  pin 1
// SCK/CLK  is          //  pin 2
///////////////////////////////////////////
// E-Ink Display (Vcc) Power feeding Pin
   pinMode (PWR,OUTPUT);//  pin 8
   digitalWrite(PWR,HIGH);
///////////////////////////////////////////
// configure sleep mode for cpu
   xmc2go.configureSleepMode(SLEEP_MODE,USIC_OFF ,LEDT_OFF,CCU_OFF,WDT_OFF,FLASH_OFF);
///////////////////////////////////////////
// time for demo product setup
   delay(3000); 
//////////////////////////////////////////
 }

void loop() 
{
/// 3D Magnetic sensing Begins here and I2C bus is used ///
/// inside "Tle493d_w2b6.h" library with following APIs ///
  Tle493dMagnetic3DSensor.begin();
  delay(50);
  Tle493dMagnetic3DSensor.enableTemp();
  delay(50);

/// Fetch X,Y,Z axis magnetic data ///
  Tle493dMagnetic3DSensor.updateData();
  Xm = Tle493dMagnetic3DSensor.getX();
  Ym = Tle493dMagnetic3DSensor.getY();
  Zm = Tle493dMagnetic3DSensor.getZ();
  delay(150);
////////////////////////////////////////////////////////////
/// Debug LED to check if thread is running ///
/// Not necessary in actual Applicantion    ///
  heartbeat_blink();
////////////////////////////////////////////////////////////
// following while loops detects change in 3D magnetic
// field, which will happend is the nearby magnets are
// moved from their default positions
  while(change_tracker == 1)
  {
   Tle493dMagnetic3DSensor.updateData();
   Xm = Tle493dMagnetic3DSensor.getX();
   Ym = Tle493dMagnetic3DSensor.getY();
   Zm = Tle493dMagnetic3DSensor.getZ();
//   dXm = abs(Xm-Xm_Old);
//   dYm = abs(Ym-Ym_Old);
//   dZm = abs(Zm-Zm_Old);
//   delay(20);
// debug LED (optional)
/// Debug LED to check if thread is running ///
/// Not necessary in actual Applicantion    ///
   heartbeat_blink();

// change in magnetic values from last values
// small number makes more sensitive to detection
// detects warrenty void
  if ( abs(Zm)>15.0 ) 
         {
          change_tracker = 0; 
          warranty_void = 1;
          heartbeat_blink();
          delay(500);
          heartbeat_blink();
          delay(500);
          }
  }
//////////////////////////////////////////////  
///3D Mag sensing done for now///////

/// Initialize SPI for E-ink Display /// 
   SPI.begin();
   SPI.setClockDivider(SPI_CLOCK_DIV4);
   SPI.setBitOrder(MSBFIRST);
   SPI.setDataMode(SPI_MODE0);   
   
/// Clears up old stickey info on display ///

   EPD.Dis_Clear_full();
   EPD.Dis_Clear_part(); 
   driver_delay_xms(DELAYTIME);

   
   EPD.EPD_init_Part();
   driver_delay_xms(DELAYTIME);

/// Prints Product & Warranty info (DUMMY Info)  ///


EPD.Dis_String(10, 10, "ACTIVE WARRANTY & ANTI",16);
EPD.Dis_String(10, 30, "TAMPER MANAGEMENT WITH",16);
EPD.Dis_String(10, 50, "XMC 1100 MCU & TLV493D",16);
EPD.Dis_String(10, 70, "**3D MAGNETIC SENSOR**",16);

  if(warranty_void == false)
  {
  EPD.Dis_String(10, 90,  "PRODUCT UNDER WARRANTY",16);
  EPD.Dis_String(10, 110, "PRODUCT UNDER WARRANTY",16);
  EPD.Dis_String(10, 130, "PRODUCT UNDER WARRANTY",16);
  EPD.Dis_String(10, 150, "PRODUCT UNDER WARRANTY",16);
  EPD.Dis_String(10, 170, "**********************",16);
  EPD.Dis_String(10, 182, "S/L: 2348332Q2Y18M6D12",16);

  }
  if(warranty_void == true)
  {
  EPD.Dis_String(10, 90,  "UNAUTHORIZED TAMPERING",16);   
  EPD.Dis_String(10, 110, "DETECTED,WARRANTY VOID",16);
  EPD.Dis_String(10, 130, "UNAUTHORIZED TAMPERING",16);
  EPD.Dis_String(10, 150, "DETECTED,WARRANTY VOID",16);
  EPD.Dis_String(10, 170, "**********************",16);
  EPD.Dis_String(10, 182, "S/L: 2348332Q2Y18M6D12",16);

/// Warranty Void Lockup, Powerdown everything   ///
/// E-Ink will retain the void msg without power ///
      while(1)
      {
      digitalWrite(14,LOW);    // power down LED
      digitalWrite(PWR,LOW);   // power down display
      xmc2go.enterSleepMode(); // power down cpu to sleep
      // program will stop here if warranty is void
      } 
  }


/// Debug LED to check if thread is running ///
/// Not necessary in actual Applicantion    ///
heartbeat_blink();
change_tracker = 1;
//  Xm_Old = Xm;
//  Ym_Old = Ym;
//  Zm_Old = Zm;
}  //void loop ends here




///// additional function /////

// Blinks LED on pin 14 to  //
// indicate code is running //

void heartbeat_blink(void)
{
   delay(50);
   digitalWrite(14,!(digitalRead(14))); 
   delay(50);
   digitalWrite(14,!(digitalRead(14))); 
}

///////////  NOTE  //////////////////////////////////////
// Serial Output Selection : On Board
// After flashing new code every time 
// power cycle is required for TLV493D
// 3D magnetic sensor to work properly 
// Unplug power (USB) & plugging again 
// will do the job Or Flashing the same
// code twice also fixes sensor problem

full code

C/C++
No preview (download only).

Credits

Shahariar

Shahariar

74 projects • 266 followers
"What Kills a 'Great life' is a 'Good Life', which is Living a Life Inside While Loop"

Comments