Pages: [1]   Go Down
Author Topic: Arduino Uno I2C with (motorshield) in Matlab  (Read 996 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,


Little background:
I am working on a project to run 2 stepper motors simultaneously using Matlab. I was able to run the 2 motors in Matlab using an Uno and a motorshield (after uploading the srv.pde. The srv.pde is required for the shield to work in my case.), but I wasn't able to run the motors simultaneously.

I tried I2C with an another Uno and using the Wire library (http://arduino.cc/en/Tutorial/MasterWriter) in addition to the AccelStepper library, I was able to run the motors simultaneously using the Arduino 1.0.2 software.


My question is:
Is there a way of adding the Wire and AccelStepper libraries to the srv.pde so that I can use I2C and AccelStepper in Matlab? Is there another way of running 2 motors simultaneously using Matlab?


Thank you.
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 615
Posts: 49414
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
after uploading the srv.pde
Which you aren't going to show us. Fine. Be that way.

Quote
Is there another way of running 2 motors simultaneously using Matlab?
Could be. I can't see what code you are using, though, so I can't help.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Attached is the srv.pde code (MATLAB Support Package for Arduino (aka ArduinoIO Package)).
(http://www.mathworks.com/matlabcentral/fileexchange/32374-matlab-support-package-for-arduino-aka-arduinoio-package)

* srv_arduino2.pde (32.49 KB - downloaded 11 times.)
« Last Edit: December 14, 2012, 12:39:42 pm by ejri » Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You might try attaching your code. Click on 'Additional Options...' under the text input box.
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 615
Posts: 49414
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
Servo servo[70];
An array of 70 servo objects. Why? You can't possibly connect 70 servos to one Arduino.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have tried to add the Wire library to the srv.pde to establish an I2C,

The slave code:

#include <Wire.h>

void setup()
{
Wire.begin(100);
Wire.onReceive(receiveEvent);
}

void loop()
{
}

void receiveEvent( int howMany)
{
while (Wire.available())
{
}
}



The master code, is the srv.pde and I added:
#include <Wire.h>
#include <AccelStepper.h>

and to the void loop(), I added

Wire.beginTransmission (100);



Do I need to end the transmission (I mean add Wire.endTransmission() to the code)? Or the transmission should automatically end when I disconnect the arduino?


Adding #include <AccelStepper.h> to the code didn't seem to have an effect, the 2 motors still don't run simultaneously. What do I have to do to fix this?

 
 


Logged

Pages: [1]   Go Up
Jump to: