lunes, 19 de diciembre de 2022

MULTIPPLEXOR (MUX) HP4067 de 16 canales para aumentar pines a tu arduino...


código básico
//codigo para usar un MUX MULTIPLEXOR/DEMULTIPLEXOR
int S0 = 7;//CONFIGURACION DE PINES
int S1 = 6;
int S2 = 5;
int S3 = 4;
int SIG = 3;//PIN DE ACTIVACION DE SEÑAL ALTO O BAJO

void setup()
{
  pinMode(S0,OUTPUT);//CONFIGURADOS COMO SALIDA PARA ACTIVAR EL CODIGO BINARIO
  pinMode(S1,OUTPUT);
  pinMode(S2,OUTPUT);
  pinMode(S3,OUTPUT);
  pinMode(SIG,OUTPUT);

}

void loop()
{
  //SE HACEN LAS COMBINACIONES BINARIAS DE CERO A 15 PARA ACTIVAR UNA CANAL
  //SE ACTIVA CANAL 0
 //digitalWrite(S0,LOW);//COMBINACION BINARIA CERO PARA ACTIVAR EL CANAL C0         S3 S2 S1 S0
 //digitalWrite(S1,LOW);//                                                           0  0  0  0  
 //digitalWrite(S2,LOW);
 //digitalWrite(S3,LOW);

// digitalWrite(S0,HIGH);//COMBINACION BINARIA UNO PARA ACTIVAR EL CANAL C1       S3 S2 S1 S0
// digitalWrite(S1,LOW);//                                                         0  0  0  1      
// digitalWrite(S2,LOW);
 //digitalWrite(S3,LOW);

// digitalWrite(S0,LOW);//COMBINACION BINARIA DOS PARA ACTIVAR EL CANAL C2        S3 S2 S1 S0
// digitalWrite(S1,HIGH);//                                                        0  0  1  0
// digitalWrite(S2,LOW);
// digitalWrite(S3,LOW);

digitalWrite(S0, HIGH);//COMBINACION BINARIA TRES PARA ACTIVAR EL CANAL C3     S3 S2 S1 S0
 digitalWrite(S1,HIGH);//                                                       0  0  1  1
 digitalWrite(S2,LOW);
 digitalWrite(S3,LOW);

//   ACTIVO EL DATO A ENVIAR POR PIN SIG
digitalWrite(SIG, HIGH);
delay(500);
digitalWrite(SIG, LOW);
delay(500);

}



código mas compacto con bitread

//codigo para usar un MUX MULTIPLEXOR/DEMULTIPLEXOR
int S0 = 7;//CONFIGURACION DE PINES
int S1 = 6;
int S2 = 5;
int S3 = 4;
int SIG = 3;//PIN DE ACTIVACION DE SEÑAL ALTO O BAJO

int seleccion_canal(byte canal)//se usa int para retornar un valor, si se usa void no retorna
{
//   bitRead(x, n)
//    Parámetros
//    x: el número desde el que leer.
//    n: qué bit leer, comenzando en 0 para el bit menos significativo (más a la derecha).
  //bitRead escribe un numero binario de un Byte ejemplo bitRead(3)= bitRead(00000011)
  //si colocamos bitRead(3,2) 3 es el numero a leer y de ese se toma o leer el valor de la posicion 2 ejemplo 1
  digitalWrite(S0,bitRead(canal,0));//s0,1                     0101
  digitalWrite(S1,bitRead(canal,1));//s1,0
  digitalWrite(S2,bitRead(canal,2));//s2,1
  digitalWrite(S3,bitRead(canal,3));//s3,0
 
}

void setup()
{
  pinMode(S0,OUTPUT);//CONFIGURADOS COMO SALIDA PARA ACTIVAR EL CODIGO BINARIO
  pinMode(S1,OUTPUT);
  pinMode(S2,OUTPUT);
  pinMode(S3,OUTPUT);
  pinMode(SIG,OUTPUT);

}

void loop()
{
  //SE HACEN LAS COMBINACIONES BINARIAS DE CERO A 15 PARA ACTIVAR UNA CANAL
  //SE ACTIVA CANAL
 seleccion_canal(3);

//   ACTIVO EL DATO A ENVIAR POR PIN SIG
digitalWrite(SIG, HIGH);
delay(500);
digitalWrite(SIG, LOW);
delay(500);

}


codigo lectira analogica demultiplexor

//codigo para usar un MUX MULTIPLEXOR/DEMULTIPLEXOR
int S0 = 7;//CONFIGURACION DE PINES
int S1 = 6;
int S2 = 5;
int S3 = 4;
int SIG = A0;//ESTA VEZ SERA USADO COMO ENTRADA

