OVERVIEW :
● This project allows users to remotely control an LED connected to a Jetson Nano using a client-server architecture.
● The Jetson Nano acts as a server, receiving commands from a client device that has a graphical user interface (GUI) built with Tkinter.
● The communication between the server and client is handled using Python sockets.
Features :
● Remote LED control over a local network
● Simple client-side GUI with a toggle button
● Uses Python sockets for communication
● Works with Jetson Nano's GPIO pins
Components Required :
● Jetson Nano
● LED
● 220Ω resistor
● Breadboard and jumper wires
● Tkinter (for GUI on the client side)
● Jetson.GPIO (for controlling the GPIO on the Jetson Nano)
System Architecture:
● The Jetson Nano acts as a server, listening for incoming commands ("on" or "off").
● The client device (another computer or Raspberry Pi) runs a GUI application to send LED control commands.
● Communication happens over a local network using Python sockets.
Circuit :
● Connect the long leg (anode) of the LED to a GPIO pin (e.g., GPIO 12) on the Jetson Nano through a 330Ω resistor.
● Connect the short leg (cathode) to the ground (GND) pin of the Jetson Nano.
Packages need to be installed:
1. Pip newer version 2. Jetson.GPIO
● Install the following packages on Jetson nano
● install the following package on client system
sudo apt install python3-tk
● Connect the server and client in same local network
Server-side Code (Jetson Nano):
import Jetson.GPIO as GPIO import socket import time # Initialize GPIO GPIO.setmode(GPIO.BOARD) GPIO.setup(12, GPIO.OUT) # Use GPIO 12 for LED (change as per your connection) # Create a socket object server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Get the IP address of the Jetson Nano host = '0.0.0.0' # Listen on all available network interfaces port = 12345 # Port to bind to # Bind the socket to the address server_socket.bind((host, port)) # Listen for incoming connections server_socket.listen(5) print(f"Server is running on {host}:{port}") while True: # Accept a new connection client_socket, client_address = server_socket.accept() print(f"Connection from {client_address}") try: # Receive the data sent by the client data = client_socket.recv(1024).decode() if data == 'on': GPIO.output(12, GPIO.HIGH) # Turn LED on print("LED ON") elif data == 'off': GPIO.output(12, GPIO.LOW) # Turn LED off print("LED OFF") else: print(f"Invalid command: {data}") except Exception as e: print(f"Error: {e}") finally: client_socket.close() # Clean up GPIO on exit GPIO.cleanup()
Client-side Code (GUI with Tkinter):
import socket import tkinter as tk # Function to send command to the server def send_command(command): try: # IP address of the Jetson Nano (Server) host = '192.168.1.4' # Replace with your Jetson Nano's IP address port = 12345 # Port used by the server # Create a socket object client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Connect to the server client_socket.connect((host, port)) # Send the command (either 'on' or 'off') to control the LED client_socket.send(command.encode()) client_socket.close() except Exception as e: print(f"Error: {e}") # Function to toggle LED state def toggle_led(): if toggle_button["text"] == "Turn LED ON": send_command("on") # Send 'on' command toggle_button.config(text="Turn LED OFF") # Update button text else: send_command("off") # Send 'off' command toggle_button.config(text="Turn LED ON") # Update button text # Create the GUI window root = tk.Tk() root.title("LED Control") # Add a toggle button to control the LED toggle_button = tk.Button(root, text="Turn LED ON", command=toggle_led, height=2, width=20) toggle_button.pack(pady=20) # Run the GUI loop root.mainloop()
How to Run the Project:
● Run the Server on Jetson Nano
● Run the Client on Any Device
● Use the GUI to control the LED
● Click the “LED ON” button to turn the LED on
● Click the “LED OFF” button to turn the LED off