{"id":182724,"date":"2025-12-05T12:08:26","date_gmt":"2025-12-05T12:08:26","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=182724"},"modified":"2025-12-05T12:08:28","modified_gmt":"2025-12-05T12:08:28","slug":"raspberry-pi-pico-w-static-ip-address-micropython","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-w-static-ip-address-micropython\/","title":{"rendered":"Raspberry Pi Pico W: Set a Static IP Address (MicroPython)"},"content":{"rendered":"\n<p>Learn how to set a static \/ fixed IP address for your Raspberry Pi Pico W. When your Pico connects to a network, some routers may assign a different IP address each time it reboots. This can be inconvenient if you need to access or communicate with your board using its IP address. In this guide, we\u2019ll show you how to assign a static IP address to your Raspberry Pi Pico W.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/11\/Raspberry-Pi-Pico-Static-IP-Address.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Pico W Setting a Static \/ Fixed IP Address MicroPython\" class=\"wp-image-182766\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/11\/Raspberry-Pi-Pico-Static-IP-Address.jpg?w=1920&amp;quality=100&amp;strip=all&amp;ssl=1 1920w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/11\/Raspberry-Pi-Pico-Static-IP-Address.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/11\/Raspberry-Pi-Pico-Static-IP-Address.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/11\/Raspberry-Pi-Pico-Static-IP-Address.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/11\/Raspberry-Pi-Pico-Static-IP-Address.jpg?resize=1536%2C864&amp;quality=100&amp;strip=all&amp;ssl=1 1536w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n<p class=\"rntbox rntclgreen\"><strong>Recommended reading: <\/strong><a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-w-wi-fi-micropython\/\" title=\"\">Raspberry Pi Pico W: Getting Started with Wi-Fi (MicroPython)<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p>To follow this tutorial, you need:<\/p>\n\n\n\n<p><strong>1)<\/strong> A <strong><a href=\"https:\/\/makeradvisor.com\/tools\/raspberry-pi-pico-w\/\" target=\"_blank\" rel=\"noopener\" title=\"\">Raspberry Pi Pico W<\/a><\/strong> or <a href=\"https:\/\/makeradvisor.com\/tools\/raspberry-pi-pico-2-w\/\" target=\"_blank\" rel=\"noopener\" title=\"\"><strong>Raspberry Pi Pico 2W<\/strong><\/a> board (these models support Wi-Fi).<\/p>\n\n\n\n<p><strong>2)<\/strong> MicroPython firmware installed on your Raspberry Pi Pico board, and an IDE to write and upload code. Follow this tutorial: <a href=\"https:\/\/randomnerdtutorials.com\/getting-started-raspberry-pi-pico-w\/#install-thonny-ide\">Programming Raspberry Pi Pico using MicroPython<\/a>.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"static-ip\">Setting a Static\/Fixed IP Address on the Raspberry Pi Pico<\/h1>\n\n\n\n<p>In the case of my network, even if I restart the Raspberry Pi Pico several times, my router will always assign it the same IP address. However, that\u2019s not the case for some other networks. In that scenario, it\u2019s nice to have a way to set a static IP address to your board, so that it doesn\u2019t change every time it resets. <\/p>\n\n\n\n<p>Additionally, setting a static IP address is also useful for projects that are not connected to your computer or don\u2019t have a way to display the IP address.<\/p>\n\n\n\n<div class=\"wp-block-group rntbox rntclgray\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<p>You can use the <span class=\"rnthl rntliteral\">ifconfig<\/span> method of the <span class=\"rnthl rntliteral\">network.WLAN<\/span> object to set a static IP address. For example, use the following line after connecting to your network.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>wlan.ifconfig((static_ip, subnet_mask, gateway_ip, dns_server))<\/code><\/pre>\n<\/div><\/div>\n\n\n\n<p>The following example connects your board to your network and then sets a static IP address.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-python\"># Rui Santos &amp; Sara Santos - Random Nerd Tutorials\r\n# Complete project details at https:\/\/RandomNerdTutorials.com\/raspberry-pi-pico-w-wi-fi-micropython\/\r\n\r\nimport network\r\nimport time\r\n\r\n# Wi-Fi credentials\r\nssid = 'REPLACE_WITH_YOUR_SSID'\r\npassword = 'REPLACE_WITH_YOUR_PASSWORD'\r\n\r\n# Static IP configuration\r\nstatic_ip = '192.168.1.100'  # Replace with your desired static IP\r\nsubnet_mask = '255.255.255.0'\r\ngateway_ip = '192.168.1.254'\r\ndns_server = '8.8.8.8'\r\n\r\n# Init Wi-Fi Interface\r\nwlan = network.WLAN(network.STA_IF)\r\nwlan.active(True)\r\n\r\n# Connect to your network\r\nwlan.connect(ssid, password)\r\n\r\n# Wait for Wi-Fi connection\r\nconnection_timeout = 10\r\nwhile connection_timeout &gt; 0:\r\n    if wlan.status() &gt;= 3:\r\n        break\r\n    connection_timeout -= 1\r\n    print('Waiting for Wi-Fi connection...')\r\n    time.sleep(1)\r\n\r\n# Set static IP address\r\nwlan.ifconfig((static_ip, subnet_mask, gateway_ip, dns_server))\r\n\r\n# Check if connection is successful\r\nif wlan.status() != 3:\r\n    raise RuntimeError('Failed to establish a network connection')\r\nelse:\r\n    print('Connection successful!')\r\n    network_info = wlan.ifconfig()\r\n    print('IP address:', network_info[0])<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/Raspberry-Pi-Pico\/MicroPython\/Static_IP_Address.py\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Static IP Configuration<\/h3>\n\n\n\n<p>Replace the values in the <span class=\"rnthl rntliteral\">static_ip<\/span>, <span class=\"rnthl rntliteral\">subnet_mask<\/span>, <span class=\"rnthl rntliteral\">gateway_ip<\/span>, and <span class=\"rnthl rntliteral\">dns_server<\/span> variables with the appropriate values for your network.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code># Static IP configuration\nstatic_ip = '192.168.1.100'  # Replace with your desired static IP\nsubnet_mask = '255.255.255.0'\ngateway_ip = '192.168.1.254'\ndns_server = '8.8.8.8'<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">How to find those values?<\/h4>\n\n\n\n<p>There are different ways to get information about the subnet mask and the gateway IP. The easiest way is to open a Terminal window on your computer and run the following command:<\/p>\n\n\n\n<p>On Windows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ipconfig<\/code><\/pre>\n\n\n\n<p>On MacOS or Linux: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ifconfig<\/code><\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"781\" height=\"115\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/09\/running-ip-config.png?resize=781%2C115&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ipconfig commang\" class=\"wp-image-162285\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/09\/running-ip-config.png?w=781&amp;quality=100&amp;strip=all&amp;ssl=1 781w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/09\/running-ip-config.png?resize=300%2C44&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/09\/running-ip-config.png?resize=768%2C113&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 781px) 100vw, 781px\" \/><\/figure><\/div>\n\n\n<p>It will return the information you\u2019re looking for: the gateway IP (the IP address of your router) and the subnet mask.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"781\" height=\"324\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/09\/WLAN-Details.png?resize=781%2C324&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ipconfig wlan details\" class=\"wp-image-162286\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/09\/WLAN-Details.png?w=781&amp;quality=100&amp;strip=all&amp;ssl=1 781w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/09\/WLAN-Details.png?resize=300%2C124&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/09\/WLAN-Details.png?resize=768%2C319&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 781px) 100vw, 781px\" \/><\/figure><\/div>\n\n\n<p>In my case, the subnet mask is <strong>255.255.255.0<\/strong> and the gateway IP address is <strong>192.168.1.254<\/strong>.<\/p>\n\n\n\n<p>For the DNS server, you can always use<strong> 8.8.8.8<\/strong>, which is Google\u2019s public DNS server.<\/p>\n\n\n\n<p>When choosing the static IP address for your Raspberry Pi Pico, make sure that the address is not already being used by another device. To do that, you can use software like Angry IP Scanner (compatible with Windows and Mac OS). Or you can login to your router dashboard and check which IP addresses are already assigned.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Setting a Static IP Address<\/h3>\n\n\n\n<p>After assigning the proper values for the configuration variables, we can simply use the <span class=\"rnthl rntliteral\">ifconfig()<\/span> method and pass as arguments the static IP, the subnet mask, the gateway IP, and the DNS server, in this order.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>wlan.ifconfig((static_ip, subnet_mask, gateway_ip, dns_server))<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Inserting Your Network Credentials<\/h3>\n\n\n\n<p>To test this code, don&#8217;t forget to insert your network credentials in the following lines so that your board can connect to your router:<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>ssid = 'REPLACE_WITH_YOUR_SSID'\npassword = 'REPLACE_WITH_YOUR_PASSWORD'<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Testing the Code<\/h3>\n\n\n\n<p>After inserting your network credentials and desired IP address settings, you can run the code on your Raspberry Pi Pico.<\/p>\n\n\n\n<p>Notice that it will have the IP address you defined in the code. In our case, <strong>192.168.1.100<\/strong>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"705\" height=\"269\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/09\/rpi-pico-set-static-ip-address.png?resize=705%2C269&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Pico Set Static IP address\" class=\"wp-image-162287\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/09\/rpi-pico-set-static-ip-address.png?w=705&amp;quality=100&amp;strip=all&amp;ssl=1 705w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/09\/rpi-pico-set-static-ip-address.png?resize=300%2C114&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 705px) 100vw, 705px\" \/><\/figure><\/div>\n\n\n<p>You can also check your router&#8217;s dashboard or AngryIP Scanner to confirm that your RPi Pico has been assigned the IP address you chose.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"591\" height=\"253\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/11\/RPi-Pico-IP-Address-On-Angry-IP-Scanner.jpg?resize=591%2C253&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Pico with Static IP Address on AngryIPScanner\" class=\"wp-image-182730\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/11\/RPi-Pico-IP-Address-On-Angry-IP-Scanner.jpg?w=591&amp;quality=100&amp;strip=all&amp;ssl=1 591w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/11\/RPi-Pico-IP-Address-On-Angry-IP-Scanner.jpg?resize=300%2C128&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 591px) 100vw, 591px\" \/><\/figure><\/div>\n\n\n<p>Restart your board, and check that it remains with the same IP address.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>This was a quick guide showing you how you can modify your MicroPython scripts to set a static\/fixed IP address to your Raspberry Pi Pico. We have other Wi-Fi and network-related guides for the Raspberry Pi Pico that you may like:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-w-wi-fi-micropython\/\" title=\"\">Raspberry Pi Pico W: Getting Started with Wi-Fi (MicroPython)<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-w-http-requests-micropython\/\">Raspberry Pi Pico W: Getting Started with HTTP GET Requests (MicroPython)<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-web-server-micropython\/\">Raspberry Pi Pico: Web Server (MicroPython)<\/a><\/li>\n<\/ul>\n\n\n\n<p>Learn more about the Raspberry Pi Pico with our resources:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/projects-raspberry-pi-pico\/\" title=\"\">All our Raspberry Pi Pico Projects and Guides<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-w-micropython-ebook\/\" title=\"\">Learn Raspberry Pi Pico\/Pico W with MicroPython eBook<\/a><\/li>\n<\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to set a static \/ fixed IP address for your Raspberry Pi Pico W. When your Pico connects to a network, some routers may assign a different IP &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Raspberry Pi Pico W: Set a Static IP Address (MicroPython)\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-w-static-ip-address-micropython\/#more-182724\" aria-label=\"Read more about Raspberry Pi Pico W: Set a Static IP Address (MicroPython)\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":182766,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[324,326],"tags":[],"class_list":["post-182724","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-raspberry-pi-pico","category-raspberry-pi-pico-micropython"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2025\/11\/Raspberry-Pi-Pico-Static-IP-Address.jpg?fit=1920%2C1080&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/182724","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=182724"}],"version-history":[{"count":9,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/182724\/revisions"}],"predecessor-version":[{"id":185414,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/182724\/revisions\/185414"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/182766"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=182724"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=182724"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=182724"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}