I was trying to connect Arduino Mega 2560 to Mathematica for a Hardware in the loop simulation. I needed to output 12 variables from Mathematica on 12 PWM Arduino Channels. but an Uno Board does not support that number of PWM channels.

The Mathematica Arduino Link supports two boards only; Uno and Yun, and when i connected Mega 2560 it identified it automatically as Uno Board with Uno Pin Configurations. the following code illustrates...

In[1]:= ArduinoMegaDAQ = DeviceOpen["Arduino", "COM7"]

Out[1]= DeviceObject[{"Arduino", 1}]

In[2]:= ArduinoMegaDAQ["Properties"]

Out[2]= {"ArduinoInstallLocation", "BoardType", "PinConfigurations", "SerialPort"}

In[3]:= ArduinoMegaDAQ["BoardType"]

Out[3]= "Uno"

In[4]:= ArduinoMegaDAQ["PinConfigurations"]

Out[4]= Dataset[ <> ]

enter image description here

I thought that maybe changing Pin Configurations using DeviceConfigure[] might help but i couldn't do that, Also, Mathematica apparently does not even see the other pins. Any Suggestions?

  • 1
    $\begingroup$ I've spoken with Wolfram support today and they are conducting pre-release testing of a package to control a broader array of microcontrollers, not only limited to Arduino. While I didn't ask about the Mega board, the engineer has said it will support more forms of Arduino and beyond. He also said some of this functionality will be built into Mathematica 12, to be released "soon." $\endgroup$
    – Ghersic
    Commented Oct 24, 2018 at 17:35

1 Answer 1


You will not be able to identify the other pins with current Mathematica (currently 11.3) . Currently, Mathematica has not updated to FIRMATA version which limits reading pins available in UNO. I have also addressed this issue several times. Everything points to that Wolfram has choosen to concentrate in the Raspberry Pi integration.

If you looking to read other pins beyond A5 and D13, you will need to connect using Serial function. Here is a sample to read analog pins. Notice that you must manually assign the port ID. My sample here is for a windows platform which uses COM1-COMx

    dev = DeviceOpen["Serial", {"COM9", "BaudRate" -> 115200}]
(* This is for windows platform port format.Replace COMx  with x been \
port number and budrate same as in sketch*)

data = {};

volt = {};

task = RunScheduledTask[
  If[DeviceExecute[dev, "SerialReadyQ"],
   Module[{csv, raw},
    csv = FromCharacterCode[DeviceReadBuffer[dev]];
    raw = Flatten[Cases[ImportString[csv, "CSV"], {_Real}]];
    volt = ToExpression[raw, TraditionalForm];
    data = Join[data, volt];



//Setup of the Arduino with Mathematica
void setup() {Serial.begin(115200);}

void loop() {
//A value of 1023=5V,a value of 0=0V
//Arduino Mega and other boards may use any analogRead pin.
int value=analogRead(A14);
float voltage=value*(5.0/1023.0);


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.