I had this idea a while back and I finally got around to trying it and it's incredibly useful! The full Python and Arduino source code for both sides is included at the end of this article.
Update Update: The project name has now been changed from ArduinoCLI to Bang (!) in order to avoid confusion with the arduino-cli utility.
Update: The github repository for this project now includes an examples folder where you can submit pull-requests to include your own Bang sketches in the gallery! Currently the examples includes:
- bang.ino example sketch
- macFreeDiskSpace.ino sketch to monitor and blink an LED if your Windows/Mac/Linux disk drive falls below a certain amount of free space
- macPlayMusic.ino sketch to play any song in your music library when your Arduino sketch tells it to play it
- macSpeechSynthesizer.ino sketch to make your Mac speak anything your Arduino tells it to
- openWeatherMap.ino sketch to retrieve the city name, latitude, longitude, current conditions, temperature, feels like temperature, humidity, wind speed, and wind direction for any zip code.
- datetime.ino sketch to retrieve the current date and time from Windows, Mac, and Linux hosts!
- isMacAsleep.ino sketch to retrieve whether the host machine is asleep or not! Special thanks to reddit user u/NoBodyDroid for the idea!
- power.ino sketch for Windows, Mac, and Linux to tell the host machine to go to sleep, reboot, or shutdown
- pjlink.ino sketch for an example of invoking the PJLink command line tool.
- hue.ino example sketch for controlling the lights in your home via the Hue Bridge using 'curl' commands.
- fileIO example sketch for using the disc drive on the host machine as a file system for your Arduino! Includes support for random access reading and writing in addition to the basic file creation, appending, reading, and deleting. Integrating long term log files from your Arduino has never been easier.
- more to come... 😄
The basic idea is simple: Use the Python Agent (provided) that runs on your PC/Mac/Linux machine that accepts serial commands from your Arduino and then executes them on the host machine. And by optionally adding an additional FTDI module or another Arduino you can continue to use the Serial monitor for debugging. By just using any common Arduino you can send commands to the host to be executed and received the results to allow you control over tons of devices and access to tons of information using nothing more than your Arduino and your imagination.
Update: The platform has now been updated even more to now allow you to use the host terminal as a serial debugging device.
No Python programming is needed! The complete working Python Agent source code is included in this project.
The provided Arduino sketch allows you to issue commands as-is using the serial monitor window of the Arduino IDE, and to receive and display the response (if any) from your host machine after the command has been executed. In order to send commands and receive the response you will need an FTDI module or another separate Arduino. This is optional and is only needed if you want the output of the command to be sent back to your Arduino such as when using your host machine to request information from the internet for example.
The only programming involved might be to create your own Arduino sketch to send commands to the Python Agent using the serial port to issue the commands you would like to be executed on your PC/Mac/Linux machine.
This basically turns your host machine and all of it's abilities into a "service" at the beck and call of your Arduino projects! 😄
This is useful as can be for all kinds of things such as (and many of these have now been implemented since the initial writing of this article. Those implemented so far have a check-mark ✅ ):
- ✅ Invoke 'curl' commands to send internet requests and optionally retrieve the response back to your Arduino. Many of the following ideas are just expanded ideas of this basic ability.
- ✅ Play and stop music or movies on your host machine
- Retrieve sports updates using public API's such as NHL's and MLB's API's
- ✅ Write and retrieve data to files on your host machine and take advantage of it's much larger capacity versus an SD card! Basically all file functionality that you can do from the command line like creating files, appending to them, reading them back, searching for files, deleting them, etc.
- Post or retrieve posts with reddit without using a complex reddit API (and their limitations! 😉)
- Access and use a running database server on your host machine
- Submit sensor data to running machine learning training
- Submit Queries to a running machine learning model
- ✅ Retrieve the current time from the host machine
- Post updates or retrieve information from social media platforms.
- Monitor social media channels for specific keywords or trends.
- Retrieve and manipulate calendar events.
- Set reminders or schedule tasks on the host machine.
- ✅ Monitor system security logs for security events.
- Perform advanced text processing tasks, such as parsing log files or analyzing textual data.
- Perform Git operations like cloning repositories, pulling updates, and pushing changes.
- Integrate with version control systems for automated tasks.
- Send and receive emails using command-line tools.
- Monitor email accounts for specific conditions (e.g., new messages from a particular sender).
- Scrape data from websites for information retrieval.
- Automate form submissions on websites.
- Network: Ping a list of servers to check their availability.
- Perform traceroute to analyze network paths.
- Change network configurations dynamically.
- Image and Video Processing**:** Manipulate images or videos using command-line tools.
- Extract frames from videos or perform basic image recognition tasks.
- Implement basic intrusion detection or prevention mechanisms.
- ✅ Control your local intranet based lighting systems without complex software.
- ✅ Invoke the speech functionality supported by the macOS's "say" command or using Windows Powershell's ability to run the System.Speech.Synthesis.SpeechSynthesizer.
- ✅ Start any program on your host machine
- ✅ Turn your machine off by issuing a "shutdown" command
- ✅ Post and retrieve content from a Cloud service
- Print things on your local printer from your Arduino!
- Many many more things!
Comments
Please log in or sign up to comment.