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() {
Serial.begin(9600);
}
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
and
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 also include keyboard.h and want the Leonardo send keyboard presses.