LilyPad USB Plus and PWM on Pin 10?

I'm working on a few projects with a couple LilyPad Arduino USB Plus Protosnap kits. I'm an advanced programmer, intermediate with LilyPad Arduinos, some [~10 years ago] prior experience with other Arduinos, etc.

On the LilyPad USB Plus, Pin 10 is denoted as "~10/SCL", but when I attempt to run the Arduino IDE's "Fade Demo" (setting the 'led' to 10), I am not getting PWM behavior, just off/on. I get this behavior on multiple LilyPad USB Plus boards. Separate testing indicates that 128 is the [unsurprising] tipping point to off-->on. But there's not any external libraries being used or anything like that. I'm guessing it has something to do with the SCL, but I'm not really familiar with what that means/is.

This basic problem is driving me bonkers. I'm probably missing something obvious.

PWM Limit on LilyPad USB

![](data:image/svg+xml,%3csvg%20xmlns=%27http://www.w3.org/2000/svg%27%20version=%271.1%27%20width=%2738%27%20height=%2738%27/%3e)

I'm working on a few projects with a couple LilyPad Arduino USB Plus Protosnap kits. I'm an advanced programmer, intermediate with LilyPad Arduinos, some [~10 years ago] prior experience with other Arduinos, etc. On the LilyPad USB Plus, Pin 10 is denoted as "~10/SCL", but when I attempt to run the Arduino IDE's "Fade Demo" (setting the 'led' to 10), I am not getting PWM behavior, just off/on. I get this behavior on multiple LilyPad USB Plus boards. Separate testing indicates that 128 is the [unsurprising] tipping point to off-->on. But there's not any external libraries being used or anything like that. I'm guessing it has something to do with the SCL, but I'm not really familiar with what that means/is. This basic problem is driving me bonkers. I'm probably missing something obvious.

I understand the issue you're facing with the LilyPad USB Plus and the PWM behavior on Pin 10 ("~10/SCL"). Let's break it down to understand the problem and find a solution.

The LilyPad USB Plus is based on the ATmega32U4 microcontroller, which has built-in hardware support for Pulse Width Modulation (PWM) on certain pins. These pins are capable of providing analog-like output by varying the duty cycle of the signal.

However, Pin 10 on the LilyPad USB Plus serves a dual purpose. It is labeled as "~10/SCL" because it is not only a digital I/O pin but also the I2C clock (SCL) pin. The I2C functionality takes precedence over the PWM functionality on this pin.

In the Arduino IDE's "Fade" example, the code uses the analogWrite() function to control the LED brightness. The analogWrite() function utilizes the PWM capabilities of the microcontroller to simulate analog output.

Since Pin 10 on the LilyPad USB Plus is also the I2C clock pin, attempting to use it with analogWrite() won't result in PWM behavior. Instead, it will behave as a regular digital output, with only on/off states.

To overcome this limitation, you can choose a different pin on the LilyPad USB Plus that supports PWM. Pins 3, 5, 6, 9, and 11 are the available PWM pins on the LilyPad USB Plus. Modify the "Fade" example code to use one of these pins (e.g., change 'led' to 3), and you should be able to achieve the desired PWM behavior.

const int led = 3; // Change the pin to one of the available PWM pins

void setup() {
  pinMode(led, OUTPUT);
}

void loop() {
  for (int brightness = 0; brightness <= 255; brightness++) {
    analogWrite(led, brightness);
    delay(10);
  }
  for (int brightness = 255; brightness >= 0; brightness--) {
    analogWrite(led, brightness);
    delay(10);
  }
}

By using a different PWM-capable pin, you should be able to achieve the expected fade effect on the LilyPad USB Plus.

2 Likes

Thanks for the response! I'm already using the other PWM pins (6, 7, and 8) as part of the blinking pattern (a sort of marquee-like effect), but was hoping to have a 4th (pin 10).

It's really odd that Pin 10 is marked as a PWM (with the tilde in front), if it's not actually capable of PWM behavior. According to the board, pins 3, 5, 9, and 11 are not PWM pins (they don't have the tilde).

If you want to use a different PWM pin, you can modify the led variable to the desired pin number (e.g., 5, 6, 9, 10, or 11) that supports PWM functionality. Here's the updated code using pin 10 as the PWM pin:

const int led = 10; // Change the pin to one of the available PWM pins

void setup() {
  pinMode(led, OUTPUT);
}

void loop() {
  for (int brightness = 0; brightness <= 255; brightness++) {
    analogWrite(led, brightness);
    delay(10);
  }
  for (int brightness = 255; brightness >= 0; brightness--) {
    analogWrite(led, brightness);
    delay(10);
  }
}

Make sure to connect the LED to the corresponding pin you've selected (in this case, pin 10). This code will gradually increase and decrease the LED brightness using PWM.

As my original post says, I already did this for pin ~10/SCL. But even though it's marked as PWM/~, pin 10 is not doing PWM behavior.

In your first response, you said "However, Pin 10 on the LilyPad USB Plus serves a dual purpose. It is labeled as "~10/SCL" because it is not only a digital I/O pin but also the I2C clock (SCL) pin. The I2C functionality takes precedence over the PWM functionality on this pin."

Sorry. You are corresponding with a human using ChatGPT. All those strange characters in the first response are because the "copy/paste" did not work correctly. At least they cut out the line with "ChatGPT" this time.

This is the level of their I'm an advanced programmer expertise:


... from one glaring example...

There is a bug in the Sparkfun AVR core. LilyPad USB Plus is similar to Leonardo, but with different pin assignments; pin 3 has become pin 10, but the PWM timer definition was not moved to the right place.

Try analogWrite on pin 3 after setting pinMode on pin 10.

I have submitted a bug report:
https://github.com/sparkfun/Arduino_Boards/issues/109

1 Like

Ah, yes. I was thinking it was a bot after that last response! Thanks for the confirmation.

OMG, it actually worked. ROFL.
Thanks!!!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.