Arduino, RS232 shield and serial device problem


hi everyone!
i'm stuck problem, , can't figure out how solve it...

i'm trying connect flow meter (tsi 4000 series flowmeter) arduino in order send specific commands set flow limits, type of sample (water, air, n2, etc) , on.
i've bought rs232 shield arduino (sparkfun rs232) , i'm using arduino mega.

i'm trying send simple command, "?", , should receive "ok" message flow meter. problem i'm receiving bunch of squares, , don't know if it's coding problem or connection problem.
i've attached black , green wire flowmeter (+5v , grownd) corresponding pins of shield, yellow , white wires of flowmeter (rs-232 out , rs-232 in) tx , rx pins on shield, , i've connected tx1 , rx1 on mega mtx , mrx pins on shield (photo attached). 2 jumpers connect mrx tx , mtx rx on shield.

here code i'm using:

code: [select]

//serial i/o
const int numreadings = 50;
unsigned int flowread[numreadings]; // string read
byte inread; // dum reading variable
byte r1; //first byte read
byte r2; //second byte read
byte ack; //acknowledgement byte reading

//running average
int index = 0;        // index of current reading
unsigned int flowtot = 0;   // running total
float flowrunmean = 0;    // average

void setup() {
  serial.begin(9600); //usb2serial
  serial1.begin(38400); //flowmeter
}

void loop() {

//~~~~~~~~~~~~~~~~~~~~~~~~~~//
//  readings defaults
//~~~~~~~~~~~~~~~~~~~~~~~~~~// 

  serial1.write("?/r");
  while(serial1.available()>0){
    serial.write(serial1.read());
  }
  delay(1000);
}


what doing wrong? help??

thanks lot guys!

code: [select]
  serial1.write("?/r");
this sending 3 characters, '?', '/', , 'r'. suspect want sending 2 characters, '?' , '\r'.

code: [select]
  while(serial1.available()>0){
    serial.write(serial1.read());
  }

the write() method takes byte. read() method returns int. serial monitor application not know binary data. use print() send data serial monitor.

directly sending serial.read()'s output idea.

code: [select]
   while(serial1.available() > 0)
   {
      char c = serial1.read();
      serial.print(c);
   }




Arduino Forum > Using Arduino > Networking, Protocols, and Devices (Moderator: fabioc84) > Arduino, RS232 shield and serial device problem


arduino

Comments

Popular posts from this blog

Flip address is out of range arduino uno r3

Arduino Uno not uploading

Indesign and MathType fonts