I have a problem with my arduino and I seriously need help to solve it.
The Problem:
I placed LED stripes behind my Monitor and connected it to my arduino.
I do already have the right code to change the colors.
Now: I want the arduino UNO to automaticly turn itself off when i put my pc/Mac
to sleep so i don't have to every time pull out the usb cable from it.
At the end of the Day it seems to more an "problem" with my Mac than my arduino,
but I still need help.
Are the USB ports on the computer still powered when the computer is sleeping? It sounds like they are.
If so, the immediate solution that comes to my mind is to have the computer send a message to the Uno before going to sleep. Since it sounds like you already have the Uno connected via to the computer via USB the most easy solution for sending this message would be serial. So the Uno constantly listens on Serial for the message and then when it's received it "turns itself off'. Exactly what "turns itself off" means here could vary from just turning off the LEDs but continuing to run normally or going into various sleep modes.
Next you have the question of how to get the computer to send this serial message before going to sleep, since likely there is no built in provision for such a thing. You could write a script or batch file that first sends the serial message using the appropriate application, then puts the computer to sleep and always use that system to put the computer to sleep rather than the usual way.
You'd just need to write a script for the Mac. Same idea as the batch file, just different terminology. I said "script or batch file" because you said "pc/Mac" so I thought there might be a Windows computer as well as a Mac. I don't use Mac but I'm sure it would be a very simple script. In pseudocode it would look something like:
Where "SerialApplication" is the application you use to send the serial communication, "arduinoPort" is the serial port of the Arduino, "9600" is the baud rate set in the Serial.begin() statement of your Arduino sketch, "s" is the command you want to send to the Arduino to tell it the computer is going to sleep, "sleep" is the command to put the Mac to sleep, "w" is the command to send the Arduino to tell it the computer has woken back up. I would create a shortcut to this script and put it somewhere convenient so you can easily use it to put the computer to sleep. You would need to do a bit of research to find a program that can be controlled from the command line to send a message over serial. I'm not sure if there is anything like that already installed on your computer but I'm sure there are lots of options for free software that will do this.
On the Arduino side it's also very simple. In setup():
Serial.begin(9600);
in loop():
if (Serial.available()) {
char receivedCharacter = Serial.read();
if(receivedCharacter == 's') {
// turn off the LEDs
}
else if(receivedCharacter == 'w') {
// turn on the LEDs
}
}
Diesefrage:
I'm sorry for me asking stupid questions but i'm no professional.
They're not at all stupid questions.
Diesefrage:
Sorry for my bad english I'm from germany
Your English is great and certainly much better than my German.
You may find it easier to go the opposite way to what @pert has described and have a program/script running on the Mac that just responds to a "ping" request on the serial port from the Arduino. If the Arduino doesn't get a response, it assumes the Mac has gone to sleep and turns the lights off. It keeps pinging, and when the Mac wakes up it will respond to the Arduino again and the lights will come on.
The sleep/wake hook described by @pert is more elegant if you can get it to work, as you will get an instant response and not waste all those ping requests. But if you can't get to work, then this approach should be pretty simple, as I assume on a Mac you have the equivalent of Startup programs on Windows or init.d in Linux.
I agree that's a better way because it allows you to still use the standard ways of putting the computer to sleep. It might be a bit more work to implement the "pong" script on the computer but then again maybe not because I'm not sure whether my suggestion would have worked for turning the Arduino back on after the computer wakes up (is the rest of the script run after the computer wakes?). The other downside I can see is if you have it on Serial it will prevent upload while the "pong" script has the port open but you probably aren't doing uploads to that Uno very frequently and can always just stop the script when you need to do so or even use a separate USB-serial adapter with software serial for the ping port.
Hi!
This might be a old thread but it's describing something that I want to achieve as well.
I would like to implement the "ping-pong" script, but I'm not experienced at this. So I wonder if anyone has any tips on where I can learn how to make the two scripts?