0

I am aware of the simplicity of the question. Nevertheless...

I need to code into the arduino the execution of a file. More precisely a .exe. To put things in perspective. I have little to no knowledge of coding. Yet I need to put together a photocabin. I have the arduino to count the coins inserted to my coin collector and I need to take a picture when the precise ammount is reached. Then reset the ammount to avoid taking more pictures. here is what my code looks so far: (taken from the examples on the arduino page)

const int coinInt = 0;
//Attach coinInt to Interrupt Pin 0 (Digital Pin 2). Pin 3 = Interrpt Pin 1.

    volatile float coinsValue = 0.00;
    //Set the coinsValue to a Volatile float
    //Volatile as this variable changes any time the Interrupt is triggered
    int coinsChange = 0;                 
    //A Coin has been inserted flag

void setup()
{
  Serial.begin(9600);                 
//Start Serial Communication
  attachInterrupt(coinInt, coinInserted, RISING);   
//If coinInt goes HIGH (a Pulse), call the coinInserted function
//An attachInterrupt will always trigger, even if your using delays

}

void coinInserted()   

//The function that is called every time it recieves a pulse
{
  coinsValue = coinsValue + 0.05; 
//As we set the Pulse to represent 5p or 5c we add this to the coinsValue
  coinsChange = 1;                           
//Flag that there has been a coin inserted
}

void loop()
{
  if(coinsChange == 1)         
//Check if a coin has been Inserted
  {
    coinsChange = 0;             
//unflag that a coin has been inserted

   if(coinsValue >= 0.30)
  {
       here goes the code to open a file, then the code to reset coinsValue 

  }
  }
}

Thanks a million.

4
  • 6
    There is no way the Arduino can run a .exe on your PC. At most it can send some kind of signal to say "Hey! PC! It's time to run the program!". Simplest thing would be to send it through the serial port. You need some process on the PC side listening for this signal and acting accordingly. How you do that is more a Windows programming issue than a real Arduino question. May 29, 2015 at 18:15
  • How do you tell apart different type of coins? What do you use to take the picture? May 29, 2015 at 20:15
  • That was not your original question and is probably best as a question in itself.
    – NULL
    May 29, 2015 at 20:16
  • 1
    @igor I use a coin colector sending out pulse signals to tell different coins apart. from sparkfun.com I will be using either a webcam software or eos utility I have not yet decided. May 30, 2015 at 3:15

2 Answers 2

1

First of all you need to develop a windows app. You can achieve this by downloading visual studio express for windows desktop from here. Then you must create a project in your language of your preference. You will have to add a serial port component and set the properties to match your arduino serial ones. Then from the event that handles the "data available" of your serial port you can check if there is an incoming character from your arduino and create an if statement that runs the .exe file. Then you must add serial.print('c') to your code when there is a coin inserted. By doing so, you will manage to communicate between arduino and your windows app.

More info and full guide can be found here

1
  • Tried the solution and have managed to implement it so thank you. Jun 9, 2015 at 14:57
1

I used the following code to run a program, not from the arduino, but from software listening to a specific character sent from the arduino. Thanks for your help. I share the code that I used. It doesn´t need to print the character, but I copied it exactlyy from microsoft help pages (lost the link). I just aded the if statement and the start.process part (I got this from a stackoverflow answer). Without any further delay:

using System;
using System.IO.Ports;
using System.Diagnostics;

class PortDataReceived
{
    public static void Main()
    {
        SerialPort mySerialPort = new SerialPort("COM3");

        mySerialPort.BaudRate = 9600;
        mySerialPort.Parity = Parity.None;
        mySerialPort.StopBits = StopBits.One;
        mySerialPort.DataBits = 8;
        mySerialPort.Handshake = Handshake.None;
        mySerialPort.RtsEnable = true;

        mySerialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);

        mySerialPort.Open();

        Console.WriteLine("Press any key to continue...");
        Console.WriteLine();
        Console.ReadKey();
        mySerialPort.Close();
    }

    private static void DataReceivedHandler(
                        object sender,
                        SerialDataReceivedEventArgs e)
    {
        SerialPort sp = (SerialPort)sender;
        string indata = sp.ReadExisting();
        Console.WriteLine("Data Received:");
        Console.Write(indata);
        if (indata == "c")
        {
            Process.Start(@"C:\Users\Laptop\Desktop\print.ahk");
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.