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.