Pages: [1]   Go Down
Author Topic: trouble with rs232 comunication (solved)  (Read 797 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I followed this arduino tutorial http://www.arduino.cc/en/Tutorial/ArduinoSoftwareRS232 exactly how it shows but the "hi" that should apear just apears a strange "number" (its not a number and its not a letter its something stange like ₢° and things like these) and when i type any letter on the keyboard it should send it for me back but it send another strange "number".

Anyone have any idea what it could be ?
Thanks all.
« Last Edit: October 15, 2012, 09:39:21 am by finthugo » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Anyone have any idea what it could be ?
Could be a coding issue. Too bad you didn't post any code.

Could be an issue with the wiring. Too bad you didn't post a schematic.

Could be that the device that the Arduino is talking to isn't doing what you think it is. Too bad you didn't tell us what it is.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well the schematic i cant post, because as you can see on the tutorial i have posted (http://www.arduino.cc/en/Tutorial/ArduinoSoftwareRS232) it does not show a schematic its just say "plug a capacitor between pin 1 and 3" and things like this, the code is that one:
Code:
#include <ctype.h>

#define bit9600Delay 84  
#define halfBit9600Delay 42
#define bit4800Delay 188
#define halfBit4800Delay 94

byte rx = 6;
byte tx = 7;
byte SWval;

void setup() {
  pinMode(rx,INPUT);
  pinMode(tx,OUTPUT);
  digitalWrite(tx,HIGH);
  digitalWrite(13,HIGH); //turn on debugging LED
  SWprint('h');  //debugging hello
  SWprint('i');
  SWprint(10); //carriage return
}

void SWprint(int data)
{
  byte mask;
  //startbit
  digitalWrite(tx,LOW);
  delayMicroseconds(bit9600Delay);
  for (mask = 0x01; mask>0; mask <<= 1) {
    if (data & mask){ // choose bit
     digitalWrite(tx,HIGH); // send 1
    }
    else{
     digitalWrite(tx,LOW); // send 0
    }
    delayMicroseconds(bit9600Delay);
  }
  //stop bit
  digitalWrite(tx, HIGH);
  delayMicroseconds(bit9600Delay);
}

int SWread()
{
  byte val = 0;
  while (digitalRead(rx));
  //wait for start bit
  if (digitalRead(rx) == LOW) {
    delayMicroseconds(halfBit9600Delay);
    for (int offset = 0; offset < 8; offset++) {
     delayMicroseconds(bit9600Delay);
     val |= digitalRead(rx) << offset;
    }
    //wait for stop bit + extra
    delayMicroseconds(bit9600Delay);
    delayMicroseconds(bit9600Delay);
    return val;
  }
}

void loop()
{
    SWval = SWread();
    SWprint(toupper(SWval));
}

But i do belive that the problem is in the "schematic" of this tutorial because i found some on the google and thats kinda diferent.

Moderator edit: Now with added Code Tagstm!
« Last Edit: October 15, 2012, 08:02:01 am by AWOL » Logged

Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
But i do belive that the problem is in the "schematic" of this tutorial because i found some on the google and thats kinda diferent.

And ?

Please post your schematic, what you've found "on the google" and how the two are "kida different".
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What are you trying to talk to? Why is that such a difficult question?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

the one that i found on google is that one http://www.extremeelectronics.co.in/avrtutorials/images/rs232_sche.GIF

the arduino tutorial say:
1 capacitor between 1 - 3
1 capacitor between 1 and ground
1 capacitor between 4 - 5
and 1 between 6 and ground

the on o googles tutorial say
1 capacitor between 1 - 3
1 capacitor between 2 and vcc
1 capacitor between 4 - 5
and 1 between 6 and ground
and 1 more between vcc and ground

i tried both ways with the same result smiley-cry

the arduinos tutorial also say to jump all the unused pins to vcc. the google one just say to keep it non conected.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i tried something that this tutorial said http://extremeelectronics.co.in/avr-tutorials/rs232-communication-the-level-conversion/

that says to plug out your mcu (arduino in case) and jump rx and tx to see if the comunication with the computer is working, then you open hyperterminal and the character that you send it should give you back. That has a good result so the problem is problaby in the code, does anyone already tried the code that i posted before ? ty all.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

See reply #4. It is impossible to try your code without knowing what you are trying to talk to.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i´m tring to comunicate the arduino with the computer rs232 port using hiperterminal software (im doing that for a test to comunicate with a rs232 sensor later but for now forget the sensor) the both tutorial that i posted is for that arduino <--> max232 <--> pc.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I solved the problem smiley-grin i dont know why but the computer recognized what i was tried to type when i used this simple code below
with this schematic tutorial http://extremeelectronics.co.in/avr-tutorials/rs232-communication-the-level-conversion/

Code:
#include <SoftwareSerial.h>
SoftwareSerial portOne(6, 7);

void setup()
{

  Serial.begin(9600);
    portOne.begin(9600);
}



  
void loop()
{


  portOne.write('x');
  float x = portOne.read();
  delay(100);
  portOne.write('y');
  float y = portOne.read();
  delay(100);

  Serial.print(x);
  Serial.println(y);  

}  
ty all
« Last Edit: October 16, 2012, 06:53:40 am by finthugo » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
float x = portOne.read();
The SoftwareSerial::read() method that you are using here returns an int, with the useful data in the low order byte. It does not read a whole float.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 473
Posts: 18695
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
void loop()
{


  portOne.write('x');
  float x = portOne.read();
  delay(100);
  portOne.write('y');
  float y = portOne.read();
  delay(100);

  Serial.print(x);
  Serial.println(y);



<sigh> Code tags please.

Please edit your post, select the code, and put it between [code] ... [/code] tags.

You can do that by hitting the # button above the posting area.


That code is fundamentally wrong. You should check for data available before reading it. eg.

Code:
  if (portOne.available ())
    {
    byte x = portOne.read ();
    // do something with x
 
   }

Logged

Pages: [1]   Go Up
Jump to: