rwaldron / johnny-five

JavaScript Robotics and IoT programming framework, developed at Bocoup.
http://johnny-five.io
Other
13.26k stars 1.76k forks source link

Adafruit Motor Shield Support #380

Closed brandonaaskov closed 8 years ago

brandonaaskov commented 10 years ago

My particular use case is to drive a 12V stepper motor. I have the AdvancedFirmata that I need. Even have the motor shield and Arduino on two separate power supplies. But I realized I have no idea how to address the pins with this thing. The motor terminals I'm using are "M3" and "M4" but that doesn't tell me which PWM pins to use.

Then I read this...

image

Give that, is this something that would get support at the firmata level? This is a bit low-level for me, so I'm just barely treading here.

I don't think it makes a difference, but here's my code for reference:

var five = require("johnny-five"),
    board = new five.Board()

board.on("ready", function() {
  var options = {
    type: five.Stepper.TYPE.DRIVER,
    stepsPerRev: 200,
    pins: [11, 12]
  }

  var stepper = new five.Stepper(options)
  stepper.step(1000, function() {
    process.exit(1)
  })
})
Resseguie commented 10 years ago

@dtex might be able to help here

dtex commented 10 years ago

Hi @brandonaaskov , is that v1.2 of the motor shield? Sadly we don't have support this board in Johnny-Five. @xseignard and @alexbudin were working on it (#216) but I don't think they have anything ready to go. I'd be willing to look into it but those boards are no longer available. If you want to use Johnny-Five (and you do, it's awesome) you will have to use a different motor shield. To the best of my knowledge Johnny-Five supports every shield out there except for the Adafruits (including V2.0)

brandonaaskov commented 10 years ago

I just picked up the board, so it's V2.0. I'm trying to make some tutorials for the very beginners, and being able to grab a motor shield off the shelf is hugely helpful. I snagged the Adafruit one because I was already making an order. Is there a different motor driver (ideally a breakout board or shield for simplicity) that J5 supports? My goal is to use Johnny-Five for everything, but using readily available hardware always helps.

rwaldron commented 10 years ago

I'm wondering if there is misunderstanding here, Stepper and Motor are unrelated classes. I own the stepper motor that @brandonaaskov linked to and have used it with the Stepper class (+AdvancedFirmata). These drivers have been tested and confirmed with Johnny-Five's Stepper class:

rwaldron commented 10 years ago

@brandonaaskov I just ordered this: https://www.adafruit.com/products/1438, I'll report back when I know more

dtex commented 10 years ago

Doh! Yes I misunderstood. I overlooked all FIVE occurrences of the word "stepper" in the original question.

rwaldron commented 10 years ago

(I'm going to post a bunch of links and code snippets here, just so I don't forget them)

// M1 and M2 => port 1
// M3 and M4 => port 2
// `num` is decremented, so 0 => 1 and 1 => 2

if (num == 0) {
  pwma = 8; ain2 = 9; ain1 = 10;
  pwmb = 13; bin2 = 12; bin1 = 11;
} else if (num == 1) {
  pwma = 2; ain2 = 3; ain1 = 4;
  pwmb = 7; bin2 = 6; bin1 = 5;
}
brandonaaskov commented 10 years ago

Awesome! I'll pick up that EasyDriver from Sparkfun since I'm getting a few other things as well (missile switches ftw!).

Just so that I can wrap my head around it, is the Adafruit board more difficult because of the 74HC595 latch? It seems like that's the case since the Arduino has to speak to that instead of the PWM pins directly, but like I said, I'm treading water here :)

rwaldron commented 10 years ago

@brandonaaskov you must make absolutely sure to provide the necessary amount of power to the driver board. I literally ruined 3 boards by not paying as close attention as I should've

brandonaaskov commented 10 years ago

Looks like it can take 7V-20V for a power supply. I would imagine not giving it enough power would just cause brownouts and weird behavior. Underpowering it wouldn't fry the board... would it?

rwaldron commented 10 years ago

Heh. I meant that I was providing too much :) I literally burned the boards with electricity.

rwaldron commented 10 years ago

Ok, my board was delivered, but I'm about to go on vacation for 10 days, so please be patient with me :) thanks!

