Arduino Uno Reading Tx/Rx from Car Head Unit.

Hi,
I am new with Arduino Uno. I am just try to creating an interface so that I can operate my JVC stereo from Car's Control Panel.
There are three wires from Car's Control Panel i.e. (UART Control Panel to Stereo/Rx, UART Stereo to Control Panel/Tx, UART GND).

Now I have connected all three wires to Arduino and trying to read the code using Serial.Read() Program.

Now its showing ASCII values on screen and if print the HEX value it shows numbers like 3,10,60,75 etc.

Now the problem is that its continuously showing values and tx light keeps on blinking even if I dont press any button from the Control Unit of my Car. But if I press the button it shows lot of ASCII characters on screen instead of some characters showing while idle..

Now how do i distinguish the values and make them logical so that I can read the exact values and code as per the button pressed on the control unit..

Please guide me...

Used this code to read the Data:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(0, 1); // RX, TX

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(57600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}

Serial.println("Goodnight moon!");

// set the data rate for the SoftwareSerial port
mySerial.begin(4800);
mySerial.println("Hello, world?");
}

void loop() { // run over and over
if (mySerial.available()) {
Serial.write(mySerial.read());
}
if (Serial.available()) {
mySerial.write(Serial.read());
}
}

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

The code in the second example can probably be used to capture the data that is coming in so that you can study it.

It would be a big help if you can post a link to the datasheet for the stereo you are trying to connect to.

...R

Thanks for the reply but the thing is control panel is sending the values which I am trying to read...

May be this will help, this is exactly what I am trying to do but instead of these multiple wires I have tx and rx...

samrishi_24:
Thanks for the reply but the thing is control panel is sending the values which I am trying to read...

That's what my examples are for.

...R

Ok I will try the second exapmle and then will let you know... and please if you can help me with one more thing.... that I need to use serial port 0,1.. So can you please modify the code and then give me. That will be very much helpful.. Thanks in advance...

samrishi_24:
Ok I will try the second exapmle and then will let you know... and please if you can help me with one more thing.... that I need to use serial port 0,1.. So can you please modify the code and then give me.

That's your job.

In any case, what makes you think the examples don't already use pins 0 and 1 on an Uno?

...R

Hi...

I tried your example second one.. but not getting any output in the monitor... but when I use this specific code I get some garbage values on the monitor when I press any button on car's head unit... attached screen...

#include <SoftwareSerial.h>

SoftwareSerial mySerial(0, 1); // RX, TX

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(57600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}

Serial.println("Goodnight moon!");

// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
mySerial.println("Hello, world?");
}

void loop() { // run over and over
if (mySerial.available()) {
Serial.write(mySerial.read());
}
if (Serial.available()) {
mySerial.write(Serial.read());
}
}

I am not a arduino programmer. I just want to make this happen in my car...

Please help...

Wires are attached in the pins.. 0,1 and gnd

SoftwareSerial mySerial(0, 1); // RX, TX

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(57600);

Stupid. You can NOT do software serial on the hardware serial pins while doing hardware serial on the hardware serial pins.

How can I achieve this... can you pls tell me that..?

samrishi_24:
How can I achieve this... can you pls tell me that..?

It should be completely obvious. Use different pins, and connect the mySerial object to those other pins.

You don't HAVE a mySerial object, do you? So why that stupid name?

samrishi_24:
How can I achieve this... can you pls tell me that..?

Read the reference section about SoftwareSerial

...R

I tried with the pins 10,11 but still data is coming continuously and showing in terms of garbage on the monitor...

It should be like when I click the button then only I get some value.... thats all I want... :confused:

samrishi_24:
I tried with the pins 10,11 ....

How can we know exactly what you did when you have not posted your program.

...R

This one I have used.... which is showing garbage values and continuously receiving the value.... and when I hit any button I get these values faster and much more than when in the idle....

#include <SoftwareSerial.h>

SoftwareSerial mySerial(0, 1); // RX, TX

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(57600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}

Serial.println("Goodnight moon!");

// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
mySerial.println("Hello, world?");
}

void loop() { // run over and over
if (mySerial.available()) {
Serial.write(mySerial.read());
}
if (Serial.available()) {
mySerial.write(Serial.read());
}
}

Why would you want to send "Hello World" to a car stereo?

Back in Reply #6 you said you were not getting any results with my code. Now that you know how to use SoftwareSerial try my code again using SoftwareSerial to receive data from the stereo and Serial to print the results to the Serial Monitor.

...R

Hi I tried this code first and can not seen any thing in the monitor...

#include <SoftwareSerial.h>

SoftwareSerial mySerial(0, 1); // RX, TX
const byte numChars = 32;
char receivedChars[numChars];   // an array to store the received data

boolean newData = false;

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(57600);
/*while (!Serial) {
  ; // wait for serial port to connect. Needed for native USB port only
}*/


Serial.println("<Arduino is ready>");

// set the data rate for the SoftwareSerial port
mySerial.begin(9600);

}

