Loading...
  Show Posts
Pages: 1 [2] 3
16  Using Arduino / Programming Questions / Code works on ATtiny84, but not ATtiny44A on: November 19, 2012, 12:21:54 am
The ATtiny44 and 84 are both pin-compatible, and as far as I know, just the same microcontroller but with different EEPROM and flash memory sizes.

However, for some reason, my code here for this Simon Says game (see bottom of post) only works on an ATtiny84, not an ATtiny44A. At first I thought it was a voltage issue. I'm only using 2 AA batteries, and I was using an ATtiny84V, which requires less voltage according to the datasheet. However, I tried it on a regular ATtiny84 (which should require the same amount of voltage an ATtiny44A does) and it worked just fine.

I'm kind of stumped on this one. Can anyone think of why the code won't work? I'm running them at 8MHz, internal oscillators. When I use the ATtiny84, everything works right - the startup sound plays, and then the light sequence flashes. When I use the ATtiny44A, no startup sound plays, no light sequence flashes. Here's a video of how it works with the ATtiny84:




My code is here:

Code:
/*
 Application Name: Simon Says Game Kit
 Description: A simple game of Simon Says.
 Author: Jeff Murchison
 Contact: jeff@jeffmurchison.com
 Date: November 15, 2012
 Version: 1.0
 License:
 
 This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
 http://creativecommons.org/licenses/by-nc-sa/3.0/
 
 To purchase a kit, please visit:
 http://jeffmurchison.com/blog/simon-says-game-kit/
 
 Notes:
 
 This code uses cores from the arduino-tiny project, and is designed for use on an ATtiny84.
 For more information and to download the cores, visit the arduino-tiny Google Code page:
 http://code.google.com/p/arduino-tiny/
 
 */


#include <EEPROM.h>   // We're going to be writing some stuff to the microcontroller's EEPROM

int buzzerPin = 2;  // The buzzer pin
int buttonPin[] = {
  0, 7, 8, 9, 10}; // The four button input pins
int ledPin[] = {
  0, 3, 4, 5, 6};  // LED pins
int buzzerTone[] = {
  50, 200, 400, 600, 800};  // Buzzer Tones for the different buttons (fail, 1, 2, 3, 4)

int turnCount = 1;  // Turn counter
int buttonState = 0;  // Button state checker

const int maxTurns = 100; // The maximum number of random numbers that will be generated.
int randomArray[maxTurns]; // Array that will store the random numbers for the game
int inputArray[maxTurns];  // Array that will store user input

int eepromValue = 0;

boolean playedThisTurn = false;  // Boolean variable for if the sequence has been played already
boolean buttonPressed = false; // Boolean variable for f a button has been pressed



void setup()
{
  //Serial.begin(9600);  // Serial is commented out as the ATtiny doesn't support it. Useful for debugging on an ATmega328.

  pinMode(buzzerPin, OUTPUT);  // Set the buzzer to output

  for(int x=1; x <= 4; x++) {  // Set pinmodes for button, LED pins, set LEDs HIGH (off)
    pinMode(ledPin[x], OUTPUT);
    digitalWrite(ledPin[x], HIGH);
    pinMode(buttonPin[x], INPUT);
  }
  //Serial.print("---------");
  //Serial.println("");
  randomArrayGen();
  //Serial.print("Random Array Generated.");
}


void loop()
{
  eepromValue = EEPROM.read(0);
  if ((eepromValue + turnCount) >= 255) {   // EEPROM bytes can only hold a value from 0 to 255. This ensures we don't overflow.
    EEPROM.write(0, turnCount);
  }
  else {
    EEPROM.write(0, (turnCount + eepromValue)); // Add the turncount to EEPROM value 0. We use this for random seed.
  }
  if (playedThisTurn == false) {  // If the player hasn't pushed a button this turn yet, then..
    //Serial.println("");
    //Serial.println("");
    //Serial.print("Turn:");
    //Serial.print(turnCount);
    //Serial.println("");
    //Serial.println("Playing Array");
    //Serial.println("---------");
    playedThisTurn = true;  

    for (int x=1; x <= turnCount; x++) {  // Play all of the moves in the random array at the beginning of each turn
      LEDandTone(ledPin[randomArray[x]], buzzerTone[randomArray[x]]);
      //Serial.println(randomArray[x]);
    }
    //Serial.println("---------");
  }

  for (int z=1; z <= turnCount; z++){
    //Serial.println("");
    //Serial.println("");
    //Serial.print("inputNumber: ");
    //Serial.print(z);
    buttonCheck(z);
    buttonPressed = false;
  }
  turnCount++;
  delay(500);
}


