Ir al contenido principal

Ralsina.Me — El sitio web de Roberto Alsina

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.

Product Review: Ajazz Zinc Mechanical Keyboard.

I don't do prod­uct re­views of­ten, but this key­board is a spe­cial case:

  • Me­chan­i­cal key­boards are fash­ion­able now
  • Of­ten you will buy the key­board with­out test­ing it
  • This one is pret­ty un­known
  • It's re­al­ly a mixed bag ex­pe­ri­ence and I think oth­ers may ben­e­fit from the re­view, even if they are buy­ing a dif­fer­ent one.

Dis­claimer I bought this key­board with my own mon­ey and no­body ev­er gives me any toys to play with. Come on, com­pa­nies, give me free stuff, please?

Any­way, this is my re­view af­ter us­ing it for a cou­ple of days.

Specs

  • Ajazz Brand (not very well known)
  • Re­al Cher­ry MX Red switch­es (nice!)
  • 68 keys, ded­i­cat­ed cur­sor keys but no nu­mer­i­cal key­pad or func­tion keys.
  • Full met­al body
  • White keys, white back­light
  • Weight 600g
  • Wired or Wire­less (BT 3.0)

The Good

Typing

Typ­ing in this is pure plea­sure. I like the lin­ear red switch­es be­cause they feel al­most ex­act­ly like a Com­modore 64, which is the typ­ing feel­ing I as­so­ciate with my child­hood and ear­ly ado­les­cence, bet­ter than the tac­tile blue switch­es which I as­so­ciate with IBM mod­el M key­boards and my lat­er, not so hap­py teenage years.

The key­caps are dou­ble-shot ABS plas­tic, which I like enough. While I may have liked them to be a bit more tex­tured they are ok, not too smooth, they are not mushy, they don't jig­gle.

It's not even all that loud, while still be­ing sat­is­fy­ing­ly clack­y.

The look

I am a suck­er for how this look­s. I hate the black­-with­-red-or-rg­b-­lights gamer-key­board look (spe­cial­ly since I am not a gamer!) this ba­by has white keys on a sil­ver body with white back­light and a "naked" pro­file ex­pos­ing the switch­es.

The back­light has three lev­els (and of­f) and can do a "breathe" ef­fect and that's it. So, ba­si­cal­ly, it lets you type in the dark if you need to look at keys and not much else. Which is enough for most grownup­s.

The layout

The ded­i­cat­ed ar­row keys are nice, all the keys are in rea­son­able po­si­tions and have de­cent sizes.

The extras

It comes with a key­cap-ex­trac­tor, a USB ca­ble and a car­ry­ing pouch. Noth­ing fan­cy but more than good enough.

The Not Good

The Layout

I would love for this to have two more keys.

  • There is no Home key (Fn-End is Home) which is ... not ter­ri­ble.

  • There is no ~ key.

For a Linux user and software developer that is a pain in the butt because ~ means "home folder". For a spanish speaker it's even worse because ~n is how we type ñ which is, you know, a letter we need to use because "año" means "year" but "ano" means butthole. So it's kinda important.

In this keyboard that character is Fn+Shift+Esc which is just too awkward.

Yes, I know how to fix it!

I could remap that key to ~ but then I have no Esc key which sucks when using vim. So, I remapped Esc to Caps Lock and voilá, the keyboard is usable (but a bit weird)

# This is the easy way
xmodmap -e 'clear Lock' -e 'keycode 0x09 = dead_tilde grave'\
-e 'keycode 0x42 = Escape'

The Bluetooth

I was ex­pect­ing the blue­tooth in this key­board to suck be­cause it's BT 3.0 but I had no idea the depths and va­ri­ety of the ways in which it suck­s.

  • Yes, the range sucks
  • Yes, the la­ten­cy sucks

But al­so:

  • When in BT mode it be­haves like a com­plete­ly dif­fer­ent key­board.

In wired mode, Fn+= is F12 a key I use a lot because it drops down my terminal.

In BT mode, Fn+= is Volume up, which in wired mode is Fn+n ... which still works in BT mode.

So, in BT mode I have no func­tion keys at al­l, and have mul­ti­me­dia keys in two places.

But that's not al­l!

This keyboard supports three devices simultaneously. You switch between them using Fn+Q | W | E and there is a nice LED indicator at the top of the keyboard that shows on what mode you are in by changing color.

Here, let me show it to you:

The prob­lem is, when you are ac­tu­al­ly us­ing the key­board, this is how you (don't) see them:

So, just ig­nore that this key­board even has a BT mode and learn to love the ca­ble.

The Feet

There are no mov­able "feet", it has a small in­cline, and it's ok, the an­gle is nice. BUT... it's not per­fect­ly lev­el. There is a tiny wob­ble be­tween the low­er-right and up­per-left. Sure, I just shim a lit­tle thing in there and it's fixed, but this key­board is not very cheap so this sur­prised me.

Conclusions

It's ok? It's prob­a­bly bet­ter for peo­ple who are not span­ish-s­peak­ing lin­ux-user­s.

It´s prob­a­bly a bet­ter idea to get a more well-­known brand, and/or a cheap­er key­board if you are go­ing to gam­ble on buy­ing them sight-un­seen.

Am I hap­py I got it? yeah. Even as I am writ­ing this not-very-­com­pli­men­ta­ry re­view I am hap­pi­ly clack­ing away with a smile on my face.

The lay­out need­ed tweak­ing but is ok now, the feel is awe­some, and it looks great on my desk.


Contents © 2000-2020 Roberto Alsina