Altium
Raspberry Pi Pico

Raspberry Pi Pico W and Adafruit IO with Arduino IDE

Raspberry Pi Pico W:

Raspberry Pi Pico W

Raspberry Pi Pico W and Adafruit IO with Arduino IDE– Recently, I got Raspberry Pi Pico W from SunFounder at quite a reasonable price with free shipping. You can also try their Ultimate starter kit based on Raspberry Pi Pico W. Anyway, there are lots of things I am going to cover in this article. I will be comparing Raspberry pi Pico with Raspberry Pi Pico Wireless, I will also explain how to program Raspberry Pi Pico W using Arduino IDE, And I will also explain how to use Raspberry Pi Pico W with Adafruit IoT platform for sensor monitoring.

I have already written several articles on Raspberry pi Pico and in all those articles I have used MicroPython. So, if you want to learn how to program Raspberry pi Pico using MircroPython then I highly recommend; read my previous articles. Because in today’s article, I will be only using Arduino IDE.




Raspberry Pi Pico W:

Raspberry Pi Pico W is Raspberry Pi’s first wireless microcontroller board, designed especially for physical computing. Microcontrollers are a different type of device than Single Board Computers (like the Raspberry Pi 4 and previous generations of Pi), they don’t run an operating system and they are typically programmed to do just one task – though that task can be pretty intricate and exciting! They’re perfect for experimenting with hardware and using as the brains of custom devices, machines and inventions. With the onboard 2.4GHz wireless capabilities of the Pico W, it’s now possible for your creations to talk to each other, and to the internet! Apart from the addition of wireless networking, Raspberry Pi Pico W is very similar to Raspberry Pi Pico and, like all RP2040-based boards, can be easily reprogrammed over USB from a Raspberry Pi or other computer using the C/C++ SDK or the official MicroPython port.

Raspberry Pi Pico W comes without header pins so you’ll need to pick some up separately if you’re planning on plugging your Pico into a breadboard or one of our Pico add-ons. A Pico WH (with pre-soldered headers) is in the works but won’t be available at launch.

Pico W Specifications

Raspberry Pi Pico W has been designed to be a low cost yet flexible development platform for RP2040, with a 2.4GHz wireless interface and the following key features:

  • RP2040 microcontroller chip designed by Raspberry Pi in the United Kingdom
  • Dual-core ARM Cortex M0+ processor, flexible clock running up to 133 MHz
  • 264kB of SRAM, and 2MB of on-board Flash memory
  • On-board single-band 2.4GHz wireless interfaces (802.11n)
  • Castellated module allows soldering direct to carrier boards
  • USB 1.1 Host and Device support
  • Low-power sleep and dormant modes
  • Drag & drop programming using mass storage over USB
  • 26 multi-function GPIO pins
  • 2×SPI, 2×I2C, 2×UART, 3×12-bit ADC, 16×controllable PWM channels
  • Accurate clock and timer on-chip
  • Temperature sensor
  • Accelerated floating point libraries on-chip
  • 8×Programmable IO (PIO) state machines for custom peripheral support

Raspberry Pi Pico W and Pico WH incorporate an Infineon CYW43439 wireless chip. CYW43439 supports IEEE 802.11 b/g/n wireless LAN, and Bluetooth 5.2; of these, only wireless LAN is supported at launch



Raspberry Pi Pico W Pinout:

Raspberry Pi Pico W

Raspberry Pi Pico W Vs Raspberry Pi Pico:

Raspberry Pi Pico W

The main difference between the Raspberry Pi Pico and Raspberry Pi Pico W is that the Raspberry Pi Pico W has Wi-Fi connectivity while the Raspberry Pi Pico does not have any WiFi connectivity. The remaining specifications for both the Raspberry Pi Pico and Raspberry Pi Pico W are exactly the same.

Raspberry Pi Pico W Raspberry Pi Pico
Microcontroller RP2040 microcontroller chip RP2040 microcontroller chip
RAM 256kB 256kB
Processor Dual-core ARM Cortex M0+ processor Dual-core ARM Cortex M0+ processor
Flash memory 2MB 2MB
GPIO Pins 26 26
ADC 3 CH 12 bit 3 CH 12 bit
I2C 2 2
SPI 2 2
UART 2 2
PWM 16 16

As you can see the layout of the pins is also exactly the same.

Raspberry Pi Pico W

