Re: atmega328P not accepting anything

by smkoberg on Mon Jun 18, 2012 7:41 pm

Well, I'm back again.
Got my new components today and soldered everything onto the board except the resistors for the LED's and tried burning the bootloader and got the following message:

Code: Select all
avrdude: Version 5.11, compiled on Sep  2 2011 at 19:38:36
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "C:\Program Files\arduino-1.0.1\hardware/tools/avr/etc/avrdude.conf"

         Using Port                    : \\.\COM3
         Using Programmer              : stk500v1
         Overriding Baud Rate          : 19200
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
avrdude: Recv:
avrdude: stk500_getsync(): not in sync: resp=0x00

avrdude done.  Thank you.


I have the board set to UNO, the programmer set to ArduinoISP, and I uploaded the ArduinoISP sketch to the boarduino before trying to burn the bootloader.

I have a .1uF capacitor in series for RTS as well as a 10K pullup resistor, I don't have the battery installed to keep everything working on the 5V coming from the USB, and its still not working.
User avatar
smkoberg
 
Posts: 55
Joined: Tue Aug 11, 2009 2:45 am
Location: Herndon, VA

Re: atmega328P not accepting anything

by philipm on Mon Jun 18, 2012 11:55 pm

Sadly, that error means the chip isn't responding.

The first things I would try would be to:
- use a multimeter to check the power and ground connections. Disconnect everything. Put one probe on a known ground connection and touch every pin on the chip in turn. Confirm that only the ground pins have near 0 resistance. Repeat for the power pins.
- connect the power and check it's actually reaching the chip (very carefully, you don't want to short anything with your multimeter probe)
- reload the ArduinoISP onto the boarduino (without the new chip connected). Remember to set the correct programmer. Enure you get the "Upload Done" message on the IDE.
- remake all the connections, change the programmer back to ArduinoISP and try the bootloader load again (at least a couple of times).

You might have thermal or static damage on the chip - but in my experience that is much less likely than a short or bad connection, hence try the above first.
philipm
 
Posts: 29
Joined: Tue Dec 27, 2011 9:50 am

Re: atmega328P not accepting anything

by smkoberg on Tue Jun 19, 2012 12:49 pm

philipm wrote:You might have thermal or static damage on the chip

Interesting, could that have been cause by accidentally dropping the chip on a carpeted floor? :oops:
User avatar
smkoberg
 
Posts: 55
Joined: Tue Aug 11, 2009 2:45 am
Location: Herndon, VA

Re: atmega328P not accepting anything

by philipm on Tue Jun 19, 2012 7:11 pm

More likely to come from you. I don't use static precautions and haven't had any issues. It's possible, but not likely. If you wander around your house regularly getting static shocks, you probably need grounding. Other than that, just don't rub them on your cat! ;)
philipm
 
Posts: 29
Joined: Tue Dec 27, 2011 9:50 am

Re: atmega328P not accepting anything

by smkoberg on Wed Jun 20, 2012 5:56 pm

Well, I did the checks for continuity and bridging and found nothing, so I decided to try burning the bootloader/sketch again, but this time, it worked; however, I have a power issue now :roll:

I designed this thing to sit in the lid of a mason jar, which is why I wanted to use the CR2032, but now it's not working with the battery. It works while getting 5V from the FTDI cable, but once the battery is in and the switch is flipped, i get nothing.

Any ideas on how I can supply more power while keeping a smallish footprint?
User avatar
smkoberg
 
Posts: 55
Joined: Tue Aug 11, 2009 2:45 am
Location: Herndon, VA

Re: atmega328P not accepting anything

by philipm on Wed Jun 20, 2012 9:32 pm

Congratulations on getting the chip to bootload and program successfully.

I had no idea that the CR2032 had some much internal resistance (and therefore low constant current capability). There is a nice article on it here:
http://interactive-matter.eu/blog/2009/ ... coin-cell/

You have a few choices at this stage. If you can fit them into the design, I'd go for AAA batteries. These have good capacity (800-100 mAh) and both the batteries and the holders are banned.

If they are just too big, you can go for CR123A. They give 3v/1500mAh for lithium, though are more expensive. They are just over half the size of an AA, but a bit fatter and of course, you only need one per board.

Another alternative is LiPO rechargable. These are available from hobby stores in various sizes and capacities. Though probably more expensive still and you may find charging lots of them a logistical issue too.

