Sunday, November 3, 2013

Trinkets

OK, my parts were received from Adafruit.com, see previous post.

The USB Power Gauge works as expected, it is very handy to check the charge rate on my Cell Phone, and for checking power consumed by any USB device, including my Raspberry Pie and/or the BeagleBone computers. The USB Power Gauge provides information that is otherwise a little difficult to obtain.

I had also purchased three Adafruit Trinkets. I followed the recommended software (Ardunio IDE) install instruction, and modification needed for the Trinket. And then, I proceeded to "Brick" all three Trinkets (or at least that is what I thought). I have used the Ardunio Interactive Development Environment (IDE) many times in the past and was not expecting any problems.

Because the "Trinket" has only 512 Bytes EEPROM (boot loader ROM) part the loader (about 1.5K bytes) is placed in FLASH RAM, which leaves about 5.5K bytes for user programs.

While loading a user program into the remaining FLASH RAM, if something goes wrong, part of the boot loader can be overwritten, and therefore it is somewhat easy to "Brick" the Trinket.

Instructions are provide to "UnBrick" the Trinket, but that requires yet another Arduino and downloaded programs.

While reading many pages on the web trying to understand my problem, I discovered that for Linux machines may not support USB in the way that the Arduino IDE for the Trinket desires. The recommended method is to use a external USB Hub to connect the Trinket to a Linux computer.

It worked, . . . how or why, I do not know !!

The Trinkets were NOT actually Bricked, . . . they just looked and acted like it. While plugged into a Hub, they now respond as desired by the Arduino IDE.

My first task was, of course, to run "Blinky", the "Hello World" program.

Once that worked, I quickly put together the following CW sketch to send/blink "CQ" on the LED.


/*
  This Sketch Blinks CQ on the LED
*/
 
int led = 1; // blink 'digital' pin 1 - AKA the built in red LED

int WPM = 13; // Words Per Minute
int ditTime = 1200 / WPM;
int dahTime = ditTime * 3;

// the setup routine runs once when you press reset:
void setup() {
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);
  delay(2000);

}

// the loop routine runs over and over again forever:
void loop() {

    for(int j = 0; j < 3; j++) {
      dah(); // C
      dit();
      dah();
      dit();
      eoc();
      
      dah(); // Q
      dah();
      dit();
      dah();
      eoc();
    }
    eow();
    
    delay(10000);
}


void eoc() { // End of Charactor
    delay(ditTime * 3); // added to previous End-of-Char time
}

void eow() { // End of Word
    delay(ditTime * 7); // added to previous End-of-Char time
}

void dit() {
    cwpulse(ditTime);
}

void dah() {
    cwpulse(dahTime);
}

void cwpulse(int duration) {
    digitalWrite(led, HIGH); 
    delay(duration);
    digitalWrite(led, LOW);
    delay(ditTime);
}


// End   

A more complete and non-trivial CW sketch would be table driven, but this was quick-n-dirty just to just get something to work.

More complex and interesting programs will hopefully follow.

I think the Trinket will have a place in my bag of tricks, for small Ham Radio Projects. I am currently thinking of maybe a Beacon Trinket Shield, and/or a Tennis Ball Launcher Trigger Controller.

--

1 comment:

  1. Hi Eldon,

    I used to get really frustrated with the whole Arduino IDE / Bricked microcontroller problem, so I ended up buying an AVRISP MKII programmer ($45 or so) and have not had a single problem since. The Atmel Studio ($0) is very good and it has never bricked a microcontroller yet.

    Adafruit are great, I agree. I recently bought one of their NeoPixel RGB LED Rings and i'm currently writing some code for the ATTiny85 (the same chip as is on the trinket) to drive the leds with. I'll be blogging about that at some point in the next week or two.

    All the best.
    wardy -- wardyprojects.blogspot.com

    ReplyDelete