Canada
Asked — Edited

I’M Trying To Connect An Ardui

I’m trying to connect an Arduino Nano with the EZ-B v4 to offload some of the work. UART1 and UART2 work fine!

Problem is with UART0 (information is send but corrupted)

Connection:

  • Arduino GND to EZ-B v4 GND

  • Arduino RX connected to UART0 TX (first pin), D5 or D18

Attached to the Arduino is a 2x16 character LCD (I2C connection) to display (the serial information (also visible true the Serial Monitor) using a simple protocol; 0 (0x30) = clear LCD, 1 (0x31) = start at line 1, 2 (0x32) = start at line 2. All other information is just displayed.

All is fine and Information is displayed correctly when attached to pin D5 or D18.

When connected to the TX pin of UART0 information is sporadically send but corrupted. Touching the wire (on the outside!) changes the behavior of the characters received (more characters but still corrupted)??!!


ARC Pro

Upgrade to ARC Pro

Experience early access to the latest features and updates. You'll have everything that is needed to unleash your robot's potential.

#1  

This is the Script I used: :loop UARTInit(0, 0, 9600) #initialize UART0 UARTWrite(0, 0, 0x30) sleep(100) UARTWrite(0, 0, 0x31, "Hello UART-zero") UARTWrite(0, 0, 0x32, "Second Hello") sleep(100)

UARTInit(0, 1, 9600) #initialize UART1 UARTWrite(0, 1, 0x30) sleep(100) UARTWrite(0, 1, 0x31, "Hello UART-one") UARTWrite(0, 1, 0x32, "Second Hello") sleep(100)

UARTInit(0, 2, 9600) #initialize UART2 UARTWrite(0, 2, 0x30) sleep(100) UARTWrite(0, 2, 0x31, "Hello UART-two") UARTWrite(0, 2, 0x32, "Second Hello") sleep(100) Goto (loop)

PRO
Synthiam
#2  

Sounds like your wire has a loose connection or is broken. Try a new wire and secure it better on both ends.

Long as your arduino and ezb are set to 9600, there shouldn’t be a problem.

Also, post the arduino code.

#3  

It's not the wire. I added an extra wire via a breadboard to measure the voltage (I should use an oscilloscope but I don't have one) and noticed the changed behavior. I changed the wire nevertheless but problem is the same. Arduino Nano is on a breadboard EZ-Bv4 is connected with 3 wires originating from UART0 TX (first pin), D5 and D18 I use an extra wire to connect the Nano RX with one of the EZ-B wires

