Go Down

Topic: ePrime2 Interfacing with Arduino (Read 960 times) previous topic - next topic

isaacsda

Initial disclaimer: I am relatively new to both Arduino and ePrime2.
I am attempting to run a psychological experiment using ePrime2 (version 2.10). I need the Arduino to select randomly (as programmed in ePrime) between 2 channels. The ePrime2 code is not triggering any errors, and the Arduino board is functioning correctly, as evidenced by trials of simple sketches. Here is the pertinent section of the ePrime code:
---------------------------------
'Initialize StrWrite
Dim strWrite As String

'Get Channel attribute
Select Case c.GetAttrib("Channel")
   Case 1
      strWrite = "1"
   Case 2
      strWrite = "2"
End Select

'Write a string of data to the serial device
Serial.WriteString strWrite
---------------------------------
Do I need to upload a particular sketch to the Arduino in order for the above ePrime code to actually interface with Arduino? Or is there another issue I'm overlooking? I appreciate any guidance. Thanks for your time.
David

Robin2

I have no idea what ePrime2 is and you have not provided a link to any of its documentation. I presume it is a program running on a PC.

The code snippet you posted does not show how the ePime2 selects or opens the serial port and communication won't happen if that is not done correctly.


For receiving serial data on an Arduino have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

The technique in the 3rd example will be the most reliable. It is what I use for Arduino to Arduino and Arduino to PC communication.

You can send data in a compatible format with code like this (or the equivalent in any other programming language)
Code: [Select]
Serial.print('<'); // start marker
Serial.print(value1);
Serial.print(','); // comma separator
Serial.print(value2);
Serial.println('>'); // end marker


..R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up