Published on

How to Use WhatsApp on a Raspberry Pi

Authors
  • avatar
    Name
    how-to.digital
    Twitter

How to Use WhatsApp on a Raspberry Pi

Introduction

WhatsApp is a popular messaging application that allows users to send text messages, make voice and video calls, and share media files. By setting up WhatsApp on a Raspberry Pi, you can conveniently access and use the application on your Pi. In this tutorial, we will walk you through the step-by-step process of installing and using WhatsApp on a Raspberry Pi.

Prerequisites

Before you get started, ensure that you have the following:

  1. Raspberry Pi (any model)
  2. MicroSD card with the latest Raspberry Pi OS installed
  3. USB microphone and speaker (optional)
  4. HDMI display and keyboard (for initial setup)
  5. Internet connection
  6. Mobile phone with WhatsApp installed

Step 1: Set Up Raspberry Pi

  1. Connect your Raspberry Pi to a power source, HDMI display, and keyboard.
  2. Insert the MicroSD card with Raspberry Pi OS into the Pi's SD card slot.
  3. Power on the Pi and follow the on-screen instructions to set up the operating system.
  4. Connect the Pi to your Wi-Fi network to ensure internet connectivity.

Step 2: Install Required Dependencies

  1. Open a terminal on your Raspberry Pi or connect to it remotely using SSH.
  2. Update the package lists by running the following command:
sudo apt update
  1. Install the required dependencies by executing the following commands:
sudo apt install python3 python3-pip libatlas-base-dev
pip3 install selenium

Step 3: Download and Configure WhatsApp Webdriver

  1. In the terminal, create a new directory for the WhatsApp project by running:
mkdir whatsapp && cd whatsapp
  1. Download the Chrome webdriver for Selenium by executing the following commands:
wget https://chromedriver.storage.googleapis.com/$(wget -O - https://chromedriver.storage.googleapis.com/LATEST_RELEASE)/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
rm chromedriver_linux64.zip
  1. Move the downloaded webdriver to /usr/local/bin using the command:
sudo mv chromedriver /usr/local/bin/

Step 4: Create the WhatsApp Bot Script

  1. Create a new file using the command:
nano whatsapp_bot.py
  1. Copy and paste the following Python script into the file:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument("--headless") # Run Chrome in headless mode (without GUI)
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-dev-shm-usage")

driver = webdriver.Chrome(options=chrome_options)
driver.get('https://web.whatsapp.com')

input('Scan the QR code and press enter to continue...')

# You can now interact with WhatsApp using Selenium webdriver commands

driver.quit()
  1. Save and exit the file by pressing Ctrl+X, followed by Y, then Enter.

Step 5: Run the WhatsApp Bot

  1. Make the Python script executable by running:
chmod +x whatsapp_bot.py
  1. Execute the script with the following command:
./whatsapp_bot.py
  1. Scan the QR code displayed on the Raspberry Pi screen with your WhatsApp mobile app to authenticate.
  2. Press enter in the terminal to start interacting with WhatsApp using Selenium webdriver commands.

Conclusion

Congratulations! You have successfully set up and used WhatsApp on your Raspberry Pi. You can now further customize the Python script and automate tasks on the WhatsApp platform using the Selenium webdriver. Enjoy using WhatsApp on your Raspberry Pi!