Message Boards Message Boards

GROUPS:

MicrocontrollerKit support for AT Mega 2560

Posted 1 year ago
2517 Views
|
9 Replies
|
14 Total Likes
|

I am trying to use Mathematica's MicrocontrollerKit, which was introduced with the release of 12.0 and was featured in a video during the WTC2019 in a video last week. The very first example of the Microcontroller Kit Tutorial works with a regular Arduino Uno, but it fails with an Arduino Mega 2560. However, both Arduinos work with the Arduino IDE, which is also used by Mathematica's MicrocontrollerKit! For very good reasons, we rely on the Arduino Mega 2560, which is one of the most versatile Arduino.

This error message appears when clicking the <strong>Red Button:

The error message obviously refers to a communication issue. The RX/TX lights blink erratically while MicrocontrollerEmbedCode fails. Mathematica's MicrocontrollerKit provides 149 Target entities, but there is none that fits Arduino Mega 2560. Did I miss a target name? Is there a way to specify the communication properties?

Mathematica's MicrocontrollerKit is really nice, since it provides a simple link between the huge Control Systems section and real life.

9 Replies

Dear Ernst, is this question related to Wolfram Technologies? If so, please could you clarify how with more details.

Hi, the question certainly relates to Wolfram Technologies. I updated my post extensively and provided a clear description of the problem. I am surprised by how few discussions center around Mathematica's MicrocontrollerKit and the access to Connected Devices. I have been using Mathematica for years to operate scientific cameras and various microcontrollers.

Hello Ernst,

The Mega couldn't make it in the first release.

The Mega and Uno use two different mcus. The Microcontroller Kit does not yet support the ATmega2560 that is used by the Mega. It has a different instruction set than the ATmega328 used by the Uno.

Thanks for your feedback and interest. It helps us to prioritize the next batch of mcus that need to be supported.

Dear Suba, thank you for the swift and clear response. We use the Mega for controlling our microscopes, i.e. not for collecting any images, but for organizing the movements of stages, filter changers, ..., the Nano for driving small motors and various Arduino originals and clones during the software development process. Since you are also using the Arduino IDE, or at least parts of it, I was sure it was an issue of some command line option. Obviously, I was wrong. In any case, I look forward to your next version of the MicrocontrollerKit.

Posted 4 months ago

If you're willing to add an extra step or two, you can simply generate the code in Wiring and copy and paste it into the arduino IDE and then upload...you can then use the MCkit to generate code for any compatible board, I rarely have to modify it to fix anything.

I use the mcKit to generate code for an esp32. an Example could be like this:

code = 
 MicrocontrollerEmbedCode[
  ssmd, <|"Target" -> "ArduinoUno", 
   "Inputs" -> {"A0" -> "Analog", "A1" -> "Analog", "A2" -> "Analog"},
    "Outputs" -> {"Serial"}|>, <|"ConnectionPort" -> None|>, <|
   "Language" -> "Wiring"|>]
Framed[StringTrim[code["SourceCode"]], 
 Background -> Darker[Black, 0.4]]

I know this post is old, but maybe someone will come along and see it.

POSTED BY: Mor Bo
Answer
Posted 4 months ago

Thanks for pointing that out. You can avoid the manual operations with some additional functions.

The following will create a file and open it using the Arduino IDE.

dir = CreateDirectory[FileNameJoin[{$HomeDirectory, "Demo"}]]; 
MicrocontrollerEmbedCode[
  NonlinearStateSpaceModel[{{Which[x > 0, 0, True, 1]}, {x}}, {x}, {}, {Automatic}, Automatic, SamplingPeriod -> 2], 
  <|"Target" -> "ArduinoUno", "Outputs" -> 13 -> "Digital"|>, 
  <|"ConnectionPort" -> "p"|>, 
  <|"Language" -> "Wiring", "WorkingDirectory" -> dir, "CleanIntermediate" -> False, "CreateBinary" -> False|>]; 

SystemOpen[RenameFile[FileNameJoin[{dir, "Demo.cpp"}], FileNameJoin[{dir, "Demo.ino"}]]]

This could be customized to handle repeated evaluations, etc.

Your mileage will vary with this approach because, for example, if we are trying to leapfrog to a Mega from a Uno there is no pin A12 on the latter.

However, the Mega is supported in 12.1. The official announcement will come, along with a whole bunch of other Arduino boards, in 12.2.

Please include support for the Teensy 4.0 in a future version of the microcontroller kit. It offers stunning performance at an incredible price and is programmable through the Arduino IDE as well. (https://www.pjrc.com/store/teensy40.html)

Keeping this thread active and echoing the above to request support for both the Arduino Mega 2560 and the various Teensy 2.X, 3.X, and 4.X variants (right now I am using Teensy 3.2 boards, but I am fully supportive of the work that Paul at PJRC has put into his entire line).

Posted 11 months ago

Thanks again for all the feedback.

As an update, the plan is to add support for the Mega in the 12.1 release.

The Teensy boards will probably come later next year.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract