Using UART to read CMPS10.

Hi all,

No matter how many past posts I read and try to extract advice from, I just can't seem to solve my problem.

I am using an Uno and a CMPS10 (http://www.robot-electronics.co.uk/htm/cmps10doc.htm).

I can get the compass to work well using I2C, however the UART mode is tripping me up.

I have connected the Arduino and CMPS10 as instructed for UART mode, that is: 5V to Vin; Rx (Uno) to Tx (CMPS); Tx(Uno) to Rx(CMPS); Ground to Mode; and, ground to ground.

Any pointers/hints as to where I may have gone wrong would be really appreciated. My code is included below.

Thanks in advance,

Henry.

I am trying to use the following code:

//List of commands available to serial communication
#define CMD        0x00  // define blank message to send to clear path
#define GET_VER    0x11  // Defines address of GET_VERSION
#define GET_ANG8   0x12  // Angle as single byte 0-255
#define GET_ANG16  0x13  // Angle as two bytes, high byte first 0-3600
#define GET_PITCH  0x14  // Pitch angle +/- 0-85deg
#define GET_ROLL   0x15  // Roll angle +/- 0-85deg
#define GET_MAG_R  0x21  // Raw magnetic data, 16bit signed: X high, X low, Y high, Y low, Z high, Z low
#define Get_ACC_R  0x22  // Raw accelerometer data, 16 bit signed: X high, X low, Y high, Y low, Z high, Z low
#define GET_ALL    0x23  // Address to get: angle high, angle low (0-3600), pitch, roll +/- 0-85deg

void setup() {
  Serial.begin(9600);  // Start serial at default rate for CMPS10
  while (!Serial) {
    ; // wait for serial port to connect.
  }
  Serial.println("Hello from Serial");
}

void loop() {
  
  int ver;
  byte highByte, lowByte;

  Serial.write(GET_VER);
  delay(10);
  ver = Serial.read();
  Serial.print(ver);
  Serial.print(";    ");

  Serial.write(GET_ANG16);
  delay(500);
  if(Serial.available() > 0 ) {
    highByte = Serial.read();
    lowByte = Serial.read();
  }
  Serial.print(highByte, DEC);
  Serial.print(";    ");
  Serial.print(lowByte, DEC);
  Serial.println(";    ");
  
  delay(1000);
}
  Serial.println("Hello from Serial");

What is that device supposed to do with this?

You aren’t trying to talk to it and the PC on the same serial port, are you? That’s what it looks to me like.

I accidentally left that in when checking I could print a message to the serial monitor. I have removed this.

Could you clarify how I would know if I was using the same serial port for both PC and compass? I have the Uno plugged into my PC using the supplied USB cable, and have used jumper wires to connect the UNOs Tx and Rx pins (D0 and D1) to the compass.

Many thanks,

Henry.

Regarding above post, would I be right in saying that the inbuilt Tx and Rx pins (D0 and D1) are those that also go to the PC via the USB? Or am I completely off the track?

henryt: Regarding above post, would I be right in saying that the inbuilt Tx and Rx pins (D0 and D1) are those that also go to the PC via the USB? Or am I completely off the track?

On most Arduinos, that is the case. The Leonardo does not connect RX and TX to Serial.

Thank you.

I have used SoftwareSerial.h to set up another UART on my board.

Is it possible to print to the Serial monitor the results from this? Would it be as simple as setting a variable up to hold the result from mySerial and then using the Serial.print function to send this to the Serial monitor?

I have made this work now!

Thank you for all your help - it is the little bits of knowledge that really got me there!