Posts

Showing posts with the label MicroPython

How to Power a Raspberry Pi Pico: USB, VSYS, Batteries and More

Image
The Raspberry Pi Pico is very relaxed about power. Its on-board regulator accepts anything from about 1.8 V to 5.5 V and turns it into the 3.3 V the chip needs, so you can run it from a USB cable, a phone charger, a power bank, AA batteries or a single lithium cell. Here's how each option works, which pins to use, and how to avoid the common mistakes.

Getting Started with MicroPython on the Raspberry Pi Pico

Image
Introduction to Raspberry Pi Pico  (scroll down to get to setup instructions) The Raspberry Pi Pico has quickly become a popular choice among hobbyists, students, and developers due to its affordability and versatility. With its compact size and powerful features, the Pico opens up a world of possibilities for various applications. In this review, we'll explore why the Raspberry Pi Pico is an excellent investment, showcasing real-world examples of how it can be used. Why Choose the Raspberry Pi Pico? Home Automation: With its GPIO pins and support for various interfaces, the Pico can be used to create smart home automation systems. You can connect sensors to monitor temperature, humidity, and motion, and control lights, switches, and appliances based on predefined conditions. The Pico's ability to communicate with Wi-Fi and Bluetooth modules further expands its capabilities in this area. Robotics: The Pico is a fantastic choice for robotics projects. Its GPIO pins can be connec...

How to Connect a Raspberry Pi Pico W to WiFi with MicroPython

Image
Getting a Raspberry Pi Pico W onto your WiFi network is the first step for almost every connected project, whether that's fetching the time from the internet, sending sensor readings somewhere or hosting a tiny web page. Below is the MicroPython code I use to connect a Raspberry Pi Pico W to WiFi and then blink the onboard LED, so you can see at a glance that it worked. Tested on a Raspberry Pi Pico W . What you need A Raspberry Pi Pico W. The original Pico has no wireless chip, so this code won't work on it. A micro-USB cable that carries data, not just power. MicroPython installed on the Pico W and Thonny on your computer. If you haven't done this yet, see Get started with Raspberry Pi Pico . Your WiFi network name (SSID) and password. The Pico W only supports 2.4 GHz WiFi. MicroPython code Replace YOUR SSID and YOUR PASSWORD with your own network details, then press Run in Thonny. import network import machine import time # Set SSID and password for you...

How to Blink an LED on the Raspberry Pi Pico and Pico W (MicroPython)

Image
Blinking an LED is the "Hello, World!" of microcontrollers. It's the quickest way to check that MicroPython is installed properly and that your code is actually running on the board. Below is the code to blink the onboard LED in MicroPython, with versions for both the wireless Pico W and the original (non-wireless) Pico, plus a few variations once you've got the basics working. Tested on a Raspberry Pi Pico W . What you need A Raspberry Pi Pico or Pico W A micro-USB cable that carries data MicroPython installed on the board and Thonny on your computer. See Get started with Raspberry Pi Pico if you haven't set these up yet. Why there are two versions On the original Pico, the onboard LED is connected to GPIO 25, so you can control it like any other pin. On the Pico W, that pin is used by the wireless chip, and the LED is wired to the wireless chip instead. MicroPython hides this detail for you: on the Pico W you refer to the LED by the name "LED...

Calculate the Speed of Sound from Temperature and Humidity in MicroPython

Image
The code below calculates the speed of sound in air in MicroPython, taking both temperature and humidity into account. It's useful anywhere you time sound to measure something, such as an ultrasonic distance sensor, where using a fixed figure like 343 m/s can throw your readings out by several percent on a cold morning or a hot afternoon. Tested on a Raspberry Pi Pico W . Why temperature and humidity matter Sound travels faster in warmer air because the air molecules are moving faster and pass the vibration along more quickly. Temperature is by far the biggest factor: the speed rises by roughly 0.6 m/s for every 1 °C. In dry air it's about 331 m/s at 0 °C and 343 m/s at 20 °C. Humidity has a smaller effect. Water vapour is lighter than the nitrogen and oxygen it replaces, so humid air carries sound slightly faster. At 20 °C, going from completely dry air to 100% humidity only adds about 1.3 m/s, but the effect grows in hot weather, so it's worth including if you want ...

How to Change the NTP Server in MicroPython (Raspberry Pi Pico W)

Image
The Raspberry Pi Pico W doesn't have a battery-backed clock, so every time it powers up it has no idea what the date or time is. MicroPython's ntptime module fixes that by fetching the time from an internet time server (an NTP server). By default it asks pool.ntp.org , but you can point it at any NTP server you like, such as Google's public time service, a server closer to you, or your own router. Here's how to change the NTP host and set the clock to your local time. The device must be connected to the internet. Tested on a Raspberry Pi Pico W . What you need A Raspberry Pi Pico W (or another MicroPython board with WiFi) MicroPython firmware and Thonny. See Get started with Raspberry Pi Pico . Your WiFi details. If you haven't connected the Pico W to WiFi before, start with Connecting to WiFi . MicroPython code Fill in your WiFi name and password, set UTC_OFFSET_HOURS to your time zone and run the script: import network import ntptime import time SS...

Popular posts from this blog

How to Connect a Raspberry Pi Pico W to WiFi with MicroPython

How to Blink an LED on the Raspberry Pi Pico and Pico W (MicroPython)