void randomArrayGen ()  // Function for generating the random array
{
  randomSeed(EEPROM.read(0));
  for (int x=1; x < maxTurns; x++) {
    randomArray[x] = random(1, 5);
    //Serial.println(randomArray[x]);
  }
  for (int t=600; t <= 1000; t=t+7){
    tone(buzzerPin, t);
    delay(20);
    noTone(buzzerPin);
    delay(10);
  }
  delay(500);
}

void LEDandTone(int ledPin2, int buzzerTone2)
{
  tone(buzzerPin, buzzerTone2);  
  digitalWrite(ledPin2, LOW);
  delay(400);
  digitalWrite(ledPin2, HIGH);
  noTone(buzzerPin);
  delay(100);
}


void buttonCheck(int inputNumber)  //Function for allowing user input and checking input against the generated array
{
  while (buttonPressed == false){  // As long as a button has not been pressed this turn, keep checking button inputs
    for(int y=1; y <= 4; y++) {
      buttonState = digitalRead(buttonPin[y]);
      if (buttonState == HIGH) { //Checking for button push

        //Serial.println("");
        //Serial.print("Button Pressed: ");
        //Serial.print(y);
        //Serial.println("");

        LEDandTone(ledPin[y], buzzerTone[y]);
        inputArray[inputNumber] = y;

        playedThisTurn = false;
        buttonPressed = true;
        y = 5;

        if (inputArray[inputNumber] == randomArray[inputNumber]) { //Checks value input by user and checks it against
          //Serial.print("CORRECT!");
          //Serial.println("");                
        }                                    
        else {
          //Serial.print("INCORRECT");
          //Serial.println("");
          //Serial.println("");
          //Serial.println("------- DEBUG INFO -------");
          //Serial.println("");
          //Serial.print("inputArray[inputNumber]: ");
          //Serial.print(inputArray[inputNumber]);
          //Serial.println("");
          //Serial.print("randomArray[inputNumber]: ");
          //Serial.print(randomArray[inputNumber]);
          //Serial.println("");
          //Serial.print("[inputNumber]: ");
          //Serial.print(inputNumber);
          //Serial.println("");
          //Serial.print("turnCount: ");
          //Serial.print(turnCount);
          //Serial.println("");
          fail();  
        }
      }
      /*if (buttonPressed == true){
       Serial.println("Exiting buttonState loop.");
       }*/
    }
    /*if (buttonPressed == true){
     //Serial.println("Exiting for loop.");
     }*/
  }
  //Serial.print("Exiting while loop, inputNumber should increment after this");
  delay(200);
}


void fail()  //Function used if the player fails to match the sequence
{
  tone(buzzerPin, 50);
  for (int x=1; x <= 4; x++){
    digitalWrite(ledPin[x], LOW);
  }
  delay(2000);
  //EEPROM.write(0, turnCount+(EEPROM.read(0)));
  turnCount = 1; //Resets turn value so the game starts over without need for a reset button
  for (int x=1; x <= 4; x++){
    digitalWrite(ledPin[x], HIGH);
  }
  noTone(buzzerPin);
  delay(1500);
  randomArrayGen();
}
17  Topics / Product Design / Re: Extra long headers for shields? on: November 13, 2012, 04:33:10 pm
Those ones are still only 10.5mm long. Actually, this is where I get the majority of my components, they're cheaper than almost everywhere else.

