Welcome to the N1IR Electronics Website. Totally off the cuff, one take, unrehearsed video projects for anyone interested in amateur radio, electronic design, makers, hardware hackers and science.


Get off you duff and build something!
Training the hand and mind since 1982.

Saturday, July 13, 2013

ATTIny85 Basic Combo Lock

Today I made a simple 4 button combo lock of a shed, I would like to thank Tanner Ewing for the original code. I've changed it to work on a ATTINY85 and eliminated the kill switch, a reset switch is optional for a 5th button but I wanted to make this as minimal as possible. With a little bit more code you can put a retry limit and lock it out for x amount of time after so many retries. Also you can extend the number of button pushes or even have double taps to make the combo more complex. I also can open the shed with a key so if there is an issue with power I can still get in.





ATTIny85 Basic Combo Lock


ATTIny85 Basic Combo Lock Code:
*************************************************************
 EXAMPLE 1
/*
Basic Combo Lock password 1234

N1IR - Chris Johnson
email: n1ir@arrl.net

Arduino 1.0 IDE using ATTINY85
http://hlt.media.mit.edu/?p=1695

Pin 1 = RESET  Pin 8 = VCC
Pin 2 = PB3    Pin 7 = PB2
Pin 3 = PB4    Pin 6 = PB1
Pin 4 = Gnd    Pin 5 = PB0

Work Cited
http://www.electronics123.com/s.nl/it.I/id.30/.f

*/

// set pin numbers:
const int buttonPin1 = 0; // Pin 5 = PB0
const int buttonPin2 = 1; // Pin 6 = PB1
const int buttonPin3 = 2; // Pin 7 = PB2
const int buttonPin4 = 3; // Pin 2 = PB3
const int RelayPin =  4;  // Pin 3 = PB4

// variables will change:
int buttonState1 = 0;         // variable for reading the pushbutton status
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int combCheckSum = 0;

void setup() {
 
  pinMode(RelayPin, OUTPUT);  // initialize the LED pin as an output:   
  pinMode(buttonPin1, INPUT); // initialize the pushbutton pin as an input:
  pinMode(buttonPin2, INPUT);
  pinMode(buttonPin3, INPUT);
  pinMode(buttonPin4, INPUT);
  // initialize the pushbutton pin as an input:
}

void loop(){
  // read the state of the pushbutton value:
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);
  buttonState3 = digitalRead(buttonPin3);
  buttonState4 = digitalRead(buttonPin4);

 if (buttonState1 == LOW) {    // check if the 1st pushbutton is pressed
     combCheckSum = 1000;}     // if all statements are true make the checksum 1000

 if (buttonState2 == LOW) {    // check if the 2nd pushbutton is pressed
 if (buttonState1 == HIGH) {   // check if the 1st pushbutton is released
    
 if (combCheckSum == 1000) {   // check previous checksum
     combCheckSum = 1100;      // if all statements are true make the checksum 1100
 }
 }

else {
   combCheckSum = 0;          // If 1st and 2nd push button is not the corect one restart loop
 }
 }

 if (buttonState3 == LOW) {    // check if the 3rd pushbutton is pressed
 if (buttonState2 == HIGH) {   // check if the 2nd pushbutton is released
 if (combCheckSum == 1100) {   // check previous checksum
     combCheckSum = 1110;      // if all statements are true make the checksum 1110


}

else {
   combCheckSum = 0;          // If 3rd push button is not the corect one restart loop
}
}

if (buttonState4 == LOW) {    // check if the 4th pushbutton is pressed
if (buttonState3 == HIGH) {   // check if the 3rd pushbutton is released
if (combCheckSum == 1110) {   // check previous checksum
    combCheckSum = 1111;      // if all statements are true make the checksum 1111
}
}
else {
   combCheckSum = 0;          // If 4th push button is not the corect one restart loop
}
}

 //unlock the door.

 if (combCheckSum == 1111) {
   digitalWrite(RelayPin, HIGH);
   delay(3000);
   digitalWrite(RelayPin, LOW);
   combCheckSum = 0;
 }
}