brandonaaskov commented 10 years ago

Perfect timing! I just got back from a week-long vacation and my sparkfun motor driver just arrived!

rwaldron commented 10 years ago

Well... I won't be back until late next week :|

brandonaaskov commented 10 years ago

Have fun! I'll see how far I can get with the replacement board.

rwaldron commented 9 years ago

https://github.com/rwaldron/johnny-five/commit/255d17a97493b103a9200f67d14275e7e016fa60

dtex commented 9 years ago

I re-opened this because the issue was specifically in reference to stepper motors which are not yet supported.

rwaldron commented 9 years ago

Ugh. I'm the worst.

brewh0use commented 9 years ago

Have you ever had a chance looking into this again? I was hoping to hook up a stepper motor the adafruit motor shield, but haven't had any luck so far :-(

rwaldron commented 9 years ago

@dtex are you still working on this?

dtex commented 9 years ago

No, but I did get a 12V stepper motor to test with.

brewh0use commented 9 years ago

Please let me know if there is any way I can help. Happy to test with the motors that I have available.

rwaldron commented 9 years ago

I hate to pass the buck, but if you want to get unblocked, the EasyDriver or the Pololu Drivers work great ;)

spokke commented 9 years ago

hi all... i'm developing a automower and have adafruit shield 4 directional motors (no stepper) connected to a mega .. i'd like to know if i can connect through johnny ... thank you ...

rwaldron commented 9 years ago

@spokke which adafruit shield motor shield? v1 or v2?

Edit

The v2 is simple to connect: https://learn.adafruit.com/adafruit-shield-compatibility/motor-slash-stepper-slash-servo-shield-v2#arduino-mega-2560-r2

dtex commented 9 years ago

The V1 shield should also work with a Mega per the Adafruit site and both V1 and V2 are supported by Johnny-Five.

BrianGenisio commented 9 years ago

The V1 shield supports stepper and servo connections in addition to regular motors. When I wrote the V1 driver (ShiftRegister), I only got regular motors working. IIRC, the code for steppers is a bit more complicated than regular motors, but not as much. They both use the shift registers to use 3 pins to control lots more. The Motor.js:Controllers["ShiftRegister"] code was loosely based off of this code: https://github.com/adafruit/Adafruit-Motor-Shield-library/blob/master/AFMotor.cpp

spokke commented 9 years ago

thank for all response .... the shield is this http://www.amazon.it/gp/product/B00E19VXR0?psc=1&redirect=true&ref_=oh_aui_detailpage_o02_s00 ... i will try soon .. which pin must i use ? thank you

BrianGenisio commented 9 years ago

That is a V1 shield.

rwaldron commented 9 years ago

spokke commented 9 years ago

ok i will take an example and try in a few days (i hope) :)

BrianGenisio commented 9 years ago

Again, this shield won't work with Stepper motors without writing new code inside J5. It will only work with regular motors. B

On Wed, Jun 24, 2015 at 4:17 PM spokke notifications@github.com wrote:

ok i will take an example and try in a few days (i hope) :)

— Reply to this email directly or view it on GitHub https://github.com/rwaldron/johnny-five/issues/380#issuecomment-114997791 .

spokke commented 9 years ago

Ok i need for normal motor no stepper

Inviato da iPhone

Il giorno 24/giu/2015, alle ore 23:26, Brian Genisio notifications@github.com ha scritto:

Again, this shield won't work with Stepper motors without writing new code inside J5. It will only work with regular motors. B

On Wed, Jun 24, 2015 at 4:17 PM spokke notifications@github.com wrote:

ok i will take an example and try in a few days (i hope) :)

— Reply to this email directly or view it on GitHub https://github.com/rwaldron/johnny-five/issues/380#issuecomment-114997791 .

— Reply to this email directly or view it on GitHub.

reconbot commented 8 years ago

I'm going to close this issue due to it's age, but if you'd like to continue with it feel free to comment and we'll reopen.

trentrand commented 4 years ago

For those who landed here looking for help with the Adafruit Motor/Stepper/Servo Shield V2, it is now supported in Johnny-Five. See the example here: https://github.com/rwaldron/johnny-five/wiki/Motor#adafruit-motorstepperservo-shield-v2