0

I'm translating a program about an RFM Hopper Transmission from Arduino to C, but I'm stuck with the method Serial, since I don't exactly know what it does.

It only appears in the following line, inside the main of the program.

Serial.begin(115200);

I've searched online through the documentation of Arduino and only understand that it's used for comunication between the Arduino board and the other devices.

If cannot use it in my C program though, what am I missing?

https://www.arduino.cc/reference/en/language/functions/communication/serial/

If I can explain anything with more detail from my project please feel free to ask.

BarberaThor
  • 19
  • 1
  • 4
  • 1
    The link you give includes a list of serial functions and each of them links to its own page, with examples. Arduino also publishes a [Software Serial Example](https://www.arduino.cc/en/tutorial/SoftwareSerialExample) in their tutorials, and there is plenty of other tutorial material to be found. Note that Arduino's language is not C, it is more like C++. – Weather Vane Feb 06 '20 at 16:33
  • Thanks, I will surely research more into that link, although my main question is still up and it relates with your last note, since my program is in C and i can't find any similar method to replace it with. All I see is written in Arduino or C++. – BarberaThor Feb 06 '20 at 16:42
  • Possible duplicate of [How to open, read, and write from serial port in C?](https://stackoverflow.com/questions/6947413/how-to-open-read-and-write-from-serial-port-in-c) Although it is focussed on Linux. – Weather Vane Feb 06 '20 at 16:46
  • 1
    [Here](https://www.arduino.cc/reference/en/language/functions/communication/serial/begin/) is the documentation for `Serial.begin` (not just `Serial`). – user253751 Feb 06 '20 at 17:11

1 Answers1

1

Serial is an object, predefined in the Arduino environment, which is in C++ (not C )

To use it, you should call Serial.begin(<baud>); in the setup() function of the Arduino environment, then you can use any method of Serial or the underlying base class Stream

datafiddler
  • 1,755
  • 3
  • 17
  • 30
  • I see, but would you know how to translate it or use it in a C program? I just can't find any related or similar method? – BarberaThor Feb 06 '20 at 16:49
  • @BarberaThor Well, what do you want the C program to do? Do you want it to send messages out the serial port? (does your computer *have* a serial port?) – user253751 Feb 06 '20 at 17:11
  • @user253751 My program is for a PIC (microcontroller), and I want it to send data to an Arduino device. The computer will only be used to check that the data is being received properly. – BarberaThor Feb 06 '20 at 17:28
  • 2
    So you have an arduino sketch that you want to modify/port or rewrite to run on a PIC? So what you really need to do is understand what the sketch does and then implement that behavior/configuration on a PIC. Serial.begin(115200); will set up a UART for 115200baud, 8 data bits, 1 stop bit, and no parity. So set up a UART on the PIC in that configuration. You’ll also need to implement all the other things they did with the serial port, such as sending and receiving data. – GC78 Feb 07 '20 at 23:32