---
title: "How to Connect Raspberry Pi Pico to Twitter using Ethernet HAT and IFTTT"
url: "https://maker.wiznet.io/viktor/projects/how-to-connect-raspberry-pi-pico-to-twitter-using-ethernet-hat-and-ifttt/"
markdown_url: "https://maker.wiznet.io/viktor/projects/how-to-connect-raspberry-pi-pico-to-twitter-using-ethernet-hat-and-ifttt/md"
type: "WCC: WIZnet Created Content"
author: "viktor"
author_url: "https://maker.wiznet.io/viktor/"
original_author: "Viktor"
published: "2023-07-18"
language: "en"
hardware: ["Raspberry Pi Pico", "WIZnet Ethernet HAT"]
likes: 1
views: 4798
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# How to Connect Raspberry Pi Pico to Twitter using Ethernet HAT and IFTTT

> This projects aims to guide how to connect Rpi Pico to Twitter with help of WIZnet Ethernet HAT, IFTTT and Micropython

Original author: Viktor

## Components

- **Raspberry Pi Pico** x 1 ([docs](https://www.raspberrypi.com/documentation/microcontrollers/raspberry-pi-pico.html))
- **WIZnet Ethernet HAT** x 1
- Software: **MicroPython** ([docs](http://micropython.org/))
- Software: **ifttt Maker service** ([docs](https://ifttt.com/maker_webhooks))

## Documents and links

- [post-tweet.py](https://maker.wiznet.io/_lib/download.asp?path=project/2281&downfile=post%2Dtweet0%2Epy) (code)
- [Pico Custom firmware](https://maker.wiznet.io/_lib/download.asp?path=project/2281&downfile=pico%2Dcustom%2Dfirmware%2Euf2) (code)

## Article

**1. Introduction**

To continue my micropython journey started in previous [project](http://maker.wiznet.io/viktor/projects/ble%2Dto%2Dethernet%2Dcentral/), this time I decided to try connecting Raspberry Pi Pico and Twitter using WIZnet Ethernet HAT and Micropython.

As WIZnet Ethernet HAT is designed to be pin-compatible with Raspberry Pi Pico, connecting these boards is simple. For more details about the board, refer to [docs page](http://docs.wiznet.io/Product/Open-Source-Hardware/wiznet_ethernet_hat) and [youtube video](https://www.youtube.com/watch?v=RTyaJc1gNrg)

![](https://maker.wiznet.io/upload/ckeditor5/687822326%5F1689695597%2Epng)

| Pico Pin | Description |
| --- | --- |
| GPIO16 | Connected to MISO on W5100S |
| GPIO17 | Connected to CSn on W5100S |
| GPIO18 | Connected to SCLK on W5100S |
| GPIO19 | Connected to MOSI on W5100S |
| GPIO20 | Connected to RSTn on W5100S |
| GPIO21 | Connected to INTn on W5100S |

Please note that this project can be replicated using W5100S-EVB-Pico or W5500-EVB-Pico boards. In this case you can skip 3rd step with "Customizing Micropython firmware".

**2. Setup IFTTT**

IFTTT, or If This, Then That, acts as the bridge connecting Raspberry Pi Pico to Twitter. It's a free service that facilitates the integration of various data services. I'll create an applet that responds to a webhook, sending data to IFTTT. Subsequently, IFTTT will include this data in a message sent to Twitter.

(a) Visit [IFTTT](https://ifttt.com/explore), create account and login

(b) Click "Create" button

![](https://maker.wiznet.io/upload/ckeditor5/687822326%5F1689695970%2Epng)

(c) Click on "Add" button to create a trigger event.

![](https://maker.wiznet.io/upload/ckeditor5/687822326%5F1689696050%2Epng)

(d) Search for "webhook" and click on the tile

![](https://maker.wiznet.io/upload/ckeditor5/687822326%5F1689696158%2Epng)

(e) Select "Receive a web request"

![](https://maker.wiznet.io/upload/ckeditor5/687822326%5F1689696167%2Epng)

(f) Create an Event name and press "Create trigger" button

![](https://maker.wiznet.io/upload/ckeditor5/687822326%5F1689696251%2Epng)

(g) "If" is now configured, now let's set "Then That". Click "Add"

![](https://maker.wiznet.io/upload/ckeditor5/687822326%5F1689696350%2Epng)

(h) Type "Twitter" in the search bar and click on the icon

![](https://maker.wiznet.io/upload/ckeditor5/687822326%5F1689696447%2Epng)

(i) Select "Post a tweet"

![](https://maker.wiznet.io/upload/ckeditor5/687822326%5F1689696530%2Epng)

(j) Type in your Twitter account (make sure it is correct). Customize your tweet text, press "Add ingredient" to add variable

![](https://maker.wiznet.io/upload/ckeditor5/687822326%5F1689696654%2Epng)

(k) Click "Continue" button

![](https://maker.wiznet.io/upload/ckeditor5/687822326%5F1689696716%2Epng)

(l) Review the applet, toggle the button to opt in for notifications and click "Finish" button

![](https://maker.wiznet.io/upload/ckeditor5/687822326%5F1689696754%2Epng)

(m) Visit [webhook page](https://ifttt.com/maker_webhooks) and click "Documentation" button

![](https://maker.wiznet.io/upload/ckeditor5/687822326%5F1689696897%2Epng)

(n) Copy the post link.

```plaintext
https://maker.ifttt.com/trigger/{event}/json/with/key/YOUR API KEY HERE
```

Remove/json, change {event} to your trigger name (in my case "post-tweet") and insert your API key.

```plaintext
https://maker.ifttt.com/trigger/post-tweet/with/key/YOUR API KEY HERE
```

**3. Custom Micropython firmware**

As I am using Raspberry Pi Pico, the basic Micropython firmware doesn't have WIZNET5K library. Therefore I need to build a firmware that would contain this library.

*Disclaimer: It is my second time using Micropython, there might be better and easier way to add network library to Pico. Below changes are effective as of July 2023.*

(a) Clone micropython repository

(b) Navigate to "ports/rp2/boards/PICO" folder and make following changes

(c) In mpconfigboard.h add

```plaintext
// Board and hardware specific configuration
#define MICROPY_HW_BOARD_NAME                   "Raspberry Pi Pico"
#define MICROPY_HW_FLASH_STORAGE_BYTES          (1408 * 1024)

#define MICROPY_PY_NETWORK                      (1)
```

(d) In mpconfigboard.cmake add

```plaintext
# cmake file for Raspberry Pi Pico

set(MICROPY_PY_NETWORK_WIZNET5K W5100S)
set(MICROPY_PY_LWIP 1)
set(MICROPY_FROZEN_MANIFEST ${MICROPY_BOARD_DIR}/manifest.py)
```

(e) Create new manifest.py file and copy following

```plaintext
include("$(PORT_DIR)/boards/manifest.py")

require("bundle-networking")
```

(f) Build and flash firmware to the Pico board

**4. The code**

(a) Import modules and libraries

```plaintext
from usocket import socket
from machine import Pin,SPI
import network
import time
import urequests
```

(b) Initialize WIZnet chip. In my case I used static IP, make sure to update according to your environment.

```plaintext
#W5x00 chip init
def w5x00_init():
    spi=SPI(0,2_000_000, mosi=Pin(19),miso=Pin(16),sck=Pin(18))
    nic = network.WIZNET5K(spi,Pin(17),Pin(20)) #spi,cs,reset pin
    nic.active(True)
    nic.ifconfig(('192.168.11.30','255.255.255.0','192.168.11.1','8.8.8.8'))
    while not nic.isconnected():
        time.sleep(1)
        print(nic.regs())
    print(nic.ifconfig())
```

(c) Post the message to Twitter using the urequests.post

```plaintext
    message = "https://maker.ifttt.com/trigger/post-tweet/with/key/YOUR_API_KEY_HERE?value1=Hello%20World"
    urequests.post(message)
```

The complete code:

```plaintext
from usocket import socket
from machine import Pin,SPI
import network
import time
import urequests

#W5x00 chip init
def w5x00_init():
    spi=SPI(0,2_000_000, mosi=Pin(19),miso=Pin(16),sck=Pin(18))
    nic = network.WIZNET5K(spi,Pin(17),Pin(20)) #spi,cs,reset pin
    nic.active(True)
    nic.ifconfig(('192.168.11.30','255.255.255.0','192.168.11.1','8.8.8.8'))
    while not nic.isconnected():
        time.sleep(1)
        print(nic.regs())
    print(nic.ifconfig())
        
def main():
    w5x00_init()

    message = "https://maker.ifttt.com/trigger/post-tweet/with/key/YOUR_API_KEY_HERE?value1=Hello%20World"
    urequests.post(message)
    
if __name__ == "__main__":
    main()
```

**Note**: IFTTT has a rate limit of 25 tweets per day, so make sure to add sleep interval when posting in a loop

**5. Result**

After running the code, you will get an email from IFTTT (if opted for notifications) and see the corresponding post in your Twitter account.

![](https://maker.wiznet.io/upload/ckeditor5/687822326%5F1689698192%2Epng)

**6. Next plan**

I might use this to automate my SNS posting. Stay tuned for next project :)

---

Source: https://maker.wiznet.io/viktor/projects/how-to-connect-raspberry-pi-pico-to-twitter-using-ethernet-hat-and-ifttt/
