Skip to content

DragonRex004/ArduinoHMI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ArduinoHMI

ArduinoHMI

ArduinoHMI is an open-source project that transforms your Raspberry Pi into a dynamic Human-Machine Interface (HMI) for your Arduino. It establishes a bidirectional communication bridge, allowing the Arduino to define and control a graphical user interface (GUI) on the Raspberry Pi, and receive real-time callbacks from user interactions.

This project enables you to build complex, interactive interfaces on a powerful platform (Raspberry Pi) while keeping the control logic simple and encapsulated on your microcontroller (Arduino).

✨ Features Dynamic UI Rendering: The Arduino sends a JSON-based UI definition to the Raspberry Pi, which dynamically creates the corresponding Tkinter widgets.

Bidirectional Communication: Supports sending data from the Arduino to the Pi (UI definitions, updates) and receiving user-interaction callbacks from the Pi.

Configurable Connection: A modern startup menu allows users to easily configure serial port settings (port, baud rate, data bits, parity, stop bits) without touching the code.

Interactive Components: Includes support for dynamic labels, buttons, and textboxes.

Inactivity Screensaver: A built-in screensaver with a bouncing logo helps to conserve power and adds a polished touch to the application.

🚀 Installation Follow these steps to set up the ArduinoHMI software on your Raspberry Pi.

Step 1: Install Python Libraries Make sure your Raspberry Pi has Python installed (it's usually pre-installed). You'll need the pyserial and ArduinoJson libraries.

Bash

sudo apt-get update sudo apt-get install python3 python3-pip pip3 install pyserial Step 2: Set up the Arduino Library Download the ArduinoHMI library for your Arduino IDE.

Open your Arduino IDE.

Go to Sketch > Include Library > Manage Libraries....

Search for ArduinoJson and install the latest version.

Copy the ArduinoHMI.h and ArduinoHMI.cpp files from this repository's ArduinoHMI/ directory into a new folder named ArduinoHMI in your Arduino libraries folder. This is typically located at ~/Documents/Arduino/libraries/.

Step 3: Copy the Python Code Copy the entire ArduinoHMI.py file to your Raspberry Pi. You can do this using scp, a USB drive, or by simply creating a new file on the Pi and pasting the code.

💻 Usage

  1. Arduino Sketch The Arduino is the "brain" of your HMI. Use the ArduinoHMI library to define and send the user interface.
#include "ArduinoHMI.h"

// Create an instance of the library
ArduinoHMI ui;

// Callback function for a button click
void onButtonClick(int id, const char* value) {
  // A simple print statement
  Serial.println("Button clicked!");
  // Update a label
  ui.updateLabel(1, "Button clicked!");
}

// Callback function for textbox changes
void onTextBoxChange(int id, const char* value) {
  // Read the value from the textbox
  Serial.print("Textbox content: ");
  Serial.println(value);
}

void setup() {
  // Initialize the communication
  ui.begin(9600);
  
  // Define the UI layout with specific positions
  ui.addLabel(1, "Enter a command:", 20, 20);
  ui.addTextBox(2, "Default Text", onTextBoxChange, 180, 20, 150, 30);
  ui.addButton(3, "Submit", onButtonClick, 180, 70, 100, 30);
  
  // Send the UI definition to the Raspberry Pi
  ui.sendUI();
}

void loop() {
  // Process incoming callbacks from the Raspberry Pi
  ui.handleSerial();
}

Upload this sketch to your Arduino.

  1. Raspberry Pi Software On your Raspberry Pi, you need a simple script to run the HMI application. Create a file named main.py in the same directory as arduinoui.py.

Python

main.py

from arduinoui import ArduinoUI

# Set a default serial port for your Raspberry Pi
# Linux/macOS: '/dev/ttyACM0' or '/dev/ttyUSB0'
# Windows: 'COM3'
DEFAULT_PORT = '/dev/ttyACM0' 

# Create an instance of the HMI application
ui_app = ArduinoUI(default_port=DEFAULT_PORT)

# Start the application. The configuration menu will appear first.
ui_app.start()

Run the application with:

python3 main.py

A window will pop up, allowing you to select your serial port and connect to the Arduino.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published