Blink Sketch led blinks too fast

Hi All,

I have successfully uploaded the Blink Sketch to my new Lilypad Atmega 328 Main Board however...

The blink rate of the LED is twice as fast as the rate stated in the sketch. For example, if the sketch states 1000ms the LED blinks for only 500ms.

Here's my setup:

MacBook Pro (mid 2010) + OSX 10.9.5 (ARDUINO IDE 1.0.6) >> FTDI Basic (FTDI driver 2.2.18 installed) >> Lilypad Atmega 328 Main Board

I can't believe I am the first to have this problem but have scoured the web and the forum for an answer without luck. Apologies if I have simply missed a thread somewhere.

Any help is much appreciated.

Nick

Edit 1: Arduino IDE 1.0.5 info added.
Edit 2: I just updated to IDE 1.0.6, hasn't solved the problem.

[wild guess]
Have you got the correct board chosen in the IDE Tools > Board? Maybe there's a scaling thing in a timer and the wrong board treats it different?
[/wild guess]

Thanks for the response, JimboZA.

I believe I have the correct board selected: 'Lilypad Arduino w/ ATmega328'

Other wild guesses welcome!

Bests,

Nick

njwheelbarrow:
Other wild guesses welcome!

Your stopwatch is wrong?

Can you reliably click a half second to time?- or are you counting many and taking a total?

Perhaps change the time to 10 seconds and see if you get 5?

}

