Author Topic: Arduino's "hidden" UART port??  (Read 9327 times)

0 Members and 1 Guest are viewing this topic.

Offline Hawaii00000Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 347
  • Helpful? 2
Arduino's "hidden" UART port??
« on: December 23, 2008, 09:06:47 PM »
In a recent post I was told I can connect a CMUcam to the arduino via the hardware UART port. The only hardware UART port on the Arduino that I'm aware of is the USB, but the post seemed to indicate that I can use  digital ports 0 and 1 as a hardware UART.Is this right?
"God chose to make the world according to very beautiful mathematics."
-Paul Dirac
**************************************************************
Its Hawaii Five-O. Get it?

Offline airman00

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,650
  • Helpful? 21
  • narobo.com
    • Narobo.com - Mechatronics and related
Re: Arduino's "hidden" UART port??
« Reply #1 on: December 23, 2008, 09:10:03 PM »
yes
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline Hawaii00000Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 347
  • Helpful? 2
Re: Arduino's "hidden" UART port??
« Reply #2 on: December 24, 2008, 02:58:05 PM »
Awesome. Thanks Airman!
"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: Arduino's "hidden" UART port??
« Reply #3 on: January 12, 2009, 01:14:10 PM »
Note that these are in fact the same port, so make sure only one device is connected at a time, or, quoting Admin,
Quote
Stuff will fry and kittens will cry

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

Offline pomprocker

  • Supreme Robot
  • *****
  • Posts: 1,431
  • Helpful? 16
  • Sorry miss, I was giving myself an oil-job.
    • Nerdcore - Programming, Electronics, Mechanics
Re: Arduino's "hidden" UART port??
« Reply #4 on: January 12, 2009, 01:39:41 PM »
Arduino also has a library to make a software serial port

Offline Ro-Bot-X

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,431
  • Helpful? 25
  • Store: RoBotXDesigns.ca
    • Ro-Bot-X Designs
Re: Arduino's "hidden" UART port??
« Reply #5 on: January 12, 2009, 09:20:35 PM »
I am using the 3 pin TTL serial connector (hardware UART, digital pins 0 and 1, set at 115200 baud) to talk to my AVRcam. Because I also need to see values and other variables, I have attached a serial LCD to the digital pin 2 (set as Tx) and I am using the SoftwareSerial library to create a second serial port (set at 9600 baud). It works flawlessly.

Of course, when I program the Roboduino I have to unplug the AVRcam or the upload gets errors, but nothing fries.
« Last Edit: January 12, 2009, 09:21:34 PM by Ro-Bot-X »
Check out the uBotino robot controller!

Offline Hawaii00000Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 347
  • Helpful? 2
Re: Arduino's "hidden" UART port??
« Reply #6 on: January 12, 2009, 11:50:28 PM »
Sounds great Ro-Bot-X. Have you ever thought of making a tutorial for beginners like me...
"God chose to make the world according to very beautiful mathematics."
-Paul Dirac
**************************************************************
Its Hawaii Five-O. Get it?

Offline Hawaii00000Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 347
  • Helpful? 2
Re: Arduino's "hidden" UART port??
« Reply #7 on: January 13, 2009, 01:32:13 AM »
OR maybe you could post your code???
"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
    • Ro-Bot-X Designs
Re: Arduino's "hidden" UART port??
« Reply #8 on: January 13, 2009, 07:01:07 AM »
Sure. Here it is. It'is still a work in progress, but you can get an idea how to use it. Also you need to take a look at the AVRcam library attached, create a folder AVRcam and save the file in Arduino-0011\hardware\libraries. Also remember the LCD commands are specific to my LCD. A comercial available LCD might have different commands.

Quote
/* Mini Eric robot - using Roboduino
   - uses 2 modified servos for driving
   - uses 2 servos for a pan/tilt head
   - uses one Ping))) ultrasonic sensor mounted on the head
   - uses AVRcam for blob detection
   - uses one GP2D12 sensor mounted on a pan servo
   - uses 4 servos for arms
   - uses 1 servo for waist bend
   - uses a software serial port to talk to a serial LCD
*/

//Includes
#include <SoftwareSerial.h>
#include <SoftwareServo.h>
#include <AVRcam.h>

//Sensors
#define SharpPin 0    // analog pin 0
#define PingPin 15    // digital pin 15 (analog 1)
#define ClawSensor 16 // digital pin 16 (analog 2)

//Servos
#define LmotorPin 9    // digital pin  9, PWM pin
#define RmotorPin 10   // digital pin 10, PWM pin
#define BendPin 11     // digital pin 11, PWM pin
#define LgripPin 12    // digital pin 12
#define PanPin 4       // digital pin 4
#define LrotatePin 5   // digital pin 5, PWM pin
#define RrotatePin 6   // digital pin 6, PWM pin
#define TiltPin 7      // digital pin 7
#define RgripPin 8     // digital pin 8