Hope this helps.
philipm
 
Posts: 29
Joined: Tue Dec 27, 2011 9:50 am

Re: atmega328P not accepting anything

by smkoberg on Wed Jun 20, 2012 9:45 pm

Okay, since my last post, I've almost got the darn thing working. I flashed the bootloader (Arduino Duemilanove) and uploaded the sketch (below) and got it working for a period of time. When it first started working, it worked the way it was intended: random LED would fade in/out, similarly to a firefly, but after a period of time, the program would 'hiccup' and only one of the LEDs, on pin 9 [PD5(T1)], would fade, but not in a random fashion. I've linked to a video I took to show you what happens. Also, the pattern seems to be consistent now every time I turn on the board, it's no longer randomizing the LED selection like the code is supposed to.

http://youtu.be/MZIbIdOqNnE

Code: Select all
/*This sketch is intended to approximate the blinking of fireflies.  It varies the delay between
blinks and varies the total blink time.  I've used the random() function to vary which PWM  output
is chosen for the next blink.
Hope you get some enjoyment out of it.  I created it as a fun night light for my kids.
Chad Richardson -- Chad@ChadsCustomWood.net
*/

int lightPin = A0; //23
int lightVal;
int value;
int pwmPin = 11;                    // light connected to digital pin 11-- I just chose an initial value
//int ledpin2 = 9;
long time=0;
int period = 500;
int i = 0;
long blink_delay = 1000;      // these must be declared as long due to the random() operation
long blink = 3;
long random_led = 55;
const byte pwmPins [] = {3, 5, 6, 9, 10, 11}; //5, 11, 12, 15, 16, 17

void setup()
{
  pinMode(lightPin,INPUT);                  //nothing to setup
}

void loop()
{
 
  choose_firefly();
  fade();

  blink_delay = random(500, 2001);
  delay(blink_delay); 
  blink = random(2, 5); 
}
void fade()
{
  for(i=0; i<255;)
  {
    time = i;
    value = abs(-127+127*cos(4*PI/period*i));      //the -127 value shifts the cosine curve negative with a zero initial value; abs shifts everything positive
    analogWrite(pwmPin, value);           // sets the value (range from 0 to 255)
    delay(blink);
    i++;
  }
}

void choose_firefly()
  {
    pwmPin = pwmPins [random (0, 6)]; 
  }
User avatar
smkoberg
 
Posts: 55
Joined: Tue Aug 11, 2009 2:45 am
Location: Herndon, VA

Re: atmega328P not accepting anything

by philipm on Thu Jun 21, 2012 2:37 am

