marostoth
Posts: 2
Joined: Sat Mar 10, 2018 11:45 am

johnny-five dc motors not working properly

Sun Mar 11, 2018 10:33 am

Hello guys, so I've seen this tutorial on ExplainingComputers (https://www.youtube.com/watch?v=DyQxvfwQbTg, and yes I've tried his code and also not working) and it made me to jump into this rpi stuff. TBH this stuff is really cool. But this build is making me go crazy. After trying to google this issue and playing with wiring and code I have to ask for help here.

So far the motors do spin all directions using Johnny-Five when controlled individually. But as soon as it comes to control them both they just refuse to cooperate. In all the videos on YT it seems so easy so it makes me really think that only someone experienced can spot what is wrong. So you will help with any suggestions or anything at all because seems like I came to an end with my "what if".

Motor Controller
https://www.dfrobot.com/product-66.html

This is how is all connected
https://www.dropbox.com/s/k4tu8s54qxbv6 ... 2.jpg?dl=0
https://www.dropbox.com/s/s2k1knk2nr0u5 ... 5.jpg?dl=0

Code and wire connection just if it helps you to better understand.

// motorRight dir: 'P1-11' pwm: 'P1-12'
// motorLeft dir 'P1-36' pwm: 'P1-35'

On the Motor Controller the pin11 is connected to M2, pin12 to E2, pin36 to M1 and pin35 to E1

This is the behavior when running script
https://www.dropbox.com/s/0q4s3lc2hsolyz5/mk01.mp4?dl=0

Basically as I see it only the reverse bit of the code is running than one side keeps on running forever.

This is the code that is used for the video above

Code: Select all

const Raspi = require('raspi-io');
const five = require('johnny-five');
const board = new five.Board({
  io: new Raspi()
});

// motorRight dir: 'P1-11' pwm: 'P1-12'
// motorLeft dir 'P1-36' pwm: 'P1-35'

board.on("ready", function() {
  
   var motors = new five.Motors([
     { pins: { dir: 'P1-11', pwm: 'P1-12' }, invertPWM: true },
     { pins: { dir: 'P1-36', pwm: 'P1-35'}, invertPWM: true }
   ]);

  board.repl.inject({
    motors: motors
  });

  // Go forward at full speed for 5 seconds
  console.log("Full speed ahead!");
  motors.forward(255);
  board.wait(5000, function () {
    motors.stop();
  });

  // Go backwards at full speed for 5 seconds
  console.log("Now backwards!");
  motors.reverse(255);
  board.wait(5000, function () {
    motors.stop();
  });

  // Go left...
  console.log("To the left!");
  motors[0].reverse(200);
  motors[1].forward(200);
  board.wait(5000, function () {
    motors.stop();
  });

  // Go right...
  console.log("To the right!");
  motors[0].forward(200);
  motors[1].reverse(200);
  board.wait(5000, function () {
    motors.stop();
  });

  // Use REPL if you want to go further
  console.log("Done auto-driving! Use `motors` to control motors in REPL");

});
Also this is the first time ever I am trying to ask for help on any forum so hopefully this won't count as bad way to start a topic. Thanks for any help.

Forris
Raspberry Pi Certified Educator
Raspberry Pi Certified Educator
Posts: 247
Joined: Fri Jan 06, 2012 7:46 pm

Re: johnny-five dc motors not working properly

Tue Mar 20, 2018 1:02 pm

Ok, just a couple of quick thoughts.

1- You don't seem to have any ground connection between the motor board and the Pi. Whenever you use external power for motors, you need to make sure you also make a ground connection between the batteries and the Pi, otherwise the circuit will not work.

2- I'm confused about your code, which you say is from the video, but the code linked to on the Youtube page is Python, while yours looks like C ?

Darren.

User avatar
DougieLawson
Posts: 33787
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: johnny-five dc motors not working properly

Wed Mar 21, 2018 9:32 pm

Forris wrote:
Tue Mar 20, 2018 1:02 pm

2- I'm confused about your code, which you say is from the video, but the code linked to on the Youtube page is Python, while yours looks like C ?
Looks like Javascript (probably with Node.js or NodeRED) to me.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

marostoth
Posts: 2
Joined: Sat Mar 10, 2018 11:45 am

Re: johnny-five dc motors not working properly

Thu Mar 22, 2018 8:03 pm

Thank you guys for the feedback.

First thing, yes it was the grounding of Pi that was causing my problem. As soon as I fixed that, everything started to work.

Second think, you are right it is JavaScript and Node.js. It was my attempt to make things work since the language is familiar to me and I miss brackets and semicolons from Python.

I still have a question as you guys have experience. What book or resource would you recommend to learn electronics? Something you find helpful, just to avoid such mistakes in the future.

Return to “General programming discussion”

Who is online

Users browsing this forum: No registered users and 5 guests