*************************************************************
 EXAMPLE 2


/*
Basic Combo Lock password 2413

N1IR - Chris Johnson
email: n1ir@arrl.net

Arduino 1.0 IDE using ATTINY85
http://hlt.media.mit.edu/?p=1695

Pin 1 = RESET  Pin 8 = VCC
Pin 2 = PB3    Pin 7 = PB2
Pin 3 = PB4    Pin 6 = PB1
Pin 4 = Gnd    Pin 5 = PB0

Work Cited
http://www.electronics123.com/s.nl/it.I/id.30/.f

*/

// set pin numbers:
const int buttonPin1 = 0; // Pin 5 = PB0
const int buttonPin2 = 1; // Pin 6 = PB1
const int buttonPin3 = 2; // Pin 7 = PB2
const int buttonPin4 = 3; // Pin 2 = PB3
const int RelayPin =  4;  // Pin 3 = PB4

// variables will change:
int buttonState1 = 0;         // variable for reading the pushbutton status
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int combCheckSum = 0;

void setup() {
 
  pinMode(RelayPin, OUTPUT);  // initialize the LED pin as an output:   
  pinMode(buttonPin1, INPUT); // initialize the pushbutton pin as an input:
  pinMode(buttonPin2, INPUT);
  pinMode(buttonPin3, INPUT);
  pinMode(buttonPin4, INPUT);
  // initialize the pushbutton pin as an input:
}

void loop(){
  // read the state of the pushbutton value:
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);
  buttonState3 = digitalRead(buttonPin3);
  buttonState4 = digitalRead(buttonPin4);

 if (buttonState2 == LOW) {    // check if the 1st pushbutton is pressed
     combCheckSum = 1000;}     // if all statements are true make the checksum 1000

 if (buttonState4 == LOW) {    // check if the 2nd pushbutton is pressed
 if (buttonState2 == HIGH) {   // check if the 1st pushbutton is released
    
 if (combCheckSum == 1000) {   // check previous checksum
     combCheckSum = 1100;      // if all statements are true make the checksum 1100
 }
 }

else {
   combCheckSum = 0;          // If 1st and 2nd push button is not the corect one restart loop
 }
 }

 if (buttonState1 == LOW) {    // check if the 3rd pushbutton is pressed
 if (buttonState4 == HIGH) {   // check if the 2nd pushbutton is released
 if (combCheckSum == 1100) {   // check previous checksum
     combCheckSum = 1110;      // if all statements are true make the checksum 1110


}

else {
   combCheckSum = 0;          // If 3rd push button is not the corect one restart loop
}
}

if (buttonState3 == LOW) {    // check if the 4th pushbutton is pressed
if (buttonState1 == HIGH) {   // check if the 3rd pushbutton is released
if (combCheckSum == 1110) {   // check previous checksum
    combCheckSum = 1111;      // if all statements are true make the checksum 1111
}
}
else {
   combCheckSum = 0;          // If 4th push button is not the corect one restart loop
}
}

 //unlock the door.

 if (combCheckSum == 1111) {
   digitalWrite(RelayPin, HIGH);
   delay(3000);
   digitalWrite(RelayPin, LOW);
   combCheckSum = 0;
 }
}

Friday, July 12, 2013

Chitty Chitty Bit Bang - Bit Banging ATTiny 85 using Ubuntu and RS232

Bit Banging ATTiny 85 using Ubuntu and RS232

*****update this will work with the USB to RS232 converter*****
 just subututue ttyS0 with ttyUSB0

$ sudo avrdude -p t85 -c dasa -P /dev/ttyUSB0


Video Notes:

Read ATTINY 85, make sure connections are okay:

$ sudo avrdude -p t85 -c dasa -P /dev/ttyS0


