Sunday, February 16, 2014

RPi programming troubles

So, a lot of progress has been made on the RPi front, though none of it good!

Setting up the I2C to be automatic, using a startup script:
http://www.stuffaboutcode.com/2012/06/raspberry-pi-run-program-at-start-up.html

GPIO code:
https://code.google.com/p/raspberry-gpio-python/wiki/Inputs


For some reason, PureData refuses to recognize the USB sound card and crashes every time. The sound card works when I play a sound clip in the terminal with aplay. Since the prospect of programming logic in PD is daunting at best and nightmarish at worse, I've decided to just go with python since all the code exists for it already. In python I've successfully programmed a key scan program to read all the GPIO buttons and report which buttons have been pressed on the I2C LCD.

HOWEVER. VNC viewer will not play nice with pygame! And so far pygame is the best candidate for sound manipulation with python. I'm not liking python anyways. Maybe its time to switch to Java? I'll have to learn I2C in Java because I won't have the sample code to rely on.

Saturday, January 18, 2014

Autotrigger 555 circuit for the Casio SK1!

The Casio SK1 has 3 voices which can be independently programmed and played together with a "auto play" button. By somehow triggering the auto play button rhythmically, then, we can create loops! The idea came from Casper's SK1 page (http://casperelectronics.com/finished-pieces/casper-sk-1/).

What we need is an extended-duty astable circuit, as seen here: (http://www.doctronics.co.uk/555.htm#more_astables)
Calculations: Because I needed the circuit to trigger for loops, I need the timer to go off between 2 and 15 seconds. Any shorter or longer than that is not really useful for me. I also know that the POTs I can buy go up to 500K, and any larger than that would be expensive custom parts. That still leaves you with one degree of freedom, a relation between R1 and C. Looking at the available parts at the store, I determined R1 to be 5K, R2 to be a 500K pot, and C to be 33uF.
Using the falstad circuit simulator (http://www.falstad.com/circuit/), it works! The on time is about 250ms, and the off time goes up to about 15-20 seconds.


The idea is to use the 555 timer's output current to electronically spoof a press of the 'auto play' button. The buttons on the SK1 are scanned by the CPU: merely finding one of the two wires corresponding to the auto play button on the PCB and dumping current into it is not enough, the leads have to be connected at the exact time that the key is being scanned. We need a switch that puts current into the sensor line of the key only when both the 555 timer and the output line of the key are both simultaneously active.

At the time of original writing, I had some MPF-102s handy from the contact mic, so I used those thinking that it would be the same. It didn't work. I then used a power mosfet, which didn't work either because the SK1's button scan did not put enough voltage to fully flip the mosfet to either an on or off position. That was a diagnostic headache. Finally I came across a blog of a contemporary doing similar SK1 stuff who used a NPN (http://www.electronicmusing.com/blog/2014/01/casio-sk-1-overhaul-part-two/#more-435), so in the end I had to go with an NPN bipolar junction transistor and it finally worked! A red LED with a ballasting 1k resistor in parallel with the transistor on the 555 circuit serves as an indicator light.

Linear or Log pot? Using my new breadboard, turns out the linear taper gives me better control of the cycle time.

I am using a CMOS 555 chip, a PA 7555. Why CMOS? The LM555 was built in the 70s and draws dozens of mAs, which is way too much to run on batteries. The entire circuit above takes a bit less than 2mA to run. This current is drawn from the mic circuit of the SK1: off the proximal end of R113, VC on the schematics, and using the mic jack's ground trace as the ground (VL1). The timer itself resides on a piece of perfboard wedged under the mic.



Results
The looping function does everything thought it would! It now repeatedly plays back programmed key sequences quite well. The accuracy of the timing requires very fine adjustments of the knob but it is reliable enough once it warms up after going through a couple cycles. Some outstanding issues: 1) a bit of added noise from the wire that connects the 555 output to the key spoofing transistor is audible when I switch on my line-in pass-through mod, 2) the pot for the timer knob is occasionally unpredictable, 3) when the auto-play button is triggered, any sustained notes being played stop.

Video of the looping sk1 in action to come soon! It's quite fun to play with!