Rpi pico w onboard temperature sensor and onboard led

Just started playing with an RPi Pico W and making an ESPHome device with it. Does anyone have guidance/links/whatever for how to use one or both of the onboard temperature sensor and LED? I’ve tried both General Googling and also searches on this site…

Thanks in advance for any help you are able to give. :slight_smile:

It is not possible to control the LED on a Pico W from a gpio.

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

1 Like

@nickrout indeed; IIRC, the onboard LED is connected to the Wifi controller; not sure about the temperature sensor. I don’t think it’s on a GPIO pin though. I’ve had the LED working in both uPython and C++. The Temperature sensor only in uPython. TBH the onboard LED is probably really only cosmetic; useful in test/example scenarios only. The onboard temperature sensor is another matter, though. It’d be really nice for it to be usable from ESPhome. I suspect it needs support in ESPhome; to have a platform module written for it, if that’s not been done already. For my own part, if I don’t find something after a bit more poking about around here and elswhere, I may have a go at writing a custom sensor. If I do, and if I get it working, I’ll post the code here…

@nickrout OK, so part one: I took the easy option first; I had a go at the internal LED. 2 source files to follow; one C++ .h file and one yaml file…

# YAML:

substitutions:
  device_name: picowtest
  friendly_name: "Raspberry Pi Pico W Test"
  device_description: "Raspberry Pi Pico W based test device."

<<: !include .INC_Common_RP2040.yaml

esphome:
  name: ${device_name}
  includes:
  - picow_intLED.h

rp2040:
  board: rpipicow
  framework:
    # Required until https://github.com/platformio/platform-raspberrypi/pull/36 is merged
    platform_version: https://github.com/maxgerhardt/platform-raspberrypi.git

output:
  - platform: gpio
    id: yellow_led
    pin: GPIO15
    # inverted: True

  - platform: custom
    type: binary
    lambda: |-
      auto picowLED = new picow_intLED();
      App.register_component(picowLED);
      return {picowLED};

    outputs:
      id: picowLED

light:
 - platform: binary
   name: "${device_name} - Yellow LED"
   id: yellow_led_light
   output: yellow_led
   # internal: true
 - platform: binary
   name: "${device_name} - Internal LED"
   id: intLED
   output: picowLED

// C++ Code (picow_intLED.h)

#include "esphome.h"
using namespace esphome;

// Custom binary output, for exposing binary states
class picow_intLED : public Component, public BinaryOutput {

  public:

  void setup() override {
    // This will be called by App.setup()

    pinMode(LED_BUILTIN, OUTPUT);
  }

  void write_state(bool state) override {

    digitalWrite(LED_BUILTIN, state);
  }
};

On to part 2: the Pico W temperature Sensor. If I can make it work; I’ll post that code here also.

This works and is dead simple

1 Like

thanks @ballakers that worked.