ATtiny support in Arduino software ATTINY MASTER.zip


Modified DASA Programmer

 Make sure your RS-232 outputs 5V if using this programmer!!






Sunday, July 7, 2013

Police Style Strobe Light ATTiny85

Here is a new project for the freshmen it's a police style strobe light, you know the ones the flash three times then flash the other side three time and back and forth. I used the Arduino IDE to program and compile, I also used High-Low Tech Hardware file add-on and finally a stripped version (just resistors, took out the zeners) of the serial programmer DASA and the add-on for DASA to the Arduino software.





here is the code:

/*

Police Style Strobe Light

N1IR - Chris Johnson
email: n1ir@arrl.net

Arduino 1.0 IDE using ATTINY85
http://hlt.media.mit.edu/?p=1695

Pin 1 = RESET  Pin 8 = VCC
Pin 2 = PB3    Pin 7 = PB2
Pin 3 = PB4    Pin 6 = PB1
Pin 4 = Gnd    Pin 5 = PB0

*/

int led1 = 2; //delcare PB3 as led1
int led2 = 3; //declare PB4 as led2
int del = 500; //delay time in mS


void setup() {               
  pinMode(led1, OUTPUT); //Set led1 "PB3" to output   
  pinMode(led2, OUTPUT); //Set led2 "PB4" to output
}

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

//Flash led1 three times 
 digitalWrite(led1, HIGH);  //Turn on led1 
 delay(del);                //Delay x amount of time
 digitalWrite(led1, LOW);   //Turn off led1
 delay(del);
 
 digitalWrite(led1, HIGH); 
 delay(del);
 digitalWrite(led1, LOW); 
 delay(del);

 digitalWrite(led1, HIGH);  dasa
 delay(del);
 digitalWrite(led1, LOW); 
 delay(del);
// End flash led1 three times

 delay(del); // Pause betwwen led1 and led2

 //Flash led2 three times
 digitalWrite(led2, HIGH); 
 delay(del);
 digitalWrite(led2, LOW); 
 delay(del);

 digitalWrite(led2, HIGH); 
 delay(del);
 digitalWrite(led2, LOW); 
 delay(del);

 digitalWrite(led2, HIGH); 
 delay(del);
 digitalWrite(led2, LOW); 
 delay(del);
// End flash led2 three times
}

Programming an ATtiny w/ Arduino 1.0 from High-Low Tech Group at MIT

This tutorial shows you how to program an ATtiny45, ATtiny85, ATtiny44 or ATtiny84 microcontroller using the Arduino software. These are small, cheap ($2-3) microcontrollers that are convenient for running simple programs. The ATtiny45 and ATtiny85 have eight legs and are almost identical, except that the ATtiny85 has twice the memory of the ATtiny45 and can therefore hold more complex programs. The ATtiny44 and ATtiny84 have 14-legs and more inputs and outputs. Thanks to Mark Sproul for his work on making the Arduino core portable across processors.

ATtiny45/85 vs. an Arduino Board

The ATtiny45 or 85 is a great option for running simple Arduino programs: it’s small, cheap and relatively easy to use. It does, however, have some limitations relative to the ATmega328P on an Arduino Uno. There are fewer pins, meaning you can’t connect as many components. There’s less flash memory (4KB or 8KB instead of 32KB), meaning your programs can’t be as big. There’s less RAM (256 or 512 bytes instead of 2KB), meaning you can’t store as much data. And there’s no hardware serial port or I2C port (Wire library), making communication trickier. (There are workarounds, like the SoftwareSerial library or the TinyWire library, but they’re not as robust and flexible.)
In short, then, if your project requires only a few simple inputs and/or outputs, you’re probably fine using an ATtiny. If you’re trying to hook up more components or do more complex communication or data processing, though, you’re probably better off with something like the ATmega328P on an Arduino Uno. If you want something smaller and cheaper than a full Arduino board, you might try using an ATmega328P on a breadboard instead.

