atmega328P not accepting anything
Moderators: adafruit_support_bill, adafruit

Re: atmega328P not accepting anything

by philipm on Thu Jun 21, 2012 3: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 10:50 am

Re: atmega328P not accepting anything

by philipm on Thu Jun 21, 2012 8: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 | TOGGLE FULL SIZE

#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 10:50 am

Re: atmega328P not accepting anything

by philipm on Sat Jun 23, 2012 10: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 10:50 am

Re: atmega328P not accepting anything

by smkoberg on Tue Jun 26, 2012 1: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 3:45 am
Location: Herndon, VA

Re: atmega328P not accepting anything

by philipm on Wed Jun 27, 2012 8: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 10:50 am

Re: atmega328P not accepting anything

by smkoberg on Fri Jun 29, 2012 7: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 4388 times
User avatar
smkoberg
 
Posts: 55
Joined: Tue Aug 11, 2009 3:45 am
Location: Herndon, VA

Re: atmega328P not accepting anything

by philipm on Sat Jun 30, 2012 8: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 10:50 am

Re: atmega328P not accepting anything

by smkoberg on Mon Jul 02, 2012 7: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 4436 times
FireFliesV2Top.png
Top of the board
FireFliesV2Top.png (148.93 KiB) Viewed 4436 times
User avatar
smkoberg
 
Posts: 55
Joined: Tue Aug 11, 2009 3:45 am
Location: Herndon, VA

Re: atmega328P not accepting anything

by philipm on Tue Jul 03, 2012 11:02 am

Cool. For future reference, you should try to make the paths to the crystal/resonator shorter. Longer paths increase capacitance which can cause issues. You could also try the circuit without the crystal/resonator and just use the internal clock (since for this project you don't need anything like 16Mhz!), will save you a few milliamps too. You can leave the PCB as is, just don't solder it on and change the target when burning the bootloader.
philipm
 
Posts: 29
Joined: Tue Dec 27, 2011 10:50 am

Re: atmega328P not accepting anything

by smkoberg on Fri Jul 13, 2012 4:36 pm

Alright, here I am with two final questions, hopefully.

First; if I do decide to go the route of leaving out the resonator, what would I change the target to?

Second; for the final project, I want to have the LED's hanging below the PCB so I can hang them in a mason jar/paper lantern. What is the smallest gauge wire I can use that will work for this? I found a website a few days ago, and I can't remember/find it now, but it said that 28 gauge wire will allow enough current to illuminate the LED's.
User avatar
smkoberg
 
Posts: 55
Joined: Tue Aug 11, 2009 3:45 am
Location: Herndon, VA

Re: atmega328P not accepting anything

by john444 on Fri Jul 13, 2012 8:13 pm

Hi SmokoBerg,

The low strength and availability of small wire sizes may be more of a problem than the wire's resistance.
For example,
30-awg wire has about 0.1-ohm / ft.
40-awg magnet wire is slightly more than 1-ohm / ft.

So, if you plan on going 10's of feet with 40-awg wire,
just allow for the wire resistance (both ways) by reducing the current-limiting resistor's value.

BTW, 30-awg Wire-wrap wire is surprisingly strong, easy to work with and readily available.
With a hand wrapping tool, you can strip and wrap wires on LED pins quickly. Don't even need to solder.
I would recommend it for connecting your LEDs.
Good Luck, John
john444
 
Posts: 443
Joined: Sun Mar 04, 2012 2:42 pm
Location: Claremore, Ok

Re: atmega328P not accepting anything

by philipm on Sat Jul 14, 2012 8:48 am

If you leave out the resonator, use the target:
"ATmega328 on a breadboard (8 MHz internal clock)"

In fact you can try it on your current test board without disconnecting the resonator. It will just ignore it and use the internal clock. So if it works without drama, you can be confident with the final design. ;)
philipm
 
Posts: 29
Joined: Tue Dec 27, 2011 10:50 am

Re: atmega328P not accepting anything

by smkoberg on Tue Jul 17, 2012 3:57 pm

john444 wrote:BTW, 30-awg Wire-wrap wire is surprisingly strong, easy to work with and readily available.

If you think 30-AWG wire would work, then I'm sure 28-AWG wire would work too. I'm not using through hole LED's, so my plan was to strip the coating off a few mm's of the wire and solder to the pads on a 1206 SMT LED. Also, I'm not planning on running wires any longer than 1 foot, so I think the resistance shouldn't be too much of an issue.

philipm wrote:If you leave out the resonator, use the target:
"ATmega328 on a breadboard (8 MHz internal clock)"

I pulled up my Arduino IDE to check and that isn't listed as an option in the boards menu. All I have are different flavors of Arduino.
User avatar
smkoberg
 
Posts: 55
Joined: Tue Aug 11, 2009 3:45 am
Location: Herndon, VA

Re: atmega328P not accepting anything

by mtbf0 on Tue Jul 17, 2012 11:50 pm

smkoberg wrote:
philipm wrote:If you leave out the resonator, use the target:
"ATmega328 on a breadboard (8 MHz internal clock)"

I pulled up my Arduino IDE to check and that isn't listed as an option in the boards menu. All I have are different flavors of Arduino.


try the lilypad target.
"i want to lead a dissipate existence, play scratchy records and enjoy my decline" - iggy pop, i need more
User avatar
mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am
Location: oakland ca

Re: atmega328P not accepting anything

by philipm on Wed Jul 18, 2012 9:25 am

The lilypad has a resonator on it, so doesn't use the internal oscillator. The fuse settings need to be different to enable the internal oscillator. (Do please correct me if I am wrong!)

Add the following to your boards.txt file and you'll get the new target...

Code: Select all | TOGGLE FULL SIZE
##############################################################

atmega328bb.name=ATmega328 on a breadboard (8 MHz internal clock)

atmega328bb.upload.protocol=stk500
atmega328bb.upload.maximum_size=30720
atmega328bb.upload.speed=57600

atmega328bb.bootloader.low_fuses=0xE2
atmega328bb.bootloader.high_fuses=0xDA
atmega328bb.bootloader.extended_fuses=0x05
atmega328bb.bootloader.path=arduino:atmega
atmega328bb.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex
atmega328bb.bootloader.unlock_bits=0x3F
atmega328bb.bootloader.lock_bits=0x0F

atmega328bb.build.mcu=atmega328p
atmega328bb.build.f_cpu=8000000L
atmega328bb.build.core=arduino:arduino
atmega328bb.build.variant=standard
philipm
 
Posts: 29
Joined: Tue Dec 27, 2011 10:50 am