// the loop function runs over and over again forever
void loop() {
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

By my reckoning 10 flashes should take 20seconds (1sec ON, 1sec Off), the stopwatch says 10 flashes takes 10 seconds.

EDIT: I just uploaded the blink sketch to my Arduino Uno and the LED blinked at the correct rate (10blinks = 20secs). This would suggest, perhaps, that the problem lies within the configuration of the Lilypad.

Long may your wild guesses continue!

Nick

Could the type of USB>>mini USB cable effect the timing? I borrowed one from the school I work in and just realised it is from a webcam. It has one of those cylindrical cases just before the USB end and a label stating:

P/N HueHD-v2W

Hue HD appears to be the camera model. This is a USB 2.0 cable.

Nick

njwheelbarrow:
This would suggest, perhaps, that the problem lies within the configuration of the Lilypad.

I'd say so yep, or perhaps an inherent LP problem that nobody ever noticed before?

JimboZA:
LP problem

LP?

I googled the abbreviation but I presume you don't mean a problem with Latin Percussion?

Nick

Ah, 'Low Power', thanks abbreviations.com

I'll get a new cable a couple of mins and update this thread with news!

Thanks for all of your input, JimboZA.

Nick

No actually I meant LilyPad....

JimboZA:
No actually I meant LilyPad....

Never overestimate how dim I can be sometimes. Crikey, I shock myself sometimes.

Nick

I have now tried a new USB>>USBmini cable and it hasn't solved the problem.

Help is still appreciated to solve the timing problem.

Nick

After further experimentation: When I connect an analogue sensor to one of the input pins and load a sketch to read the incoming data, I have to set the baudrate of the serial monitor to twice that of the sketch in order to view the incoming data correctly. For example, if the sketch sets the baudrate to 9600 then the serial monitor must be set to 19200 else the incoming data looks like gobbledigook.

I thought I'd mention this as it may give some of you an idea of what might be going wrong with my Lilypad.

Thanks,

Nick

The Lilypad is supposed to run at 8MHz but I suspect it is running at 16.

ChilliTronix:
The Lilypad is supposed to run at 8MHz but I suspect it is running at 16.

This seems to make sense, however, after a brief search I have found numerous Lilypads advertised as 16MHz boards. For example:

http://www.tested.com/tech/robots/456466-know-your-arduino-guide-most-common-boards/

So now I am confused, if my LP is supposed to be working at 8MHz should I return it as faulty? OR, if it is supposed to be clocking at 16MHz then why does is take figures such as 1000ms in a sketch and interpret them as 500ms?

Help! Thanks for all input.

Nick

njwheelbarrow:
if it is supposed to be clocking at 16MHz then why does is take figures such as 1000ms in a sketch and interpret them as 500ms?

well if the program defines 1 millisecond as 100 oscillations from an oscillator, then an oscillator running at the twice the speed will complete the 100 oscillations in half the time. Just imagine if the motor in your analog watch were to spin at twice the speed.

There is an easy fix to this.

make a folder in your arduino folder, where you keep all your sketches, called "hardware". Then inside that folder make a file called "boards.txt" if there isnt already. Now add this to it.

This "should" work, no guarantees...
EDIT : This apparently does not work

lilypad328_2.name=LilyPad Arduino w/ ATmega328 (16Mhz)

lilypad328_2.upload.protocol=arduino
lilypad328_2.upload.maximum_size=30720
lilypad328_2.upload.speed=57600

lilypad328_2.bootloader.low_fuses=0xFF
lilypad328_2.bootloader.high_fuses=0xDA
lilypad328_2.bootloader.extended_fuses=0x05
lilypad328_2.bootloader.path=atmega
lilypad328_2.bootloader.file=ATmegaBOOT_168_atmega328.hex
lilypad328_2.bootloader.unlock_bits=0x3F
lilypad328_2.bootloader.lock_bits=0x0F

lilypad328_2.build.mcu=atmega328p
lilypad328_2.build.f_cpu=16000000L
lilypad328_2.build.core=arduino
lilypad328_2.build.variant=standard

EDIT: This apparently does not work

Post a picture of your Lilly pad or a link to where you got it from.

Is there a crystal or oscillator in your LiliPad board? Unless there is one, it should be 8Mhz. It might, however, have been flashed with a regular 16Mhz bootloader.

If it has no XTALs or OSCs present in the board, you can simply try flashing the proper bootloader. That is easy if you have another arduino or another ISP such as USBasp.

Ps991:
This "should" work, no guarantees...

Wow, thanks for all of your responses guys and gals, I really appreciate the help. In response...

Ps991:

I have followed your instructions, when I try to upload the Blink sketch to the 'new' board I get the following error (I do not get this error when I upload the same sketch using the default LP Atmega 328 board). Any ideas?:

Arduino: 1.0.6 (Mac OS X), Board: "LilyPad Arduino w/ ATmega328 (16Mhz)"
Blink.ino:18:21: error: Arduino.h: No such file or directory
Blink.ino: In function 'void setup()':
Blink:20: error: 'OUTPUT' was not declared in this scope
Blink:20: error: 'pinMode' was not declared in this scope
Blink.ino: In function 'void loop()':
Blink:25: error: 'HIGH' was not declared in this scope
Blink:25: error: 'digitalWrite' was not declared in this scope
Blink:26: error: 'delay' was not declared in this scope
Blink:27: error: 'LOW' was not declared in this scope

ChilliTronix:
I bought the board on Ebay for £7.99 from MJC-Digital-UK: mjc-digital-uk on eBay
Here's a pic of the front of the board: lilypad atmega 328 front
Here's a pic of the back of the board: lilypad atmega 328 rear

AlxDroidDev:

Is there a crystal or oscillator in your LiliPad board? Unless there is one, it should be 8Mhz. It might, however, have been flashed with a regular 16Mhz bootloader.

How do I find out?

That is easy if you have another arduino

I have an Uno, any good?

Thank you all,

Nick

njwheelbarrow:
How do I find out?

I have an Uno, any good?

The UNO is more than enough: http://arduino.cc/en/Tutorial/ArduinoISP
Do you see the 3x2 rows of pins near where it is written "JP3" on your board? That is the ISP header, and the pins position is standardized. Those are the pins that will connect to your UNO. The "square pin" is PIN 1 (MISO).

I made a mistake: I believed the LilyPad used the internal 8Mhz oscillator. It does, however, use an external resonator. There also one present in the pic you posted. Do you have a magnifying glass or something similar, so you can read what's written on it? On the pic you posted, the resonator is the device closest to the bottom-left corner of the Atmega.

If you decide to take "reflash bootloader" road, this is the rough idea:

  • Take your UNO, open the IDE, select UNO and its COM port
  • Open the Example sketch ArduinoISP and upload it to your UNO
  • disconnect everything
  • connect your UNO to the LilyPad using the link above. On the Link, they show another Arduino board being programmed, but you'll connect the UNO pins to the LilyPad`s ISP header instead.
  • Open the IDE, and select: Board-> LilyPad; Programmer-> Arduino ISP
  • Connect your UNO to the computer`s USB
  • Select Tools -> Burn Bootloader
  • It might take up to 2 minutes to finish (around 1 minute is normal).
  • After that, you can connect your LilyPad to the USB, reflash the sketch and see if it works properly.