On my first view of the code, it looks ok (though you may want to set the pinmode for the leds to output in the setup and the variable "time" isn't used, so can be removed).

Have you tried running it from usb power to rule out that the microcontroller may be behaving strangely as the voltage drops? Or try a fresh battery...
philipm
 
Posts: 29
Joined: Tue Dec 27, 2011 9:50 am

Re: atmega328P not accepting anything

by philipm on Thu Jun 21, 2012 7:59 am

I've had a play around with your code. It looks correct and should work. I've rewritten it a little to see if that helps give it properly random behaviour.

Please note the following changes
- power mode (don't set to 1 if using 5V if your resistors are designed for 3.3v!) - sets up the pin mode for the LEDs
- random seed initialisation (making each turn on of each device different)
- took out the cos function - straight PWM should look identical for the periods you are using (put back later if desired)
- added a brightness gold of up to 1/4 second when max brightness reached (take out if not desired)

Code: Select all

#define POWER 0 // 0 for LOW power mode, 1 for HIGH power mode

int pwmPin = 11;  // light connected to digital pin 11-- I just chose an initial value
// int period = 500;
long blink = 3;
const byte pwmPins [] = {3, 5, 6, 9, 10, 11}; //5, 11, 12, 15, 16, 17

void setup()
{
  // setup input or output depending on power mode
  for (int i = 0; i < 6; i++)
  {
    if(POWER == 1)
    {
       pinMode(pwmPins[i], OUTPUT);
    }
    else
    {
       pinMode(pwmPins[i], INPUT);
    }
  }
  randomSeed( analogRead(0) ); // set the seed so every turn on on every device is different!
}

void loop()
{
  setup_next_firefly();
  fade();

  delay( random(500, 2001) ); 
}

void fade()
{
  int value;
 
  for(int i = 0; i < 255; i++) //fade in
  {
    // the next line is way too clever! based on your short period, should look the same with simpler code
    // value = abs(-127+127*cos(4*PI/period*i));
    analogWrite(pwmPin, i);
    delay(blink);
  }
  delay( random(1,250) ); // hold at max brightness for up to 1/4 second
  for(int i = 255; i > 0; i--) //fade out
  {
    // the next line is way too clever! based on your short period, should look the same with simpler code
    // value = abs(-127+127*cos(4*PI/period*i));
    analogWrite(pwmPin, i);
    delay(blink);
  }
 
 
}

void setup_next_firefly()
{
    pwmPin = pwmPins [random (0, 6)];
    blink = random(1, 3); 
}
philipm
 
Posts: 29
Joined: Tue Dec 27, 2011 9:50 am

Re: atmega328P not accepting anything

by philipm on Sat Jun 23, 2012 9:47 am

Looking at your video, seems almost certain that your microcontroller is browning out (not enough current from the battery). This is why it blinks the same LED, it's effectively resetting between runs. Adding the random seed call from my code will mask this, but you still have a power issue I think. Try a bypass cap on the atmega, or with a new battery to see it it helps.

Let us know how you get on. :)
philipm
 
Posts: 29
Joined: Tue Dec 27, 2011 9:50 am

Re: atmega328P not accepting anything

by smkoberg on Tue Jun 26, 2012 12:59 pm

Well, I took out the CR2032 and jury rigged a CR123A clip and battery to V+ and GND on the board to see if that would help. It worked, for a bit. Now it wont even turn on. The battery still reads at 3V and I've made sure all the connections with the new battery are good, which they are.
User avatar
smkoberg
 
Posts: 55
Joined: Tue Aug 11, 2009 2:45 am
Location: Herndon, VA

Re: atmega328P not accepting anything

by philipm on Wed Jun 27, 2012 7:42 am

Tricky one. That should work. You could try measuring the current of the circuit in use, should be about 20 mA plus the LED when on.

I still think it's worth putting a bypass 0.1uF cap as near as possible to the power pins on the atmega. Every IC should really have one.
philipm
 
Posts: 29
Joined: Tue Dec 27, 2011 9:50 am

Re: atmega328P not accepting anything

by smkoberg on Fri Jun 29, 2012 6:00 pm

So, I've redone the schematic for this project and included the bypass capacitor for the voltage, the capacitor/resistor pair for the reset line during sketch uploading, and the CR123A battery clip for the power source.

I'm currently working on updating the PCB design which will hopefully be the final product.

I've also replaced the LED packages to a modified 3mm version so I can have two through holes which will allow me to suspend the LEDs in a jar/paper lantern/etc. for the final project.

*EDIT* - I measured the amperage being used when I had the CR123A hooked up by removing one of the wires connected directly to the battery clip and used a pair of alligator clips to connect my meter, in series, to the V+ side, which gave me a reading of about 16-18mA when one of the LEDs was at full brightness.
Attachments
firefliesV2_schematic.jpg
Screen capture via Eagle
firefliesV2_schematic.jpg (91.73 KiB) Viewed 4061 times
User avatar
smkoberg
 
Posts: 55
Joined: Tue Aug 11, 2009 2:45 am
Location: Herndon, VA

Re: atmega328P not accepting anything

by philipm on Sat Jun 30, 2012 7:59 am

Great work. Glad you got it working and are refining to a final and very solid design. Would love to see some video of the finished effect. =)
philipm
 
Posts: 29
Joined: Tue Dec 27, 2011 9:50 am

Re: atmega328P not accepting anything

by smkoberg on Mon Jul 02, 2012 6:17 pm

Thanks for the support!
Here's what I've thrown together for a board using the Mayhew Lab's 3D PCB viewer:

I'll definitely be taking some video of the finished product when it's all said and done.
Attachments
FireFliesV2Bottom.png
Bottom of the board
FireFliesV2Bottom.png (112.03 KiB) Viewed 4109 times
FireFliesV2Top.png
Top of the board
FireFliesV2Top.png (148.93 KiB) Viewed 4109 times
User avatar
smkoberg
 
Posts: 55
Joined: Tue Aug 11, 2009 2:45 am
Location: Herndon, VA