int seleccion_canal(byte canal)//se usa int para retornar un valor, si se usa void no retorna
{
//   bitRead(x, n)
//    Parámetros
//    x: el número desde el que leer.
//    n: qué bit leer, comenzando en 0 para el bit menos significativo (más a la derecha).
  //bitRead escribe un numero binario de un Byte ejemplo bitRead(3)= bitRead(00000011)
  //si colocamos bitRead(3,2) 3 es el numero a leer y de ese se toma o leer el valor de la posicion 2 ejemplo 1
  digitalWrite(S0,bitRead(canal,0));
  digitalWrite(S1,bitRead(canal,1));
  digitalWrite(S2,bitRead(canal,2));
  digitalWrite(S3,bitRead(canal,3));
 
}

void setup()
{
  Serial.begin(9600);
  pinMode(S0,OUTPUT);//CONFIGURADOS COMO SALIDA PARA ACTIVAR EL CODIGO BINARIO
  pinMode(S1,OUTPUT);
  pinMode(S2,OUTPUT);
  pinMode(S3,OUTPUT);
  //pinMode(SIG,OUTPUT);

}

void loop()
{
  //SE HACEN LAS COMBINACIONES BINARIAS DE CERO A 15 PARA ACTIVAR UNA CANAL
  //SE ACTIVA CANAL
 seleccion_canal(0);
int bits = analogRead(A0);
Serial.println(bits);
delay(50);


}


domingo, 30 de octubre de 2022

SOLUCION al error de conexión BLUETOOTH de APPINVENTOR con el modulo HC0...

código para descargar de la aplicación de appinventor




//#include <SoftwareSerial.h>
//para este ejemplo se usara la biblioteca myserial, si usa la nativa de arduino y tiene algun compoenente conectado a el desconectelo mientras envia
//SoftwareSerial mySerial(16, 17); // RX, TX//pines de conexion de un puerto auxiliar de comunicacion
int led1=13;
int led2=2;
char DATO;
void setup()
{

 
  Serial.begin(9600);//configura la velocidad de comunicacion serial hacia el computador y pines, esta biblioteca
  //comparte los pines fisicos del arduino junto los del pc
  //mySerial.begin(9600);//configuro la velocidad de comunicacion de los pines a usar
  //mySerial.println("buenvenidos");//sirve para imprimir un mensaje por el puerto que usted declare
  Serial.println("bienvenido");//imprime un mensaje por el puerto serie hacia el computador por el puerto nativo del pc
  pinMode(led1,OUTPUT);
  pinMode(led2,OUTPUT);
  digitalWrite(led2,LOW);//apaga un led
  digitalWrite(led1,LOW);//apaga un led
  delay(2000);
}

void loop()
{
 
  if(Serial.available()>0)
  {    
          DATO = Serial.read(); //LEE LOS DATOS DEL PUERTO SERIA Y LOS ALMACENA EN DATO
 /////////////////////////////////////////////////////////////////////////////////////////          
          Serial.println(DATO);
          if(DATO == '1')//si la letra que llega es A el servo se coloca en cero grados
          {
           digitalWrite(led1,HIGH);//prende un led
           Serial.println("LED PIN 26 ENCENDIDO");//imprime un mensaje por el puerto serie hacia el computador
          }
//////////////////////////////////////////////////////////////////////////////////////////
          if(DATO == '2')//si la letra que llega es 1 el servo se coloca en cero grados
          {
            digitalWrite(led1,LOW);//apaga un led
            Serial.println("LED PIN 26 APAGADO");//imprime un mensaje por el puerto serie hacia el computador
          }
//////////////////////////////////////////////////////////////////////////////////////////
          if(DATO == '3')//si la letra que llega es A el servo se coloca en cero grados
          {
           digitalWrite(led2,HIGH);//prende un led
           Serial.println("LED PIN 26 ENCENDIDO");//imprime un mensaje por el puerto serie hacia el computador
          }
//////////////////////////////////////////////////////////////////////////////////////////
          if(DATO == '4')//si la letra que llega es 1 el servo se coloca en cero grados
          {
            digitalWrite(led2,LOW);//apaga un led
            Serial.println("LED PIN 26 APAGADO");//imprime un mensaje por el puerto serie hacia el computador
          }
//////////////////////////////////////////////////////////////////////////////////////////
             
             
  }
}

domingo, 23 de octubre de 2022

manejo de array o arreglos, sumar números, datos booleanos | aprende a p...

manejo de teclado 4x4 matricial con arduino | arduino desde cero @Edi...

