You may be able to build your Arduino code to run on a Raspberry Pi at https://create.arduino.cc/ but there are no guarantees.
To read a serial device and do something with your data on a Raspberry Pi you're going to get more success with a simple python program
import serial, string, time, sys
output = " "
ser = serial.Serial('/dev/...
That is very much the premise of Ultibo.
What is Ultibo?
Imagine if you could have the simplicity and freedom of Arduino with
the power and features of a Raspberry Pi. With the ease of a
microcontroller and the flexibility of a real computer, Ultibo gives
you a platform for creating anything without the limitations of a
traditional operating ...