MATLAB Answers

Serial port for Raspberry Pi embedded

2 views (last 30 days)
Marco
Marco on 21 Jul 2014
Edited: Walter Roberson on 25 Jul 2015
Hello everybody,
I'm trying to access a serial port of Raspberry Pi. My aim is to have an embedded code, so I'm using simulink, with a Matlab function and a small c-code.
It's all pretty basic right now, since I get an error just with these few lines which should initialize and open the serial port.
The Matlab Function is:
function fcn(var)
%#codegen
persistent initflag;
if strcmp(coder.target, 'rtw'),
if isempty(initflag),
%initialiaze
coder.ceval('serialpi_init',var)
initflag = 1;
end
end
The c-code is:
#include </home/pi/wiringPi/wiringPi/wiringPi.h>
#include </home/pi/wiringPi/wiringPi/wiringSerial.h>
void serialpi_init (double var){
int fd;
fd = serialOpen ("/dev/ttyACM0", 9600) ;
}
void serialpi_output(double var){
}
The error that I get is when simulink try to download the model:
The call to realtime_make_rtw_hook, during the after_make hook generated the following error:
Error executing SSH command: make: Entering directory `/home/pi/prova_seriale_rasp_rtt'
"gcc" -I"./" -O3 -D"MODEL=prova_seriale_rasp" -D"NUMST=1" -D"NCSTATES=0" -D"HAVESTDIO=" -D"ONESTEPFCN=0" -D"TERMFCN=1" -D"MAT_FILE=0" -D"MULTI_INSTANCE_CODE=0" -D"INTEGER_CODE=0" -D"MT=0" -D"CLASSIC_INTERFACE=0" -D"TID01EQ=0" -D"_USE_TARGET_UDP_=" -D"_RUNONTARGETHARDWARE_BUILD_=" -c ./linuxUDP.c ./codice_c_raspberry.c ./ert_main.c ./prova_seriale_rasp.c ./prova_seriale_rasp_data.c
"gcc" ./linuxUDP.o ./codice_c_raspberry.o ./ert_main.o ./prova_seriale_rasp.o ./prova_seriale_rasp_data.o -lm -ldl -lpthread -lrt -o ./MW/prova_seriale_rasp
./codice_c_raspberry.o: In function `serialpi_init':
codice_c_raspberry.c:(.text+0x8): *undefined reference to `serialOpen'*
collect2: ld returned 1 exit status
make: *** [MW/prova_seriale_rasp] Error 1
make: Leaving directory `/home/pi/prova_seriale_rasp_rtt'
Some ideas?
Many thanks,
Marco

  0 Comments

Sign in to comment.

Answers (2)

Murat Belge
Murat Belge on 8 Sep 2014
You did not specify the source code for serialOpen() in your System Object. Change your C-code to the following:
#include </home/pi/wiringPi/wiringPi/wiringPi.h>
#include </home/pi/wiringPi/wiringPi/wiringSerial.h>
#include </home/pi/wiringPi/wiringPi/wiringPi.c>
#include </home/pi/wiringPi/wiringPi/wiringSerial.c>
void serialpi_init (double var){
int fd;
fd = serialOpen ("/dev/ttyACM0", 9600) ;
}
void serialpi_output(double var){
}
Note the inclusion of two C-files specifying the source for wiringPi.c and wiringSerial.c.

  0 Comments

Sign in to comment.


walid AL-ATABANY
walid AL-ATABANY on 24 Jul 2015
Dear Marcu,
Do you know how can I access the bluetooth instead of the serial port in raspberry pi. also where should I put this c-code? is it in the same matlab function?
Regards

  0 Comments

Sign in to comment.

Sign in to answer this question.