Smart Cities - Tiny House at Home: Difference between revisions
No edit summary |
|||
| Line 127: | Line 127: | ||
[[File:Screenshot 2023-06-24 at 9.23.58 pm.png | 900px]] | [[File:Screenshot 2023-06-24 at 9.23.58 pm.png | 900px]] | ||
=Setting up VNC= | =Setting up VNC Server= | ||
==Check if VNC is Already Installed== | ==Check if VNC is Already Installed== | ||
In recent versions of Raspberry Pi OS, VNC comes pre-installed but might be disabled by default. | In recent versions of Raspberry Pi OS, VNC comes pre-installed but might be disabled by default. | ||
| Line 229: | Line 229: | ||
Now you can access your Raspberry Pi 4 from any device on the same network! | Now you can access your Raspberry Pi 4 from any device on the same network! | ||
=Setting up VNC Viewer= | |||
To install a VNC client on a Raspberry Pi 4 and use it to access another Raspberry Pi with a VNC server already running, follow these steps: | |||
==Install VNC Viewer on the Raspberry Pi 4== | |||
* Open a terminal on your Raspberry Pi 4. | |||
* Install the RealVNC Viewer (the VNC client): | |||
<syntaxhighlight lang="bash"> | |||
sudo apt update | |||
sudo apt install realvnc-vnc-viewer | |||
</syntaxhighlight> | |||
Confirm the installation by running: | |||
<syntaxhighlight lang="bash"> | |||
vncviewer --version | |||
</syntaxhighlight> | |||
This should display the version of VNC Viewer installed. | |||
==Get the IP Address of the Remote Raspberry Pi== | |||
* On the Raspberry Pi with the VNC server running, open a terminal. | |||
* Find its IP address by running: | |||
<syntaxhighlight lang="bash"> | |||
hostname -I | |||
</syntaxhighlight> | |||
Note the first IP address (e.g., 192.168.1.102). | |||
==Use VNC Viewer to Access the Remote Raspberry Pi== | |||
Launch VNC Viewer on your Raspberry Pi 4 by typing: | |||
<syntaxhighlight lang="bash"> | |||
vncviewer | |||
</syntaxhighlight> | |||
* In the VNC Viewer window: | |||
* Enter the IP address of the remote Raspberry Pi (e.g., 192.168.1.102). | |||
* Click Connect. | |||
* Log in to the remote Raspberry Pi: | |||
* Enter the username and password of the remote Raspberry Pi. | |||
* After successful authentication, you will see the remote Raspberry Pi's desktop. | |||
==Save Connection for Future Use== | |||
* VNC Viewer allows you to save connections for easy access later. | |||
* Click File > New Connection in VNC Viewer and save the remote Pi's details. | |||
Revision as of 03:01, 15 December 2024
Raspberry Pi OS
- Starting with a fresh install of the Raspberry Pi Debian Bookworm OS with desktop (64 bit).
- Use the Raspberry Pi Imager to install the OS on a 16MB micro SD card.
- Complete the set up and updates on the Raspberry Pi.
Install the Python IDE (not thonny) and the MQTT broker
- Open the Terminal and enter these commands
sudo apt update
sudo apt -y full-upgrade
sudo apt install -y idle3 arduino
Install Virtual Environment
- These days Python must run in a virtual environment so that each user gets their own Python
- The virtual environment has to be activated before each use
- The linux prompt then changes from:
- <username>@home:~ $ to (env) <username>@home:~ $
- Create a virtual environment for Python called env in your /home/<username> directory.
- In Linux (and other operating systems), a virtual environment is an isolated Python environment that allows you to install and manage Python packages separately from the system-wide Python installation.
- This ensures that your Python projects have their own dependencies and versions of libraries without affecting or being affected by other projects or the global Python environment.
- Enter the commands in the Terminal.
cd ~
python3 -m venv env
- Activate the virtual environment with the commands.
cd ~/env
source bin/activate
- Dectivate the virtual environment with the command.
deactivate
Configure the Python Idle3 shortcut to auto-activate the Python virtual environment
- Click Raspberry | Programming
- Right Click IDLE (using Python-3.11)
- Click Properties | Desktop Entry
- In the Command: field enter
/home/<username>/env/bin/python3.11 -m idlelib.idle
Arduino Uno - One Wire Temperature sensor
Frizing - Circuit diagram
- In this circuit diagram the data line is connected to pin 2.
- In the Arduino code below the data line is connected to pin 4.
One Wire Library installation
- Select Sketch > Include Library > Manage Libraries
- Wait for libraries to update. This may take 1-2 minutes.
- In the search bar enter onewire and press Enter.
- Install the One Wire library.
- Use the One wire library with the author Paul Stoffregen
- In this example the onewire library version 2.3.7 was installed.
Dallas Temperature Library installation
- After installing the onewire library now enter Dallas as the search term.
- In this instance version 3.9.0 of the DallasTemperature library was installed.
Arduino Uno Code
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is conntec to the Arduino digital pin 4
#define ONE_WIRE_BUS 4
// Setup a oneWire instance to communicate with any OneWire devices
OneWire sensor_1_wire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensor1(&sensor_1_wire);
void setup(void)
{
// Start serial communication for debugging purposes
Serial.begin(9600);
// Start up the library
sensor1.begin();
}
void loop(void){
// Call sensor1.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
sensor1.requestTemperatures();
Serial.print("Celsius temperature: ");
// Why "byIndex"? You can have more than one IC on the same bus (pin). 0 refers to the first IC on the wire
Serial.println(sensor1.getTempCByIndex(0));
delay(1000);
}
Serial Monitor output
- Temperature readings output to the Serial Monitor.
Setting up VNC Server
Check if VNC is Already Installed
In recent versions of Raspberry Pi OS, VNC comes pre-installed but might be disabled by default.
- Check Installation:
- Open a terminal on your Raspberry Pi.
- Run:
vncserver --version
If VNC is installed, it will display the version. If not, install it (see step 3).
Enable VNC on Raspberry Pi
- Open the Raspberry Pi Configuration Tool:
- GUI: Go to Start Menu > Preferences > Raspberry Pi Configuration.
- CLI: Run:
sudo raspi-config
- Navigate to:
- Interface Options > VNC > Enable
- Confirm and exit the configuration tool.
- Verify that the VNC service is running:
systemctl status vncserver-x11-serviced.service
If not running, start it:
sudo systemctl start vncserver-x11-serviced.service
Install VNC (if not installed)
If VNC isn't pre-installed:
- Update the package list:
sudo apt update
Install VNC Server:
sudo apt install realvnc-vnc-server
Connect to the Raspberry Pi Using VNC Viewer
Find the Raspberry Pi’s IP Address:
hostname -I
- Note the first IP address (e.g., 192.168.1.100).
- Install VNC Viewer on your client device:
- Download VNC Viewer for Windows, macOS, or Linux.
- Open VNC Viewer on your client device and enter the Raspberry Pi’s IP address (e.g., 192.168.1.100).
- Log in with your Raspberry Pi's credentials:
Username: pi
Password: (default is raspberry, or your custom password).
Optional: Configure VNC
- Resolution Adjustment:
Edit /boot/config.txt to set a virtual desktop resolution:
sudo nano /boot/firmware/config.txt
Add or modify:
hdmi_force_hotplug=1
hdmi_group=2 # Set to 2 for DMT (monitor resolutions)
hdmi_mode=9 # Example: 800x600 @ 60Hz
This sets a resolution of 800x600. Save and reboot:
sudo reboot
hdmi_force_hotplug=1
- Forces the Raspberry Pi to output HDMI signals even if no HDMI display is detected at boot.
- This is essential when you're using VNC without a physical monitor connected.
Now you can access your Raspberry Pi 4 from any device on the same network!
Setting up VNC Viewer
To install a VNC client on a Raspberry Pi 4 and use it to access another Raspberry Pi with a VNC server already running, follow these steps:
Install VNC Viewer on the Raspberry Pi 4
- Open a terminal on your Raspberry Pi 4.
- Install the RealVNC Viewer (the VNC client):
sudo apt update
sudo apt install realvnc-vnc-viewer
Confirm the installation by running:
vncviewer --version
This should display the version of VNC Viewer installed.
Get the IP Address of the Remote Raspberry Pi
- On the Raspberry Pi with the VNC server running, open a terminal.
- Find its IP address by running:
hostname -I
Note the first IP address (e.g., 192.168.1.102).
Use VNC Viewer to Access the Remote Raspberry Pi
Launch VNC Viewer on your Raspberry Pi 4 by typing:
vncviewer
- In the VNC Viewer window:
- Enter the IP address of the remote Raspberry Pi (e.g., 192.168.1.102).
- Click Connect.
- Log in to the remote Raspberry Pi:
- Enter the username and password of the remote Raspberry Pi.
- After successful authentication, you will see the remote Raspberry Pi's desktop.
Save Connection for Future Use
- VNC Viewer allows you to save connections for easy access later.
- Click File > New Connection in VNC Viewer and save the remote Pi's details.