Can not connect raspberry pi 4 to matlab

I have a raspberry pi 4 model B 1GB RAM that I am trying to connect to matlab R2020a for processor in the loop simulation.
I downloaded the matlab support package for raspberry pi and followed the instructions multiple times carefully, but every time it fails to discover raspberry pi hardware and doesn't give any error messages except "could not detect raspberry pi hardware in allotted time". Even the "test connection" button fails.
I tried different network connections and different power supply and different SD card and redownloaded the raspbian image to make sure it is not corrupted, but always failed.
note: I was using raspbian image R20.1.0 as suggested by the support package instructions.
Any help would be appreciated.

4 Comments

Hello Mustafa,
I hope your SD card size is >= 4GB.
Sometimes, when the raspberry pi boots up for the first time with a new image, it may take a little longer than expected.
After you get that error message "could not detect raspberry pi hardware in alloted time", you can try any of the following steps to ensure the image is correctly flashed.
1) If you have a HDMI cable(4b needs micro hdmi cable), connect the pi to a monitor to see the boot live status. If it booted fine, then just get the ip addr and continue using MATLAB with the pi. (If you see any spurious messages on the monitor when it is booting up, please comment them here.)
2) If you do not have HDMI cable, just restart the pi after waiting for atleat 4-5 mins. MathWorks customized Rasbian image speaks out the IP address when it boots up.
Please try this and let me know how this goes.
Thanks,
Prasanth
Hello Prasanth
I tried some troubleshooting the past couple of day, but still wasn't able to successfully connect the RPI to Matlab.
I don't have a separate monitor to test if the RPI boots, so I when to a friend who has one and made 2 attempts:
In the first attempt I wrote a raspbian image using Raspbian Imager on an SD card and successfully booted the RPI and opened desktop and even opened a web page through internet access through ethernet to make sure the RPI it self is intact.
In my second attempt I wrote the raspbian image through the Matlab/RPi hardware setup wizard and also successfully booted into desktop, but still wasn't able to establish a communication between Matlab and RPI.
I tried again at home. So far I have tried different ethernet cables, different SD cards, different SD card readers, different power supplies, different raspbian image downloads, and waited more than 5 minutes to make sure RPI booted. But still get the same "could not detect raspberry pi hardware in allotted time", and also test connection botton doesn't work. Attached is an image of the output.
I ignored that, carried on, and finished the setup process, and tried to make a connection to RPI using "mypi = raspi" the Matlab command line, but got this error:
Error using matlabshared.internal.ssh2client
Error connecting to SSH server at 169.254.0.2
Error in codertarget.raspi.raspberrypi (line 183)
obj.Ssh = matlabshared.internal.ssh2client(hostname, ...
Error in raspberrypi (line 1)
classdef raspberrypi < codertarget.raspi.raspberrypi
Attached is a screenshot of the errors that came out.
ANY HELP??
Thank you for replying soon with the debugging information.
Here are my suggestions.
1) Good to know that the raspberry pi booted normally with MathWorks image when you connected a monitor. How is raspberry pi connected to the network at your home? Is the pi connected to your home wifi? Or did you do you use a USB to ethernet cable and connected the pi to your pc? Also I am curious to see what "Network setting" you have choosen in the setup wizard.
2) I see you are calling raspi obj as below:
r= raspi(raspberrypi-sfsdfsd,pi,raspberry); % this is incorrect way
% those values must be of character array type. Try the below instead.
r=raspi('your raspberrypi host name','pi','raspberry'); % correct way
Also, ensure that you pi is in the same network as your PC.
Check out the link below as well.
Thanks,
Prasanth
Hello Prasanth
Sorry for the delayed reply. I setup a new PC with fresh install of Windows 10, Matlab/Simulink, MinGW, .NET Framework, and a monitor to always check that RPI boots and be able to interacte with it.
I was able to successfully connect RPI to Simulink when connecting to a wireless network or manually entering network settings (Fig 1).
1) However, I always fail to connect when choosing to connect directly to host computer (Fig 2). RPI doesn't speak ip adress in this mode, and wasn't able to determine its ip adress by typing "ifconfig" in linux terminal (Fig 3). if I just carry on and finish the setup process and try to deploy a simple example It fails connecting to SSH server (Fig 4-5). And if I create a RPI object and openSHELL() and enable it, I get a different error (Fig 6). Am I missing something?
2) I could settle for connecting by manually entering network settings as I would still be using an ethernet cable as I prefere. However, if I close Matlab and shut off RPI and come back again, I might sometimes be successful in deploying the model and somtimes not (Fig 7). Is there a proper way to reestablish the connection between Matlab or Simulink and RPI?
Thank you very much for the help, I really appreciate it.

