Thursday, 15 October 2015

Guitar tutor - 12 frets done

A little while back, we started a project that has been a bit of a brain-itch for a while: a light-up-LED-neck guitar tutor. We got our idea working for the first 12 frets on the guitar neck and - as every good guitarist will tell you - everything on the guitar repeats from the 12th fret onwards. So every time we light up the first fret, for example, we should light up the 13th. If the 5th fret is lit, the (12+5=) 17th fret is also lit up.

This basically means that once we've got the first 12 frets working, we need to simply recreate the original design, with less space between the LEDs (since the frets get closer together the further up the neck you go).

With this in mind, we're concentrating on getting the firmware working for the first 12 frets on our guitar tutor. As it turns out, each "string" of 12 LEDs is actually made up of three sections of four LEDs in a row. So it's not really much more than a bit of bit-shifting that gets our patterns out onto the guitar neck. But because the entire fingerboard is made up from a number of sections, we had to play about with bit-shifting to get the right pattern to appear in the right section. In particular, we had to make sure everything worked properly, even when it spanned two (or more) PCB sections.



Here we're making sure that good old pentatonic box one works correctly, even when split up over two different sections of PCBs. Eagle-eyed readers will spot that it's actually the "blues" version of the pentatonic box one, with the added flatted fifth - the "blues note".

Here's a video showing how the firmware can display chords, scales and patterns, for the first 1-12 frets along the neck.



In a final version, the nasty orange wires placed over the top of the PCBs would obviously be tracks running on the reverse of a double-sided board. But for home-etching, and to simply prove the concept works, big, ugly, surface-laid wires will suffice!

For those interested, the patterns displayed are all in the key of A:

  • pentatonic box one
  • pentatonic box two 
  • pentatonic box three
  • pentatonic box four (note how the pattern "wraps around" - what appears on frets 1-4 would also appear on frets 13-16 if there were in place on the neck)
  • pentatonic box five
  • A major chord (E-shape)
  • A minor chord (E-shape)
  • A major chord (A-shape)
  • A minor chord (A-shape)
  • A major chord (C-shape barre)
  • A major chord (D-shape barre)
  • "BB King Box"
  • "Albert King Box"
  • "Clapton Box"
  • Entire pentatonic scale - all positions


The patterns then repeat, this time with the root notes (A) highlighted by flashing them at 250ms intervals. The ability to highlight "target notes" can be very useful when learning to play melodic phrases, so we might even look at highlighting other notes in the scales, such as the thirds, flatted thirds and fifths, to help us mix the major and minor sounding scales.



Wednesday, 7 October 2015

Removing a fingerboard from guitar neck

After playing about with an "electronic guitar tutor" idea, it seemed a good idea to get the design off the table and actually onto a guitar. We've a few guitar parts knocking around at Nerd Towers, including an old Marlin Explorer, and some spare guitar necks (the origins of which have been forgotten, but there are two or three old body-less guitar necks hanging around too).

Now the usual approach when it comes to removing something from something tends to be a mallet and chisel (failing that, a flat-headed screwdriver, claw hammer and a crowbar or level). This time, we thought we'd try to be a bit smart about things.

A lot of people online have reported success using a household iron, a palette knife, and lots of patience. We've got all three. Ok, two out of three - but, as Mr MeatLoaf might say, two out of three ain't bad. And an iron and a palette knife were easy enough to get hold of. In fact, the palette knife is more like a large carving knife. But it's old and blunt, so it'll do. One out of three ain't bad... ok, one out of three is pretty poor.

Anyway, whacking the iron up to full steam and  placing it directly onto the frets got us going quite quickly.


Lots of people online say you need to do this really slowly. Take your time. To get to the 12th fret (less than half way) in about an hour is considered good going. Whether it was our super-awesome Russell Hobbs iron, or just sheer brute force, we made much faster progress than that!

After the fingerboard started to lift, things slowed down a bit. It became apparent that we weren't heating the fingerboard quite so well as we did at the start.