Servo Lmotor;
Servo Rmotor;
Servo Pan;
Servo Tilt;

//Media
#define Led 13      //digital pin 13                         
#define Speaker 17  //digital pin 17 (analog 3)

#define rxPin 3
#define txPin 2

SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);

//Variables
unsigned int PingTime = 0;
byte center = 90;
int dx=0, dy=0;
byte xMid = 144/2;
byte yMid = 88/2;
byte num = 0;

//----------------------------------------------------------------
void setup() {
  delay(1000);    //wait 1 second before start for debug purposes
  //AVRcam initialisation - initializes the hardware serial at 115200 bps
  camIni(1, 1, 1, Servo::refresh);
  //sensors
  pinMode(PingPin, OUTPUT);
  digitalWrite(PingPin, LOW);
  //head servos
  Pan.attach(PanPin);
  Tilt.attach(TiltPin);
  //software serial for LCD
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  mySerial.begin(9600);
  mySerial.print("AVRcam test");        // print in the first LCD line       
  mySerial.print(2, BYTE);              // print in the second LCD line
  mySerial.print(5, BYTE);              // start from the fifth position
  mySerial.print("robot");              // text to print

  delay(100);    //wait a little
  Clear_LCD();
 
  Pan.write(center);
  Tilt.write(center);
  Servo::refresh();
}



//================================================================
void loop(){
  Read_Camera();
  Pan_Tilt();
  Servo::refresh();
  delay(100);
  Read_Ping_Sensor();



int Read_Ping_Sensor() {
  //trigger the sensor
  pinMode(PingPin, OUTPUT);
  digitalWrite(PingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(PingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(PingPin, LOW);
  //receive the echo
  pinMode(PingPin, INPUT);
  digitalWrite(PingPin, HIGH);               // turn on pull up resistor
  PingTime = pulseIn(PingPin, HIGH);
  mySerial.print(1, BYTE);                   // print in the first LCD line
  mySerial.print(1, BYTE);                   // start from the first position
  mySerial.print("Ping: ");                  // text to print
  mySerial.print(PingTime, DEC);                // variable to print
  return PingTime;
}

void Read_Camera() {
  byte obj;
  obj = camRead();
  num = camObjNum();
  if (num >0) {
      Process_Objects();
  }
  switch (obj) {
    //case 0:
      // obj found
      //Process_Objects();
    case 1:
      // comunication error
      mySerial.print(2, BYTE);                   // print in the second LCD line
      mySerial.print(1, BYTE);                   // start from the first position
      mySerial.print("comm error      ");
    case 2:
      // obj not found
      mySerial.print(2, BYTE);                   // print in the second LCD line
      mySerial.print(1, BYTE);                   // start from the first position
      mySerial.print("no obj found    ");
  } 
}

int Process_Objects() {
  dx=0;
  dy=0;
  byte size = 0;
  byte i, s, ox, oy;
  for (byte j; j < num; j++) {
    s = camObjSize(j);
    if (s > size){
      size = s;
      i = j;
    } 
  }
  ox = camObjX(i); // range: 0-144
  oy = camObjY(i); // range: 0-88
  dx = ox - xMid;
  dy = oy - yMid;
  Clear_LCD();
  mySerial.print(2, BYTE);                // print in the second LCD line
  mySerial.print(1, BYTE);                // start from the first position
  mySerial.print("dX: ");                 // text to print
  mySerial.print(dx, DEC);                // variable to print
  mySerial.print("   dY: ");              // text to print
  mySerial.print(dy, DEC);                // variable to print
  return dx;
  return dy;
}

void Pan_Tilt() {
  int x = dx/8;
  int y = dy/6;
  Pan.write(center - x);
  Tilt.write(center + y);
}

void Clear_LCD() {
  mySerial.print(5, BYTE);          // select LCD command mode
  mySerial.print(1, BYTE);          // clear screen

Check out the uBotino robot controller!

Offline Hawaii00000Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 347
  • Helpful? 2
Re: Arduino's "hidden" UART port??
« Reply #9 on: January 14, 2009, 01:29:42 AM »
Awesome!! thanks Ro-Bot-X this should help a lot.
"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
    • Ro-Bot-X Designs
Re: Arduino's "hidden" UART port??
« Reply #10 on: February 12, 2009, 10:38:16 PM »
Also there is a setting for the serial speed that would make things work better for 115200 bps. I have modified (as per mbateman's instructions) the file wiring_serial.c to reflect that setting. Download the attached file and write it over the file with the same name found in Arduino-0011\hardware\cores\arduino\ .
Check out the uBotino robot controller!