Sign in to comment.

Answers (6)

Hello Mustafa
I have the same question with you,and I don't know how to solve it.Any help would be appreciated.Thank you.

2 Comments

I wasn't able to fully resolve my problem. Still some types of connections work such as through home network or by entering network settings manually, while other connections such as directly to host computer don't work. What I did was used a different host computer with fresh install of windows, drivers, updates, MATLAB. Try at least to make sure your windows, drivers, and MATLAB are upto date, and reinstall the support package. Try connecting through a home network if you would like to use wifi connectivity and make sure the router doesn't have too many other devices connected to it. Also you could try to enter network settings manually if you would like to connect the RPI directly via ethernet, just set the host name you desire and let it assign IP adress automatically, that worked for me. Last but not least make sure your RPI is compatible with your MATLAB version. I hope that is of help, and best of luck.
I 'm sorry to reply to you in a few days.I've tried every one of these four methods in the past few days,but each failed in the end. At the end of each attempt,the hara ware could not be connected. My friend and I made the same attempt. My friend succeeded, but I failed. Maybe I should change a new computer. Thank you very muchufor your help. Ifi can solve this problem, I wil discuss my solution with you.Thank you again for your help.

Sign in to comment.

Chew Wen Da
Chew Wen Da on 31 May 2021
Edited: Chew Wen Da on 31 May 2021
I was having the same issue too while using version R2020a. After updating the version to R2021a, I can finally reach my RPI. By the way, the firmware also updated to version (mathworks_raspbian_DL_R21.1.0), previously in R2020a is (mathworks_raspbian_DL_R20.1.0). These are from the download link given in the support window.This post helped me a lot, thanks!
Unfortunately after the IP is detected, my laptop just cannot establish the connection to the board and keep showing either these 2 lines of error. Furthermore, its taking 3 to 4 mins to show too. Please help!
Thanks in advance.

1 Comment

Hi, to update on this matter, the problem has been resolved! I tried to use MATLAB online to connect to my RPI and I follow through the process step by step including reinstallation of the firmware (you can follow the link below). In the end I get to connect and realized that my RPI model is not the same as written on my RPI 4B board, it was a RPI 2B instead. After this, I tried to make connection again with MATLAB R2021a and it works fine!
After all, I think the issue can be resolve by installing the MATLAB firmware from the terminal. You can access to your RPI interface using VNC Viewer. Just input the IP address, ID and password.
Connect to Raspberry Pi Hardware Board in MATLAB Online
https://www.mathworks.com/help/supportpkg/raspberrypiio/ug/connect-to-raspberry-pi-hardware-board-in-matlab-online.html

Sign in to comment.

Hi, I had the same issue. I was able to resolve it by using the raspberry pi imager to write the original Raspbian OS to the SD card and using the advanced setting to enable headless setup and configure the network settings. Then using the hardware setup on MATLAB I was able to select "Customize the existing Raspbian OS on my hardware" and the Test connection was sucessful. Just ensure that you know the IP adress of both your Raspberry Pi and Network.
Hope this helps.
位默
位默 on 11 Feb 2023
Hi dear, I need you to help me, I have encountered the same problem as your right, I can't find the package for Raspberry Pi 4 Model B in MATLAB,I used a Raspberry Pi 3 Model B+ but it fails:
Could not detect the Raspberry Pi hardware in allotted time. Try using "Test Connection" button.
Any help would be appreciated.
Hi dear, I need you to help me, I have encountered the same problem as your right, I can't find the package for Raspberry Pi 4 Model B in MATLAB,I used a Raspberry Pi 3 Model B+ but it fails:
Could not detect the Raspberry Pi hardware in allotted time. Try using "Test Connection" button.
Any help would be appreciated.
Hi dear, I need you to help me, I have encountered the same problem as your right, I can't find the package for Raspberry Pi 4 Model B in MATLAB,I used a Raspberry Pi 3 Model B+ but it fails:
Could not detect the Raspberry Pi hardware in allotted time. Try using "Test Connection" button.
Any help would be appreciated.

Categories

Find more on MATLAB Support Package for Raspberry Pi Hardware in Help Center and File Exchange

Products

Release

R2020a

Asked:

N/A
on 6 May 2020

Answered:

on 11 Feb 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!