Serial ASCII

Hello,

I am using a Mega2560 to communicate with a serial audio device (CFSoundIII). The excerpt from the manual describing the serial protocol is attached for reference.

I have tried several ways using Serial.print and Serial.write without any luck. Here is one example that doesn’t work:

void setup() {
// initialize both serial ports:
Serial2.begin(2400);
}
void loop () {
Serial2.write(“01”);
Serial2.write(“p+”);
Serial2.write(01);
Serial2.write(“03”);
delay(3000);
}

My wiring is very simple with TX2 from Arduino going to the RX of the serial device and the ground lines are connect. The device works and I can get it to play using external triggers. The issue I believe is the format in which the commands are being sent.

Any help in translating what the manual says (attached) to code will be most helpful.

p.s. I can make the device work using a Basic Stamp II with the following command: SEROUT TXPIN,2400,[1,“p+”,01,3].

many thanks in advance,

Al

Serial2.write("01");
  Serial2.write("p+");
  Serial2.write(01);
  Serial2.write("03");

Why notSerial.print (F("01p+0103"));

This fragment:

SEROUT TXPIN,2400,[1,"p+",01,3].

suggests that you are writing out four arguments which are int, string, int, int. The code in your loop() is string, string, int, string. Could that be an issue?

Thanks AWOL but:
Serial.print (F("01p+0103"));
didn't work?

And econJack, the sequence you suggest:
Serial2.write(01);
Serial2.write("p+");
Serial2.write(01);
Serial2.write(03);

doesn't work either.

Really puzzling?

Thanks AWOL but:
Serial.print (F("01p+0103"));
didn't work?

You're asking me?

Really puzzling?

void loop () {
  Serial2.write("01");
  Serial2.write("p+");
  Serial2.write(01);
  Serial2.write("03");
  delay(3000); 
}

No very simple the SOH value is a single char with the value 01 NOT the string you are sending! The same applies to the ETX.

So it is

void loop () {
  Serial2.write(1); //single char not a string!
  Serial2.write("p+");
  Serial2.write(01);
  Serial2.write(03);//single char not a string!
  delay(3000); 
}

The description clearly says send a SOH char, then 'p', then '+', then "01", then an ETX,
thus this should do it:

  Serial.write (0x01) ;
  Serial.print ("p+01") ;
  Serial.write (0x03) ;

or

  Serial.print ("\x01p+01\x03") ;

However, I suspect they say "ASCII hexadecimal" when they mean "binary",
so its probably

  Serial.print ("\x01p+\x01\x03") ;

alnajjar:
p.s. I can make the device work using a Basic Stamp II with the following command: SEROUT TXPIN,2400,[1,“p+”,01,3].

Perhaps have the Stamp send that to the Arduino and have the Arduino print hex bytes to serial monitor.

Perhaps have the Stamp send that to the Arduino and have the Arduino print hex bytes to serial monitor.

Hey, who said you could open the fresh air window?

Great thoughts. I am away from the bench for the evening (ET) and will try these suggestions and report back tomorrow.

Many thanks.

MarkT: I tried the two examples you suggested and no luck.

GoForSmoke: I did what you suggested by hooking the Stamp to the Arduino. Attached is the data I get on the serial monitor every time the Stamp sends the command (which I double checked and work perfectly with the serial device). Here is how I read data from the Stamp:

if (Serial2.available() > 0) {
// read the incoming byte:
incomingByte = Serial2.read();
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
}

I tried sending the exact bytes received from the Stamp via the Arduino to the serial device and I still get nothing:
Serial2.write(127);
Serial2.write(36);
Serial2.write(141);
Serial2.write(198);
Serial2.write(38);
Serial2.write(0);

Thanks to all and the puzzle continues…

Al

serial data.jpg

Then serial must be configured differently I guess, those bytes look nonsense:
7F 24 8D C6 26 00

baudrate, stop bits, parity - make sure its all correct.

I think you are correct. The only difference between what the Stamp is doing and Arduino, is that the setting of the serial command from the Stamp is 'inverted' and not 'true'. The Stamp has two distinct types of 2400 8N1: 'inverted' or 'true'. If I setup the Stamp to send 'true' signal to the serial device then it won't work. I am not sure why the Stamp needs to send 'inverted' and whether I should (and if so how) duplicate in my Arduino code.

Thanks again,

Al

I am not sure why the Stamp needs to send 'inverted'

True RS232 vs. TTL serial?

I am not sure why the Stamp needs to send 'inverted' and whether I should (and if so how) duplicate in my Arduino code.

SoftwareSerial can do inverted. Have you tried SoftwareSerial?

alnajjar:
GoForSmoke: I did what you suggested by hooking the Stamp to the Arduino. Attached is the data I get on the serial monitor every time the Stamp sends the command (which I double checked and work perfectly with the serial device). Here is how I read data from the Stamp:

if (Serial2.available() > 0) {
// read the incoming byte:
incomingByte = Serial2.read();
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
}

I tried sending the exact bytes received from the Stamp via the Arduino to the serial device and I still get nothing:
Serial2.write(127);
Serial2.write(36);
Serial2.write(141);
Serial2.write(198);
Serial2.write(38);
Serial2.write(0);

Thanks to all and the puzzle continues...

Al

I would have expected different from
1,"p+",01,3
I would have expected at least somewhere in there decimal bytes
1, 112, 43, 1, 3 = 1, "p+", 1, 3

127 = DEL
36 = $
141 and 198 are extended ascii
38 = &
0 = NULL

Possibly one device sent data before the other was ready? Something unexpected is going on for sure.

first, you seem to not be sending the & or ~ or ! as described in the spec, is there a reason for this?

Second, if you can receive data from the stamp but cant send it you probably have a wiring problem because we know the baud rate is ok.
It is entirely possible you have bad hardware

I haven't tried software serial. I am new to Arduino, and although transitioning from Parallax has been smooth, this serial problem has been the only problem to date.

I will try it and report back.

Many thanks.

I am forgetting things. Serial is more than baud rate. there is start bit, stop bit(s), parity bit and data bits.
Arduino serial is 1 start bit, 8 data bits, no parity and 1 stop bit.

Haven't tried softwareSerial yet. Just looked at the documentation and cannot find the parameter for inverted TTL. Any examples you can suggest that show how to do inverted logic with softwareSerial?

When Googled it, I found NewSoftwareSerial (NewSoftSerial | Arduiniana) that has a third parameter (true or false) for inverted logic. According to the NewSofwareSerial, that after V 1.0, this NewSoftwareSerial is included in the core application. So I am confused as to how to do this.

Thanks!