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]
// 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.
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.
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.
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?
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
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.
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
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.
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.