Excel to Arduino over USB(serial)

Hi,

I have been trying for a few days and unfortunately i have hit a brick wall. What i am trying to do is get excel to send a value over serial to the arduino. The arduino will read the value and then manipulate a set of LED's accordingly.

My Arduino Code is:

//excel converts the binary to a byte value. Arduino interprets byte value
//must send 3 numbers at a time. The buffers is looking for 3 so 001, not just 1
String content = ""; //save read characters as string
char inChar;
int ledControl = 0;

void setup() {
  //opens serial port so that data can be sent to arduino
  Serial.begin(9600, SERIAL_8N1);
  //set pins to output so you can control the shift register
  pinMode(8, OUTPUT); //Pin connected to ST_CP of 74HC595, latch
  pinMode(12, OUTPUT);//Pin connected to SH_CP of 74HC595, clock
  pinMode(11, OUTPUT);//Pin connected to DS of 74HC595, data

  //set everything low ready for processing
  digitalWrite(8, 0);
  digitalWrite(12, 0);
  digitalWrite(11, 0);

}

void loop() {

  while (Serial.available() > 0) // Don't read unless you know there is data
  {
    inChar = Serial.read();
    content.concat(inChar);
  }
  if (content.length() == 3)
  {
    ledControl = content.toInt();
    digitalWrite(8, 0); //set latchPin to zero prior to sending data
    shiftOut(11, 12, LSBFIRST, ledControl); //queue up bits ready to shift out, (datapin, clockpin, msb/lsb, data)
    digitalWrite(8, 1); //shift out data bits
    content = "";
  }
}

And my Excel VBA code is:

Sub tester()

COMport = FreeFile
Close #COMport

'open comport, need to change com number to correct one
Open "COM4:9600,N,8,1" For Binary As #COMport

'send data to arduino, number on the end the important bit
'Put #COMport, , "085"

Close #COMport

End Sub

So my arduino code works fine i have no issues with that. The problem is the communication piece. If i start arduino serial monitor first to establish communication, then go to excel it works fine. But i cannot communicate properly with the arduino directly from excel after a fresh reboot.

I appear to be missing a handshake of sorts with the arduino upon restart. Any idea how to solve this. Preferably via excel only without a 3rd party application.

Cheers.

Open "COM4:9600,N,8,1" For Binary As #COMport

Why Binary ?

But i cannot communicate properly with the arduino directly from excel after a fresh reboot.

Which Arduino are you trying to communicate with? There are many more properties for the Serial class than you are setting. The Micro and Leonardo, for instance, need to have DTREnable set to true in order for communications to happen.

The Serial Monitor sets all the properties correctly. Your code, apparently, does not.

Hi,

ieee488, the line is just from another example i have seen and it worked so never really questioned it. If another type is better please let me know.

PaulS, it is an Uno.

Yalankelo:
ieee488, the line is just from another example i have seen and it worked so never really questioned it. If another type is better please let me know.

Google VBA serial port

ieee488, I have on numerous occasions, 99% of what i can find either requires extra bits to be installed such as mscomm or plcdaq. Unfortunately installing extra bits of software other than excel is not an option.

Attached are a copy of the serial monitor read outs for when i open the port using excel compared to with the arduino serial monitor.

When i open it with excel i seem to be missing a lot of the setup information for the serial port. Any ideas how to implement this via excel.

Excel Com OpenClose.JPG

Yalankelo:
Unfortunately installing extra bits of software other than excel is not an option.

Then you'll have to learn how to use the Windows API version of controlling the serial port, won't you ? ? ?

For those intrigued, I found this page as a solution.

http://dev.emcelettronica.com/serial-port-communication-in-excel-vba

Seriously helped me understand what is going on as well as the various calls and functions required. Hopefully can help some other people out as well.

Yalankelo:
For those intrigued, I found this page as a solution.

http://dev.emcelettronica.com/serial-port-communication-in-excel-vba

Seriously helped me understand what is going on as well as the various calls and functions required. Hopefully can help some other people out as well.

Yep. Been there. Done that. 2014.