Message Boards Message Boards

19
|
67691 Views
|
35 Replies
|
29 Total Likes
View groups...
Share
Share this post:

Programming the world with Arduino and Wolfram Language

Posted 10 years ago

Attachments:
POSTED BY: Ian Johnson
35 Replies
POSTED BY: Moderation Team

HEllo... Not much esxciting going on between Mathematica and Arduino. Old firmware FIRMATA does not allow to read all the pins from MEGA. Please, reopen and take over the subject or comment .

POSTED BY: Jose Calderon

Yes.. I already posted an issue

For ecample, it does not explain hot to get the Device Properties.

POSTED BY: Jose Calderon

NOW IT WORKED!!!!\ I will check again with your link .. But the Wolfram guide in too confusing.

POSTED BY: Jose Calderon
POSTED BY: Ian Johnson
POSTED BY: Jose Calderon

I think there might have been a problem with the sketch I uploaded. I have modified the sketch, can you try reuploading the sketch?

Additionally, if you have 10.1, you can just use the builtin Arduino functionality (which evolved from this), documented at http://reference.wolfram.com/language/ref/device/Arduino.html

POSTED BY: Ian Johnson

Yes.. I uploaded using the Arduino loader..

POSTED BY: Jose Calderon

And you know that your serial port is "COM3"?

POSTED BY: Ian Johnson

I also use <|11 -> 1> but dod not work either.

enter image description here

enter image description here

POSTED BY: Jose Calderon

Hi again Jose,

So what exactly is not working for you? Have you uploaded the sketch to your Arduino with the Arduino software?

Ian

POSTED BY: Ian Johnson

Programming the World with Arduino and Mathematica

In[2]:= arduinoObject = DeviceOpen["Arduino", "COM3"]

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

Where "COM4" is my serial port, replace that with whatever port your Arduino is attached on.
Now for some basic device control, we can use

In[15]:= DeviceWrite[arduinoObject, <|11 -> "HIGH"|>]

Out[15]= <|11 -> "HIGH"|>

In[9]:= <|1 -> 1|>

Out[9]= <|1 -> 1|>

Also tested the LED with the insire 3V power supplied to confirm the LED is ok.

enter image description here

POSTED BY: Jose Calderon

This is a great subject. But a bit advance for new users. May you explain what is the "Arduino firmware" and ho w it differs from a "sketch"?

Also , explain what is a Wolfram package and how it is different from running a standard notebook?

Thank you!

POSTED BY: Jose Calderon

Hi Jose,

The Arduino firmware as I called it in the post is the same thing as a sketch. They are the same.

A Wolfram Language package is a file that contains Wolfram Language code and definitions that is meant to be portable. It is intended that packages contain useful definitions that is to be used multiple times. It is similar to a library file in other programming languages. You load packages with either the function Get or the function Needs. In my post, << is a shorthand notation for Get.

Ian

POSTED BY: Ian Johnson
Posted 9 years ago
POSTED BY: Updating Name
Posted 9 years ago
POSTED BY: Andi Hofma
POSTED BY: Ian Johnson

Hi there,

I just wonder whether the link to the firmware has been disabled on purpose or whether it's just me who cannot access it.

Cheers,

Marco

POSTED BY: Marco Thiel

I reattached the file as an attachment to the post. The file had a limited amount of time it was hosted on the server, and I had thought that the official driver would be in the software by the time it had expired, but unfortunately not. It will be a little bit longer before the official driver (which was derived from this work) will be integrated into the product.

Ian

POSTED BY: Ian Johnson

Dear Ian,

thanks a lot! That's great. Fantastic work!

Thanks,

Marco

POSTED BY: Marco Thiel
POSTED BY: Marco Thiel
POSTED BY: Ian Johnson
POSTED BY: Marco Thiel

I work remotely from Minnesota, but anyways I did somewhat manage to get to 1KHz, but I can't confirm that it was 1KHz, as I don't have an oscilloscope handy, but it appeared to be flickering so fast that it almost seemed steady. I accomplished that by just using

Do[(
DeviceWrite[arduinoObject,<|pinNumber->1|;
Pause[1/2000];
DeviceWrite[arduinoObject,<|pinNumber->0];
Pause[1/2000]),
{1000}]

However when I wrapped that in Timing, it took about seven seconds to evaluate, and the light would flicker as I mentioned for about twoish seconds (again, don't have an oscilloscope handy, so can't confirm the time), then it would flash on and off for about two more seconds, then after that it would stay steady on either on or off, depending on which time I ran it, i.e. sometimes it would end with being on, sometimes it would end with being off. So that leads me to suspect that Mathematica is either doing stuff after sending the commands that takes seven seconds, or that it is getting "confused" with all the serial output such that it doesn't output correctly, on top of being slower than suspected.

Also, thanks for the tip on Mac serial discovery, I may have to integrate that into the FindDevice functionality!

Ian

POSTED BY: Ian Johnson

Hi,

this might be interesting in terms of Arduino's speed:

http://www.dustynrobots.com/robotics/arduino-data-logging-and-speed-test/

http://arduino.cc/en/Reference/AnalogRead

This one is the fastest I could find:

http://forums.adafruit.com/viewtopic.php?f=31&t=30557

which claims about 100kHz sampling rate. And in

http://community.wolfram.com/groups/-/m/t/250923

I had trouble getting even close to that. The decay can happen very fast and I need a sampling rate that is as high as possible.

Cheers,

Marco

POSTED BY: Marco Thiel
POSTED BY: Ian Johnson
POSTED BY: Ian Johnson

Thanks for the suggestion, I attached a notebook, which is just basically the original post in notebook form.

POSTED BY: Ian Johnson

This is great - it is nice to have this all in one notebook. But I actually meant ArduinoDriver.m file that is currently linked to webpage with an expiration date. That file won't be accessible after some time. If you wish to attach it - your original post can take many attachments.

POSTED BY: Sam Carrettie

Ian, when using your wonderful Arduino Driver with an Arduino Micro I find that serialBufferRead, at odd times, does not contain the full data array upon which or also unrelated to this occurrence the notebook looses connection to arduinoObject. Is it advisable to include a second If statement in ArduinoRead[pin_] which checks for the Length of serialBufferRead ? I am using OS X 10.9.5 . I include a notebook with results. Thank you in advance, Hanspeter

Attachments:
POSTED BY: Hanspeter Helm
POSTED BY: Ian Johnson

Thank you Ian for looking into my problem. With a pause the error rate is significantly lower (almost perfect). I find that the error which I reported appears ALWAYS, when the Arduino Serial Monitor pop-up window is open at the time the Mathematica program is running, but this is not surprising.

I have a second question though: Why do commands like
DeviceConfigure[arduinoObject,<|"A5"->"analogInput"|>] or DeviceConfigure[arduinoObject,<|6->"digitalInput"|>] trigger a continuously repeated transmission of the serial buffer from the Arduino Micro, rather than enable a single transmission once a DeviceRead statement is sent ?

Thanking in advance,

Hanspeter

POSTED BY: Hanspeter Helm

I'm glad that helped!

And the reasoning I had for putting the device into an always reporting mode is that once one read is triggered, it's likely that more reads are going to be expected, so that was a way to help performance with something like

Dynamic[DeviceRead["Arduino",2]]

or something similar. In the version of the driver that will be released with Mathematica soon, this has changed so that one request provides one response, rather than putting the Arduino into an always reporting cycle.

POSTED BY: Ian Johnson
POSTED BY: Sam Carrettie
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