Shahariar
Published © GPL3+

Magnetic Field Visualizer

Utilizing TLV493D 3D Magnetic sensor to visualize a magnet's NS pole direction, heading, magnetic field line & strength on an E-ink Display.

BeginnerFull instructions provided2 hours2,776
Magnetic Field Visualizer

Things used in this project

Hardware components

3D Magnetic Sensor 2Go
Infineon 3D Magnetic Sensor 2Go
×1
SparkFun Breadboard holder
×1
Waveshare 1.54 E-ink Display
×1
Boot Kit XMC1100 (Arduino shield compatible)
Infineon Boot Kit XMC1100 (Arduino shield compatible)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Sch

Connect according to the pin map

Sch extra

wiring

Code

main.c

C/C++
Download full code (include fonts and libraries for graphics API)
#include <SPI.h>
#include "epd1in54.h"
#include "epdif.h"
#include "epdpaint.h"
#include <Tle493d_w2b6.h>
#include <RTC.h>
#include <DeviceControlXMC.h>


int COLORED  = 0; // White in Black
int UNCOLORED = 1;  // Black in White
int pos = 20;

XMCClass xmc2go;

uint32_t temperature = 0;
// TLV493 variables //
float Xm = 0.0;
float Ym = 0.0;
float Zm = 0.0;
/////////////////////

unsigned char image[8192];   // takes 8k RAM 
//////////////////////////////////////////////////
// width must be multiple of 8
Paint paint(image, 0, 0);     
Epd epd;                     
Tle493d_w2b6 Tle493dMagnetic3DSensor = Tle493d_w2b6();
//////////////////////////////////////////////////////

void setup() 
{

///// Init Full Display Update ///////////
  if (epd.Init(lut_full_update) != 0) 
  {return;}
/////////////////////////////////////////////
  
///// Init Partial Display Update ////////
  if (epd.Init(lut_partial_update) != 0) 
  {return;}
//////////////////////////////////////////
////////// Clears Up Full Disp ///////////
// bit set = white, bit reset = black
  epd.ClearFrameMemory(0xFF);   
  epd.DisplayFrame();
  epd.ClearFrameMemory(0xFF);   
  epd.DisplayFrame();
//////////////////////////////////////////
}



void loop() 
{
  /// Get Mag sensor running here ///
  Tle493dMagnetic3DSensor.begin();
  delay(50);
  Tle493dMagnetic3DSensor.enableTemp();
  delay(50);
  Tle493dMagnetic3DSensor.updateData();

    Xm = Tle493dMagnetic3DSensor.getX();
    Ym = Tle493dMagnetic3DSensor.getY();
    Zm = Tle493dMagnetic3DSensor.getZ();
  int angle = 180+(57.3*Tle493dMagnetic3DSensor.getAzimuth());
  char VAL[4];
  //  Data Optained From Mag ///// 


   SPI.begin();
   SPI.setClockDivider(SPI_CLOCK_DIV4);
   SPI.setBitOrder(MSBFIRST);
   SPI.setDataMode(SPI_MODE0);
  // Set Active Area on Disp with Orientation and Color //
  // more RAM allows more disp area to be used at once
  paint.SetWidth(200);
  paint.SetHeight(200);
  paint.SetRotate(ROTATE_270);
  paint.Clear(UNCOLORED);


    int strength = sqrt (Xm*Xm + Ym*Ym);
    int Xn = Xm; // 20*round(Xm/strength);
    int Yn = Ym; //20*round(Ym/strength);
    
    for(int c=0;c<(strength/2);c++)
    {
    paint.DrawCircle(100+(c*4),150, c*4,COLORED);
    paint.DrawCircle(100-(c*4),150, c*4,COLORED);
    
    }
   paint.DrawFilledRectangle(98,140,102,160,COLORED);
  
   paint.DrawFilledCircle(100+Xn,50-Yn, 3,COLORED);
   paint.DrawStringAt(105+Xn,35-Yn, "S", &Font20, COLORED);

   paint.DrawFilledCircle(100-Xn,50+Yn, 3,COLORED);
   paint.DrawStringAt(105-Xn,35+Yn, "N", &Font20, COLORED);
   paint.DrawStringAt(0,0, itoa(angle,VAL,10), &Font20, COLORED);
   paint.DrawLine(100+Xn, 50-Yn, 100-Xn,50+Yn, COLORED);
    

////////////////////////////////////////////////////////////////////////////////
   epd.SetFrameMemory(paint.GetImage(), 0, 0, paint.GetWidth(), paint.GetHeight());
   epd.DisplayFrame();
////////////////////////////////////////////////////////////////////////////////
 //  delay(200);
} // loop ends here //

Full Code

Arduino
Download and Unzip
Try on Arduino 1.8.5
No preview (download only).

Credits

Shahariar

Shahariar

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

Comments