I ended up revising my design to not go over the USB or power jacks on the board, so I have no problem with using the shorter headers now.
18  Topics / Product Design / Re: Itead, Members with Experience... on: November 13, 2012, 04:24:14 pm
I've ordered a lot of boards from iTead, and the turnaround is typically a week. Shipping to me (Toronto) is about 2 weeks using the regular shipping option, or 3 days using DHL expedited.

The quality has always been pretty great, and their customer service is very nice. Also, sometimes you get extra of your own boards if someone else decided to open-source their project and your boards were grouped together. At least, that's what I think is the reason I sometimes get 11 or 12 boards instead of 10.
19  Community / Products and Services / Re: Great PCB House for Prototyping on: November 05, 2012, 11:54:14 am
So if I ordered from itead a 25mm x 50mm design, but under the 50mm x 50mm ordering code, would I received just 10 pcb's and effectively waste half the order, or would they supply twice as much, ie 20 pcbs?
No, you would get 10 PCBs. If you want to get 20, you would either double-up or add another 10 PCBs to your order. If you want to cut them, invest in a scroll saw or a dremel. I just cut some of mine this past weekend and had no problem with the scroll saw.
20  Community / Products and Services / ArduinoISP Deluxe Shield - easily program attiny + atmega microcontrollers on: October 27, 2012, 05:59:36 pm
I just got in the latest version of my ArduinoISP Deluxe Shield. I designed this shield to easily program microcontrollers using the ArduinoISP sketch and an Arduino. The latest version supports the following microcontrollers:

- ATtiny13
- ATtiny24/44/84
- ATtiny25/45/85
- ATtiny2313/4313
- ATmega168/328

And it should also work with any other microcontroller that is pin-compatible with one of those listed (like the ATtiny13, and ATmega8/48/88).

It's very easy to use and is really helpful if you like using bare AVR microcontrollers in your projects like I do. If you'd like to learn more about it, you can check out this blog post. If you'd like a shield for yourself, then I'm selling them over at Tindie.

Here are some pics of it (click for full res):







21  Using Arduino / Project Guidance / Re: MAX7219 and resistors for 7-segment displays on: September 26, 2012, 10:04:18 pm
Actually I've got one more question for someone. The datasheet recommends a 0.1uF ceramic and 10uF electrolytic decoupling capacitors between GND and V+. If I'm using two MAX7219s, can I use one set of capacitors, or should I use two sets?
22  Using Arduino / Project Guidance / Re: MAX7219 and resistors for 7-segment displays on: September 25, 2012, 10:17:01 pm
The 30mA is max continuous current and 90mA is a peak current when the display is multiplexed, note the "1/10 duty cycle, 0.1ms pulse width" meaning it would be on for 0.1ms then off for 0.9ms in a multiplexed setup.

That's what I thought, just wanted to make sure! Thanks for your help.
23  Using Arduino / Project Guidance / Re: MAX7219 and resistors for 7-segment displays on: September 25, 2012, 06:14:15 pm
BTW, absolute maximum ratings are to be avoided. The rated typical segment drive current is 40mA, but the minimum is 30mA, so that is what should be designed for.

I was checking out the LEDcontrol library last night and it seems like a good library to use. Also, I'm aware that I'd probably burn it out at the absolute max rating. I just listed those ratings because they were what jumped out at me.

I was unaware, however, of the 30mA minimum. I was planning on using these 7-segment displays, however I'm not sure about something from the datasheet:



(I want to use the green ones).

Will this display be ok to use? I believe the 90mA peak forward current means that I can safely put 40mA to it for a very short period of time, like the MAX7219 would as it cycles the digits on/off.
24  Using Arduino / Project Guidance / Re: MAX7219 and resistors for 7-segment displays on: September 25, 2012, 03:33:35 pm
And if you wire them in parallel without current limiting resistors, there is nothing to assure that the current is divided equally between them.

