In this Instructable, I'll show you how to hook up your Arduino to your Mac and throw up an actual flag when the alert of your choice occurs. In our example, we'll be doing an email alert, but you can use AppleScript to call this when almost anything happens.
I've created a little Instructables flag to go off when I receive comments on my instructables.
Let's get started!
Remove these ads by
Signing UpStep 1: What you Need
An Arduino: I know at least that the Duemilanove and the Diecimila will work. I don't know if older board versions will work.
A Flag: I made an instructables flag to alert me when I get instructables comment.
A 47 Ohm resistor: This is to prevent the Arduino from resetting at the close of a serial connection
A Servo
Wires to connect the Arduino to the Servo. My wires were a bit longer than needful.
Software:
Tod Kurt's Arduino Serial C code. Tod put this code up which makes it tremendously easy to communicate with the Arduino. Files included here. For more info look here:
http://todbot.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/
- Arduino Code
- Run Flag Applescript








































Visit Our Store »
Go Pro Today »




I tried adobe application installer but it didn't work...so please help!
The applescript simply calls runs the C script which puts the flag up. Depending on what email client you use, you may be able to write a script for that which will run the same C shell script in windows.
You would be able to use to c script, but not the Applescript. You. Would have to find a way to call the c script from within your email client.
Thanks
here is my test terminal command:
./arduino-serial -b9600 -p /dev/tty.usbserial-A700dYg4 -s f
results in: "Running forward" in the serial monitor
and here's my arduino code:
#include
AF_DCMotor motor(2, MOTOR12_1KHZ);
void setup() {
Serial.begin(9600);
motor.setSpeed(255);
}
void loop() {
if (Serial.available() > 0) {
int inByte=Serial.read();
switch (inByte) {
case 'f':
Serial.println("Running forward");
motor.run(FORWARD);
delay(500);
motor.run(RELEASE);
break;
case 'b':
Serial.println("Running backward");
motor.run(BACKWARD);
delay(500);
motor.run(RELEASE);
break;
default:
Serial.println("default value reached");
}
}
}
thanks for your time/advice!
I have this weird problem though, the Arduino only responds properly if the IDE and serial monitor are open, otherwise I just get a quick double blink from the LED. How can this be?
Thanks!
I haven't looked very hard at the Uno's reset. I know they made some changes to engage the reset which is probably why your setup isn't working right. On the Arduino, the board resets automatically when a serial connection closes. In my setup the resistor on the reset pin holds it high to prevent it from resetting.
If the reset on the Uno is different, it may be what's preventing this from working.
And to thank you for this project. I'm using it to control a simple status light on an applescript and photoshop-action based photo booth.
Fun!
I put the file in the correct folders but I get this error:
sh: /Users/drummerboyx/Library/Scripts/arduino-serial.c: Permission denied
Any ideas?
./arduino-serial -b 9600 -p /dev/tty.usbserial-A4001lGx -s 1
and see if they don't read something like:
./arduino-serial.c -b 9600 -p /dev/tty.usbserial-A4001lGx -s 1
if you did end up compiling your executable as a .c file for some reason, you can change it's permissions in the info window of the file. Select the file in the finder and choose "Get Info".
and for anyone else who doesn't know how:
gcc ./arduino-serial.c
gcc -o arduino-serial arduino-serial.c
The -o flag directs the output to a particular file.
Glad you figured out. Hope you find it successful
I've been considering redoing the instructable. The applescript should be sending a single command, and the arduino handling it on the otherside based on that. That would make for a smarter program.
I tested the terminal part, and it worked, but when I tried the AppleScript part I got an error message: "sh: /Users/leandrolucianitavares/Library/Scripts/arduino-serial: No such file or directory". I created the folder "Scripts" at the Library Folder, and put both the arduino-serial.c and the AppleScript file(which i called LedArduino) into it. I tried everything i could tought to solve it, but it was not effective! Could you help me?
Thanks,
Leandro Tavares
I'd double check that you've put the Applescript into your user's library folder and not the library folder at the root of the system. That is:
Make it's in:
/Users/yourUsername/Library/Scripts/
and not
/Library/Scripts/
Secondly, in your Mail rule, make sure that the path is properly set. In my example, I wrote
~/Library/Scripts/
The tilde (~), if you're unaware is a shortcut to your user directory. If it's not there, Mail will try to look for the script at the root level, (Just /Library/Scripts/ ) and it's not there...
I hope that helps. If you still have problems, PM me and we'll talk more details...
By the way, I am expanding it for other applications (Adium as an example), but I am using LEDs instead of servos! I am thinking about a push button to turn off the LEDs (representing that the message was received) !
I was looking for a project like this!!
Again, thanks for this!!!
Leandro Tavares
A push button to turn "off" is great. Make sure you have debouncing in there to make it work properly. It's also occurred to me that putting the "off command" into the Arduino via hardware, such as two connected pins would be great. One set to high output, the other reading for a high or low output, or if that pin wasn't set, then you could wait for software command to send the "off" signal.
Good luck with your project. I'm glad you found a solution, and glad you found this useful!