# Initializing widgets from my Pi Pico W

**URL:** <https://discourse.nodered.org/t/initializing-widgets-from-my-pi-pico-w/86647>\
**Category:** Dashboard\
**Created:** [21 March 2024 21:53 UTC](https://discourse.nodered.org/t/initializing-widgets-from-my-pi-pico-w/86647 "2024-03-21T21:53:41Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![badflash](https://avatars.discourse-cdn.com/v4/letter/b/d6d6ee/32.png) [@badflash](https://discourse.nodered.org/u/badflash)\
**Post date:** [21 March 2024 21:53 UTC](https://discourse.nodered.org/t/initializing-widgets-from-my-pi-pico-w/86647/1 "2024-03-21T21:53:41Z")

</div>

I'm wondering if there is a way to initialize a switch or slider from the program on my Pi Pico W when it first runs. I tried sending a feed to them, but it made a race condition.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![AndrewBeasley](https://avatars.discourse-cdn.com/v4/letter/a/f17d59/32.png) [@AndrewBeasley](https://discourse.nodered.org/u/AndrewBeasley)\
**Post date:** [21 March 2024 23:09 UTC](https://discourse.nodered.org/t/initializing-widgets-from-my-pi-pico-w/86647/2 "2024-03-21T23:09:53Z")

</div>

MQTT?

Put a command into a thread and use the MQTT node to start a flow wto set the widgets when it receives a message.

You could use the contents of the message and a switch node to action only one widget if you want to.

---

<div class="post-metadata">

**Author:** ![badflash](https://avatars.discourse-cdn.com/v4/letter/b/d6d6ee/32.png) [@badflash](https://discourse.nodered.org/u/badflash)\
**Post date:** [21 March 2024 23:24 UTC](https://discourse.nodered.org/t/initializing-widgets-from-my-pi-pico-w/86647/3 "2024-03-21T23:24:23Z")

</div>

Can you give me any more details? I'm new to this and have no idea how to do what you suggest.

---

<div class="post-metadata">

**Author:** ![AndrewBeasley](https://avatars.discourse-cdn.com/v4/letter/a/f17d59/32.png) [@AndrewBeasley](https://discourse.nodered.org/u/AndrewBeasley)\
**Post date:** [22 March 2024 01:25 UTC](https://discourse.nodered.org/t/initializing-widgets-from-my-pi-pico-w/86647/4 "2024-03-22T01:25:26Z")

</div>

Forgive me - I'm on an iPad and limited as to what I can access at the mo for examples ☹

For a general intro to MQTT have a look at [http://www.steves-internet-guide.com/mqtt/](http://www.steves-internet-guide.com/mqtt/) and his [Configuring the Node-Red MQTT Publish and Subscribe Nodes](https://stevesnoderedguide.com/configuring-the-mqtt-publish-node)

There is an intro to MQTT on the Pico at [How to Send and Receive Data Using Raspberry Pi Pico W and MQTT (Updated) | Tom's Hardware](https://www.tomshardware.com/how-to/send-and-receive-data-raspberry-pi-pico-w-mqtt)

---

<div class="post-metadata">

**Author:** ![badflash](https://avatars.discourse-cdn.com/v4/letter/b/d6d6ee/32.png) [@badflash](https://discourse.nodered.org/u/badflash)\
**Post date:** [22 March 2024 13:04 UTC](https://discourse.nodered.org/t/initializing-widgets-from-my-pi-pico-w/86647/5 "2024-03-22T13:04:38Z")

</div>

I've gone over both of those in great detail., but they don't seem to address initializing the widgets. I will look again.

---

<div class="post-metadata">

**Author:** ![AndrewBeasley](https://avatars.discourse-cdn.com/v4/letter/a/f17d59/32.png) [@AndrewBeasley](https://discourse.nodered.org/u/AndrewBeasley)\
**Post date:** [22 March 2024 14:41 UTC](https://discourse.nodered.org/t/initializing-widgets-from-my-pi-pico-w/86647/6 "2024-03-22T14:41:01Z")

</div>

They will not - without knowing what the widgets are its hard to give any advice on that - these really help to address the race condition by single threading the request.

A bit more detail (and flow) could help give more targeted advice.

---

<div class="post-metadata">

**Author:** ![badflash](https://avatars.discourse-cdn.com/v4/letter/b/d6d6ee/32.png) [@badflash](https://discourse.nodered.org/u/badflash)\
**Post date:** [22 March 2024 15:00 UTC](https://discourse.nodered.org/t/initializing-widgets-from-my-pi-pico-w/86647/7 "2024-03-22T15:00:15Z")

</div>

I'm using the Switch and the Numeric Node. I don't see a way to set a default value. I also don't see a way to make them stop sending values. I keep getting the last topic and message over and over until I select a new one. I have a feeling that is what was causing the race condition. I would send a message to the switch or Numeric node and it would not stop sending even though my program only sent it once.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [22 March 2024 15:02 UTC](https://discourse.nodered.org/t/initializing-widgets-from-my-pi-pico-w/86647/8 "2024-03-22T15:02:28Z")

</div>

Make the mqtt topic storing the value be a retained topic and feed that into the switch. Code it so that it does not send the value out again to prevent a loop.

---

<div class="post-metadata">

**Author:** ![badflash](https://avatars.discourse-cdn.com/v4/letter/b/d6d6ee/32.png) [@badflash](https://discourse.nodered.org/u/badflash)\
**Post date:** [22 March 2024 15:23 UTC](https://discourse.nodered.org/t/initializing-widgets-from-my-pi-pico-w/86647/9 "2024-03-22T15:23:03Z")

</div>

Right now I just send it once before the start of the while true: loop, so it should not be sent over and over. Looking at the HiveMQ feed, I didn't see it, so it seems to be at Node-Red. I'm not sure what to configure to clear that out after it gets it.

---

<div class="post-metadata">

**Author:** ![badflash](https://avatars.discourse-cdn.com/v4/letter/b/d6d6ee/32.png) [@badflash](https://discourse.nodered.org/u/badflash)\
**Post date:** [22 March 2024 15:37 UTC](https://discourse.nodered.org/t/initializing-widgets-from-my-pi-pico-w/86647/10 "2024-03-22T15:37:38Z")

</div>

When I monitor the feed in HiveMQ I see it only sent once. If connect a MQTT input node to a debug, I only see it once. If I then also connect the same MQTT input to the switch the debug shows the message over and over. I don't get it.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [22 March 2024 15:49 UTC](https://discourse.nodered.org/t/initializing-widgets-from-my-pi-pico-w/86647/11 "2024-03-22T15:49:49Z")

</div>

Are you talking about a ui-switch in the node red dashboard? If so then set it to _not_ pass messages through.

---

<div class="post-metadata">

**Author:** ![badflash](https://avatars.discourse-cdn.com/v4/letter/b/d6d6ee/32.png) [@badflash](https://discourse.nodered.org/u/badflash)\
**Post date:** [22 March 2024 15:59 UTC](https://discourse.nodered.org/t/initializing-widgets-from-my-pi-pico-w/86647/12 "2024-03-22T15:59:04Z")

</div>

This is a dashboard switch. Not sure what a UI switch is. I'd post a picture, but I can't figure out how.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [22 March 2024 16:02 UTC](https://discourse.nodered.org/t/initializing-widgets-from-my-pi-pico-w/86647/13 "2024-03-22T16:02:35Z")

</div>

That is a ui-switch (or ui\_switch if using the old dashboard). In either case disable message pass through.

---

<div class="post-metadata">

**Author:** ![badflash](https://avatars.discourse-cdn.com/v4/letter/b/d6d6ee/32.png) [@badflash](https://discourse.nodered.org/u/badflash)\
**Post date:** [22 March 2024 16:09 UTC](https://discourse.nodered.org/t/initializing-widgets-from-my-pi-pico-w/86647/14 "2024-03-22T16:09:55Z")

</div>

Yes, that does initialize it in Node-Red, but the position on the dashboard does not show the proper possition. Any ideas how to fix that? After it is operated it works fine.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [22 March 2024 16:17 UTC](https://discourse.nodered.org/t/initializing-widgets-from-my-pi-pico-w/86647/15 "2024-03-22T16:17:54Z")

</div>

> [@badflash](#):
>
> I'd post a picture, but I can't figure out how.

Copy to the clipboard and CTRL-V in the forum works for me, or there is an upload button  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/a/0a65c4a8207a3d18b4b9b092c5b039af662a5fab.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [22 March 2024 16:25 UTC](https://discourse.nodered.org/t/initializing-widgets-from-my-pi-pico-w/86647/16 "2024-03-22T16:25:53Z")

</div>

> [@badflash](#):
>
> the position on the dashboard does not show the proper possition

Make sure you have 'show state of input` selected.

---

<div class="post-metadata">

**Author:** ![badflash](https://avatars.discourse-cdn.com/v4/letter/b/d6d6ee/32.png) [@badflash](https://discourse.nodered.org/u/badflash)\
**Post date:** [22 March 2024 16:38 UTC](https://discourse.nodered.org/t/initializing-widgets-from-my-pi-pico-w/86647/17 "2024-03-22T16:38:04Z")

</div>

That did it, thanks!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [5 April 2024 16:38 UTC](https://discourse.nodered.org/t/initializing-widgets-from-my-pi-pico-w/86647/18 "2024-04-05T16:38:36Z")

</div>

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