I've searched quite a lot for this and tried to piece bits of code together but with no luck so far.

All i'm looking to do is have a command I can run in terminal/bash script on the Mac trigger some code to run on the Arduino (Leonardo)

It doesn't matter what data the Mac sends, I only have one command to run so it doesn't need to look like separate buttons or anything.

So far i've tried

int incomingByte = 0;   // for incoming serial data
void setup() {

void loop() {

    // send data only when you receive data:
    if (Serial.available() > 0) {
            // read the incoming byte:
            incomingByte = Serial.read();
//run commands

and then from terminal/script both

echo "1" > /dev/tty.usbmodemHIDPC1 9600


screen > /dev/tty.usbmodemHIDPC1 9600

I see the Arduino light flash when I run those two commands in terminal which would seem to suggest that its receiving the data, but nothing runs.

I have stripped out my code that is due to be run by the way for simplicity. I've got working keyboard presses ready to go to enter in the "run commands".

  • 1
    how do you know that the code does not run? – jsotola Jan 5 at 23:59
  • 3
    stty -F /dev/tty.usbmodemHIDPC1 speed 9600 && echo "1" > /dev/tty.usbmodemHIDPC1 – Majenko Jan 6 at 0:08
  • @jsotola it's set to write some letters with the keyboard, but nothing is written. Will try Majenkos edit below. – Danny Shepherd Jan 6 at 13:00
  • @Majenko neither of those commands did anything unfortunately, just locked terminal up - the Arduino hasn't even flashed either – Danny Shepherd Jan 6 at 13:06
  • Also asked at: forum.arduino.cc/index.php?topic=588990 If you're going to do that then please be considerate enough to add links to the other places you cross posted. This will let us avoid wasting time due to duplicate effort and also help others who have the same questions and find your post to discover all the relevant information. – per1234 Jan 7 at 0:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.