Arduino + Windows script help

Archer

Honorary Master
Joined
Jan 7, 2010
Messages
22,470
Reaction score
1,379
Location
Netherlands
Windows scripts are definitely not what I'm good at :p So help me please!
What I would like to do is the following:
On shutdown of windows (maybe even hibernate, but we can leave that for later) send a message over serial/usb to an arduino. Now how the blue blazes do I get that right??
Then, I'll likely keep serial comms open 24/7 on the arduino, and use any input there to trigger an interrupt. This part I should be able to figure out though :p
 
I can help with old school serial but with usb you need to write drivers etc which takes quite a bit more time.

Let me know if you want a sample...
 
Just been reading up. Looks fairly simple if you do it in python. I can help out if you want.
Do you already have the Arduino sketch you want to use?

I'm just reading up on this project: http://principialabs.com/arduino-python-4-axis-servo-control/

What end result are you trying to achieve?
I'd just create a scheduled job that runs before shutdown that calls the required script to send commands to your Arduino .
 
Thanks NP,

I just want to set the servo to a certain position before the PC shuts down. The servo part is simple, but the interface with windows is not (to me anyway).
 
Thanks NP,

I just want to set the servo to a certain position before the PC shuts down. The servo part is simple, but the interface with windows is not (to me anyway).

You could do it in a windows service in C#? Python would work as well, I suppose. If you'd like and if you could tell me exactly how you want it to function, I could probably smack something together for you over the weekend?
 
Its not urgent at all, I just need to know it can be done before I go down this path :p I might still have a look at doing this with hard wires
How I thought it would function is that windows would simply set a flag which would cause me to exit a while loop.
 
Its not urgent at all, I just need to know it can be done before I go down this path :p I might still have a look at doing this with hard wires
How I thought it would function is that windows would simply set a flag which would cause me to exit a while loop.

Better would be to have an interrupt fire on the Arduino, rather than a while loop. In other words, hook it up via serial as you would, but instead of actually chatting via the serial, one could pulse a pin on the DSUB to which the Arduino could listen and do its thing. Depends how many things you'd like it to do though. If you want it to perform functions based on a larger amount of parameters, you'd then rather go the serial-communication route.
 
Yes I assumed the use of an interrupt, sorry for not making that clear. And the only thing I need it to do is set the flag so that I exit the loop.
 
Yes I assumed the use of an interrupt, sorry for not making that clear. And the only thing I need it to do is set the flag so that I exit the loop.

Yep, that's pretty simple to do if your USB/Serial adapter supports it. I've used some really crap ones and also some really pricey ones, that simply couldn't handle per-pin settings. Most of them seem to work, but as I'm sure you know, it would be best to take a multimeter to them just to confirm, before assuming that they work.
 
Hopefully getting my Arduino today :D

Looking at that link from NP I think I'll use a python script to output a fixed character just before shutdown. Then I'll simply always look for serial.available in the Arduino in the main loop, and when it gets that specific character, I'll run whatever shutdown stuff I need to. Sound about right? It might not even need a fixed character, but I'm hoping it will reduce the chances of random signals triggering a shutdown command. Will just have to see how it goes

So now for the noob question... after I figure out how to actually code in python, how the blue blazes do I link it up to run when windows is about to shutdown?
 
Top
Sign up to the MyBroadband newsletter
X