From 6fa73d1211a33dfccd63aa93b203b2d089d1e2e0 Mon Sep 17 00:00:00 2001 From: Casey Barajas Date: Wed, 27 Dec 2023 11:43:25 -0600 Subject: [PATCH] Basic Stuff --- README.md | 78 ++++++++++++++++++++++++++++++++++++++++++++ app.py | 24 +++++++------- main.ino | 17 ++++++++++ requirements.txt | 2 ++ templates/index.html | 13 -------- 5 files changed, 108 insertions(+), 26 deletions(-) create mode 100644 README.md create mode 100644 main.ino create mode 100644 requirements.txt diff --git a/README.md b/README.md new file mode 100644 index 0000000..c47ff56 --- /dev/null +++ b/README.md @@ -0,0 +1,78 @@ +# ZeroDuino + +ZeroDuino is a project that allows you to connect and control an Arduino board using a Raspberry Pi through a Python/Flask-based web interface. + +## Table of Contents +- [Introduction](#introduction) +- [Features](#features) +- [Requirements](#requirements) +- [Installation](#installation) +- [Usage](#usage) +- [Contributing](#contributing) +- [License](#license) + +## Introduction + +The ZeroDuino project aims to provide a convenient way to interact with an Arduino board using a Raspberry Pi. By leveraging the power of Python and Flask, it allows you to control the Arduino's inputs and outputs through a web-based interface. + +## Features + +- Web-based interface for controlling Arduino inputs and outputs +- Real-time monitoring of Arduino sensor data +- Support for multiple Arduino boards +- Easy integration with existing Python projects + +## Requirements + +To use ZeroDuino, you will need the following: + +- Raspberry Pi with Ubuntu 20.04 Server +- Arduino board +- Python 3.x +- Flask + +## Installation + +1. Clone the ZeroDuino repository to your Raspberry Pi: + + ```shell + git clone https://github.com/Laughable33/ZeroDuino.git + ``` + +2. Install the required Python packages: + + ```shell + pip install -r requirements.txt + ``` + +3. Connect your Arduino board to the Raspberry Pi. + +## Usage + +1. Navigate to the project directory: + + ```shell + cd ZeroDuino + ``` + +2. Start the Flask server: + + ```shell + python app.py + ``` + +3. Open a web browser and enter the following URL: + + ``` + http://localhost:5000 + ``` + +4. You should now see the ZeroDuino web interface. Use it to control and monitor your Arduino board. + +## Contributing + +Contributions to the ZeroDuino project are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request on the GitHub repository. + +## License + +This project is licensed under the [MIT License](LICENSE). diff --git a/app.py b/app.py index b603f28..3fd2c7a 100644 --- a/app.py +++ b/app.py @@ -1,20 +1,18 @@ -from flask import Flask, render_template, request +from flask import Flask, request import serial +import time app = Flask(__name__) +arduino = serial.Serial('/dev/ttyACM0', 9600) -ser = serial.Serial('/dev/ttyACM0', 9600, timeout=1) -ser.flush() +def send_to_arduino(speed): + arduino.write(f"{speed}\n".encode()) -@app.route('/') -def index(): - return render_template('index.html') - -@app.route('/send_text', methods=['POST']) -def send_text(): - text = request.form['text'] - ser.write(text.encode()) # Send the text to the Arduino - return ('', 204) +@app.route('/motor', methods=['POST']) +def motor(): + speed = request.form.get('speed', type=int) + send_to_arduino(speed) + return f"Motor set to {speed}" if __name__ == '__main__': - app.run(debug=True, host='0.0.0.0') + app.run(host='0.0.0.0', port=8080) diff --git a/main.ino b/main.ino new file mode 100644 index 0000000..8cb621e --- /dev/null +++ b/main.ino @@ -0,0 +1,17 @@ +#include + +Servo motor; + +void setup() { + Serial.begin(9600); + motor.attach(9); // Attach the motor to pin 9 +} + +void loop() { + if (Serial.available() > 0) { + int speed = Serial.parseInt(); // Read the speed value sent from the Raspberry Pi + if (speed >= 0 && speed <= 180) { + motor.write(speed); // Set the motor speed + } + } +} diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..43edbd3 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +flask +serial \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index f7d1c1a..e69de29 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,13 +0,0 @@ - - - - Control LCD - - -

Send Text to LCD

-
- - -
- -