Serial Interfacing problems

Hi everybody,
I’m quite new to Arduino and I’m working on my very first project. Connected an LCD on pin 8-13 and used AD5 to read out 3 buttons, works all perfect so far.

My project implies communication with a small Mini-Z R/C car. The objective is to change settings inside the car without a computer with ICS software, instead using an Andruino with LCD and buttons.

The car has a kind of single wire interface with regular serial communication like RS232, but with 5V levels. So one wire is used for Tx as well as for Rx and of course the GND is connected to the car as a reference as well.

Because of the one wire solution I wired the Arduino Uno like this:

Writing to the car works perfectly well, I can change the settings and verify these on the computer with ICS software and everything seems to work well.

When I try to read from the car, a small protocol comes into play. You need to send 0xC5 to the car, and then the car sends back a 18byte long code. Unfortunately in my setup it doesn’t.

This is the code I use to see if bytes are sent to the serial port:

void ReadProgram() {
  unsigned long timeplus3sec;
  pinMode(0, INPUT);
  lcd.clear();
  lcd.print("Read Setup");
  timeplus3sec = millis()+3000;
  Serial.begin(9600);
  Serial.flush();
  Serial.write(0xC5);
  while((Serial.available() < 18) && (millis()<timeplus3sec)) {
    lcd.setCursor(0,1);
    lcd.print("Waiting...");
    lcd.print(Serial.available());
    delay(100);
  }
  Serial.end();
}

Unfortunately the Serial.available() counter stays on 0 and after 3 secs the code continues without having recieved anything.

Now I did some experimenting with Terminal.exe, to see if anything happens, and well there does seem to happen something:

  1. Running ReadProgram(); displays C5 on my terminal screen. So, as expected, the Arduino sends a 0xC5 to the car, but no reaction comes back?
  2. Running the Arduino while Serial.begin(9600) is not active. If I send a C5 with my Terminal, I get a reaction from the car: C5 5A 64 FF 02 02 01 FF BC 44 88 78 FF 2C 05 5A 3C 87
  3. When I try to sent C5 with the Terminal during the 3secs of waiting in ReadProgram(), nothing happens: the Terminal displays nothing on the screen, I get no respond back from the car on the Terminal and not in Arduino.

Just to make sure the reception in the Arduino works fine I tried this example from the Arduino website:

void loop() { 
  if (Serial.available() > 0) {
		// read the incoming byte:
		incomingByte = Serial.read();
                Serial.write(incomingByte);
		// say what you got:
                lcd.clear();
		lcd.print("I received: ");
		lcd.print(incomingByte, DEC);

	}
  
}

This only works well with the Terminal.exe when the interface cable with the diode is not connected. So my guess something goes wrong with the cable, maybe in combination with the USB/TTL Serial convertor which is on the board.

This is the complete setup to give you an idea:

I hope somebody has a suggestion,
Thanks,
Hannu.

I think the problem is this - when you are not transmitting, the output goes to a TTL low, with its 40mA drive capability overpowering any hi/lo the car is trying to put out. Try using pinMode to make the Tx line an input right after you finish transmitting, then set it back to an output before you transmit again.

Hi CrossRoads,
Thank you for your reply, this is what I changed:

void ReadProgram() {
  unsigned long timeplus3sec;
  pinMode(0, INPUT);
  lcd.clear();
  lcd.print("Read Setup");
  timeplus3sec = millis()+3000;
  Serial.begin(9600);
  Serial.flush();
  Serial.write(0xC5);
  pinMode(1, INPUT);
  while((Serial.available() < 18) && (millis()<timeplus3sec)) {
    lcd.setCursor(0,1);
    lcd.print("Waiting...");
    lcd.print(Serial.available());
    delay(100);
  }
  Serial.end();
  pinMode(1, OUTPUT);
  delay(1000);
}

Unfortunately it didn’t change anything, thanks anyway.

On thing I haven’t mentioned before is that I enable stop bit, but I think it is not relevant:

UCSR0C = UCSR0C | B00001000;

Where do you actually read the data coming in?

with something like incomingByte = Serial.read();

CrossRoads: Where do you actually read the data coming in?

with something like incomingByte = Serial.read();

Well, for now I'm just testing if data is coming in. As long as the buffer is empty there is no use reading the data. Once the buffer is filles (after the while loop) I will provide code for reading out the buffer with Serial.read();.

Just reading through a thread on the old forum: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1279276197 This is guy is doing quite the same thing as I am, and he has the same problem: the device will not recieve. He has found the cause on Reply #4, using a board without the USB controller. Is there maybe a way to disable this controller? Thanks, Hannu.

That would be my guess: you have a USB cable connected. Simply power the board from Vin. Then the USB-->Serial converter will be out of the picture and it will not interfere with the RxD.