Sending data from VB2010 to Arduino

Hey guys,

I am new to arduino and VB but have programming experience with C, although not great with it. I just made a little mini maze game in VB, and would like to send data to an arduino with certain events. I.e when the mouse pointer hits a wall, it will send some data so that the arduino can recognize that happening and will process this data. What is the best way to do this?

Thanks guys

In your VB application have it open a com port to communicate with the arduino, then send the desired data to the arduino for what ever you want it to do.

What is the best way to do this?

With some real requirements.

The only way for the PC and the Arduino to communicate is via the serial port. The PC sends data to the serial port. The Arduino reads it. The Arduino sends data to the serial port. The PC reads it.

I.e when the mouse pointer hits a wall, it will send some data so that the arduino can recognize that happening and will process this data.

Where is this wall the mouse pointer (do you mean cursor?) going to hit? What is the Arduino supposed to do? With what data is it supposed to do it? Is the Arduino supposed to reply in some fashion? What will the PC do with the reply?

Having the PC talk to the Arduino, and get replies is easy. Defining what triggers the sending of data, what data is to be sent, how that data is to be interpreted by the receiver, what action is to be performed, and what reply is to be sent, and how that reply is to be understood, and what the PC does with the response is the hard part.

The cursor will hit/touch any rectangle which I have already placed in my application. The Arduino is supposed to acknowledge that the cursor hit one of the maze walls, and energize one or more electromagnets placed underneath a Mouse pad so that it can attract an iron core centered in the mouse. i.e when a collision has occured, one of the digital pins on the Arduino must go high and energize the electromagnet coil. The PC will not reply at all, the communication is only PC -> Ardunio. The electromagnetic attraction will simply physically move the mouse on the pad, and as a result, the cursor will move. I was thinking that the data to be sent will be some sort of Hex value, which I will map to cause the proper digital output on the arduino to go high. I.e FF received will turn pin 13 high, 0A received will turn pin 11 high, etc.

Hope that helps and thank you very much

I was thinking that the data to be sent will be some sort of Hex value, which I will map to cause the proper digital output on the arduino to go high. I.e FF received will turn pin 13 high, 0A received will turn pin 11 high, etc.

Good. The idea that the PC sends data in a known format to the Arduino is correct. I presume, though, that the first value should be 0x0F, not FF.

Once you know what you want to send, and it appears that you do, writing the code to send the data is easy. Reading the data on the Arduino is easy, too.

The only decisions left are when to send the data, how often to send data (both of which seem to have physical limits), and whether to send the data in binary or as strings. Binary is quicker, and is a good match for what you are trying to do.

Don't forget, on the Arduino side, that you need to turn stuff off, too.

I see. Thanks for clarifying this can be done. I am just not sure the best way to do this however, and what kind of code requires this communication to happen. I have installed Firmata protocal and will look at the sample codes for it, is this a good direction?

About turning stuff off in the Arduino, you are correct. I imagine that some sort of conditional statement examining all digital outputs, and if one is on, it will turn off all outputs and then turn on the necessary one upon awall collision or any other event.

VB has a SerialPort object. Use that to open the serial port that the Arduino is connected to. Write data to the serial port. The VB side is simple.

You could use Firmata on the Arduino, and the corresponding dll on the PC side, but you will really understand what is happening if you develop and implement your own protocol.

A protocol is simply a defined set of commands with expected behavior. As you mentioned, a command can be as simple as 0x0F meaning to turn all pins off, and turn pin 13 on. Or, you could get more complicated with two byte commands. 0x0D, 0x01 could mean to turn pin 13 on, while 0x0B, 0x00 would mean to turn pin 11 off. You could have a command like 0xFF, 0x00 to turn all pins off, and 0xFF, 0x01 to turn them all on.

You could expand the idea, and turn multiple pins on and/or off in one operation.

Try writing some code, and post it here if you get stuck.

Thank you paul. I am currently on the path to trying to write some code and will post it here fro your review. Much appreciate your help