/* I2C LCD 16x2 Arduino Tutorial

//Libraries #include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd (0x27, 16, 2); // Set the LCD I2C address, if it's not working try 0x27. //LiquidCrystal_I2C lcd (0x27, 20, 4); // Set the LCD I2C address (20 chars 4 lines), if it's not working try 0x27.

void setup(){ Serial.begin (9600);

lcd.init(); // iInit the LCD for 16 chars 2 lines // lcd.init(); // iInit the LCD for 20 chars 4 lines lcd.backlight(); // Turn on the backligt (try lcd.noBaklight() to turn it off (mind CAPITALS!!!) // lcd.noBacklight(); lcd.setCursor(0,0); //First line lcd.print("EZ-B4 LCD Display"); lcd.setCursor(0,1); //Second line lcd.print("Ardumotive.com");

}

void loop(){ ReadInputFromPC (); }

void ReadInputFromPC () { if (Serial.available ()) { delay (100); while (Serial.available () > 0) { int temp = Serial.read();

  Serial.print ("Debug ");
  Serial.println (temp); 

  if (temp == 48) {
    lcd.clear ();
  }
  else {
    if (temp == 49) {
      lcd.setCursor (0,0);
    }
    else {
      if (temp == 50) {
        lcd.setCursor (0,1);
      }
      else{ 
        if (temp != 10) {
          lcd.write(temp);
        }
      }
    }
  }
}     

}
}

PRO
Synthiam
#4   — Edited

The delay after reading on the Nano means you're skipping/missing bytes from the transmitter (EZ-B)

Quote:

[font=OpenSans, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"]if (Serial.available ()) { [font=OpenSans, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"]delay (100); <--- THIS IS BAD [font=OpenSans, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"]while (Serial.available () > 0) { [font=OpenSans, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"]int temp = Serial.read();

[/font][/font][/font][/font]

[font=OpenSans, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"][font=OpenSans, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"][font=OpenSans, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"][font=OpenSans, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"][font=OpenSans, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"][font=OpenSans, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"]

Also, you're writing to the LCD between character reads from the UART. That's going to cause a delay while the write occurs - which will also result in missing characters.  Also, you're DEBUG.WRITE() which is sending data out of a UART and that's gonna be slow as well which could result in the arduino not being able to keep up to the character transmissions[/font][/font][/font][/font][/font] [font=OpenSans, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"][font=OpenSans, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"][font=OpenSans, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"][font=OpenSans, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"][font=OpenSans, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"] Instead, write your program to cache/buffer the serial read until a terminator character is sent. Following that, transmit the data in a batch to the lcd.[/font]

[font=OpenSans, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica Neue, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol, Noto Color Emoji]-OR-[/font]

[font=OpenSans, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica Neue, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol, Noto Color Emoji]check to see if there's DMA available on your arduino and read from a DMA buffer[/font]

[font=OpenSans, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica Neue, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol, Noto Color Emoji]-OR-[/font]

[font=OpenSans, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica Neue, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol, Noto Color Emoji]can the arduino have an interrupt execute when a new serial character arrives? If so, do that and add it to a buffer. Then have the main loop read from that buffer[/font][/font]

[font=OpenSans, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"][font=OpenSans, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica Neue, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol, Noto Color Emoji]Either way, that code is skipping/missing characters transmitted from the ez-b. The UART doesn't "wait until a character is received". That's not how serial works. Serial transmits whether the receiver is listening or not - there's no acknowledgement on serial. So by DELAY(100) and LCD.Write(), the Arduino is doing stuff while the EZ-B is transmitting data. This means the arduino is missing bytes because the arduino is busy doing something else instead of receiving data.[/font][/font][/font][/font][/font][/font]

PRO
Synthiam
#5  

Here - this is a little buffer i wrote for arduino this morning... use something like this.

#define _BUFFER_SIZE 512

byte        _INPUT_BUFFER[_BUFFER_SIZE];
unsigned int _WRITE_POSITION = 0;
unsigned int _READ_POSITION = 0;

bool IsAvail() {

  return _WRITE_POSITION != _READ_POSITION;
}

void serialEvent() {

  while (Serial.available()) {

    _WRITE_POSITION++;

    _INPUT_BUFFER[_WRITE_POSITION % _BUFFER_SIZE] = Serial.read();
  }
}

byte ReadByte() {

  while (_WRITE_POSITION == _READ_POSITION && Serial.available() == 0);

  serialEvent();

  _READ_POSITION++;

  return _INPUT_BUFFER[_READ_POSITION % _BUFFER_SIZE];
}

void loop() {

  if (IsAvail()) {

    byte temp = ReadByte();
    
    if (temp == 48) 
      lcd.clear ();
    else if (temp == 49) 
      lcd.setCursor (0,0);
    else if (temp == 50) 
      lcd.setCursor (0,1);
    else if (temp != 10) 
      lcd.write(temp);
  }
}
#6  

Thanks for your response! It's close to midnight in Amsterdam. I will give this a try tomorrow morning. Why is UART1 and UAERT2 working correctly with my code? The corrupted data is only with UART0

PRO
Synthiam
#7   — Edited

That's unusual if that's the case - i would imagine the wire in the UART0 connector is loose. The UART's are hardware on the EZ-B and using high precision timing.

Also, while writing that little bit of code for you, i ended up writing an arduino sketch that pretends to be an EZ-B v4 so ARC can connect to it via USB. The only thing it doesn't do audio or video or hardware UART

Get some rest and try again tomorrow:)

#8   — Edited

I replaced the wire (again), used your code but the problem is still there. problem is not that I'm missing characters but UART0 corrupts the characters.

I managed to get a small oscilloscope (BitScope Micro) to work and measured the signals. UART1 and UART2 signal are 3V, UART0 signal is less than 2V