Serial Communication

Hello Everybody,

I have a question regarding Arduino Serial Communication.
I have written a program in Visual Basic to control the Arduino Board and I am sending strings through the serial from Visual Basic. For example, I want to send "1;255". In this string, the number "1" is the pin number and the number "255" is the analog value that needs to be written to the pin. However, I am unable to write a program that takes everything to the left of the semicolon and declare it to be the pin number and take everything to the right of the semicolon and set it to be the analog value that needs to be written to the pin. Can somebody help me with the program. I am a new comer to Arduino Programming. So I will appreciate if somebody wrote me a complete program and tell me what each of the line in the code does!

Thanks and Regards,
Sudhanva Sreesha
sudhanvas@yahoo.com

However, I am unable to write a program that takes everything to the left of the semicolon and declare it to be the pin number and take everything to the right of the semicolon and set it to be the analog value that needs to be written to the pin. Can somebody help me with the program. I am a new comer to Arduino Programming.

That is a challange esp for newcomers to Arduino programming. The hardware serial and supporting software library are single character at a time interface. What you require is software that can assemble the characters sent from the PC, a character at a time, and then parse the required information from the sent string. There is no general purpose Arduino friendly string parsing library avalible that I'm aware of, so you are kind of on your own to build the needed functions.

Lefty

Why not put Bitlash on the Arduino and send commands to it to do what you want?

Bitlash is an interpreted language shell that runs on Arduino. You could send commands like:

a5=255

to set the PWM rate on pin 5.

Bitlash is open source and free; see http://bitlash.net

-br

http://entropymouse.com

If you can write a VB application, you have some programming skills.
Read the tutorials, work through the examples, experiment and modify a little, and ask us about your coding problems.
Requests for others to write complete sketches for you tend to fall on deaf ears.

Well, to give a little better help, below is some working code that shows how I parce info from a string using "WString.h". Its info can be found at the below link. I'm still working on collecting a string from te serial port using "WString.h".

#include "WString.h"

void setup()
{
  Serial.begin(9600);

 #define maxLength 100
 String url = String(maxLength);
 String teststring = String(maxLength);
 String finalstring = String(maxLength);

 int ind1 = 0;
 int ind2 = 0;
 int pos = 0;

  url.append("GET /?-0p1500t1000-1p2200s1000-2p1500-3p500 HTTP/1.1");
  Serial.println("url before replace: ");
  Serial.println(url);
  

  url.replace('-', '#');
  Serial.println("url after replace: ");
  Serial.println(url);
  

  Serial.println("URL length: ");
  Serial.println(url.length());
  
  pos = url.length();
  
  ind1 = url.indexOf('#');
  Serial.println("location of first #: ");
  Serial.println(ind1);
  
  teststring = url.substring(ind1, pos);
  Serial.println("intermediate teststring: ");
  Serial.println(teststring);
  
  ind2 = teststring.indexOf(' ');
  Serial.println("location of space: ");
  Serial.println(ind2);

  finalstring = url.substring(ind1, ind2+ind1);

  Serial.println("finalstring: ");
  Serial.println(finalstring);

}
void loop() {}