UART Arduino Uno

Talk about Arduino board, sheilds. Sharing Arduino projects, program, problems, solutions, suggestions..... many more, all are welcome.

UART Arduino Uno

Postby phdatdt » Thu Nov 08, 2012 10:42 pm

I want to test the Arduino Uno UART. so I connect the Rx ( pin 0) to Tx (pin 1)
in order to test I want to send and ASCII string of "AT" to Tx. as Rx is connected to Tx. How can I get the string at Rx ? i meant I'm supposed to get the string of "AT" at Rx, any sample code that help me to send the string "AT" to Tx and receive it as a string in Rx ?

any guy can help me ? thanks
phdatdt
Freshie
 
Posts: 6
Joined: Thu Jul 05, 2012 5:13 pm

Re: UART Arduino Uno

Postby yonghui » Fri Nov 09, 2012 7:29 am

i think u can refer to arduino's site for the reference. http://arduino.cc/en/Reference/Serial

and if u wan sample i think arduino' IDE will has the example code for its serial implementation.
u can connect the board to computer and display the things on computer's hyperterminal
thanks&regards,
yh
yonghui
Moderator
 
Posts: 732
Joined: Mon Sep 28, 2009 3:27 pm

Re: UART Arduino Uno

Postby shahrul » Fri Nov 09, 2012 8:15 am

CODE: SELECT_ALL_CODE
int data;

void setup()
{
  Serial.begin(9600); //Sets the data rate in bits per second (baud) for serial data transmission.
  Serial1.begin(9600); //Sets the data rate in bits per second (baud) for serial data transmission.
  Serial.println("Enter"); //Prints data to the serial port as human-readable ASCII text followed by new line.
  Serial.println("1 - Manufacturer identification");
  Serial.println("2 - Model identification");
  Serial.println("3 - Software version");
  Serial.println("4 - IMEI number");
  Serial.println("5 - Calling");
  Serial.println("6 - Hang Up");
  Serial.println("7 - Send message");
  Serial.println("8 - Read message");
  Serial.println("9 - Delete message");
}

void loop()
{
  if(Serial.available()>0) //Get the number of bytes available for reading from the serial port.
  {
    data=Serial.read();
   
    if (data=='1')
    {
      Serial1.print("AT+CGMI\r"); //Manufacturer identification
    }
   
    if (data=='2')
    {
      Serial1.print("AT+CGMM\r"); //Model identification
    }
   
    if (data=='3')
    {
      Serial1.print("AT+CGMR\r"); //Software version
    }
   
    if (data=='4')
    {
      Serial1.print("AT+CGSN\r"); //IMEI number
    }
   
    if (data=='5')
    {
      Serial1.print("ATD+60136289844;\r"); //Calling
    }
   
    if (data=='6')
    {
      Serial1.print("ATH\r"); //Hang Up
    }
   
    if (data=='7')
    {
      Serial1.print("AT+CMGF=1\r"); //Set text mode
      delay(100);
      Serial1.print("AT+CMGS="); //Send message
      Serial1.write((byte)0x22); //"
      Serial1.print("+60136289844"); //Phone no
      Serial1.write((byte)0x22); //"
      Serial1.write((byte)0x0D); //Enter
      Serial1.print("Hai, I'm chipKIT");//Text message
      Serial1.write((byte)0x0D); //Enter
      Serial1.print("Reply, if you receive this message");//Text message
      Serial1.write((byte)0x1A); //Ctrl+Z
    }
   
    if (data=='8')
    {
      Serial1.print("AT+CMGR=1\r"); //Read message
    }
   
    if (data=='9')
    {
      Serial1.print("AT+CMGD=1,0\r"); //Delete message
    }
  }
 
  if(Serial1.available()>0) //Get the number of bytes available for reading from the serial port.
  {
    data=Serial1.read(); //Reads incoming serial data.
    Serial.write(data); //Writes binary data to the serial port.   
  }
}

Video http://shahrulnizam.com/chipkit-lesson-gsm-modem/
User avatar
shahrul
Professional
 
Posts: 812
Joined: Sat May 16, 2009 9:54 pm
Location: Selangor


Return to Arduino Based

Who is online

Users browsing this forum: No registered users and 74 guests