I'm new to Arduino..
I'm currently trying to create a GPRS connection through SIM card. For that, I need to connect a serial UART port.
I don't know how to define the Serial UART. Could you please help me with that?
Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It only takes a minute to sign up.
Sign up to join this communityI'm new to Arduino..
I'm currently trying to create a GPRS connection through SIM card. For that, I need to connect a serial UART port.
I don't know how to define the Serial UART. Could you please help me with that?
In the setup function you will need to call the Serial.begin()
function.
To receive a serial character you should call the Serial.available()
function inside an if statement.
To send a character you can either use the Serial.write()
or Serial.print()
functions.
Below is a simple example program that will echo the characters back to the PC.
//-------------------------
// Simple serial loopback
//-------------------------
void setup()
{
// initialize the serial communication:
Serial.begin(9600);
}
void loop()
{
byte inChar;
// check if data has been sent from the computer:
if (Serial.available())
{
// read the most recent byte
inChar = Serial.read();
// send back the charater
Serial.write(inChar);
}
}
There are plenty of "built-in" examples in the Arduino IDE that use the various serial functions. These can be viewed without any hardware attached. In the IDE go to File
> Examples
and from there a lot of the examples for the serial UART are in the Communications
section. Details of these examples can be found on the Arduino Tutorial site.
The Arduino has only one UART which is used for program upload and for the serial terminal output to your computer. While you can connect it to another serial device that will make debugging cumbersome as 1) you won't be able to send any debug output; and 2) you will need to change it back and forth between your computer and the GPRS as you re-build and upload your code. You pretty much need a second UART to do this any kind of conveniently.
Look up the library module called SoftwareSerial which can simulate a UART on a second pair of pins, with some limitations: It is limited to communicating at 9600 baud; it can not transmit and receive at the same time; at most, one SoftwareSerial port can be receiving (or even listening) at any one time; and it can interfere with some other internal hardware, notably the interrupt system and at least one of the timers. (The link points to the Arduino website whose documentation isn't always the very latest, but what's there will give you the idea).
In many cases, and yours is likely one of them, these are not show-stoppers, just something to be aware of as your code becomes more complex. As long as you can operate your device by occasionally sending it a string and receiving another in reply, and your system doesn't include other high-speed devices that must be serviced quickly when they request it, you probably won't notice the limitations.