Shahariar
Published © CC0

Underwater/Weatherproof Equipment UI with Magnetic Sensors

A Demonstration of (UI) user Input Interface for Fully Enclosed Waterproof/Underwater equipment with Infineon 3D Magnetic and Hall Sensor

BeginnerFull instructions provided4 hours207
Underwater/Weatherproof Equipment UI with Magnetic Sensors

Things used in this project

Hardware components

Boot Kit XMC1100 (Arduino shield compatible)
Infineon Boot Kit XMC1100 (Arduino shield compatible)
×1
3D Magnetic Sensor 2Go
Infineon 3D Magnetic Sensor 2Go
×1
S2GO 2 HALL TLE4966K
Infineon S2GO 2 HALL TLE4966K
×1
Grove - OLED Display 1.12'' V2
Seeed Studio Grove - OLED Display 1.12'' V2
×1
Reed Switch, SPST-NO
Reed Switch, SPST-NO
×1
AA Batteries
AA Batteries
×1
Amazon Web Services Air Tight Plastic Enclosure ( transparent food container with seal)
×1
SparkFun Magnets
×12
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
Breadboard, 170 Pin
Breadboard, 170 Pin

Story

Read more

Schematics

Schematic

ver 1.0.5

Code

main

C/C++
#include <Arduino.h>
#include <U8g2lib.h>
#include <Tle493d.h>
#include "Infineon_logo.h" // includes GUI info for OLED display

#define SLIDE_SWITCH 14  // pin 14 got INT0, connect hall sensor
#define SENSOR_1 0 // ADC to connect pH sensor
#define SENSOR_2 2 // ADC to connect conductivity seosor
#define SENSOR_3 4 // ADC to waterproof temperature sensor
#define SENSOR_4 6 // ADC to connect Turbidity sensor
#define SENSOR_5 8 // ADC to connect Salinity seosor


#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif

//U8G2_SH1106_128X32_VISIONOX_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/U8X8_PIN_NONE);
Tle493d Tle493dMagnetic3DSensor = Tle493d();
float switch_position = 0.0;
int rotary_switch_old_position = 0;
volatile byte toggle = 0;



void setup(void) 
{
  // add falling edge interrupt on user button MagSlide Hall switch 
  pinMode(SLIDE_SWITCH,INPUT);
  attachInterrupt(digitalPinToInterrupt(SLIDE_SWITCH), MagSlideBtn, FALLING);
  // init 1306 OLED display
  u8g2.begin();
  // init 3D mag sensor for sensing rotary selector switch
  Tle493dMagnetic3DSensor.begin();
  Tle493dMagnetic3DSensor.enableTemp();
  u8g2.clearBuffer();
  // vibe the Infineon Logo
  draw_logo();
  u8g2.sendBuffer();  // transfer internal memory to the display
  delay(50);
}

