MATLAB Answers

Do Simulink "Deploy to Hardware" and "External" modes work with Arduino Uno clones?

조회 수: 285(최근 30일)
Multiplexer
Multiplexer 2017년 8월 8일
댓글: Thai Hoa 2021년 4월 11일
Hello,
There are two popular clones of original Arduino Uno:
- old clones that use CH340 chip for USB to Serial communication with PC and programming (requires 3rd party Serial to USB driver)
- new clones that use ATmega16u2 for USB to SErial communication with PC and programming (claims to use original Arduino drivers)
My question is, does anybody know, have anybody tried running Arduino Uno clones with Simulink External/Deploy mode? If yes did it work? Which board exactly were you using (new clone with ATmega16u2 or old with CH340)?
I'm asking this question because I'm planning practical demonstration on how to program Arduino with Simulink and unfortunately I can't enforce that every single participant will have original Arduino and I'm trying to find out how severe problem it can be if one tries to use clone.
  댓글 수: 3
Erzen Sinameta
Erzen Sinameta 2020년 7월 26일
Hi,
I'm trying to do a simple project using an Arduio clone (Elegoo Uno R3) but there isn't the external mode option when i run the simulation, so i can't complete this project.
Could you help me solve this problem?
Thank you!

댓글을 달려면 로그인하십시오.

채택된 답변

Sudeshna Bhattacharya
Sudeshna Bhattacharya 2017년 11월 7일
편집: Sudeshna Bhattacharya 2017년 11월 7일
The "Deploy to Hardware" should work fine with both CH340 and ATmega16u2 clones. For most of the Arduino boards the External mode baud rate is set to 921600. I have observed that CH340 cannot handle baudrate greater than 230400. This is the reason that External mode fails.
There is a hidden API to change the default External mode baudrate. Open the model. Check the default External mode baudrate by executing the below command:
>>codertarget.arduinobase.registry.setBaudRate(gcs)
If you want to change the baudrate to a lower value say 230400 then use: >>codertarget.arduinobase.registry.setBaudRate(gcs,230400)
If you have an issue with External mode even after setting External mode baudrate to 230400 then keep lowering it till External mode works.
Ideally the clones with ATmega16u2 that use original Arduino drivers should work seamlessly in External mode. I have not yet tested though.
  댓글 수: 3

댓글을 달려면 로그인하십시오.

추가 답변(10개)

Erneto Rosas
Erneto Rosas 2019년 3월 12일
Hello every one, i just fixed the problem, first i noticed that i just received the error message in the external mode because in normal mode that worked well, what you have to do when you are using a USB-SERIAL CH340 is to change the BaudRate by using the command codertarget.arduinobase.registry.setBaudRate(gcr,*nomberofBaudRate)
the Baud rates choices are 76800, 115200,128000, 153600, 230400, 460800, 921600, 1500000, 2000000.
mine worked using the 153660
  댓글 수: 3
Thai Hoa
Thai Hoa 2021년 4월 11일
thank you so much, After three days, i do it <3

댓글을 달려면 로그인하십시오.


Javier Pérez de Arrilucea Santiró
I am running Matlab 2020a and I cannot even select the external mode in the drop-down menu (not appearing).
My clone is using the ATmega.

Kwadwo Dompreh
Kwadwo Dompreh 2017년 11월 2일
yes, Arduino mega2560 (clone from china) works fine in external mode for R2015a but does not work in external mode for R2017a (In normal only).

Jingbo
Jingbo 2017년 11월 3일
I tried to run simulink block in arduino board (CH340 driver) with external mode,it always shown some errors. Finally, I change another arduino board (with original driver), everything is good , external mode run on simulink went well. IF you want to buy cheap arduino board for simulink external mode and display and tune real-time.we recommend you buy farduino from Amazon that is cheaper than original arduino board.

David Sandells
David Sandells 2018년 8월 5일
I found that a baud rates of 115200 and 128000 worked for my Elegoo Nano board (uses CH340 driver). It wouldn't take the next 'standard' rate of 256000. Not sure if some other intermediate values might work.
FYI - I had previously tried changing the startDaemon file to the .m file version as suggested in the "Why am I unable to connect to Arduino in External Mode?" post. I didn't play with the delay value suggested in that post as it was already set to 180 seconds in the file provided. Anyway that solution on its own didn't have any affect but I guess it could have helped in combination with the baud rate change I mentioned above (which is why I mention it here).
  댓글 수: 1
David Sandells
David Sandells 2018년 8월 5일
I've just found a post ( CH340 max serial speed ) which states the supported speeds of the CH340 chip as ".....76800, 115200, 128000, 153600, 230400, 460800, 921600, 1500000, 2000000 baud."
I got 153600 and 2000000 (the highest one) to work on my board but not any of the ones in between!

댓글을 달려면 로그인하십시오.


Pablo Angulo
Pablo Angulo 2019년 4월 6일
In Conclusion, I could work in external mode, with my Arduino MEGA 2650 Made in China whith CH340 controller in Matlab R2017b, in effect we must to change Boud Rate, in may case worked using 153660 as well, the example code is:
For the follow example you must to have opened your Simulink Project, after that:
>>get_param(gcs, 'name');
In Worspace windows :
Name Value
ans 'ArduinoTest'
>>codertarget.arduinobase.registry.setBaudRate('ArduinoTest',153660)
For checking Boud Rate you can wrinte im promp
>>codertarget.arduinobase.registry.setBaudRate('ArduinoTest')
After that you can try to play your Clone Arduino Made in China in External Mode.
Thanks a lot

Anshuman Deshpande
Anshuman Deshpande 2019년 5월 13일
In my case for Arduino Uno, it worked with--> codertarget.arduinobase.registry.setBaudRate(gcs,153660)

Md Ohirul Qays
Md Ohirul Qays 2019년 9월 13일
Matlab 2018b interfaced with Arduino 2560 performed the command line successfully.
>> codertarget.arduinobase.registry.setBaudRate('ModelName',153600)
Nextly, the another baud rate 9600 is followed properly as well.

Angel Casas
Angel Casas 2019년 12월 4일
Gracias a todos por sus comentarios. Tengo un Arduino NANO (clon) y me funcionó con 230400 baudios.

Jerald Prado
Jerald Prado 2021년 1월 5일
im using matlab2020, i can't resolve using the mentioned workaround. anyone encountered the same?

Community Treasure Hunt

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

Start Hunting!

Translated by