Alright thanks, that seems like it might be an issue. I have a whole couple of 7219s at my disposal so I think I might as well go with two drivers. That means more complicated code, but really it shouldn't be that bad.

Quote
Page 10 of the data sheet:
Quote
Selecting RSET Resistor and
Using External Drivers

The current per segment is approximately 100 times
the current in ISET. To select RSET, see Table 11....
.

I was a bit confused by RSET at first, I'm not sure how I missed it. Also the graph on page 4 seems to answer my other question about getting segments down to 10 or 20mA.

So now if all the segments are being properly connected to the drivers (instead of being wired in parallel like I proposed), and I have the appropriate RSET resister between ISET and V+, I should be fine without any more current-limiting resistors, right?
25  Using Arduino / Project Guidance / MAX7219 and resistors for 7-segment displays on: September 25, 2012, 01:54:39 pm
I'm trying to figure out how many resistors I need for my project, and where in line to put them. I'm using a MAX7219 to drive sixteen 7-segment common-cathode displays for a scoreboard. Yes, I know that the 7219 only actually supports 8 digits, so let me clarify.

The scoreboard has 4 sides. Each side has 4 digits; 2 for each player's score. Since I only need 4 unique digits, the other 12 displays (3 faces x 4 digits) are wired in parallel with the appropriate digit.