void loop(void) 
{
  u8g2.clearBuffer();                  // clear the internal memory
  u8g2.setFont(u8g2_font_ncenB14_tr);  // choose a suitable font

// show GUI changes based on Rotary Selector Switch position 
  switch (get_rotary_knob_position()) 
  {
    case 0:
      draw_logo();
      u8g2.sendBuffer();
      break;
    case 1:
      draw_arrow(arrow_0);
      u8g2.sendBuffer();  // transfer internal memory to the display
      delay(5);
      break;

    case 2:
      u8g2.clearBuffer();
      draw_arrow(arrow_1);
      u8g2.sendBuffer();  // transfer internal memory to the display
      delay(5);
      break;
    case 3:
      u8g2.clearBuffer();
      draw_arrow(arrow_2);
      u8g2.sendBuffer();  // transfer internal memory to the display
      delay(5);
      break;
    case 4:
      u8g2.clearBuffer();
      draw_arrow(arrow_3);
      u8g2.sendBuffer();  // transfer internal memory to the display
      delay(5);
      break;
    case 5:
      u8g2.clearBuffer();
      draw_arrow(arrow_4);
      u8g2.sendBuffer();  // transfer internal memory to the display
      delay(5);
      u8g2.clearBuffer();
      break;
    default:
      // do nothing 
      break;
  }

// if hall switch is activated (MagSlide button)
  if (toggle == 1 )
   {
    // enter inside individual UI menus and show sensor data

        while(get_rotary_knob_position()==1 && toggle == 1)
    {
      u8g2.clearBuffer();
      u8g2.setCursor(20,20);
      u8g2.print("pH  level");
      u8g2.setCursor(30,50);
      u8g2.print("pH 7.4");
     // u8g2.print(analogRead(SENSOR_1));
      u8g2.sendBuffer();
      delay(50);
    }
        while(get_rotary_knob_position()==2 && toggle == 1)
    {
      u8g2.clearBuffer();
      u8g2.setCursor(0,20);
      u8g2.print("Conductivity");
      u8g2.setCursor(20,50);
      u8g2.print(2*analogRead(SENSOR_2)+100);
      u8g2.print(" uS/cm");
      u8g2.sendBuffer();
      delay(50);
    }
        while(get_rotary_knob_position()==3 && toggle == 1)
    {
      u8g2.clearBuffer();
      u8g2.setCursor(0,20);
      u8g2.print("Temperature");
      u8g2.setCursor(40,50);
    //  u8g2.print(analogRead(SENSOR_3));
       u8g2.print("25.3 C");
      u8g2.sendBuffer();
      delay(50);
    }
        while(get_rotary_knob_position()==4 && toggle == 1)
    {
      u8g2.clearBuffer();
      u8g2.setCursor(15,20);
      u8g2.print("Turbidity");
      u8g2.setCursor(25,50);
      u8g2.print(analogRead(SENSOR_4)+30);
      u8g2.print(" NTU");
      u8g2.sendBuffer();
      delay(50);
    }
        while(get_rotary_knob_position()==5 && toggle == 1)
    {
            u8g2.clearBuffer();
      u8g2.setCursor(20,20);
      u8g2.print("Salinity");
      u8g2.setCursor(25,50);
      u8g2.print(analogRead(SENSOR_5)+30);
      u8g2.print(" ppm");
      u8g2.sendBuffer();
      delay(50);
    }

  }
}


// draw bitmap logo of Infineon from Infineon_logo.h file
void draw_logo(void) {
  u8g2.firstPage();
  do {
    u8g2.drawBitmap(0, 0, 16, 64, infineon_logo);
  } while (u8g2.nextPage());
}

// draw GUI of selector Switch from Infineon_logo.h file
void draw_arrow(const uint8_t arrow_array[1024]) {
  u8g2.firstPage();
  do {
    u8g2.drawBitmap(0, 0, 16, 64, arrow_array);
  } while (u8g2.nextPage());
  delay(5);
}


// sense RotaMag rotary selector switch position with TLE493 3D mag sensor
// then for a certain range of the value, return a knob position data
int get_rotary_knob_position(void) {
  Tle493dMagnetic3DSensor.updateData();
  switch_position = Tle493dMagnetic3DSensor.getAzimuth();

  if (switch_position > -1.3 && switch_position < -0.6)
    return 0;


  if (switch_position > -1.8 && switch_position < -1.3)
    return 1;

  if (switch_position > -2.7 && switch_position < -2.1)
    return 2;

  if (switch_position > 2.9 || switch_position < -2.9)  // transition from 359 deg to 360 or 0 deg
    return 3;

  if (switch_position > 2.3 && switch_position < 2.9)
    return 4;

  if (switch_position > 1.6 && switch_position < 2.2)
    return 5;

  else
    return 6;
}

// Interrupt service routine to detect Hall switch activation 
// with the MagSlide sliding toggle switch 
void MagSlideBtn()
{
  toggle =! toggle;
}

XMC1300_OLED1306.zip

Arduino
download, unzip and open with Arduino IDE
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