Close

Trouble Shooting Communication Protocols! - Hours of f(rustration)un?

A project log for MyComm

A portable, solar powered, handheld device that provides truly global messaging when you have no alternative.

jack-wellsJack Wells 06/08/2016 at 09:250 Comments

I would like to think I am becoming an "experienced" user of Serial communications. I have written my own packet based communication protocol for Arduino-Arduino and Arduino-Pi communications and worked with a number of different Serial devices (IMUs, Compasses, GPS etc). I also know what to do when dealing with RS232, RS422 etc. However, every device is different and every one of them has their quirks. Sometime's what works in the past trips you up in the future.


I've started working with the Rockblock Mk2 Iridium modem breakout. It works on an "AT" command system similar to older modems. There is a very well documented Arduino library available from the same person that did the Tiny GPS library (excellent library by the way). Reading the data sheet of the Rockblock states that an "AT" command with a newline will get a response "OK". Great, that's an excellent starting point to make sure everything's working. Nice and simple. I don't have an FTDI Serial-USB cable handy but I do have a Teensy 3.1 which has dedicated hardware serial ports. I can use it to pass data from the pc to the Rockblock and print back what it gets back. Easy. So I programmed the teensy with the following code:

#define IridEnablePin 23

void setup()
{
	Serial.begin(9600);
	pinMode(IridEnablePin, OUTPUT);
	digitalWrite(IridEnablePin, HIGH);

	delay(2000);
	Serial.println("MyComm Iridium Pass Through Test");
	
	Serial1.begin(19200,SERIAL_8N1);
}



void loop()
{

	while(Serial1.available())
	{
		char c = Serial1.read();
		Serial.print(c);
	}

	if(Serial.available())
	{
		while(Serial.available())
		{
			char c = Serial.read();
		        Serial1.println(c);
                }
	}


	
	delay(100);
}

Baud Rates? Check

Wiring? Check

Power? Check


PC Send "AT" and include new line.... Nothing. No response. I spent a total of 5 hours checking wiring, datasheets, reading forum after forum. There were mentions of tieing flow control signals to ground to make sure it wasn't flow control related. I tried reversing TX/RX more times than I can count. I tried changing my power supply and usb cables. Still nothing.

Then it hit me. "\n" (newline) is a very specific character and I might not be sending it correctly. So I went even more basic:

Serial1.println("AT");
And low and behold! "OK" was my reply. What I thought was a simple Serial pass through hadn't worked at all. So there we go, many hours wasted but I'm now very familiar with the Rockblock's power up sequence, wiring and general AT command options. My fixed pass through code looks like this:
#define IridEnablePin 23

void setup()
{
	Serial.begin(9600);
	pinMode(IridEnablePin, OUTPUT);
	digitalWrite(IridEnablePin, HIGH);

	delay(2000);
	Serial.println("MyComm Iridium Pass Through Test");
	
	Serial1.begin(19200,SERIAL_8N1);
}

boolean printAfterDelay = false;

void loop()
{

	while(Serial1.available())
	{
		char c = Serial1.read();
		Serial.print(c);
	}

	if(Serial.available())
	{
		delay(100);
		String NewCommand = "";

		while(Serial.available())
		{
			char c = Serial.read();
			if(c != 'n')
			NewCommand += c;
		}
		
		NewCommand.trim();

		Serial1.println(NewCommand);
	}

	if(millis() > 180000 && !printAfterDelay)
	{
		Serial.println("180 Seconds have passed. Iridium should be online");
		printAfterDelay = true;
	}
	
	delay(100);
}
Always new lessons to learn with every device,

JW


Update; After speaking with Elliot Williams from Hackaday I was told that "println" actually adds a carriage return as well as a linefeed (\r\n). So I thought; what if the Datasheet is wrong and the Rockblock actually requires a carriage return as well as the linefeed? Turns out it does! My original pass through code works when I end the PC command with carriage return + linefeed! So there you go, don't always take a datasheet's word as golden!

Discussions