Skip to main content

Ralsina.Me — Roberto Alsina's website

Old Guy @ The Terminal Ep 2: Python Sucks!

Episo­dio 2! Oh yeah!

Es­ta es una char­la relám­pa­go que dí en la Py­Con Ar­genti­na de 2018, es cor­ti­ta y sen­cil­la, ojalá les guste!

Old Guy @ The Terminal: Episodio 1!

Este es el primer (y por aho­ra úni­co, ob­vi­a­mente) episo­dio de un nue­vo canal de video lla­ma­do "Old Guy @ The Ter­mi­nal" en el que mue­stro al­gu­nas cosi­tas de Lin­ux, pro­gra­mación, co­mo se rela­cio­nan cosas ac­tuales con cosas vie­jas y ver­e­mos qué más a me­di­da que se me ocur­ran temas.

Nun­ca había he­cho al­go pare­ci­do, así que no sean muy duros con­mi­go ;-)

En este episo­dio ve­mos qué es una ter­mi­nal, co­mo se hace un pro­gra­ma para ter­mi­nal y una ter­mi­nal para el pro­gra­ma, porque por qué no.

En al­gún mo­men­to va a haber una ver­sión en in­glés (tal vez).

El código: en GitHub

Adventures In Electronics: PC Volume Knob

I have some rather un­usu­al holes in my ed­u­ca­tion. I nev­er, for ex­am­ple, learned much about elec­tron­ic­s. It has al­ways been a mis­tery, a thing oth­er peo­ple knew about.

And then one day I ran in­to this gad­get:

What is it? A vol­ume knob for your PC. It plugs via USB and you can use it to turn vol­ume up or down. I sup­pose if you press it it mutes au­dio or some­thing.

It costs 50 dol­lars. 50 fuck­ing dol­lars. For a di­al.

Sure, it's pret­ty but how hard can it be?

So, I start­ed look­ing at how to do it. Here's what I learned first:

  • The thingie that spins and gives feed­back is called a "ro­tary en­coder"
  • I would need some­thing like a mi­cro­con­troller to ... well, con­trol it.
  • It would prob­a­bly in­volve sol­der­ing.
  • There are a bunch of tu­to­ri­als / in­structa­bles on how to do it.
  • The com­po­nents are damn cheap!

The last item is im­por­tan­t. When I was a kid in the 70s, elec­tron­ics was a thing for wealthy kid­s. I was not wealthy. So, the pos­si­bil­i­ty of do­ing this sort of thing? With cheap stuff? Sign me up!

So, I did what ev­ery­one does to learn stuff in 2019: I jumped in­to youtube and asked to be taught elec­tron­ic­s. And a day lat­er ... well, I know enough to break things and to im­ple­ment this!

The goal is:

  • USB vol­ume knob.
  • Press­ing it lights a LED
  • A but­ton click mutes the speak­ers
  • A longer click en­ables the mi­cro­phone while the di­al is pressed (push-­to-talk)

So, here is the BOM:

  • The cheap­est Ar­duino-­like thing with a USB in­ter­face: Digis­park
  • A ro­tary en­coder. I used a KY-040 be­cause it's cheap and work­s.
  • A gener­ic LED (red)
  • Some bread­board ca­bles.
  • A bread­board
  • A US­B-A male/fe­male ca­ble
  • A 1k re­sis­tor

A sec­ond stage (once I have an­oth­er Digis­park) will in­volve mak­ing it nice, but for now let's make it work.