#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){
  Serial.begin(9600);
  pinMode(13,OUTPUT);
}
 
void loop(){
  char key = keypad.getKey();
 
  if (key){
    Serial.println(key);
    if(key == '1')
    {
      digitalWrite(13,HIGH);
    }
    if(key == '2')
    {
      digitalWrite(13,LOW);
    }
  }
}

sábado, 15 de octubre de 2022

manejo de pantallas LCD OLED 0.96 | arduino desde cero @Editronikx



codigo


#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
// The pins for I2C are defined by the Wire-library.
// On an arduino UNO:       A4(SDA), A5(SCL)
// On an arduino MEGA 2560: 20(SDA), 21(SCL)
// On an arduino LEONARDO:   2(SDA),  3(SCL), ...
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define NUMFLAKES     10 // Number of snowflakes in the animation example

#define LOGO_HEIGHT   16
#define LOGO_WIDTH    16
void setup() {
  Serial.begin(9600);

  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }
  display.clearDisplay();
  display.setTextSize(1);             // Normal 1:1 pixel scale
  display.setTextColor(SSD1306_WHITE);        // Draw white text
  display.setCursor(0,0);             // Start at top-left corner
  display.println("hola mundo");
  display.setTextSize(2);             // Draw 2X-scale text
  display.setTextColor(SSD1306_BLACK, SSD1306_WHITE); // Draw 'inverse' text
  display.println(123456);
  display.display();
  delay(3000);
}

void loop()
 {
 
for (int i=0;i<10;i++)
  {
    display.clearDisplay();
    display.setTextSize(1);             // Normal 1:1 pixel scale
    display.setTextColor(SSD1306_WHITE);        // Draw white text
    display.setCursor(30,0);             // Start at top-left corner
    display.println("contador");
     display.setTextSize(2);  
    display.setCursor(40,10);
    display.println(i);
    display.display();
    delay(1000);
  }
}

domingo, 25 de septiembre de 2022

aprende a programar con labview 2022 | curso gratis |estructuras case y...

medidor de velocidad Km/h arduino y un GPS NEO 6m @PCBWay

codigo

#include <SoftwareSerial.h>
#include <TinyGPS++.h>
#define rxPin 12
#define txPin 11
SoftwareSerial neogps(rxPin,txPin);

TinyGPSPlus gps;
int pulso = 2;
void setup()
{
  Serial.begin(9600);
  neogps.begin(9600);
  pinMode(pulso,OUTPUT);      
  Serial.println("Velocimetro");
  delay(3000);
}

void loop() {
   
  boolean newData = false;
  for (unsigned long start = millis(); millis() - start < 1000;)
  {
    while (neogps.available())
    {
      if (gps.encode(neogps.read()))
      {
        newData = true;
      }
    }
  }

  //If newData is true
  if(newData == true)
  {
    newData = false;
    print_speed();
  }
  else
  {
    Serial.print("No hay datos");
   
  }  
 
}

void print_speed()
{
       
  if (gps.location.isValid() == 1)
  {
     
    Serial.print(gps.speed.kmph());
    //Serial.println("km/h");
  //  Serial.print("SAT:");
   // Serial.println(gps.satellites.value());
   // Serial.print("ALT:");
   // Serial.println(gps.altitude.meters(), 0);

   
  }

}

por que todo es desechable en electrónica | la obsolescencia electrónic...

domingo, 11 de septiembre de 2022

impresionante impresora laser xTool D1 Pro 20W graba y corta madera, me...

link de compra https://www.xtool.com/?ref=uYySFVAV_qnJYJ&utm_source=influencer esta impresora me sorprendió mucho por su calidad, precisión, facilidad de manejo y armado, buena potencia Láser de alta potencia de 20 W: corte de tilo de 10 mm/acrílico negro de 8 mm en una sola pasada Velocidad de trabajo de hasta 400 mm/s: ahorro de tiempo y eficiencia Mayor precisión y estabilidad Detección de llama/movimiento/vuelco para su seguridad

sábado, 30 de julio de 2022

OXIMETRO con MAX30100 LCD OLED 1.3 | arduino desde cero @Editronikx

 código