void loop() { // run over and over
static byte ndx = 0;
  char endMarker = '\n';
  char rc;
 
  while (mySerial.available() && newData == false) {
    rc = mySerial.read();
    
    if (rc != endMarker) {
          receivedChars[ndx] = rc;
          ndx++;
          if (ndx >= numChars) {
              ndx = numChars - 1;
          }
      }
      else {
          receivedChars[ndx] = '\0'; // terminate the string
          ndx = 0;
          newData = true;
      }
  }
  showNewData();

/*if (mySerial.available()) {
  Serial.write(mySerial.read());
}*/  

}

void showNewData() {
  if (newData == true) {
      Serial.write("This just in ... ");
      Serial.write(receivedChars);
      Serial.write("......");
      newData = false;
  }
}

Then I have uncommented the following:

/*if (mySerial.available()) {
  Serial.write(mySerial.read());
}*/

and then the code become:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(0, 1); // RX, TX
const byte numChars = 32;
char receivedChars[numChars];   // an array to store the received data

boolean newData = false;

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(57600);
/*while (!Serial) {
  ; // wait for serial port to connect. Needed for native USB port only
}*/


Serial.println("<Arduino is ready>");

// set the data rate for the SoftwareSerial port
mySerial.begin(9600);

}

void loop() { // run over and over
static byte ndx = 0;
  char endMarker = '\n';
  char rc;
 
  while (mySerial.available() && newData == false) {
    rc = mySerial.read();
    
    if (rc != endMarker) {
          receivedChars[ndx] = rc;
          ndx++;
          if (ndx >= numChars) {
              ndx = numChars - 1;
          }
      }
      else {
          receivedChars[ndx] = '\0'; // terminate the string
          ndx = 0;
          newData = true;
      }
  }
  showNewData();

if (mySerial.available()) {
  Serial.write(mySerial.read());
}  

}

void showNewData() {
  if (newData == true) {
      Serial.write("This just in ... ");
      Serial.write(receivedChars);
      Serial.write("......");
      newData = false;
  }
}

Then I can see the following output:
Image 1: when i dont press any button...
Image 2: when i press many buttons on my car...

I just realized that I was wrong in what I said in Reply #14 "Now that you know how to use SoftwareSerial ". Obviously you have not yet digested the advice from Reply #9 SoftwareSerial MUST NOT BE on pins 0 and 1. They are reserved for HardwareSerial for communication with the PC. When I wrote Reply #14 I had assumed (based on Reply #11) that you were using pins 10 and 11 for SoftwareSerial so I did not check that part of your program.

Fix that and try again, and report back.

...R

Please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

Yes I have tried with both.... 0,1 and 10,11.. so whatever I post here I try with both 0,1 and 10,11....

samrishi_24:
Yes I have tried with both.... 0,1 and 10,11.. so whatever I post here I try with both 0,1 and 10,11....

The version using 0 and 1 for SoftwareSerial is WRONG. I am not going to waste time studying a wrong version. Post the correct version.

...R

Now please tell me....

I tried this code first and can not seen any thing in the monitor...

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX
const byte numChars = 32;
char receivedChars[numChars];   // an array to store the received data

boolean newData = false;

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(57600);
/*while (!Serial) {
  ; // wait for serial port to connect. Needed for native USB port only
}*/


Serial.println("<Arduino is ready>");

// set the data rate for the SoftwareSerial port
mySerial.begin(9600);

}

void loop() { // run over and over
static byte ndx = 0;
  char endMarker = '\n';
  char rc;
 
  while (mySerial.available() && newData == false) {
    rc = mySerial.read();
    
    if (rc != endMarker) {
          receivedChars[ndx] = rc;
          ndx++;
          if (ndx >= numChars) {
              ndx = numChars - 1;
          }
      }
      else {
          receivedChars[ndx] = '\0'; // terminate the string
          ndx = 0;
          newData = true;
      }
  }
  showNewData();

/*if (mySerial.available()) {
  Serial.write(mySerial.read());
}*/  

}

void showNewData() {
  if (newData == true) {
      Serial.write("This just in ... ");
      Serial.write(receivedChars);
      Serial.write("......");
      newData = false;
  }
}

Then I have uncommented the following:

/*if (mySerial.available()) {
  Serial.write(mySerial.read());
}*/

and then the code become:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX
const byte numChars = 32;
char receivedChars[numChars];   // an array to store the received data

boolean newData = false;

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(57600);
/*while (!Serial) {
  ; // wait for serial port to connect. Needed for native USB port only
}*/


Serial.println("<Arduino is ready>");

// set the data rate for the SoftwareSerial port
mySerial.begin(9600);

}

void loop() { // run over and over
static byte ndx = 0;
  char endMarker = '\n';
  char rc;
 
  while (mySerial.available() && newData == false) {
    rc = mySerial.read();
    
    if (rc != endMarker) {
          receivedChars[ndx] = rc;
          ndx++;
          if (ndx >= numChars) {
              ndx = numChars - 1;
          }
      }
      else {
          receivedChars[ndx] = '\0'; // terminate the string
          ndx = 0;
          newData = true;
      }
  }
  showNewData();

if (mySerial.available()) {
  Serial.write(mySerial.read());
}  

}

void showNewData() {
  if (newData == true) {
      Serial.write("This just in ... ");
      Serial.write(receivedChars);
      Serial.write("......");
      newData = false;
  }
}

Then I can see the following output:
Image 1: when i dont press any button...
Image 2: when i press many buttons on my car...