The other difference is that in the Raspberry Pi Pico the onboard led is on the GPIO26 while in the Raspberry Pi Pico W the onboard led is on the GPIO0. The GPIO26 in the Raspberry Pi Pico W is reserved for SPI communication with the wireless module.



Raspberry Pi Pico W with Arduino ide:

In order to use Raspberry Pi Pico W with Arduino IDE, first, you will need to install the Raspberry Pi Pico W board. For this, you will need to copy the following link.

https://github.com/earlephilhower/arduinopico/releases/download/global/package_rp2040_index.json

Next, Open the Arduino IDE. Go to the File Menu and then to Preferences. Paste the link, as you can see I have already pasted the link.

Raspberry Pi Pico W

If you have other boards links then simply put a comma and then paste the link…Finally, click on the Ok button, but as I have already pasted the link so I will click on the cancel button.

Next, go to the Tools Menu then to board, and click on the Boards Manager. Search for the Raspberry Pi Pico.

Raspberry Pi Pico W

As you can see I have already installed the Raspberry Pi Pico. Now, again go to Tools, then Board, and check if you can see Raspberry Pi Pico W.

Raspberry Pi Pico W

If you can see the Raspberry Pi Pico W then congrats you are done with the hard part. Anyway, the Arduino Ide is ready.

For the Demonstration purposes, I am going to use the DHT11 Temperature and Humidity Sensor with the Raspberry Pi Pico W. This is going to be an IoT “Internet of things” based project as I will be using Adafruit Io with Raspberry Pi Pico W for monitoring the Temperature and Humidity values from anywhere in the world. So, first let’s go ahead and take a look at the circuit diagram.



Altium Designer, Altium 365, & Octopart:

Arduino LoRa Free SMS

Altium 365 lets you hold the fastest design reviews ever. Share your designs from anywhere and with anyone with a single click. it’s easy, leave a comment tagging your teammate and they’ll instantly receive an email with a link to the design. Anyone you invite can open the design using a web browser. Using the browser interface, you’re able to comment, markup, cross probe, inspect, and more. Comments are attached directly to the project, making them viewable within Altium designer as well as through the browser interface. Design, share, and manufacture, all in the same space with nothing extra to install or configure. Connect to the platform directly from Altium Designer without changing how you already design electronics. Altium 365 requires no additional licenses and comes included with your subscription plan.

Get real-time component insights as you design with Octopart built into Altium 365. Octopart is the fastest search engine for electronic parts and gives you the most up-to-date part data like specs, datasheets, cad models, and how much the part costs at different amounts etc. Right in the design environment so you can focus on your designs. Start with Altium Designer and Activate Altium 365. Search for electronic parts on Octopart.




Amazon Links:

Raspberry Pi Pico W

Dht11 Sensor

Raspberry Pi Pico W Ultimate Kit

Other Tools and Components:

Top Arduino Sensors:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

DHT11 with Raspberry Pi Pico W:

Raspberry Pi Pico W

The Voltage and GND pins of the DHT11 Temperature and Humidity Sensor are connected with the 3.3V and GND pins of the Raspberry Pi Pico W. While the S pin or Data pin of the DHT11 sensor is connected with the GPIO pin 16. If you are not comfortable with using a breadboard, you can design a custom PCB for your Raspberry Pi Pico W. And you can send your Gerber Files to PCBWay for manufacturing High-quality PCBs. 

Raspberry Pi Pico W



Adafruit IO:

Raspberry Pi Pico W

For the Dashboard designing in Adafruit IO, you will need to read my previous article on the ESP8266, DHT11, and Adafruit IO. As I am going to use the same Dashboard. Anyway, once your dashboard is ready then you can start programming your Raspberry Pi Pico W using Arduino IDE. So, let’s go ahead and take a look at the programming.

Raspberry Pi Pico W Programming:

Just like I am using the Adafruit dashboard from my previous project, likewise I am using the same code which I wrote for the NodeMCU ESP8266 WiFi module. Below is the code that I wrote for Nodemcu ESP8266 WiFi Module. I am going to modify it a little bit.

ESP8266 and Adafruit:

#include <ESP8266WiFi.h>

#include <Adafruit_GFX.h>

#include <Adafruit_SSD1306.h>

#include “DHT.h”

#include “Adafruit_MQTT.h”

#include “Adafruit_MQTT_Client.h”

#define DHTPIN D4 //connect DHT data pin to D4

#define DHTTYPE DHT11   // DHT 11

DHT dht(DHTPIN, DHTTYPE);