As the fingerboard is lifted up by the knife, it curves up slightly. So placing the iron "longways" along the fretboard means it's not making contact with the board itself. No worries - just turn the iron around, to get a better contact with the frets (and the underlying board)


We left the iron in place for less than a minute, and found that our knife slid up two or three inches at a time, very easily. An hour to get halfway?! We we on track to have the whole thing done inside about ten minutes.


With a resounding "crack" the knife split the glue on the last two frets and the entire fingerboard came away, in one piece. Amazingly, there was no damage to either the fingerboard, nor the guitar neck. The fingerboard was already surprisingly flat; we clamped it to a flat surface while the wood cooled down, just in case, but it retained its shape perfectly.

Unfortunately, not everything was undamaged.
The sudden release of the fingerboard sent the knife flying off towards the headstock...

Ouch! 

Maybe these online luthiers have a point about taking your time and going slowly. Because this really hurts. And with "ferric fingers" (ferric chloride can discolour your fingernails for three or four days at a time) let's hope it doesn't get infected! With the fingerboard removed (and thumb taped up with plenty of tissue paper - there were no plasters immediately to hand) we tested the PCBs for a fit.


The LEDs line up nicely with the fret positions. The PCBs are slightly wider than the neck, so when we get to BuildBrighton tomorrow night, we'll have a go at sanding them down on the belt sander, to get them to fit the width of the neck.

Then it's just a case of bolting the neck back onto the guitar body and embedding a microcontroller (and character LCD display) into it. For a "let's see what we can do with these bits we've got left over" kind of project, it's been quite satisfying. And there's a very real danger it might come somewhere close to getting finished too. Maybe.


Monday, 5 October 2015

Guitar tutor with PIC 16F1829 microcontroller and 74HC595 shift registers

Griff Hamlin, Steve Stine and Papastache all have one thing in common. Ok, they have lots of things in common. Mostly, they're all awesome guitarists. Not just "a bit good" - but amazing. I love Griff Hamlin's way of teaching blues guitar with his Blues Guitar Unleashed course. I've even got a copy (though haven't yet gone much beyond the very basics). And, being a bit of a how-does-it-work geek, I love how well Steve Stine explains not just what notes to play, but why you should play them. And while Steve plays some great blues licks too, he's a wizard on just about any genre (his Thunder Rock Riffs looks pretty cool for example).

But for me, +papastache102 has some of the best "how to play and why you're playing it that way" video lessons on the interwebs (I also have quite a few of his DVDs). His mixing of major and minor pentatonic sounds, and targeting notes in the underlying chords is incredible. His moustache is almost as impressive as his guitar playing, and he regularly teams up with session supremo Tim Pierce (whose guitar playing is on a whole other level). But there's something about Bret Papa's playing that immediately identifies it as him. It's kind of Hendrix-y mixed in with some late 70s classic rock and even a bit of 80s stadium heavy metal. Just my kind of thing!

Anyway, enough about how great these guys are (but, honestly, they really are) and how great their lessons are (but, honestly, they really are) and more about microcontrollers and shift registers. And how they have anything to do with guitar playing anyway.

Well, over at Nerd Towers, we've a whole heap of LEDs and plenty of 595 shift registers knocking about. After creating a MIDI keyboard to learn how to play chords and scales on the piano, a guitar tutor was a project that some of us (mostly me, I admit it) were keen to make. And after watching a recent Papastache video (https://www.youtube.com/watch?v=jUycCxd_6GI) we just knew it's time had come!

Yeeaaaahhh. Welcome, welcome, welcome to the Nerd Club blog, Papastache!

The key to a lot of getting a guitar to sound "right" is to target the notes in the underlying chords. Sure you can just noodle around on a blues/pentatonic scale right over the top of a standard I-IV-V progression - but it'll only ever sound like someone noodling around with a scale over a chord progression. Maybe throw in a few "stock licks" to break it up a bit, but it's quite difficult to sound musical with just one scale under your fingertips!