Now, assuming I want to have each segment running at 10mA, that makes a maximum current draw for 1 unique digit 280mA (7 segments x 4 displays x 10mA [not including DP since I don't use it]). Total, that means if all the segments on all the displays were lit up at the same time, it would draw 1.12A.

However, something occurred to me. The digits wouldn't actually be on at the same time because of how the MAX7219 works, right? It cycles the digits on/off very fast so they appear to all be on at the same time, but they aren't. Technically only 1 unique digit (in other words, 4 displays) would be on at a time, meaning that if all the displays were on "at the same time", they would actually only draw a maximum of 280mA total. This means that I could just put my resistors on the SEG pins of the MAX7219. This also means that I only need 7 resistors for the whole lot of displays, instead of 7 resistors for each of the displays, right?

Another thing caught my eye though. In the MAX7219 datasheet, it says that the resistor between the ISET and V+ pins is for controlling the display brightness. Does this mean that with that single resistor between ISET and V+, I don't even need those 7 resistors on the SEG pins?

Also, the datasheet says that a 10K resistor will limit the current on each SEG pin to about 40mA, what value resistor would be required to get that down to 10 or 20mA?

Bonus question: In the datasheet for the MAX7219, it says the following under the absolute maximum section:

Quote
Current
DIG 0–DIG 7 Sink Current..............................................500mA
SEG A–G, DP Source Current........................................100mA

Does that mean 500 / 100mA per pin, or in total?
26  Using Arduino / Programming Questions / Re: Can't upload code to ATmega328P after using ArduinoISP to burn bootloader+sketch on: August 01, 2012, 09:39:26 pm
If you had two arduinos as pictured above, why not just connect USB cable to the 2nd Uno & download sketch directly?

The two-arduino setup was just me troubleshooting. I initially noticed the problem when I used my ArduinoISP shield to burn the bootloader and upload a sketch to an ATmega328P. After doing that and putting the ATmega328P back into an UNO I couldn't upload any more sketches to it, so I wanted to verify that this wasn't a problem with my shield.
27  Using Arduino / Programming Questions / Re: Can't upload code to ATmega328P after using ArduinoISP to burn bootloader+sketch on: August 01, 2012, 08:49:12 pm
That makes sense. Am I right in assuming that there's no way to upload the code "normally" using the Arduino as an ISP?
28  Using Arduino / Programming Questions / Can't upload code to ATmega328P after using ArduinoISP to burn bootloader+sketch on: August 01, 2012, 08:09:20 pm
I'm wondering if anyone can explain what's going on here and possibly find a solution. It's a little hard to explain so I'll just start by explaining how to reproduce the problem.

To reproduce it, start by wiring up two Arduino UNOs as outlined in the ArduinoISP tutorial page:



Don't forget to put a 10uF capacitor between GND and RESET on the UNO that you're plugging in to your computer (the bottom one in the diagram on that page). Follow steps 1-7 and burn the bootloader.

After successfully burning the bootloader, open the Blink example sketch and select "Upload using Programmer." The little LED for pin 13 should be blinking away nicely.

Now, unplug both UNOs and set aside the one you were just using as an ISP. Plug the UNO with the newly bootloaded ATmega328P into your computer and try to upload the Blink sketch again. The upload will fail, saying that the programmer is not responding.


Does anyone know why this is? If you burn the bootloader using the ISP but don't upload any sketch using the ISP, you can upload sketches to it directly with no problem.

Sorry if any of this is too confusing, I've spent a good 3 hours troubleshooting my connections here and I'm a bit tired. If you need clarification on anything just let me know.
29  Community / Exhibition / Gallery / Re: First shield: The ArduinoISP Deluxe shield for programming ATtiny & ATmega328P on: July 31, 2012, 02:35:40 pm
Thanks. What'd be the purpose of the decoupling capacitors? The reset pin actually does have a 10K pullup resistor on it already. I can't remember what the problem was exactly but when I had the whole thing laid out on a breadboard, I was having issues (I think related to uploading and bootloading) and the resistor solved 'em.

I designed it in Fritzing. I'd opened up Eagle and played around a little, but I found the interface a bit intimidating as a beginner. I had designed one PCB in Fritzing before (a fairly simple one that "syncs" an analog clock using an RTC) so I had a decent knowledge of how to use it. The only real challenge in Fritzing for this project was that I had to create the part for the ZIF socket. I'll definitely be looking into using Eagle for future projects though. It's definitely a more widely-used application.

The PCBs were made by iTeadStudio. After I submitted my other clock PCB to OSHPark I kept looking around for places to get PCBs made out of curiosity. iTeadStudio popped up and their prices were amazing compared to everyone else. 10 PCBs up to 5x5cm for only $12? Awesome. I ended up needing more than 5cm, so I went with the 'up to 10x10cm' option. Because I knew that the ZIF and switches would be red, I decided to pay the $6 premium and get red PCBs. Overall it was only $35 + shipping for 10 boards (they randomly gave me 2 extras actually) with 100% e-test. Not a bad price, and the quality was awesome, save for the silkscreen missing for one of my resistors (but that was only on one of the 12 boards).
30  Community / Exhibition / Gallery / ArduinoISP Deluxe shield for programming ATtiny & ATmega328P on: July 23, 2012, 05:49:18 pm
UPDATE: I've got a more recent version out now that does ATtiny2313 and ATtiny4313 chips as well. You can still buy them at the link below.

I've gotten into the habit of using the bare ATmega328P and ATtiny chips in my projects. The problem is that programming them / burning the bootloader to new chips can be annoying. You have to either get a programmer, or wire up an Arduino every time you need to program them.

I decided to make a shield where all of the chips I use can be programmed from one single socket. All you have to do is load the ArduinoISP sketch onto your Arduino, pop this shield on, and you can program an ATtiny 24/25/44/45/84/85 or an ATmega328P. For the ATMega328P, there's an external 16MHz crystal so you don't have to rely on the internal one. There's also a test LED so you can verify that the chips are working properly.

Questions and critiques welcome. This is the first real PCB I ever designed, I'm still learning! I may also do a second revision of the board so suggestions for that would also be welcome.

I also decided to sell my extra ones (with components)!

-----

Pics:









Features:

- Extra long, stackable headers
- Support for: ATtiny 24/25/44/45/84/85 and ATMega328P **
- Blink LED for testing purposes
- 16MHz crystal for programming an ATmega328P
- ZIF socket: simple to insert and remove chips for programming
- One socket for programming all different chips!

It's super easy to use. Just load up your Arduino with the ArduinoISP sketch, pop the shield on, and you're ready to program your chips and / or burn the Arduino bootloader to them.
Pages: 1 [2] 3