#include <SPI.h>
#include <Wire.h>
//#include <Adafruit_GFX.h>
#include <Adafruit_SH1106.h>
#include "MAX30100_PulseOximeter.h"
#define OLED_RESET 4
Adafruit_SH1106 display(OLED_RESET);
#define REPORTING_PERIOD_MS     1000
PulseOximeter pox;
uint32_t tsLastReport = 0;
int pulso = 2;
void onBeatDetected()
{
    Serial.println("Beat!");
    digitalWrite(pulso, HIGH);
}
void setup()  
{          
  pinMode(pulso,OUTPUT);      
  display.begin(SH1106_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3D (for the 128x64)
  display.clearDisplay();
  display.display();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.println("oximetro...!");
  display.display();
  delay(2000);
  Serial.begin(115200);
    Serial.print("Initializing pulse oximeter..");
 
    // Initialize the PulseOximeter instance
    // Failures are generally due to an improper I2C wiring, missing power supply
    // or wrong target chip
    if (!pox.begin()) {
        Serial.println("FAILED");
        for(;;);
    } else {
        Serial.println("SUCCESS");
    }
     pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
 
    // Register a callback for the beat detection
    pox.setOnBeatDetectedCallback(onBeatDetected);
 
}


void loop()
{
    // Make sure to call update as fast as possible
    pox.update();
    if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
        Serial.print("Heart rate:");
        Serial.print(pox.getHeartRate());
        Serial.print("bpm / SpO2:");
        Serial.print(pox.getSpO2());
        Serial.println("%");
 
        tsLastReport = millis();
        display.clearDisplay();
        display.display();
        display.setTextSize(1);
        display.setTextColor(WHITE);
        display.setCursor(0,0);
        display.println("OK!");
        //display.println(pox.getHeartRate());
        display.display();
        digitalWrite(pulso, LOW);
    }
  
}

domingo, 15 de mayo de 2022

sabes como crear menú en lcd con arduino? hoy te explico paso a paso | a...

#include <Key.h>
#include <Keypad.h>
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 for a 16 chars and 2 line display
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'},
};
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
char key;
int dato;
void setup()
{
  pinMode(13,OUTPUT);
  digitalWrite(13,LOW);
  lcd.init();                      
  lcd.backlight();
  lcd.setCursor(2,0);
  lcd.print("Hola amigos");
  lcd.setCursor(2,1);
  lcd.print("BIENVENIDOS");
  lcd.setCursor(2,2);
  lcd.print("CANAL EDITRONIKX");
  delay(3000);
  lcd.clear();
  lcd.setCursor(0,1);
  lcd.print("seleccione el menu");
  lcd.setCursor(3,2);
  lcd.print("con su teclado");
  delay(3000);
  lcd.clear();
}


void loop()
{
  lcd.setCursor(0,0);
  lcd.print("1.CONTROL LED");
  lcd.setCursor(0,1);
  lcd.print("2.JUEGO DE LUCES");
  lcd.setCursor(0,2);
  lcd.print("3.ACERCA DE...");
  key = keypad.getKey();
  
  if (key)
  {
    if(key == '1')
    { 
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("1.prender LED");
      lcd.setCursor(0,1);
      lcd.print("2.apagar LED");
      lcd.setCursor(0,2);
      lcd.print("3.Menu principal");
      dato = 1;
      while(dato)
      {
        key = keypad.getKey();
        if(key == '1')
        {
          digitalWrite(13,HIGH);
          lcd.setCursor(0,3);
          lcd.print("LED ONN");
        }
        if(key == '2')
        {
          digitalWrite(13,LOW);
          lcd.setCursor(0,3);
          lcd.print("LED OFF");
        }
        if(key == '3')
        {
          dato = 0;
          lcd.clear();
          lcd.setCursor(0,3);
          lcd.print("RETORNANDO MENU");
          delay(2000);
          lcd.clear();
          key = 0;
        }
      }

    }
//////////////////////////////////
  if(key == '2')
    {
      lcd.clear();
      dato = 1;
      while(dato)
      {
      lcd.setCursor(3,1);
      lcd.print("JUEGO DE LUCES");
      lcd.setCursor(3,2);
      lcd.print("3.Menu principal");
      key = keypad.getKey();
        if(key == '3')
        {
          dato = 0;
          lcd.clear();
          lcd.setCursor(0,3);
          lcd.print("RETORNANDO MENU");
          delay(2000);
          lcd.clear();
          key = 0;
        }
        for(int i=0;i<3; i++)
        {
          digitalWrite(13,HIGH);
          delay(100);
          digitalWrite(13,LOW);
          delay(100);
          
        }
      }
    }
    //////
    if(key == '3')
    {
       lcd.clear();
       lcd.setCursor(0,0);
       lcd.print("programa creado por");
       lcd.setCursor(0,1);
       lcd.print("editronikx 2022");
       lcd.setCursor(0,3);
       lcd.print("SUSCRIBETE...");
       delay(4000);
       lcd.clear();
    }
  
  }
}