Bret's video demonstrates how different scales can "attach" to different chords. And he talks a lot about mixing major and minor scales by seeing them over one another in the same place on the fretboard. Which is great. I love the theory behind it. I'm totally with Papa' all the way. Until I pick up my guitar - and then look blankly at the fretboard, as all the notes and positions fall away and I don't really even know where to start.

Which is why, with a bunch of surface mount LEDs, a handful of shift registers and an afternoon free to play about with a vat of ferric chloride, we decided it was time to start our guitar tutor in earnest.

On a very basic level, it's simply a bunch of LEDs connected to some shift registers that we can turn on and off. The firmware will need to get quite complex after that, but it's basically just a rework of the MIDI keyboard but with knobs on. The keyboard was a great "starter" project for LEDs, but it did involve a lot of wiring. This time, we're simplifying things, by making a few PCBs.



We decided to make the guitar fingerboard in sections, rather than one great big long PCB. The most obvious reason was, of course, because most of our copper clad board is 160mm x 100mm eurocard size, and our etching tank doesn't really like taking great big boards. But it also means we can build and test the "light-up-fingerboard" in sections, instead of having to build the whole thing, only to find one little bit doesn't work, and it junks the rest of the project!

Here's the top section (first four frets) with LED markers for each of the strings.


This design gets us six strings worth of markers for four frets, using three shift registers. The whole design can be repeated, but moving the LEDs closer together (vertically) and spacing them horizontally further apart for the next four frets on the guitar neck (look at a guitar fingerboard - the frets get closer together, and the neck widens as it gets closer to the guitar body).

The modular design meant we could build and test our idea in sections


And soldering up each section wasn't so daunting. Once you've done a (horizontal) row of six surface mount LEDs by hand, you're a quarter of the way through each section!



For testing, we connected wires to each section and plugged it into the breadboard testing rig. We created a single 8-bit value (starting at 0x01) and bit-shifted it left, one place every half a second. This allows us to check that every LED is working as it should, before trying to debug more complex problems in the future.



With one board out of the way, and inspired by the success, it didn't take long to create another two sections, to give us a total of 12 frets-worth of markers (as any guitar-player knows, the patterns simply repeat from the 12th fret onwards, so we'll stick at 12 for now).

Now we had to create some firmware to display chords, scales, patterns and shapes. That's not quite so easy! Because the boards were designed to be easy to create (single-sided, compact, etch-at-home) it means that the output patterns for the shift registers are not very intuitive.

We're using 32-bit values to record the positions of which LEDs we want to light up. So let's say we wanted to light up a simple C-major chord. In guitar-land, that looks like this:


So our 32-bit value for the second (A) string shown above would be 001000000000000
Similarly, the 32-bit value representing the D string would be 0100000000000
And the B string would be represented by 1000000000 (we've not included the open strings just for now, but in the final version, they'll need to be added in: we're just trying to keep things relatively simple by making the patterns match the charts in this example).

But if you watch the video above, you'll see that the first LED that lights up is not the first position on the first string. It's the fourth position/fret on the second string. Then the third (on the second string) then the second fret, then the first fret. Confusingly, the pattern doesn't repeat: it then goes to the first fret on the first string, then the second fret, third then fourth (all on the first string).

Then it skips down to the fourth fret on the fourth string (not the third), works it's way back to the first fret, before jumping up to the third string, and moving back out, from the first to the fourth fret position. This pattern repeats on the sixth and fifth strings also.

Which means, we've got to create some clever algorithms (or, if +Steve Carpenter were writing it, maybe just a bucketload of IF statements!) to turn our chord and scale patterns into "shift register" patterns, to get the right LEDs to light up at the right time.

Here's what we came up with:


Const pentatonic_box_one=1
root_fret = 1
pattern_to_show=pentatonic_box_one
Gosub load_pattern
Gosub strings_to_shift_patterns
Gosub send_shift_data

loop:
     'do nothing
Goto loop

load_pattern:
     Select Case pattern_to_show
          Case pentatonic_box_one
          string6.4B = 00001001b
          string5.4B = 00001001b
          string4.4B = 00001010b
          string3.4B = 00001010b
          string2.4B = 00001010b
          string1.4B = 00001001b
          
          If blues_as_pentatonic = 1 Then
               string2.4B = string2.4B Or 00000100b
               string5.4B = string5.4B Or 00000010b
          Endif
     EndSelect
     
     'now we've drawn these onto fret 5 (A minor for
     'pentatonic scales, E-shape chords and for A-shape
     'chords, we've already started on fret12 and
     'D-shape chords, root on fret 10) so shift these
     'along depending on the start fret required
     
     If root_fret < 5 Then
          k = 5 - root_fret 'this is how many "spaces" left we need to move the box
          string6 = ShiftLeft(string6, k)
          string5 = ShiftLeft(string5, k)
          string4 = ShiftLeft(string4, k)
          string3 = ShiftLeft(string3, k)
          string2 = ShiftLeft(string2, k)
          string1 = ShiftLeft(string1, k)
     Endif
     
     If root_fret > 5 Then
          k = root_fret - 5 'we need to move the box up k frets
          string6 = ShiftRight(string6, k)
          string5 = ShiftRight(string5, k)
          string4 = ShiftRight(string4, k)
          string3 = ShiftRight(string3, k)
          string2 = ShiftRight(string2, k)
          string1 = ShiftRight(string1, k)
     Endif
     
Return

strings_to_shift_patterns:

     'firstly, make sure that any pattern on the strings is repeated
     'up and down, beyond the 12th fret
     For i = 1 To 6
          If i = 1 Then tmp_w = string1
          If i = 2 Then tmp_w = string2
          If i = 3 Then tmp_w = string3
          If i = 4 Then tmp_w = string4
          If i = 5 Then tmp_w = string5
          If i = 6 Then tmp_w = string6
          
          tmp_w = ShiftLeft(tmp_w, 12)
          
          If i = 1 Then string1 = string1 Or tmp_w
          If i = 2 Then string2 = string2 Or tmp_w
          If i = 3 Then string3 = string3 Or tmp_w
          If i = 4 Then string4 = string4 Or tmp_w
          If i = 5 Then string5 = string5 Or tmp_w
          If i = 6 Then string6 = string6 Or tmp_w

          If i = 1 Then tmp_w = string1
          If i = 2 Then tmp_w = string2
          If i = 3 Then tmp_w = string3
          If i = 4 Then tmp_w = string4
          If i = 5 Then tmp_w = string5
          If i = 6 Then tmp_w = string6
          
          tmp_w = ShiftRight(tmp_w, 12)

          If i = 1 Then string1 = string1 Or tmp_w
          If i = 2 Then string2 = string2 Or tmp_w
          If i = 3 Then string3 = string3 Or tmp_w
          If i = 4 Then string4 = string4 Or tmp_w
          If i = 5 Then string5 = string5 Or tmp_w
          If i = 6 Then string6 = string6 Or tmp_w
     Next i
     
     'because each shift register is wired up in an weird way
     'we need to translate the strings into shift patterns
     
     'shift pattern one is first four bits of string 2 followed by
     'the first four bits of string 1 in reverse
     
     k = string2.4B And 11110000b
     k = ShiftRight(k, 4)
     j = string1.4B And 11110000b
     Gosub reverse_j
     j = ShiftLeft(j, 4)
     shift_pattern1 = k Or j

     'similarly, shift pattern two is first four bits of string 4 followed by
     'the first four bits of string 3 in reverse

     k = string4.4B And 11110000b
     k = ShiftRight(k, 4)
     j = string3.4B And 11110000b
     Gosub reverse_j
     j = ShiftLeft(j, 4)
     shift_pattern2 = k Or j

     'and shift pattern three is first four bits of String 6 followed by
     'the first four bits of string 5 in reverse

     k = string6.4B And 11110000b
     k = ShiftRight(k, 4)
     j = string5.4B And 11110000b
     Gosub reverse_j
     j = ShiftLeft(j, 4)
     shift_pattern3 = k Or j
                    
Return

reverse_j:
     Dim tmp_j As Byte
     tmp_j = 0
     If j.0 = 1 Then tmp_j.7 = 1
     If j.1 = 1 Then tmp_j.6 = 1
     If j.2 = 1 Then tmp_j.5 = 1
     If j.3 = 1 Then tmp_j.4 = 1
     If j.4 = 1 Then tmp_j.3 = 1
     If j.5 = 1 Then tmp_j.2 = 1
     If j.6 = 1 Then tmp_j.1 = 1
     If j.7 = 1 Then tmp_j.0 = 1
     j = tmp_j
Return

send_shift_data:
     
     Low shift_latch

     'Since we're sinking not sourcing current to make
     'our LEDs light up, we want to set the shift register
     'output LOW to get it to light, not high. Easiest
     'way to do this is to XOR with 0xFF to invert.
     
     For i = 1 To 3
          Select Case i
               Case 1
               k = shift_pattern1 Xor 0xff
               
               Case 2
               k = shift_pattern2 Xor 0xff

               
               Case 3
               k = shift_pattern3 Xor 0xff

          EndSelect
          
          'start with the MSB (bit 7)
          pattern = 128
          
          For j = 0 To 7
               bit_pattern = k And pattern
               If bit_pattern = 0 Then
                    Low shift_data
               Else
                    High shift_data
               Endif
               
               'toggle the clock line
               High shift_clock
               Low shift_clock
               
               'move the pattern along, to send out bit6, then 5, then 4 etc.
               pattern = ShiftRight(pattern, 1)
          Next j
     Next i
     
     'rising edge on the latch sends shift register data to the output pins
     High shift_latch
     Low shift_latch
     
Return


Amazingly, it actually works!
Here's one four-fret section showing the famous "box one" pattern of the pentatonic scale (with added "blues notes" on the flatted 5ths)



We're not done yet.
There's still plenty of coding to do, to get all the different scales, chords and patterns programmed in. But it's a very encouraging start. And hopefully it won't be too long before we can "dial in" a chord sequence, and have the guitar tutor show us which box shapes to play, where, and when........



Fixing a ferric chloride/aquarium heater - bodge warning!

We've had our aquarium heater for a while now. It's great for heating a vat of ferric chloride, prior to etching (there's a world of difference between etching "hot" and etching cold!). But every now and again it goes a bit wonky. Then, today, it stopped working altogether.


The heater itself is actually very simple. It's just a coil inside a large glass test-tube-shaped, um, tube. When in use, it sits inside the glass with a rubber bung in the top, to make it waterproof. It has a crude temperature controller on the top, which is a dial to set the temperature anywhere between about 45 and 70 degrees.

As we've had this thing for a while, it's unsurprising that the bi-metallic strip that makes up the temperature controller occasionally sticks, keeping the two contacts apart - and effectively stopping the heater from working.


We've actually repaired this particular heater before, and, at the time, jammed some extra padding in to keep the bi-metallic switch closed for longer. It looks like it's just about had enough, as the actual body of the heater is now so warped that the switch no longer closes properly.


No worries - we simply removed the bi-metallic strip and replaced it with a bit of wire, connecting the two points (the purple wire in the photo, above, is the "fix"). Now there's no temperature control at all - plug it in, and it just burns away, getting hotter and hotter!

This is a real nasty bodge. But it works. So we no longer have to wait hours and hours for a board to etch, cold. In fact, this afternoon I made a brew while the ferric was heating, answered a phone call, had a few biscuits, answered the door to the postie (yes, they only call in the afternoons, here in Hove!) and forgot that the ferric was still being heated, by an uncontrollable heating element.

Suffice to say that the ferric was rather warm when I returned to it. But it fully etched a 5" x 3.5" board in less than a minute! I'm still not sure whether this is a great hack, or a disaster just waiting to happen.