#define SCREEN_WIDTH 128 // OLED display width, in pixels

#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)

#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

// WiFi parameters

#define WLAN_SSID       “AndroidAP3DEC”

#define WLAN_PASS       “electroniclinic”

// Adafruit IO

#define AIO_SERVER      “io.adafruit.com”

#define AIO_SERVERPORT  1883

//Enter the username and key from the Adafruit IO

#define AIO_USERNAME    “electroniclinic”

#define AIO_KEY         “aio_KrWj56Oiufjv84CQca5HfWD8ewWT”

WiFiClient client;

// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.

Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);

Adafruit_MQTT_Publish Temperature = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME “/feeds/Temperature”);

Adafruit_MQTT_Publish Humidity = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME “/feeds/Humidity”);

float temp; //to store the temperature value

float hum; // to store the humidity value

int buzzer=D5;

void setup() {

  Serial.begin(115200);

  pinMode(buzzer,OUTPUT);

   pinMode(DHTPIN, OUTPUT);

  dht.begin();          //Begins to receive Temperature and humidity values. 

  Serial.println(F(“Adafruit IO Example”));

  // Connect to WiFi access point.

display.begin(SSD1306_SWITCHCAPVCC, 0x3C);

  delay(2000);

  display.clearDisplay();

  display.setTextColor(WHITE);

  delay(10);

  Serial.print(F(“Connecting to “));

  Serial.println(WLAN_SSID);

  WiFi.begin(WLAN_SSID, WLAN_PASS);

  while (WiFi.status() != WL_CONNECTED) {

    delay(500);

    Serial.print(F(“.”)); 

  }

  Serial.println();

  Serial.println(F(“WiFi connected”));

  Serial.println(F(“IP address: “));

  Serial.println(WiFi.localIP());

  // connect to adafruit io

  connect();

}

// connect to adafruit io via MQTT

void connect() {

  Serial.print(F(“Connecting to Adafruit IO… “));

  int8_t ret;

  while ((ret = mqtt.connect()) != 0) {

    switch (ret) {

      case 1: Serial.println(F(“Wrong protocol”)); break;

      case 2: Serial.println(F(“ID rejected”)); break;

      case 3: Serial.println(F(“Server unavail”)); break;

      case 4: Serial.println(F(“Bad user/pass”)); break;

      case 5: Serial.println(F(“Not authed”)); break;

      case 6: Serial.println(F(“Failed to subscribe”)); break;

      default: Serial.println(F(“Connection failed”)); break;

    }

    if(ret >= 0)

      mqtt.disconnect();

    Serial.println(F(“Retrying connection…”));

    delay(10000);

  }

  Serial.println(F(“Adafruit IO Connected!”));

}

void loop() {

  // ping adafruit io a few times to make sure we remain connected

  if(! mqtt.ping(3)) {

    // reconnect to adafruit io

    if(! mqtt.connected())

      connect();

  }

 temp = dht.readTemperature();

 hum = dht.readHumidity();

Serial.print(“temperature = “);

Serial.println(temp);

Serial.print(“humidity = “);

Serial.println(hum);

  delay(5000);

   if (! Temperature.publish(temp)) {                     //Publish to Adafruit

      Serial.println(F(“Failed”));

    }

       if (! Humidity.publish(hum)) {                     //Publish to Adafruit

      Serial.println(F(“Failed”));

    }

    else {

      Serial.println(F(“Sent!”));

    }

    display.clearDisplay();

     display.setTextSize(2);

  display.setCursor(0, 10);

  display.print(temp);

   display.print((char)247);

  display.print(“C”);

    display.setTextSize(2);

  display.setCursor(0, 30);

 display.print(“H:”+String(hum)+”%”);

  display.display();

if(temp>40)

{

  digitalWrite(buzzer,HIGH);

  }

  else

  {

      digitalWrite(buzzer,LOW);

    }

}



Raspberry Pi Pico W and Adafruit Io:

/* download the required libraries

https://www.electroniclinic.com/esp8266-with-adafruit-iot-platform-adafruit-io-adafruit-mqtt/

*/

#include <WiFi.h>

#include <DHT.h>

#include “Adafruit_MQTT.h”

#include “Adafruit_MQTT_Client.h”

#define DHTPIN 16           

#define DHTTYPE DHT11      

DHT dht(DHTPIN, DHTTYPE);  

// WiFi parameters

#define WLAN_SSID       “AndroidAP3DEC”

#define WLAN_PASS       “electroniclinic”

