Wifi communication via Simulink

I tried to start a Wifi communication with my Yun and Simulink but it doesnt work :smiley:

I connected the Yun with my local Wifi network and in the simulink hardware parameters for wifi shield properties the tick use static IP adress and disable DHCP is set??
Then I used a counter limited block and the Arduino Wifi TCP/IP Send block in my simulink model and programmed the arduino.

In another simulink model I used the TCP/IP Receive block and a scope, the remote adress is the IP adress of the Yun and the Port is 80 (also in the Yun Wifi Send block).
After clicking on run this is the error message:

An error occurred while running the simulation and the simulation was terminated
Caused by:
Error evaluating registered method ‘Outputs’ of MATLAB S-Function ‘stcpiprb’ in ‘untitled1/TCP//IP Receive’.
The specified amount of data was not returned within the Timeout period.
Please ensure that data is being sent to the specified port or specify a greater timeout value.

The WLAN LED is constant off, I guess somehting with the Program on the Yun is wrong

Nobody had a similar problem? Is it prossible to send data with simulink and the Yun at all? Because its not using the wifi shield and the Linux bridge instead.

It's hard to understand exactly what you are describing. Try rephrasing the question, and assume we have no idea what you are talking about, which is probably the case. For example, what is Simulink?

Ard_Yun: in the simulink hardware parameters for wifi shield properties

Are you using a Yun, or a WiFi Shield? They are not even close to being the same. Any code that is designed for the WiFi Shield will not work on the Yun, as the Yun uses a completely different way to manage the network. If the sample sketch you are using includes WiFi.h or Ethernet.h up at the top, it will not work with the Yun.

Please post your the sketch you are running on the Yun. Without it, we are all simply guessing.

The WLAN LED is constant off, I guess somehting with the Program on the Yun is wrong

The LEDs do not signal the functions implied by their labels. The normal state is for the green "ON" LED to be on, and the white USB LED to come on once Linux has finished booting up. The WAN and WLAN lights are usually off. This is normal and does not necessarily indicate a programming problem with the Yun.

Simulink is a Matlab toolbox, where you can install a Arduino hardware support package to program your arduino with it. http://de.mathworks.com/help/supportpkg/arduino/examples.html#d0e34 The Yun is supported by the hardware package but only things like toggle a output are working. Not even the serial Interface work, I guess that simulink is only working with Arduinos without a Linux cpu??

Worked it for anyone to get a interface running with simulink and the yun?

Ard_Yun: The Yun is supported by the hardware package

Really? Looking at the page link you provided, there are seven tutorials, and two application examples. Looking at the supported hardware for each of those 9 projects, the Yun is not listed as supported hardware for any of them.

There is a project which uses the Ethernet Shield and another that uses the WiFi Shield, but code will in no way be compatible with the Yun. The Yun handles the networking completely differently than standard Arduinos using those shields.

There are several projects which are supported by the Leonardo, using the USB interface. Those projects should work properly with the Yun, using the USB interface. But any project that uses pins 0 and 1 as a serial interface will not work, as those pins are dedicated for talking to the Linux system.

If you want to talk to the Yun over the network (wired Ethernet or WiFi) I'm sure you can get it to work. But it won't be by using one of the defined examples. You will have to analyze the WiFi Shield or Ethernet Shield examples, figure out what they are actually doing, and then translate that into the Yun's way of doing things. I'm confident it can work, but it won't be a trivial exercise.

I attache a picture with the Arduinos I can choose in Simulink, I don’t know why the Yun is in the list if it doesn’t work.

Is it possible to embed c or c++ Code generated from Matlab in a normal Arduino Project file? How can I do that?
It seems that I have to use the Bride library there and combine it with my matlab/simulink code.

OK, so you’ve selected the Yun in that dialog. So what sketch is being loaded in the Yun?

The scetch, including the block parameters, is attached.
I tried the IP of the Yun and the IP of the host pc as remote adress but both didn’t work.

Ard_Yun: The scetch, including the block parameters, is attached.

