Material density detection system used to create wet wipes with Arduino 2/2

Imagen
Construction of the final prototype Components used The components used have been, per module: Density Bar 1 - Arduino Pro Mini 5v 4 - LDRs 4 - Resistors 1k 2 - PCB Terminal Blocks Communication bar 1 - Arduino Pro Mini 5v 1 - LM2596s DC-DC step down power supply module 2 - PCB Terminal Blocks 1 - Voltage regulator TIP220 1 - Heat Sink for TIP220 1 - Rectangular LED 6W 630lm 6500K COB 170 x 15 mm. Industruino 1 - Industruino PROTO kit 1 - Relay module Keyes_SR1 Arduino with screen 1 - Arduino UNO R3 1 - 16x2 Character LCD module with I2C 3 - Resistors 10k 2 - Resistors 220 1 - LED Red 1 - LED Green 3 - Buttons 1 - Relay module Keyes_SR1 Assembly of the circuit The Fritzing scheme is as follows: Density bar Circuit that manages the density bar This circuit is responsible for obtaining the measurements and send notifications to the communications bar for redirection. Communication bar Circuit that manages the c

Líneas mínimas a añadir al código del Industruino para usar las librerías m2tklib

Según mi experiencia creando menús y formularios dentro del Industruino usando las librerías m2tklib, el código mínimo a añadir a un fichero de código es el siguiente:

Includes mínimos

#include <U8glib.h>
#include <M2tk.h>
#include <utility/m2ghu8g.h>

Declaración del tipo de pantalla

Esta declaración se ha de descomentar, si ya está o añadir al código.
U8GLIB_MINI12864 u8g(21, 20, 19, 22);

Gestión de botones

uint8_t uiKeyUpPin = 7;
uint8_t uiKeyDownPin = 3;
uint8_t uiKeySelectPin = 2;
uint8_t uiKeyExitPin = 0;

int adc_key_in = 0;

int read_LCD_buttons_original() //routine to check button inputs and pass the correct button event to GUI
{

  adc_key_in = analogRead(A5);  // read the value from the sensor
  delay(5); //switch debounce delay. Increase this delay if incorrect switch selections are returned.
  if (adc_key_in < 100) return M2_KEY_NONE; // We make this the 1st option for speed reasons since it will be the most likely result
  if (adc_key_in > 300 && adc_key_in < 315)  return M2_KEY_PREV;
  if (adc_key_in > 600 && adc_key_in < 630)  return M2_KEY_SELECT;
  if (adc_key_in > 700 && adc_key_in < 930)  return M2_KEY_NEXT;

}

uint8_t m2_es_arduino_analog_input(m2_p ep, uint8_t msg)
{
  switch (msg)
  {
case M2_ES_MSG_GET_KEY:
  return read_LCD_buttons_original();
case M2_ES_MSG_INIT:
  return 0;
  }
  return 0;
}

A incluir dentro del método setup()

void industruino_Menu_setup(void) {

  //flip the screen 180°
  u8g.setRot180();
  // Connect u8glib with m2tklib
  m2_SetU8g(u8g.getU8g(), m2_u8g_box_icon);

  // Assign u8g font to index 0
  m2.setFont(0, u8g_font_6x13r);

  // Assign icon font to index 3
  m2.setFont(3, u8g_font_m2icon_7);

}

Método loop()

void industruino_Menu_loop() {
  // menu management
  m2.checkKey();
  if ( m2.handleKey() != 0 ) {
u8g.firstPage();
do {
  m2.checkKey();
  draw();
} while ( u8g.nextPage() );
  }
}

Métodos adicionales a añadir

Método draw:
void draw(void) {
  m2.draw();
}

Comentarios

Entradas populares de este blog

Sistema de detección de la densidad del material usado para crear las toallitas húmedas con Arduino 2/2

Material density detection system used to create wet wipes with Arduino 2/2

Sistema de detección de la densidad del material usado para crear las toallitas húmedas con Arduino 1/2