Materials and Tools

For this tutorial, you’ll need:
  • An in-system programmer (ISP), a piece of hardware used to load programs onto the ATtiny. Options include:
  • ATtiny45 or ATtiny85 (8-pin DIP package) or an ATtiny44 or ATtiny84.
  • a solderless breadboard and jumper wires (unless you’re using the TinyProgrammer w/ the ATtiny45 or 85)
For more information, see our list of materials and parts and our list of prototyping supplies.

Download

Installing ATtiny support in Arduino

  • If you haven’t already, download the Arduino software, version 1.0.4 (1.0.3 and 1.0.1 should work too, but not 1.0.2). Install the Arduino software, following the instructions for Windows or for Mac OS X.
  • Download the ATiny master.zip file from the link above.
  • Unzip the attiny master.zip file. It should contain an “attiny-master” folder that contains an “attiny” folder.
  • Locate your Arduino sketchbook folder (you can find its location in the preferences dialog in the Arduino software)
  • Create a new sub-folder called “hardware” in the sketchbook folder, if it doesn’t exist already.
  • Copy the “attiny” folder (not the attiny-master folder) from the unzipped ATtiny master.zip to the “hardware” folder. You should end up with folder structure like Documents > Arduino > hardware > attiny that contains the file boards.txt and another folder called variants.
  • Restart the Arduino development environment.
  • You should see ATtiny entries in the Tools > Board menu.

Connecting the ATtiny

You’ll need to provide power to the ATtiny and connect it to your programmer. That is, connecting MISO, MOSI, SCK, RESET, VCC, and GND of the programmer to the corresponding pins on the ATtiny. (Or, if you’re using an circuit w/ an ATtiny, simply connect the programmer to the ISP header on the board – you may also need to power the board separately.)
Instructions and diagrams are available for:

Programming the ATtiny

Next, we can use the Arduino as an ISP to upload a program to the ATtiny:
  • Open the Blink sketch from the examples menu.
  • Change the pin numbers from 13 to 0.
  • Select the appropriate item from the Tools > Board menu (leave the serial port set to that of your Arduino board).
  • Select the appropriate item from the Tools > Programmer menu (e.g. “Arduino as ISP” if you’re using an Arduino board as the programmer, USBtinyISP for the USBtinyISP, FabISP, or TinyProgrammer, etc).
  • Upload the sketch.
You should see “Done uploading.” in the Arduino software and no error messages. If you then connect an LED between pin 0 and ground, you should see it blink on and off. Note that you may need to disconnect the LED before uploading a new program.

Configuring the ATtiny to run at 8 MHz (for SoftwareSerial support)

By default, the ATtiny’s run at 1 MHz (the setting used by the unmodified “ATtiny45″, etc. board menu items). You need to do an extra step to configure the microcontroller to run at 8 MHz – necessary for use of the SoftwareSerial library. Once you have the microcontroller connected, select the appropriate item from the Boards menu (e.g. “ATtiny45 (8 MHz)”). Then, run the “Burn Bootloader” command from the Tools menu. This configures the fuse bits of the microcontroller so it runs at 8 MHz. Note that the fuse bits keep their value until you explicitly change them, so you’ll only need to do this step once for each microcontroller. (Note this doesn’t actually burn a bootloader onto the board; you’ll still need to upload new programs using an external programmer.)

ATtiny Microcontroller Pin-Outs



Reference

The following Arduino commands should be supported:

Suggestions and Bug Reports

To report problems or suggest changes to the ATtiny support, please use the issues list on GitHub.

References

Alternative: ATmega328P on a Breadboard

If the ATtiny isn’t quite powerful enough but you still want to use a bare microcontroller instead of a full Arduino board, see this tutorial on using an ATmega328P on a breadboard. It allows you to use all the same functions and libraries as the Arduino Uno, but with just a microcontroller and a few small components.