-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial Support for RP2040 platform #3284
Conversation
Hey there @jesserockz, CODEOWNERS = ["@jesserockz"] And run (message by NeedsCodeownersLabel) |
tries = 0 | ||
while tries < 5: | ||
try: | ||
with ser: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Afaik this should call .close()
on the serial object if an exception happens (what the with clause is meant to do). If this code retries the connection, it should not wrap it in this with
at least at this level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The with
line was throwing the exception because the port did not (yet) exist which is why I put the try and retry around it, would it still need to close a port that did not open? The inner code catches the exception in the case when it tries to actually read from the port...
esphome/core/helpers.cpp
Outdated
@@ -76,6 +76,8 @@ uint32_t random_uint32() { | |||
return esp_random(); | |||
#elif defined(USE_ESP8266) | |||
return os_random(); | |||
#elif defined(USE_RP2040) | |||
return rand(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note this returns values from 0 to RAND_MAX, which iirc usually is 2**16
. To return a random 32 bit value it should run rand multiple times to get 0-2**32
range
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was not sure about this part at all, thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this suffice?
return rand(); | |
return ((uint32_t) rand()) + ((uint32_t) rand()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that only doubles the range from 0..216 to 0..217. You want rand()<<16 + rand(). Not sure if the casts are needed on that or not, but it's certianly safe to include them: ((uint32_t) rand())<<16 + ((uint32_t) rand());
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh duh, how did I miss that..haha
PLATFORM_ESP32, | ||
PLATFORM_ESP8266, | ||
PLATFORM_RP2040, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not that I really want a change but aren't we calling platform other things already? what about CHIPSET or something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point 😅
But it was esphome
-> platform
before which is why I guess
I'm trying to test this on my Mac (running on an M1 Mac Studio), but when I try
It looks like |
After the versions were bumped, compilation works great on my M1 Mac Studio. With the following config, I was able to get the LED flashing on my Pico via ESPHome—nice! esphome:
name: rpi-pico
rp2040:
board: pico
output:
- platform: gpio
pin:
number: 25
mode: output
id: LED
interval:
- interval: 500ms
then:
- output.turn_on: LED
- delay: 250ms
- output.turn_off: LED To install this branch, I ran |
Tried installing using windows. Got the following error
|
For those following this PR, I ave pushed another round of changes. There are still things missing, but Home Assistant can talk to the pico-w via the ESPHome API and ESPHome can update the pico-w via OTA updates. I call that progress =) Would be good to know if specific sensors/configurations do not work so I can look into them so please leave a comment if you find something. Thanks, |
Great to see this closer to merging! I am unable to test even a minimal config and haven't been able to find what's wrong with my setup, must be missing something very obvious.
|
Did you try a |
My lack of pio-fu is strong. Yes, that worked, I can toy around with rp2040home now 😃 |
|
Might be the wrong place and I might just be dumb so feel free to delete, but I can't seem to find the right device path when uploading a firmware. The .yaml file compiles successfully on both windows 11 and raspbian bullseye, but I can't seem to find the right device path for my pico w on either windows or from a pi 4. I expected the device to show up under /dev/ttyUSB*, but it doesn't, only /dev/sda and did not work. Jeef Geerling has a short blog about this on his site, but he is using mac OS and says the path for the USB volume will be different. |
@BenSisk Initially you need to put the device into bootloader mode by holding the button when powering it on. Then you can drag and drop the uf2 firmware file into the storage device that will be mounted on the computer. It will then automatically boot ESPHome. |
Hey there @esphome/core, mind taking a look at this pull request as it has been labeled with an integration ( |
I am going to merge this PR so its easier for people to test and make PRs to improve support. |
What does this implement/fix?
Basic support for RP2040
esphome/feature-requests#1924
This code is also waiting on platformio/platform-raspberrypi#36
Types of changes
Related issue or feature (if applicable): fixes
Pull request in esphome-docs with documentation (if applicable): esphome/esphome-docs#
Test Environment
Example entry for A Raspberry Pi Pico:
Example entry for A Raspberry Pi Pico W:
Checklist:
tests/
folder).If user exposed functionality or configuration variables are added/changed:
Fix preferences crashing