daniloc / PicoW_HomeAssistant_Starter

Everything you need to get started with your own Intranet of Things, using the high-quality, low-cost Pico W as the backbone.
MIT License
198 stars 20 forks source link

analogWrite doesn't seem to work #11

Closed apbarratt closed 1 year ago

apbarratt commented 1 year ago

I'm trying to make a very simple system that makes an LED fade up and down when a switch hasn't been turned on. Frustratingly I cannot get analogWrite to work in any way whatsoever.

To confirm, I've stripped back main.cpp of pretty much everything but Arduino.h and even there, I cannot turn on the LED using analogWrite, but I can with digitalWrite.

I'm struggling to think what I could be doing wrong, I've tried every possible google search I can think of but everything is for C or python in ArduinoIDE but never C++ in VSCode so even though this seems a bit off topic for the scope of this project, I'm hoping you'll be happy to assist anyway seeing as I'm using it as a basis :(

Screenshot 2023-07-30 at 21 15 45
daniloc commented 1 year ago

You know, my immediate thought is that, assuming you're on a PicoW, LED_BUILTIN may not be a PWM pin. On that model, the LED is a GPIO pin on the WiFi module, not the RP2040 chip, according to this thread:

https://forums.raspberrypi.com/viewtopic.php?t=336836

Does it work if you throw it on a breadboard and designate one of the RP2040's PWM pins for this output? (that's most of the pins: https://datasheets.raspberrypi.com/picow/PicoW-A4-Pinout.pdf).

apbarratt commented 1 year ago

I'll give it a go in a bit. Someone has a video of it working using the fade example here: https://community.element14.com/products/raspberry-pi/b/blog/posts/program-rpi-pico-using-arduino-pico

It hadn't occured to me that the pinout would be different on the W.

Sadly I have a bad feeling I've fried it in just the last couple of minutes. I was reverting my test code there and now the thing won't light up at all and it's making a very faint squealing noise so my very short attempt at trying out a pico may be over.

daniloc commented 1 year ago

At least the replacements are cheap! But I've seen this behavior before. Before giving up on the board, try holding BOOTSEL while you plug it in via USB, see if that gets you moving again.

Yeah, subtle difference. The pinout on the vanilla pico makes the LED a PWM pin:

https://datasheets.raspberrypi.com/pico/Pico-R3-A4-Pinout.pdf

apbarratt commented 1 year ago

Hmmm, nope. Got the code back to its original state, not just LED not working anymore, it's just getting stuck on the "Attempting to connect" message and it's still making the squealing noise. Oh well, think I'll be sticking to ESP chips I suppose, never had one of those do this to me after only an evening of testing.