Setting up Raspberry Pi without HDMI cable or Ethernet Cable
Hi coders,
I was wandering around to find a way to program Raspberry Pi over USB only. As I am lacking an HDMI cable I searched everywhere and found something useful. And I hope it should be available for everyone and I am presenting it for you, please note that this is a working trick for any of Raspberry Pi models which possess Wi-Fi connectivity.
1. Setting Up Raspberry Pi
I am here using a Raspberry Pi Zero W and this method is suitable for Pi Zero W. Raspberry Pi Zero W has two micro USB slots. One is only for powering and other for programming.
2. Flashing OS to SD Card
Download RASPBIAN OS. Use any of bootable SD making software like ETCHER or RUFUS and make a bootable SD card with the downloaded image.
3. Editing files to make Raspberry Pi accessible with PuTTY
After reinserting SD card we can see a new device named boot and we need to edit some files before inserting it into Raspberry Pi.
- Create a new file in boot name
ssh
with no extension which will enable SSH in Raspberry Pi
Create a file called wpa_supplicant.conf
. This is a configuration file that will allow you to pre configure the WiFi credentials. Paste this piece of code
country=USctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdevupdate_config=1network={ ssid="WIFI_SSID" scan_ssid=1 psk="WIFI_PASSWORD" key_mgmt=WPA-PSK}
On boot, the Pi will copy and use this as the default configuration file. In the file replace US with your country code and SSID and password with your credentials.
4. Accessing Raspberry Pi Terminal with PuTTY and enabling VNC Server
Insert the SD card to Raspberry Pi and wait to 90 seconds to boot. When Pi boot it will get connected to the Wi-Fi. Here I used my mobile hotspot as a network and connected my Raspberry Pi and my PC to the same hotspot which will make a network. Also it is easy to find out IP address of Raspberry Pi when connecting it to hotspot.
Provide IP address and open and we will get a terminal. Login with username as Pi
and password rasberry
. Once you are logged in you get a terminal which is originally CLI of Raspberry Pi.
In the terminal type sudoraspi-config
which gives you the configuration menu.
Go to interfacing options of which choose VNC and enable it. Exit the terminal by finishing the process.
5. Accessing Raspberry Pi GUI with VNC
Once you have enabled VNC Server go to VNC Viewer in your PC. Create a new connection by giving IP address of Raspberry Pi and give connection a new name. Invoke the device by double clicking on it, which will give you a login panel. Login with username pi
default password raspberry
. And here you get the Graphic User Interface. Check the whole thing and Code it out.
Schematics
Source: Raspberry Pi 4 Headless