Using the appearance of a file as a trigger

Hi all,

I am trying to figure out a way to interface between an arduino-controlled system, and a software that will automatically create files in a certain filepath over time.

I don't need arduino to read the file, or extract anything from the file, only become aware of the file coming into existence (from the other software) and trigger the already programmed sequences.

If anyone has any ideas on how I can accomplish this (or if you need any clarification), please let me know.

If I understand correctly, you want an application to be running on a PC (assume Windows) and when a file appears, send some message to the serial/USB port for an Arduino to see and act on?

Exactly!

So does anyone think they could help me?

It somewhat depends on what PC-side programming languages you know.

If it were my problem I'd write a little node.js script to watch for the file and send commands to the arduino through the serial port. Node has a built-in directory-watching API that makes the first part easy:

http://nodejs.org/api/fs.html#fs_fs_watch_filename_options_listener

The node-serialport module makes the second part, talking to the Arduino, pretty easy, too.

-br

I was thinking of some sort of function in the void loop part of the code through the serial port. I don't have any experience with node.js. My own personal experience is with Matlab, and getting better at C++.

I guess I should have started by saying there is no way for the Arduino to know anything about files on the PC without a program running on the PC intermediating and sending notification over the serial port when it sees it appear.

You need code on the Arduino side, too. In the function loop(), you'd look for incoming serial input from the PC program and read / check it to make sure it's your notification.

-br

Ok, how would I make an automatic serial input? Which environment works to send info to the arduino environment?

Too many to list them all here, but certainly we see people using these all the time to talk to Arduino projects: C, C++, python, node.js, Processing, Visual Basic of various flavors, ruby, and PHP for some platforms. One guy was successful using bash scripts on his raspberry pi.

All of these have a way to open the serial port and send text to it, as well as various levels of file system support.

If you're completely at a loss where to start, Processing is a development environment that is free and conceptually very similar to Arduino (because the Arduino development environment was derived from it; but I digress…); there are many examples of sending text to Arduino from Processing in the forum if you search. You can get the Processing code at http://processing.org

-br

I already have python and visual c++ 2010 express environments installed on this computer. But it seemed that I would have to write all of my codes in either Visual c++ 2010 express, or the arduino environments. Not really exporting a value from one to the other.

Can you state that as a question, please?

-br

Sure. Do you know of any specific examples of sending a command to the arduino sketch environment from either c++ visual express or python?

I already have a sketch that works perfectly, and I can use the serial monitor to trigger it, but I need it to trigger automatically when a specific file appears (would be spontaneously generated from another software running on the same computer).

I hope that this clears it up...? I know it's an odd concept. I'm not a very experienced programmer, so any specific examples/tutorials that you know of would be greatly appreciated too.

If you search the forum for "python serial" you will find lots of examples of sending data to the arduino from a python script.

I'm guessing the "python detect the presence of a file" part is not something you're likely to find here on the forum, but all you have to do is learn how to open a file in python and tell whether the open succeeded or not - that is easily google-able.

Good luck with your project,

-br