Message Boards Message Boards

How do I connect Arduino to Mathematica kernel?

Posted 13 years ago
I've recently started having fun with Arduino (see www.arduino.com for details).  The memory and processing speed is far below what is necessary to run the Mathematica kernel, but I wonder if an Arduino program might somehow make calls to a Mathematica kernel (running on a network-connected machine) and get results back.  Has anyone done this?
POSTED BY: David DeBrota
20 Replies
Actually there is a package called ArduinoLink which I demoed at the world maker faire and at the wolfram technology conference.  You use it to control the arduino with mathematica in a better way than SerialIO.  The only thing is that the kernal runs on the computer so the arduino either has to be plugged into a computer or connected by a XBee.

Here is a link to my demo at the world maker faire...

http://www.youtube.com/watch?v=eoXADAE67ig

It should be posted on the wolfram blog or other wolfram site soon.


-Christopher
@ernststelzer, I am not sure what you mean by “sketch”, but you can include images as explained in this post. Also you can properly format and color-highlight Mathematica code in the post. 

Arduino site has Interfacing page with a list of progamming languages connecting to the device, among which we can find Mathematica. For pure formatting purposes are reproduce here the snipets code (I id not try it myself though). For details on using this code please see the original page.

 Needs["NETLink`"]
 InstallNET[];
 
 NETTypeInfo["System.IO.Ports.SerialPort"]
 
 ser = NETNew["System.IO.Ports.SerialPort", "COM9"]
 ser@Open[]
 
 myEventFn[sender_, evt_] := (j = ser@ReadChar[])
AddEventHandler[ser@DataReceived, myEventFn]

Dynamic[j]

ser@Write[MakeNETObject[{254, 254}, "System.Byte[]"], 0, 2]

ser@Close[]
POSTED BY: Vitaliy Kaurov
I actually addressed this problem a while ago.  If I knew how to upload a notebook or a sketch on this site I would love to share my code, since I am very much interested in this topic.

The program "SerialCallResponseASCIIStelzer.ino" has to be started on the Arduino using the IDE.  This program accepts various ASCII codes and responds by returning comma separated analog and pin values in a string.  These are then read, converted to numbers and displayed.

"A" read single values of analog inputs A0 & A1 as well as digital pins D2, D3 & D4 (simple kind of oscilloscope!!)
"R" generate random values for A0 (0 ... 511), A1 (256 ... 1023), D2 (0, 1), D3 (0, 1), D4 (0, 1)  (as above but for test purposes)
"S" read string of 128 values of analog inputs A0 & A1 as well as digital pins D2, D3 & D4
"T" read string of 256 values of analog inputs A0 & A1 as well as digital pins D2, D3 & D4
"U" read string of 1024 values of analog inputs A0 & A1 as well as digital pins D2, D3 & D4
"Z" for test purposes Mathematica generates random single values for A0 (0 ... 511), A1 (256 ... 1023), D2 (0, 1), D3 (0, 1), D4 (0, 1)

On the Mathematica side I use  NETNew["System.IO.Ports.SerialPort", "COM3", 115200] to initiate and perform the communication.  The most recent Arduino boards allow you to connect directly via USB but that I have not explored yet.
Posted 12 years ago
Hi all,

I was playing with data capture through arduino a couple of months ago (using XBEE modems to remotely capture the temperature of the BBQ smoker emoticon )

The following links were most helpful to set me up and running data streaming through an XBEE  modem


I was finally able to connect to the serial port by using the package SerialIO created by Rob Raguet-Schofield found here

http://library.wolfram.com/infocenter/Demos/5726

and then following the instructions and testing the Arduino program that William Turkel posted in his blog.

http://williamjturkel.net/2011/12/25/connecting-arduino-to-mathematica-on-mac-os-x-with-serialio

Hope to see the package ArduinoLink being developed by Keshav Saharia being released soon.
POSTED BY: Diego Zviovich
Some people have done this using the SerialIO package.

This article looks like a fairly complete introduction to how you would use the package:
http://williamjturkel.net/2011/12/25/connecting-arduino-to-mathematica-on-mac-os-x-with-serialio/
POSTED BY: Sean Clarke
In arduinoish a sketch is a C-program.
Posted 12 years ago
Hi

A while back Christopher Wolfram and Keshav Saharia demoed controlling arduino with mathematica:

Arduino and Mathematica—Computation in the Maker World

and it was promised in various forums that the plugin will be released. Has the plugin been released? If so, where can I downoad it?
POSTED BY: selvapersonal
I'm interested in this, too. Somebody added this link a few days ago:
http://playground.arduino.cc/Interfacing/Mathematica
POSTED BY: Nick James
Posted 12 years ago
@selvapersonal The link package is released at GitHub.

At the moment it supports only MacOS X, which is due to the cross-compiler.
If you find arduino cross-compilers for other platforms, it shouldn't be that complicated to
make this work on other platforms as well.
POSTED BY: Stefan Schwarz
Folks, this is way too exiting of a discussion. I have done some work with Arduino on a Teensy board (I probably should write Teensyduino) on the MacBook and would very much be interested in some baby steps on how to get the "Mathematica kernel" running to try some of these great ideas. Any volunteer hints?
POSTED BY: Luiz Costa
Hello Luiz, welcome to Wolfram Community! Quite a few posts above link to simple articles with "baby steps" described in detail. Did you have any luck trying those?
POSTED BY: Vitaliy Kaurov
Luiz, this post that mentions Wolfram Alpha - is it also related to Arduino and mean for this thread? Or did you mean to post it a separate question related to Wolfram Alpha ?
POSTED BY: Vitaliy Kaurov
As far as I know, Wolfram Alpha is a one line interface and I can't use variables, literals, or other supporting definitions. Is that is true? I have been using literals on segmented integration with no success. One of the tasks is to integrate a trapezoidal motion profile (a graphical description of a function in the time domain) where some of the integration intervals are left in literal form, say (1, a) in the first partial integral, then (a, 3) for the second part of the integration.
POSTED BY: Luiz Costa
@vitaliyk thank you for the warm prompt greetings! No, I came on board today for this week I received your invitation to join the W. Community. Thank you for the invitation and tip! I will check those links.
POSTED BY: Luiz Costa
@vitaliyk

I'm sorry. My intention was to get an answer to my question or start a new thread. I will find out what is the proper way of doing that. What is a good discussion to direct differential/integral calculus type of issues? <P>Thank you.<\p>
POSTED BY: Luiz Costa

Yes.. but do't this package only works on Mac?

POSTED BY: Jose Calderon

Could you clarify? This will work for both MAC and Windows 8 IDE?

POSTED BY: Jose Calderon

I ran this notebook on a Mathematica 10 windows 8.1.. Nothing happened. IS there a need to install any special package? please advice.

POSTED BY: Jose Calderon

Folks.. I have spend a considerable time on the subject Arduino and Mathematica. I am not getting anywhere becasue it looks like all the work here is using MacOS. If I am wrong, please said so and shor a sample demostrating using a Windows 8.1 computer with an Arduino connected.

POSTED BY: Jose Calderon

Great video Christopher ! :)

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