No, that is just a screen shot of the Simulink settings. This is how Simulink will try to talk to the Arduino.

When I say sketch, I mean the Arduino code that is actually loaded/programmed onto the Yun. That is the code that will be listening for the connections from Simulink. That code will typically have a ".ino" file extension.

It's this code that is running on the Yun that is the question. Unless it is specifically coded to work on the Yun, it's highly unlikely that it will work. A sketch intended for use with a WiFi shield and an Uno or Leonardo or any other Arduino will simply not work with a Yun. If the sketch starts by including "WiFi.h" or "Ethernet.h" then it won't work with the Yun.

Simulink may have a menu option somewhere that says "Yun" but unless you have the correct corresponding sketch loaded into the Yun, it's not going to work.

There is no sketch programmed with “Arduino”, it should work just with the Simulink Model.

I attached another Simulink Model, which works fine on the Yun, a click on “Deploy to Hardware” compiles the Simulink Model and program the Yun.

Is it possible to import c++ files to Arduino?

It sounds like Simulink is downloading the sketch directly to the Yun? I suppose it's possible, but I would be very surprised by this.

Or perhaps you are misunderstanding how the system works, and you really do need to manually load a sketch into the Yun? Perhaps the sketch that is in there currently only handles digital output signals - that's why that feature works but others don't?

However it happens, code specific to Sinulink and the operation you want to do MUST be loaded into the Yun. The Yun does not natively have the ability to work with Simulink or any other such program. Are you sure you understand how to configure the Yun for use by Simulink? I'm guessing you're missing a very basic step here.

Try an experiment: launch the Arduino IDE and load the "BareMinimum" example (on the basic examples sub-menu.) Now, using Simulink, try the currently working digital output model again: does it still work properly? If so, Simulink does appear to be loading code into the Yun. If not, we've found the problem and you need to load a Simulink compatible sketch into the Yun.

OK, I've done some poking around on the Simulink web site. It appears that it does indeed automatically download a sketch into the Arduino.

It also appears that the digital output example that works for you is the first example "Getting Started with Arduino Hardware." You posted the block diagram for this model - if you read the last sentence of the portion of the image you excluded, it states "This model runs as a standalone application, independently of Simulink." So there is no communications between Simulink and this model. That is apparently why it works.

The other models require communications between Simulink and the model, and you are trying to do this communications over the network. None of the examples on the page you linked specifically mention compatibility with the Yun. Simulink has a hardware selection field that includes the Yun, but I suppose that is only configuring how it talks over the USB port and how it communicates with the Yun's bootloader.

Digging deeper, the "Modeling" page has links for the common modeling blocks. It also has links for Ethernet Sheild and WiFi Shield blocks. I don't see anywhere that it mentions Yun networking blocks. Remember: the Yun is NOT the same think as a regular Arduino with a WiFi Shield - the networking is completely different.

At this point, my best guess is that while Simulink does support the Yun hardware, it only goes so far as supporting the common model blocks, and does not support the networking abilities. You can probably get any of the stand-alone models to work (like you can with the basic digital output example) and you can probably get models to work that communicate over USB. But it doesn't look like Simulink supports the Yun's networking abilities, so anything that tries to communicate over the network (wired or WiFi) is probably not going to work.

This doesn't sound like a Yun issue, it sounds more like a Simulink limitation. Given the lack of response to this thread by others, I don't think you will find a lot of Yun users here that also use Simulink (probably because the Yun networking is not supported?) You will probably have better luck pursuing this task with the Simulink folks.

To get this to work with Simulink will probably take some custom programming on the Yun, but if Simulink does all of the coding behind the scenes, that may be impossible (or at least very difficult.) It sounds like Simulink was designed to use an Uno (or more likely it prefers a Mega2560) with a WiFi Shield. If you want plug and play operation, you are probably best sticking with the hardware that is specifically supported by the examples.

Thanks for your answer, I will try to build the main part of my application (a Neural Net for pattern recognition) in Simulink and generate c++ code from my Model and realize the communication in the Arduino IDE.