Here is the wiring, which is prob­a­bly a pile of crap but works for me (sor­ry, don't want to learn how to do it prop­er­ly).

Wiring be­tween the Digis­park and the KY-040:

  • P0 -> CLK
  • P1 -> SW
  • P2 -> DT
  • 5V -> +
  • GND -> GND

I also connected KY-040's SW -> 1K resistor -> LED -> 5V so the LED turns on when the button is pressed, but that's optional.

IM­POR­TANT NOTE In or­der for P1 to work prop­er­ly, I need­ed to scratch off a con­nec­tion to dis­able the on­board LED so, if that's a prob­lem, you may be able to use P5 in­stead but P5 is dis­abled in the cheap Digis­park clones. We can't use P3 and P4 be­cause they are need­ed for US­B. So, your choice.

So, here is all the wiring. If the im­age dif­fers from my de­scrip­tion, trust the im­age be­cause it's work­ing ;-)

Once you have ev­ery­thing wired, we need to work on the soft­ware side of things.

I used a cou­ple of li­braries:

I had to configure a global shortcut to enable/disable the michrophone. I used the F10 key and the command pulseaudio-ctl mute-input but you figure out what you want to do.

I wrote a Sketch that does the fol­low­ing:

  • When the en­coder ro­tates clock­wise: send Vol­ume Up key.
  • When the en­coder ro­tates coun­ter-­clock­wise: send Vol­ume Down key.
  • When the en­coder is clicked less than half a sec­ond: send mute key.
  • When the en­coder is pressed for more than half a sec­ond: send mute-in­put tog­gle short­cut.
  • When the en­coder is re­leased af­ter be­ing clicked more than half a sec­ond: send mute-in­put tog­gle short­cut.

This way, if you want to mute, just click. If you want to talk, make sure you mute in­put when the ses­sion start­s, then click­-and-hold and while it's pressed the mi­cro­phone is en­abled. Nice, is­n't it?

Does it work? Oh yeah! (No, the mu­sic is not com­ing from the PC, just look at the screen to see what changes) and sor­ry this video is so crap­py.

And here's the code (which is my 1st ar­duino sketch, but I have been pro­gram­ming for a long time ;-)

#include "TrinketHidCombo.h"
#include <SimpleRotary.h>  // https://github.com/mprograms/SimpleRotary

// Pin A, Pin B, Button Pin
// Setting the button to 5 because this code handles it manually.
SimpleRotary rotary(0, 2, 5);

void setup() {
  TrinketHidCombo.begin();
  pinMode(1, INPUT);
}


void loop() {
  static unsigned long time_pressed = 0;
  static byte ptt_flag = 0;
  byte i = rotary.rotate();
  if (i == 1) {
    TrinketHidCombo.pressMultimediaKey(MMKEY_VOL_UP);
  }
  else if (i == 2) {
    TrinketHidCombo.pressMultimediaKey(MMKEY_VOL_DOWN);
  }

  int button = digitalRead(1);
  if (button == LOW) {  // Yes, clicking the button makes it LOW
    if (time_pressed == 0) {  // It's a new click
      time_pressed = millis();
    }
    else {  // Button has been pressed a while
      if ((millis() - time_pressed) > 500 && ptt_flag == 0) {
        // Pressed half a second, switch to push-to-talk
        // I configured my machine to toggle the input muting when F10 is clicked
        TrinketHidCombo.pressKey(0, KEYCODE_F10);
        TrinketHidCombo.pressKey(0, 0);
        ptt_flag = 1;
      }
    }
  }
  else {  // Button not pressed
    if (time_pressed) {// Has been pressed
      time_pressed = 0;
      if (ptt_flag == 0) {  // Was a short click
        // Toggle mute
        TrinketHidCombo.pressMultimediaKey(MMKEY_MUTE);          
      }
      else {  // Was a long click
        // Toggle push-to-talk
        TrinketHidCombo.pressKey(0, KEYCODE_F10);
        TrinketHidCombo.pressKey(0, 0);
        ptt_flag = 0;
      }
    }
  }
  TrinketHidCombo.poll();
}

Proyectos Caseros: Almacenaje bajo escalera

Vi­vo en una casa muy vie­ja, tiene alrede­dor de 100 años, y eso tiene ven­ta­jas y desven­ta­jas. Ven­ta­jas: tiene mucha on­da, luz nat­u­ral, pisos de pinotea, aber­turas an­tiguas de vidrio par­tido de col­ores.

Desven­ta­jas: las aber­turas an­tiguas tienen vidrios de 6 dé­cadas dis­tin­tas, los pisos de pinotea son del­i­ca­dos, no hay un con­de­na­do enchufe y no hay adonde guardar na­da porque en esa época la gente no tenía cosas.

Así que hará 35 años, en una re­mod­elación, al­guien abrió el es­pa­cio aba­jo de la es­calera que va a la ter­raza y quedó un lu­gar de al­ma­ce­na­je al fon­do del lavadero.

Y aho­ra, de­spués de 15 años de vivir acá, de­cidí hac­er­lo lo más fun­cional posi­ble.

Paso 1: sacar todo.

Eso llevó un par de días porque ... había muchas cosas ar­rum­badas ahí aden­tro. Re­galé una helader­a, un minilavar­ropas, ol­las vie­jas, y muchas otras cosas.

Paso 2: el espacio.

Es un es­pa­cio de 2,40m x 80cm. En la parte derecha mide 3m de al­to. En la parte izquier­da tiene la pen­di­ente de la es­caler­a.

Tiene una puer­ta de ac­ce­so de 1,60m de al­to por 1m de an­cho.

Paso 3: objetivo.

Quiero ten­er lu­gar para guardar todo, pero fun­da­men­tal­mente:

  • Al­i­­men­­tos no pere­cederos

  • Fuentes y esas cosas

  • Her­ramien­­tas

  • Pro­­duc­­tos de limpieza

  • Val­i­­jas

  • Ca­­jas grandes varias con cosas

Paso 4: Almacenaje en altura

Quiero con­ver­tir la parte al­ta del es­p­cio en una "repisa en­trepiso" de al­ma­ce­na­je para val­i­jas y ca­jas.

/galleries/bajoescalera/IMG_20190629_115831.jpg

Agar­ré unas mén­su­las vie­jas que en­con­tré por ahí, un­os per­files en L de acero, taru­gos y un­os tablones e hice un mar­co para apo­yar un pan­el de pino de 1,20 x 70.

To­do eso es­tá a una al­tura de 1.85 así que puedo has­ta pararme aba­jo sin prob­le­mas.

Ahí ar­ri­ba irán en­tonces val­i­jas, ca­jas, y bul­tos grandes que no quiero ac­ced­er segui­do.

/galleries/bajoescalera/IMG_20190630_130804.jpg

Paso 5: Estanterías.

Es com­pli­ca­do porque los es­pa­cios a am­bos la­dos son "pro­fun­dos". Si pon­go una es­tantería ade­lante los blo­queo, si pon­go es­tanterías atrás son un poco in­ac­ce­si­bles porque hay poco es­pa­cio.

Y en la parte ba­ja es aún pe­or porque co­mo se hace para ac­ced­er a lo que se guar­da en el fon­do de todo?

Solu­ción: es­tanterías móviles con rued­i­tas.

Co­mo no ex­is­ten, me las tuve que ar­reglar.

Paso 6: Comprar una cosa rara en Mercado Libre

/galleries/bajoescalera/IMG_20190630_130822.jpg

Eso es una es­tantería jaula de acero de 6 es­tantes, mide 1,70m de al­tur­a, 70cm de pro­fun­di­dad y 1,20m de an­cho. pe­sa alrede­dor de 90kg.

Y no pasa por la puer­ta de mi lavadero, ni por la en­tra­da del ba­joescalera que mide 1mx1,50m así que ...

Paso 7: Amoladora

/galleries/bajoescalera/IMG_20190630_145130.jpg

La cor­ta­mos por la mi­tad a lo al­to. La parte de ar­ri­ba se va a con­ver­tir en la es­tantería para la parte "ba­ja" izquier­da y la parte de aba­jo en la es­tantería para la parte "al­ta" derecha.

La parte de aba­jo tiene ruedas. Pero ob­vi­a­mente la de ar­ri­ba no.

Paso 8: Rueditas

Hice un "tri­neo" para la parte de aba­jo (de pa­so, gané un es­tante!)

/galleries/bajoescalera/IMG_20190630_123526.jpg
/galleries/bajoescalera/IMG_20190630_130218.jpg

La base se fi­ja a la es­tantería us­an­do un­os per­files en L, unas planchue­las, un­os precin­tos y bue­na vol­un­tad.

Paso 9: Meter todo en el depósito

/galleries/bajoescalera/IMG_20190630_172039.jpg
/galleries/bajoescalera/IMG_20190706_132509.jpg

Paso 10: Y lo de las rueditas?

Para poder hac­er es­to, y que no quede es­pa­cio sin us­ar:

/galleries/bajoescalera/IMG_20190706_132535.jpg
/galleries/bajoescalera/IMG_20190706_132609.jpg

Conclusión

Quedé con­tento, se aprovechó muy bi­en el es­pa­cio (aunque to­davía no usé el es­pa­cio para val­i­jas). La es­téti­ca es un poco rús­ti­ca, pero ... es un ba­joescalera atrás del lavadero, no me jo­dan.

Y fue un finde di­ver­tido ju­gan­do con her­ramien­tas.


Contents © 2000-2023 Roberto Alsina