Using a cheap USB to Parallel adapter to controll stuff.

Whenever I have to control something I ssh into my desktop and work there, mostly because lately I turned a bit lazier (coding from the couch is really nice) and because I had to get rid of its screen for a while. Well, the hard disk is dying so I had to find a substitute till I buy a new one. Sometimes I don’t understand technology; that WD is at most three years old and smartd starts complaining. The Seagates in our router/print server/etc. have easily ten years spinning without a whine.

Enough ranting. Picked up a “Noganet” branded usb to parallel cable that was lurking in the basement. It appeared under Linux as /dev/usblp0 as expected (never saw one that really really implements a real parallel port). Trying to write to it resulted in a hang (the program was waiting for i/o) but pluggin a printer an cat’ing something resulted in a printed page. According to this page on BeyondLogic,

Centronics is an early standard for transferring data from a host to the printer. The majority of printers use this handshake. This handshake is normally implemented using a Standard Parallel Port under software control. Below is a simplified diagram of the `Centronics’ Protocol. […] Centronics Waveform Data is first applied on the Parallel Port pins 2 to 7. The host then checks to see if the printer is busy. i.e. the busy line should be low. The program then asserts the strobe, waits a minimum of 1uS, and then de-asserts the strobe. Data is normally read by the printer/peripheral on the rising edge of the strobe. The printer will indicate that it is busy processing data via the Busy line. Once the printer has accepted data, it will acknowledge the byte by a negative pulse about 5uS on the nAck line.
Quite often the host will ignore the nAck line to save time

So, I tied Busy(11) to ground and tried again. Success!!

From C everything is roses,

#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
/* not a single error check, will blow out very nice */
int main(int argc, char **argv)
{
    int fd = open("/dev/usblp0", O_WRONLY);
    char d = (char) atoi(argv[1]);
    write(fd, &d, 1);
    close(fd);
}

But not so with Python. I forgot to set the file to unbuffered, it wrote everything at once when exiting or flushing. The solution is to use something like

port = open('/dev/usblp0', 'wb', 0)

and you are all set to go.

It worked, somehow. The usb bus has a limit of 1000 packets per second, this means you can at most flip bits at that rate. It should work in other (faster) modes and allow me to read but haven’t figured yet how to do it, all I get now are non-working IOCTLS. Maybe the adapter is way cheaper than what I thought.

QOTD

”If someone is kind all the time under all circumstances, they’re just simple-minded. Kindness is only worth something if you have the cruel streak to back it up.”

Suzanne Vega.

Hace 16 años…

era un pendejo. Y hacía mis primeros pinitos en el mundo de la electrónica. Anoche mientras buscaba un trafo para una reparación de emergencia me encontré con esto (dice “Adrian 1993”):

Fuente regulada de 9V. Una de las primeras cosas que construí

Fuente regulada de 9V. Una de las primeras cosas que construí

Tecnología tercermundista, amplificador distribuidor para mezclas. Maña I

El otro dia en la radio abierta surgió que varias personas necesitaban monitorear la mezcla final y la consola solo tiene una salida de auriculares, el resto no cuenta con potencia suficiente. Previendo que se repetiría decidí construir un pequeño amplificador.

Materiales:

  • Unidad de cdrom / dvd / etc rota.
  • Cable de audio.
  • Plugs y jacks.
  • Cable usb (obtenido de un ratón roto)
  • Cartón, cinta de embalar y demás cosas de bricolage en cantidad necesaria

Antes que nada desarmar la unidad de cd/dvd y quitar la plaqueta del frente, en todas las unidades de descarte que tengo esta contiene un amplificador con su control de volumen.

Amplificador extraído de una unidad de cdrom

Amplificador extraído de una unidad de cdrom

Decidirse respecto a las conexiones necesarias. En mi caso necesitaba dos jacks amplificados y dos directos de consola.

Alimentación; normalmente hay casi tantas computadoras como personas y la placa que reciclé funciona a 5V, así que opté por usar un puerto usb para alimentarla.

Investigar un poquito como va conectada la plaqueta, decidir como montar el resto de los conectores. En mi caso contaba con algo de tiempo y fabriqué otro impreso. Como no tenía resistencias mas o menos chiquititas conecté las dos salidas de auricular en paralelo pero no es algo muy bueno que digamos.

Conexionado del amplificador

Conexionado del amplificador

Plaqueta auxiliar con los conectores

Plaqueta auxiliar con los conectores

Soldar todo, rematar con cartón y cinta transparente a gusto. Son increíble las cosas que pueden arreglarse con velcro y cinta. Próximamente hackmeetings en Utilísima Satelital…

Amplificador terminado

Amplificador terminado

Funciona bastante bien, para no estar blindado capta poco ruido de la instalación eléctrica aunque no sirve mucho (aún) para usarlo de pre con el bajo.

Remeras de Nariz Puntiaguda

Hace un ratito mientras leia los comics del miércoles (y los que hace como dos semanas no leo) me entero que en Nariz Puntiaguda van a regalar una remera entre los que la tengamos enlazada.

Ismurg, Ismurg, quiero una!!! se que hice mal en imprimirme la mia sobre blanco pero era irresistible.

En fin, quiero una! (o media, luego la coso sobre otra (que sea el lado impreso por favor))

Nueva válvula, veinte años juntando antiguedades…

Hace unos días me llegó por encomienda una rectificadora de mercurio 866. En momentos como estos me arrepiento de no haber terminado de armar el difusor para el flash ni la carpita. Todavía no tuve tiempo de probarla pero por lo menos el filamento está en buen estado, es increíble ver como el mercurio se va evaporando…

866 mercury rectifier

866 mercury rectifier

866_anodo_top

866 mercury rectifier. Anode detail

poor_mans_lightbox

poor mans lightbox. Cardboard and glass from the junkyard

Vuelven los 90!

pero si nunca se fueron… ya van dos seguidos. Ayer Explode de Cardigans en la radio y ahora sale Natalie Imbruglia en el programa de Maru Botana. Qué lindo era todo entonces

Solito…

Este jueves por primera vez me tocó estar solo en el programa de radio (no exactamente porque Marcos y José me dieron una gran mano a distancia). No fué del todo mala la experiencia, al principio estuve un poquitín nervioso pero luego me solté. Por suerte Antonio [antoniosacco.net] me ayudó muchísimo y hablamos sobre Software Libre orientado a personas con Necesidades Especiales.

El resumen del programa se encuentra en http://ovejafm.com/programa48

En el estudio de Futura con Antonio

En el estudio de Futura con Antonio

(ahora que veo como tenía el pelo solo faltaba que aparezca Disco Stu)

Fixing Amarok’s support for Wikipedia without recompiling

Some time ago Wikipedia changed its markup and because of that one of my favorites players, Amarok stopped showing the artist information. This wasn’t something that bugged me that much to take the approach suggested in tons of places:

edit contextbrowser.cpp and change:

from: m_wiki = m_wiki.mid( m_wiki.find( “<h1 class=\”firstHeading\”>” ) );
to: m_wiki = m_wiki.mid( m_wiki.find( “<h1 id=\”firstHeading\” class=\”firstHeading\”>” ));

… save, compile and you are done. Nice as pie. Isn’t the free software world wonderful? Not that this is something hard, but I didn’t feel like doing it that way.

Sooo, today I came back home a bit tired after college and work and instead of having some sleep I chose to tackle this little problem. From the code above, we see that there’s a function that takes a static string (in this context by “static” I mean something not generated at runtime), this means that we can [generally] replace the string in the binary and it should work.

Hands on!

#cd /usr/bin
#grep firstHeading amarokapp

Yuck. Nothing!

#ldd amarokapp
(...some output ommited)
libamarok.so.0 => /usr/lib/libamarok.so.0 (0xb79a1000)
#grep firstHeading /usr/lib/libamarok.so.0
Binary file libamarok.so.0 matches

There! so we have to modify libamarok.so.0
In my system libamarok.so.0 is a symlink to libamarok.so.0.0.0
This is nothing spectacular, first backup then edit

#cd /usr/lib
#cp libamarok.so.0.0.0 libamarok.so.0.0.0.orig
#hexedit libamarok.so.0.0.0

Here I used hexedit because it was at hand, any decent hex editor should do fine. Even vim works. In this case we can do this easily because the target string is shorter than the original, so we can pad the rest with zeroes (or add a single one at the end of the new string). Obligatory? screenshots:

hexedit of libamarok.so, before

hexedit of libamarok.so, before

hexedit of libamarok.so, after (bold: changed text)

hexedit of libamarok.so, after (bold: changed text)

Note: Close Amarok before saving!!

Mine quite certainly didn’t like having its library changed while running and died as if  I killed it with a -9. After running it again everything works as expected:

Amarok showing the Garbage page's

Amarok showing the Garbage page's

Regina Spektor's bio

Regina Spektor's bio

I really like what the compression artifacts did to the background, should change that later.

Whoaa, enough for tonight,  gotta sleep a bit.

Cine mudo: Nosferatu

Año 1838. En la ciudad de Wisborg viven felices el joven Hutter y su mujer Ellen, hasta que el oscuro agente inmobiliario Knock decide enviar a Hutter a Trasnsilvania para cerrar un negocio con el conde Orlok. Se trata de la venta de una finca en Wisborg, que linda con la casa de Hutter. Durante el largo camino, Hutter pernocta en una posada, donde hojea un viejo tratado sobre vampiros que encuentra en su habitación. Una vez en el castillo, es recibido por el siniestro conde, que se exita cuando el joven se corta un dedo.

Al día siguiente, Hutter amanece con dos pequeñas marcas en el cuello, que interpreta como picaduras de osquito. Una vez firmado el contrato descubre que el conde es, en realidad, un vampiro. Al verlo partir hacia su nuevo hogar, Hutter teme por Ellen…

Nosferatu - EllenNosferatu - Ellen y GatoNosferatu - Knock

Este domingo fui a ver Nosferatu, la versión de Murnau realizada en 1922, con música en vivo de La Secta. Estuvo muy bueno, me encontré con Andru y Vane (era obvio porque están en casi cualquier evento de La Secta) y antes tocó la banda de Peter en el playón (fusión muy buena de swing, jazz, bossa y algo de tango).

De a ratos la música de la peli se volvía algo monótona (saaangreeee, punch punch taaaa, saaangreee….) pero es un detalle menor.

Dia de paz…

Tengo quichicentos millones de cosas buenas y malas para contar en el tintero virtual, pero  hoy a pesar de estar a las corridas pude sentarme un rato en Plaza Belgrano, tomar solcito y navegar un ratito gracias a alguien que deja su conexión abierta. Por media hora estuve tranquilo, al margen de todo y me sentí casi un flogger…

Plaza Belgrano, La Plata

Plaza Belgrano, La Plata

fracaso de flogger

fracaso de flogger