Problems with Serial Communication on pin 0 and 1

Hi,

I'm new in arduino and experiment some problems since few hours. I look to different solution but no one help me.

The problem is that communication with serial works perfectly if i use serial monitor provided with arduino development tools. As far as i try with another program (like hyperterminal, small C# program) i get bytes but not the one expected.

Here is the code (just blinking one led and print OPEN to serial port:

/* 

const int ledPin =  13;      // the number of the LED pin

int ledState = LOW;             // ledState used to set the LED
long previousMillis = 0;        // will store last time LED was updated
long interval = 1000;           // interval at which to blink (milliseconds)

void setup() {
   pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
}

void loop()
{

  if (millis() - previousMillis > interval) {
   
    previousMillis = millis();   
    Serial.println("OPEN");
    
    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;    
    digitalWrite(ledPin, ledState);
  }
}

What i get in decimal format in my C# program (88 85 13 21 107 0) First problem : i sent 4 characters, get 6 ??

I try different baudrate but never get the OPEN ??

Please help me ? (on the board i just connect pin 0,1 and ground to the corresponding pin on the serial port of my PC)

First problem : i sent 4 characters, get 6 ??

    Serial.println("OPEN");

That's because you sent 6 - 'O', 'P', 'E', 'N', carriage return, and linefeed (the println function added the last two). If you don't want the carriage return and line feed, use print, not println.

(on the board i just connect pin 0,1 and ground to the corresponding pin on the serial port of my PC)

The Arduino sends serial data using 0 and 5V. The PC is expecting +12V and -12V. You need a TTL to Serial converter between the Arduino and the PC.

Damned, yes the carriage return and linefeed, completely forget this.

OK, so i need an convertor, i will look to this.

Thanks a lot for your help.

One more question : How the software monitor of the arduino development works if the voltage is not the expected one ?? perhaps i can do the same for my application (that need only few message to be passed)

How the software monitor of the arduino development works if the voltage is not the expected one ??

Was the USB cable connected when the Serial Monitor was being used?

yes of course, the voltage on usb is different that's why it's work...

No ?!

Is there arduino for dummies ?! ;D ;D

Thanks for your help.

The USB port goes to a USB to Serial converter chip, the small black chip on the Arduino. This USB/Serial chip translates between USB signals from your PC and the 0-5V TTL serial that the microcontroller can understand. The USB/Serial chip sends and receives data to/from the ATMega chip via pins 0 and 1.

When you plug the Arduino's USB into the PC, your computer is really seeing the USB/Serial converter chip (made by FTDI). Once it recognizes the chip, it installs a driver which creates a COM port. This COM port acts just like a real Serial port to your programs and lets you communicate to the Arduino via a USB connection. You should open this COM port in C# and send data to/from the Arduino with the program you already wrote. You should also be able to open the COM port in HyperTerminal and see "OPEN" being printed.

Through all this confusion it seems, that the OP directly connected Pin 0 and 1 of his Ardiuno to a legacy serial port of his PC.

Is this so, carou7?

This would explain all symptoms. The question is, what he wants to accomplish in the first place, as there already is a converter as jpgr has nicely explained...