Historical Radio Mk. II

Behold the Historical Radio, Mk. II.  it will be in the ITP winter 2009 show, which means I have to upregulate this a bit.
 
 
 
tuning indicator:
 

The Innards:  I should put all this wiring on a perfboard for reliability, but it’s still a prototype
 
 
 

There were some interesting programming problems which came up in building this
  1. latching
    To get the MP3 Trigger to play, stop, and restart as intended, I had to set up a pair of ‘latches’ to (A) have it play then stop, and (B) reset when out of the tuning window.  The first latch (isPlaying) is set when the track is started.  The second latch (stopLatch) is set when the track is manually stopped, by moving out of the tuning window.  isPlaying is reset to false when the track end signal is received (the MP3 trigger transmits an ‘X’ when the track ends or ‘x’ when playing is cancelled by action (MP3 trigger receives ‘O’).

    see code samples below.

  2. C octal number declaration ‘feature’

    – as they say, "it’s not a bug, it’s an undocumented feature"  — note this is documented in the Arduino reference.

    In C, a leading 0 (zero) declares a number as an octal, and Arduino is a descendant of C, via Java, and has therefore preserved this convention.  So, when I tried sending track numbers such as Track 008, I started getting a strange error about octal constants.  What octal constants?  I’m not declaring anything as an octal … and why is it playing the wrong track? — because it’s considering it octally (base 8, 0..7) as opposed to decimally (0..9).
    A workaround will have to be figured out, and I’m sure it won’t be particularly difficult, but this was an unpleasant surprise.

Hardware issues, and words of the wise:

Wiring everything together ‘elegantly’ often ends up with a problem.  I thought I was being so slick soldering the grounds for the LED band indicators together.  Of course one of them burned out.  And now it’s a problem to replace it.  Mercifully I can just clip it out and run a separate ground for that one, but it’s a good lesson: design for disassembly, especially with prototypes.  "If something can go wrong, it will"- human factors researcher Edward A. Murphy (bet you didn’t know he was in the HF field, working with Stapp on the famous Rocket Sled!)

code samples:

void playTrack(int track)
{
  if (isPlaying == false) // check to see if a track is playing (would be true if playing)
  {  
     isPlaying = true; // set isPlaying interlock
     stopLatch = false; // open StopLatch interlock
     Serial1.print(‘t’, BYTE); // track signal
     Serial1.print(track, BYTE);
     Serial.println("playing");
  }
}

void stopTrack()
{
  if (isPlaying == true && stopLatch == false) 
  {
    do   // do-while loop tests condition at the end. 
    {
        Serial1.print(‘O’, BYTE);  // send play/stop signal to the MP3 trigger (in this case, stop signal)
        delay (20);
      Serial.print("stop signal");
      stopLatch = true; // set interlock
    }
    while (Serial1.available() > 0); // check state of serial buffer
    if (stopLatch = true)
   {
    Serial.println("stopLatch"); // print latch state to debugger
   }
 }
}

void recycle()
{
    inByte = Serial1.read();  //Serial1 for Arduino Mega
    if (inByte == ‘X’ or inByte == ‘x’)
    {
      isPlaying = false;// sets isPlaying latch open
      Serial.print("ACK ");  // for debugging purposes
      Serial.flush();
      digitalWrite(playLight, LOW); // debugging light
      delay(20); // wait state 20ms for recycle
    }
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s