Last active
October 9, 2025 09:57
-
-
Save matiaspl/829bbca3412d31899fb411af8be8e1a2 to your computer and use it in GitHub Desktop.
Power on/off an Acer projector using a USB-to-RS232C dongle.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/ash | |
| # Serial port device (adjust this based on your system) | |
| SERIAL_PORT="/dev/ttyUSB0" | |
| # Function to configure the serial port | |
| configure_serial() { | |
| if [ ! -c "$SERIAL_PORT" ]; then | |
| echo "Error: $SERIAL_PORT is not a valid character device" | |
| exit 1 | |
| fi | |
| # Set baud rate to 115200, 8N1 (8 data bits, no parity, 1 stop bit) | |
| stty -F "$SERIAL_PORT" 9600 cs8 -parenb -cstopb || { | |
| echo "Error: Failed to configure $SERIAL_PORT" | |
| exit 1 | |
| } | |
| } | |
| # Function to send command | |
| send_command() { | |
| local command="$1" | |
| # Echo the command with a carriage return (\r) to the serial port | |
| echo -e "$command" > "$SERIAL_PORT" || { | |
| echo "Error: Failed to send command to $SERIAL_PORT" | |
| exit 1 | |
| } | |
| } | |
| # Main logic | |
| case "$1" in | |
| on) | |
| configure_serial | |
| send_command "* 0 IR 001" | |
| echo "Projector turning ON" | |
| ;; | |
| off) | |
| configure_serial | |
| send_command "* 0 IR 002" | |
| echo "Projector turning OFF" | |
| ;; | |
| *) | |
| echo "Usage: $0 {on|off}" | |
| exit 1 | |
| ;; | |
| esac | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To power the projector automatically on at 6 PM and off at 1 AM every day add the following lines to the crontab file:
00 18 * * * /location_of_the_script/acer_projector_control.sh on
00 01 * * * /location_of_the_script/acer_projector_control.sh off