// Adafruit IO

#define AIO_SERVER      “io.adafruit.com”

#define AIO_SERVERPORT  1883

//Enter the username and key from the Adafruit IO

#define AIO_USERNAME    “electroniclinic”

#define AIO_KEY         “aio_KrWj56Oiufjv84CQca5HfWD8ewWT”

WiFiClient client;

// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.

Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);

Adafruit_MQTT_Publish Temperature = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME “/feeds/Temperature”);

Adafruit_MQTT_Publish Humidity = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME “/feeds/Humidity”);

float temp; //to store the temperature value

float hum; // to store the humidity value

void setup() {

  Serial.begin(115200);

  dht.begin();          //Begins to receive Temperature and humidity values. 

  Serial.println(F(“Adafruit IO Example”));

  // Connect to WiFi access point.

  Serial.print(F(“Connecting to “));

  Serial.println(WLAN_SSID);

  WiFi.begin(WLAN_SSID, WLAN_PASS);

  while (WiFi.status() != WL_CONNECTED) {

    delay(500);

    Serial.print(F(“.”));

  }

  Serial.println();

  Serial.println(F(“WiFi connected”));

  Serial.println(F(“IP address: “));

  Serial.println(WiFi.localIP());

  // connect to adafruit io

  connect();

}

// connect to adafruit io via MQTT

void connect() {

  Serial.print(F(“Connecting to Adafruit IO… “));

  int8_t ret;

  while ((ret = mqtt.connect()) != 0) {

    switch (ret) {

      case 1: Serial.println(F(“Wrong protocol”)); break;

      case 2: Serial.println(F(“ID rejected”)); break;

      case 3: Serial.println(F(“Server unavail”)); break;

      case 4: Serial.println(F(“Bad user/pass”)); break;

      case 5: Serial.println(F(“Not authed”)); break;

      case 6: Serial.println(F(“Failed to subscribe”)); break;

      default: Serial.println(F(“Connection failed”)); break;

    }

    if(ret >= 0)

      mqtt.disconnect();

    Serial.println(F(“Retrying connection…”));

    delay(10000);

  }

  Serial.println(F(“Adafruit IO Connected!”));

}

void loop() {

  // ping adafruit io a few times to make sure we remain connected

  if(! mqtt.ping(3)) {

    // reconnect to adafruit io

    if(! mqtt.connected())

      connect();

  }

 temp = dht.readTemperature();

 hum = dht.readHumidity();

Serial.print(“temperature = “);

Serial.println(temp);

Serial.print(“humidity = “);

Serial.println(hum);

 

  delay(5000);

  

   if (! Temperature.publish(temp)) {                     //Publish to Adafruit

      Serial.println(F(“Failed”));

    }

       if (! Humidity.publish(hum)) {                     //Publish to Adafruit

      Serial.println(F(“Failed”));

    }

    else {

      Serial.println(F(“Sent!”));

    }

   

}

Whereas this is the code that I wrote for the Raspberry Pi Pico W. The code that I wrote for the Raspberry Pi Pico W is the Modified version of my previous code. The only changes I made are, as this time I am not using the Oled display module and the 5V buzzer so I deleted the related libraries and code.



Instead of using the ESP8266WiFi library I am using the WiFi library. If you have been using the ESP8266 board then you should have this WiFi library. Or else you will have to install this; for this you can read my getting started article on the NodeMCU ESP8266 WiFi Module.

Anyway, you can see, I am using the same DHT library and the same Adafruit libraries. Previously, I was using D4 pin on the ESP8266 while this time I am using GPIO Pin 16 on the Raspberry Pi Pico W. The Oled display module code is deleted.

I am using the same WiFi credentials.

The Adafruit IO settings are 100% the same.

Code inside the setup() function is exactly the same.

And the code inside the Loop() is exactly the same.

The reason, I am using the same code which I wrote for the NodeMCU ESP8266 with the Raspberry Pi Pico W is, I wanted to explain that you can convert all your ESP8266 or ESP32 related projects into Raspberry Pi Pico W based projects. I have hundreds of articles on Nodemcu ESP8266 and ESP32, you can select any project, copy code from there and use it with your Raspberry Pi Pico W. So, that’s all about the programming. Now, let’s go ahead and watch the Raspberry Pi Pico W and Adafruit IO based Temperature and Humidity monitoring system in action.

Raspberry Pi Pico W

After applying heat…

Raspberry Pi Pico W

Watch Video Tutorial

Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button