Author Topic: A UART port for the Arduino  (Read 21531 times)

0 Members and 1 Guest are viewing this topic.

Offline Hawaii00000Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 347
  • Helpful? 2
A UART port for the Arduino
« on: December 17, 2008, 01:27:19 AM »
Hey guys, I'm a little confused about the concept of UART ports and I'm hoping you guys can help. I recently got myself an Arduino so I can get started with robotics on a kind of basic level. I bought the Arduino with the knowledge that it lacked the extra UART port needed for computer vision, but since then I've been thinking a little. I was wondering if I could use the UART port that is usually used for the usb for a camera once i was done programing. I did see this kind of mention in another forum, but I'm still kind confused. The other thing is, you can buy an ethernet shield for the Arduino. Isn't ethernet a kind of UART? could something like the ethernet shield be used to give the Arduino the extra port needed for robot vision?
"God chose to make the world according to very beautiful mathematics."
-Paul Dirac
**************************************************************
Its Hawaii Five-O. Get it?

Offline HyperNerd

  • Robot Overlord
  • ****
  • Posts: 139
  • Helpful? 5
  • N3rd1n80r
Re: A UART port for the Arduino
« Reply #1 on: December 17, 2008, 11:48:39 AM »
Hi Hawaii,
I bought an Arduino recently too, and I was pretty much thinking the same thing.

Quote
I'm a little confused about the concept of UART ports

Go check out Admin's awesome tutorial about UART -> http://www.societyofrobots.com/microcontroller_uart.shtml

Just wondering, you said
Quote
I recently got myself an Arduino so I can get started with robotics on a kind of basic level.

If you are just starting with robotics, start small - a stupid little bot that just barely works. I've been doing robotics for a few years now, and I'm not bad at it, but I don't even want to attempt computer vision yet!

Anyway, I'm rambling. So, if you want to do computer vision, what you are saying is technically possible - you could connect the camera's TTL serial port to digital pins 0 and 1 on the Arduino, Rx and Tx respectively. In the code you would just tell the Arduino to send / receive data on the UART as you would normally do, it would think it was sending / receiving data from the computer, but it would be communicating with the camera. As for the code to interpret the data from the camera, I'm afraid I can't help you there without knowing what camera you are using.

The code for serial comms with the Arduino is as follows:
To send:
Code: [Select]
// Sends "A"s through the serial port every second

// 'Setup' function
void setup()
{
  // Start the UART at 9600 bits-per-second (baud)
  Serial.begin(9600);
}

// Main loop
void loop()
{
  // Print an A through the UART
  Serial.println("A");

  // Pause 1 second
  delay(1000);
}

And to receive:
Code: [Select]
// Receives data from the serial port

// Create a variable called 'val'
int val = 0;

// 'Setup' function
void setup()
{
  // Start the UART at 9600 baud
  Serial.begin(9600);
}

// Main loop
void loop()
{
  // If there is data ready...
  if (Serial.available())
  {
    // ...Set the value of our variable to whatever the data is
    val = Serial.read();

    // Print the data back through the UART
    Serial.println(val);
  }
}

You can test these by downloading them to the arduino, then:
1. Reset the Arduino
2. Open the Serial Monitor within the Arduino environment (far right button at the top)
3. Select 9600 Baud from the drop-down menu on the left
4A. If you have the "sending" program downloaded, 'A's should start appearing on the screen, 1 every second
4B. If you have the "receiving" program downloaded, when you write something in the textbox on the right and click 'send', whatever you typed should appear on the screen. The arduino has sent you back the information that you sent it.

Hope this helps!

- HyperNerd
There are 10 types of people in the world - those who understand binary, and those who don't.

Offline Hawaii00000Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 347
  • Helpful? 2
Re: A UART port for the Arduino
« Reply #2 on: December 20, 2008, 01:16:52 AM »
Thanks for the help! Too bad someone hasn't just created a library for it. :(
"God chose to make the world according to very beautiful mathematics."
-Paul Dirac
**************************************************************
Its Hawaii Five-O. Get it?

Offline Ro-Bot-X

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,431
  • Helpful? 25
  • Store: RoBotXDesigns.ca
Re: A UART port for the Arduino
« Reply #3 on: December 20, 2008, 03:22:42 PM »
Thanks for the help! Too bad someone hasn't just created a library for it. :(


For the hardware UART the commands are listed in the Language Reference:
http://arduino.cc/en/Reference/HomePage

There is also a Software Serial library, just in case you need to talk with several devices serially. It has some limitations, but it works.
http://arduino.cc/en/Reference/SoftwareSerial

Check out the uBotino robot controller!

Offline Hawaii00000Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 347
  • Helpful? 2
Re: A UART port for the Arduino
« Reply #4 on: December 20, 2008, 09:48:51 PM »
So if I use that code I can add a image processing camera?
"God chose to make the world according to very beautiful mathematics."
-Paul Dirac
**************************************************************
Its Hawaii Five-O. Get it?

Offline Ro-Bot-X

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,431
  • Helpful? 25
  • Store: RoBotXDesigns.ca
Re: A UART port for the Arduino
« Reply #5 on: December 20, 2008, 10:22:25 PM »
Arduino has the Rx and Tx pins on the side of the board (Digital pins 1 and 0). So, you can connect the CMUcam to those pins (also to the 5V and Ground) and use the hardware UART to communicate with it. But you may also have a serial LCD to display status data, so you can use any microcontroller pin to connect to the Rx of the serial LCD and use the software serial library to send data to it. Or, you may have a serial motor controller, same thing, use the software serial library for it. But make sure you use the hardware UART for the camera! Why? Because the camera is INPUT for the robot and the others are OUTPUT, you need to listen carefully for serial so you don't loose precious info, but for serial out it doesn't matter, you send it when you need it, the other modules need to be carefully listening...
Check out the uBotino robot controller!

Offline Hawaii00000Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 347
  • Helpful? 2
Re: A UART port for the Arduino
« Reply #6 on: December 21, 2008, 01:45:30 AM »
Quote
But make sure you use the hardware UART for the camera!

What do you mean when you say the hardware UART? Digital pins 1 and 0?
"God chose to make the world according to very beautiful mathematics."
-Paul Dirac
**************************************************************
Its Hawaii Five-O. Get it?

Offline SomeoneKnows

  • Beginner
  • *
  • Posts: 2
  • Helpful? 0
Re: A UART port for the Arduino
« Reply #7 on: January 04, 2009, 02:03:01 PM »
I bought the Arduino with the knowledge that it lacked the extra UART port needed for computer vision


It is true that the Arduino's only support one serial connection.

HOWEVER, there is an Arduino clone called the Sanguino http://sanguino.cc/ that supports two serial connections simultaneously. A friend bought one and it comes as a kit and is easy to build. http://sanguino.cc/buy

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,666
  • Helpful? 169
    • Society of Robots
Re: A UART port for the Arduino
« Reply #8 on: January 10, 2009, 09:54:07 PM »
Quote
I was wondering if I could use the UART port that is usually used for the usb for a camera once i was done programing.
Yeap you can, as long as only one device is plugged in at a time. If not, you get a signal conflict that can fry stuff (a bad thing).

Look into a software UART as Ro-Bot-X suggested.

 


Get Your Ad Here

data_list