Is it possible to send code from Arduino to terminal?

Is it possible to press a button and then a line of code gets sent to a mac terminal like opening an application?

Yes, as long as you use an Arduino like the Leonardo that can send keystrokes as if they came from a keyboard attached to the PC

Which Arduino board do you have ?

1 Like

If you really mean ‘terminal’, you can simply use Serial.print() calls

do you mean code (e.g. "Serial.println ("hello world");") or just some text (e.g. "hello world")?

Can you add some details to what you need to accomplish here, please?

I ask because I feel like this is the start of an XY problem (but I could very well be wrong).

Specifically, at least with Windows, the tricky part isn't sending code or debugging text to some terminal application like PuTTY or CoolTerm. The tricky part is having the terminal application and the Arduino automatically connect to one another and stay connected so you can do what you want to do at any arbitrary time in the future.

1 Like

if you mean typing some sort of UNIX command that gets automatically executed, not really unless you have a special app on the Mac listening and interpreting the commands.

Anything else would be a major security risk...

If your arduino emulates a keyboard, then you could simulate whatever is available from the keyboard on your Mac.

Arduino Leonardo

I want to be able to like press a button and then it sends code to terminal

I just want to be able to press a button and then the arduino would send code to terminal on mac and open an application using like open -a "____"

1 Like

Look at the Keyboard library examples. It should be straight forward to let the Arduino simulate a keyboard and send what you need. If the Mac likes it is a different story; I'm not a Mac user.

you could implement a program in C, C++, Java, Python, etc which reads serial data from the Arduino and on receiving a specific command calls a function to execute a shell command

The Mac will see a keyboard if you pose as a keyboard

If your active application (receiving keyboards events) is the Terminal application then whatever is “typed” from the arduino will make it to the terminal as if you had typed it from a “real” keyboard.

1 Like

the Arduino IDE connects to the Arduino thru a USB cable that supports a serial interface using pins 0 & 1. The IDE uses the serial interface to download code into the Arduino

the IDE also has a serial monitor, the magnifier icon on the right side of version 1.8.x and the tab on ver 2.x. Any serial output e.g. Serial.println ("hello world"), appears on the serial monitor.

closing the IDE and connecting a terminal emulator to the same com port allow communication between it and the Arduino

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.