Message Boards Message Boards

Trouble getting Arduino and Device* functions to work

Posted 9 years ago

I'm having trouble getting the Device functions to work with Arduinio. I'm hoping that someone can help me find out what is wrong. The circuit is very simple, with three resistors and three LEDs. I'm trying to turn them on with pin 5, 6 and 7. This code turns the LEDs on when I upload it via the Arduino software

void setup() {
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
}

void loop() {
  digitalWrite(5, HIGH);
  digitalWrite(6, HIGH);
  digitalWrite(7, HIGH);
}

I am now trying to do the same thing with Mathematica.

arduino = DeviceOpen["Arduino", "/dev/tty.usbmodem1431"]
DeviceConfigure[
 arduino,
 "PinConfigure" -> <|5 -> "Output", 6 -> "Output", 7 -> "Output"|>
 ]
DeviceWrite[arduino, <|
  5 -> 0.5, 6 -> 1, 7 -> 1
  |>]

It doesn't work. It seems like whatever code I have previously uploaded to the Arduino is still running. The connection looks alright though: Connection screenshot

You can clearly see that the pins are correctly set, but it isn't reflected in what the Arduino actually does. My guess is that the "driver software" that Mathematica uses to control the Arduino hasn't been uploaded, but how can I upload it? Or is it something else?

POSTED BY: Calle E
7 Replies
Posted 9 years ago

What are you trying to debug, it's already working?

POSTED BY: Calle E

Have you tried one pin HIGH at a time? What is the load like? Verify that you are asking just too much current from the device.

POSTED BY: Jose Calderon
Posted 9 years ago

This is done directly from Mathematica. All you have to do is to add DeviceConfigure[arduino,"Upload"] to my code, right after DeviceOpen.

POSTED BY: Calle E

Is this sketch loaded using the Arduino normal IDE or can a sketch be loaded straight from Mathematica?

POSTED BY: Jose Calderon

Glad I could help out.

Ian

POSTED BY: Ian Johnson
Posted 9 years ago

It works perfectly, thank you! WRI should improve the documentation - I couldn't figure out which command to use even though I had already guessed that I must somehow upload the code to the Arduino...

POSTED BY: Calle E

Before using the Arduino with Mathematica, you need to upload the custom sketch Mathematica uses to communicate with the Arduino.

You can do that with:

DeviceConfigure[arduino,"Upload"]

After uploading the sketch DeviceWrite, etc. commands should work as expected.

See the DeviceConfigure section of the documentation at http://reference.wolfram.com/language/ref/device/Arduino.html

Let me know if this works for you,

Ian

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