Comms between PIC and ATMega ..

I have a PIC based device that has a "RS232" output. I am trying to have the Arduino get values from it, but am having extreme difficulty doing so.

I had the TX out connected to Arduino RX, RX out to Arduino TX, and ground to ground. Using simple code to echo back the values it got, to the serial monitor, gave me numbers, that did have a pattern, but don't really mean anything (not ASCII, hex etc)

I have been told that I needed to use a MAX232, and now being told I don't because it's between 2 TTL chips. I've also been told that I can't use pins 0 and 1 for 2 serial comms, so I tired to use the softwareserial library, but it just gives me a bunch of 0's and doesn't respond to any data.

Here is the circuits and how I have it currently wired:

http://dl.dropbox.com/u/203420/WIBArd.jpg

I cannot modify the code on the PIC, but since it says it has RS232 output, then I am assuming it does and I don't need to worry about that.

The web server has fields on it's hosted page where you can enter serial strings without newlines, strings with newlines and character codes. What I am tyring to do, is just have anything sent to the Arduino via the web interface, make it to the Arduino exactly as it was sent, but I have yet been able to achieve this, mainly due to my lack of knowledge on serial! :(

So, long story short, how would I go about connecting these 2 devices together, to transfer serial data from the WIB to the Arduino.

Cheers, Dan

I have a PIC based device that has a "RS232" output

No you haven't you have a PIC based device that has a serial output at TTL levels not RS232.

You can use pins 0 & 1 to communicate with this device if you want, but you then can't use this for debugging. What you don't know is if the RX on your PIC is an input or an output. On the arduino it is an input. You need to first see if something is being sent from the PIC, use an oscilloscope or if you haven't got one convert the arduino into a scope and see. I think you are probably getting nothing out of the PIC. Once something is coming out you can connect it to the RX of the arduino or another pin if you use the new software serial library.

That's what I thought, why they labelled it RS232 is beyond me ...

Anyways, using this code:

void setup(){
  Serial.begin(9600);
}
void loop(){
  if (Serial.available() > 0){
  Serial.print(Serial.read());
}
}

This is the web interface:

If I send it "1" with string and no newline, the Arduino gives me: 103 If I send it "a" with string and no newline, it gives me: 79 If I send it "1" with string and newline: 10312161 "a" with string and newline: 7912161 "1" character code: 127 "a" character code: 0

String with newline, 1 to 9:

103
121
61
179
222
15
102
121
61
89
222
15
101
121
61
178
222
15
100
121
61
172
235
0
99
121
61

There seems to be a pattern there, So I'm not quite sure what it's doing with the data ...

Closely looking at the data, it seems that it always ends in either a 15, 61 or 0, and the 2nd number is either 121, 222 or 235, and the numbers above that are the actual values.

1 = 103 value, so technically 11 should = 103 103

And it does ...

I think I'm getting somewhere, but this is only numbers, characters are going to be a pain! Anyone know what type of encoding this could be?

Cheers, Dan

What's odd is you'd expect 44 to be 89 89, but it's 176 89 :-? :-?

Your PIC device could be sending "inverted" TTL (which is sort-of "rs232"), in which case you might get weird reception on the Arduino...

Is the "WIB" a "webserver in a box"? If so, do you have any links to the documentation for it? If the web interface is a web page, have you looked to see if it sends a get or post request? Do you know the chip's baud settings?

If it is sending inverted TTL, how would I go about getting it to work with the Arduino?

And yes, the WIB is a webserver in a box. I have the instruction booklet here for it, but it mentions barely anything about interfacing with the "rs232". The baud seems to be settable on the webpage, like in the pic above.

If it is sending inverted TTL, how would I go about getting it to work with the Arduino?

You could add a hardware inverter; lots of simple logic gates can be made to perform this (XOR gates, NOR gates, NAND gates, in addition to mere "inverters.") Also, since this would be "pretending" to be rs232, it would probably work with a real rs232 level converter (like one based on a max232.) If you have one (it's just that this would be a needlessly expensive and complex solution.)

Or, it looks like the NewSoftSerial library supports signal inversion in the software.

(I looks around a bit for info on the SiliconChips WiaB design, and there are several things that imply that it does indeed output a pseudo-rs232 (inverted) signal.)

Yess!! It works!

Except, it’s printing each character on it’s own line.

If I send it “abcd” string without newline, Arduino gives me:

a
b
c
d

If I send it with newline, it puts a big space after the last character, before the next.

#include <NewSoftSerial.h>

NewSoftSerial mySerial(2, 3, true);

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

}

void loop()                     // run over and over again
{
  if (mySerial.available() > 0){
    Serial.print(mySerial.read(), BYTE);
    Serial.println();
  }
}

Ahhh, so happy it finally works :smiley:

EDIT: Just fixed that, forgot it already sends a newline so I dont need the other serial.println :smiley:

How would this thing output punctuation? Like if I send a “,”, it gives me: %2C, and a “!” gives me %21

How do I convert those so they actually show up?

Cheers,
Dan

if I send a “,”, it gives me: %2C, and a “!” gives me %21

The code YOU have shouldn’t be doing that; perhaps it is happening at the other end. (maybe it’s even part of “the standard.”) You might have to “interpret” the characters:

byte hextoi(byte c)  // convert a single char from hex to int.
{
  if (c > '9')
    c = ((c & ~0x20) - ('A')) + '0' + 10;  //strong magic!
  return c - '0'; 
}

char getcwait() // wait for a single character.  Note that this ... waits!
{
  while (mySerial.available() == 0)
    ; // spin wait
  return mySerial.read();
}

void loop() {
  if (mySerial.available() > 0){
    char c = getcwait();
    if (c == '%') {  // encoded character (2 hex digits follow)
      c = hextoi(getcwait()) << 4 ;  //first nybble in upper 4 bits.
      c += hextoi(getcwait());  // second nybble in low bits
    }
    Serial.print(c, BYTE);
  }
}