0

How to use Adafruit Motor Shield V2 with Lego Servo Motor?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

How to use Adafruit Motor Shield V2 with Lego Servo Motor?

by lionheart on Tue Oct 28, 2014 10:43 am

Hi!

I've question about how to use Arduino Mega 2560+Adafruit Motor Shield V2 to control the Lego Power Function Servo. Basically, almost servo has 3 wires: a power wire, a signal wire and a GND but my Lego Servo has 4 wires: a power, a GND, C1 and C2 for signal. I found the detail of how lego Servo work at: http://philohome.com/pf/pf.htm
I also found a video with an instruction on how to use L298 motor shield to work with lego servo at: https://www.youtube.com/watch?v=ArEt9RWPbhE
but I don't know how to connect the C1 and C2 signal to Adafruit Motor Shield V2 and which pin that I need to attach when programming on Arduino IDE?
The second thing I want to know is if you connect the servo motor to Servo2 on the shield, how do I know which pin that I need to attach in the Arduino IDE?

Please, help me
Attachments
untitled.png
Lego Power Function Wire
untitled.png (59.56 KiB) Viewed 1367 times

lionheart
 
Posts: 6
Joined: Tue Oct 28, 2014 10:11 am

Re: How to use Adafruit Motor Shield V2 with Lego Servo Moto

by adafruit_support_bill on Tue Oct 28, 2014 1:53 pm

We don't have any of the Llego motors to test. From the chart on the philohome page, it looks like you should be able to provide 9v power to the shield, then connect GND and 9v to the motor connector and connect C1 and C2 to one of the motor channels. The H-bridge chips in the shield will drive one side high (9v) for forward and the other side high for reverse.

The servo headers on the shield are connected to pins 9 and 10 of the Arduino.

adafruit_support_bill
 
Posts: 84034
Joined: Sat Feb 07, 2009 10:11 am

Re: How to use Adafruit Motor Shield V2 with Lego Servo Moto

by lionheart on Tue Oct 28, 2014 9:15 pm

Thanks for your quick reply. I intend to connect external power supply 9V to Power Terminal block on the shield. I want to attach the lego servo motor into SERVO1 on the shield which has 3 pins available(one for 9V power and the one for GND) . Can you please show me in the picture below what exactly pins that C1 and C2 should connect to and some code for its forward and reverse direction. I don't see any sample code in the manual how to forward and reverse for servo motor?
1438-05.jpg
Adafruit Motor Shield V2
1438-05.jpg (309.08 KiB) Viewed 1340 times

lionheart
 
Posts: 6
Joined: Tue Oct 28, 2014 10:11 am

Re: How to use Adafruit Motor Shield V2 with Lego Servo Moto

by lionheart on Tue Oct 28, 2014 10:57 pm

Did you mean that I should connect to servo motor like that picture below? What 's about the signal pin(GREEN ARROW) at SERVO1 on the shield, does it can control the motor via pin 10 on mega 2560?

1438-06.jpg
Schematic
1438-06.jpg (302.21 KiB) Viewed 1335 times

lionheart
 
Posts: 6
Joined: Tue Oct 28, 2014 10:11 am

Re: How to use Adafruit Motor Shield V2 with Lego Servo Moto

by adafruit_support_bill on Wed Oct 29, 2014 5:56 am

The Lego motors are not servo motors. They have no feedback and they do not respond to the 5v RC servo pulse signal on the servo header. They require 2 9v signals C1 and C2 to operate. From the signal spec on the Philohome page, I would guess that there is an H-bridge chip internal to the motor.

The power available on the servo headers is only 5v, regardless of what you use for an external supply. You need to feed your external supply voltage directly to the motors. The output of the motor channels will give you the 2 0-9v control signals you need.

adafruit_support_bill
 
Posts: 84034
Joined: Sat Feb 07, 2009 10:11 am

Re: How to use Adafruit Motor Shield V2 with Lego Servo Moto

by lionheart on Wed Oct 29, 2014 8:58 am

Thanks for your help, have a nice day.

lionheart
 
Posts: 6
Joined: Tue Oct 28, 2014 10:11 am

Re: How to use Adafruit Motor Shield V2 with Lego Servo Moto

by dose13 on Thu Sep 17, 2015 10:00 am

I am trying to run a Lego Servo of type 88004 on the adafruit shield. I wired it according to the description above and tried to run it with the following Code:

Code: Select all | TOGGLE FULL SIZE
#include <AFMotor.h>

Lego motor (15,1);

void setup(){
Serial.begin(9600);
motor.setSpeed (10);
}
void loop(){
motor.step(1,FORWARD, single);
motor.step(1, BACKWARD, single);
}


The motor was turning forward and backward but not in a defined angle. Changing the Speed did not have an influence at all. I would be happy if someone could advise on the Code. Thank`s

dose13
 
Posts: 3
Joined: Thu Sep 17, 2015 9:38 am

Re: How to use Adafruit Motor Shield V2 with Lego Servo Moto

by adafruit_support_bill on Thu Sep 17, 2015 10:26 am

The Lego Servo motor is not a stepper motor, so you can t drive it like one. We do not have any of these in-house and have not tested them. But from what I understand, you need to vary the PWM duty cycle on one of the two control lines to control the position.

adafruit_support_bill
 
Posts: 84034
Joined: Sat Feb 07, 2009 10:11 am

Re: How to use Adafruit Motor Shield V2 with Lego Servo Moto

by dose13 on Thu Sep 17, 2015 11:11 am

I found an interesting page, which shows some code for the raspberry: See here: http://raspberrypi.stackexchange.com/qu ... spberry-pi

The first section describes the assigning of the GPIOs:

#Assigning the GPIOs to the Lego's command wires
C1 = 21
C2 = 26


The datasheets for the motor shield says:
The shield uses the SDA and SCL i2c pins to control DC and stepper motors. On the Arduino UNO these are also known as A4 and A5. ... If you want to use the servo connections, they are on pins #9 and #10. ...


I´d guess I need to change the above code to either
C1 = A4 or 9 and C2 = A5 or 10

dose13
 
Posts: 3
Joined: Thu Sep 17, 2015 9:38 am

Re: How to use Adafruit Motor Shield V2 with Lego Servo Moto

by adafruit_support_bill on Thu Sep 17, 2015 12:50 pm

Based on that data, you would want to connect to 2 of the Arduino PWM pins. On the UNO that is pins 3, 5, 6, 9, 10, and 11.

adafruit_support_bill
 
Posts: 84034
Joined: Sat Feb 07, 2009 10:11 am

Re: How to use Adafruit Motor Shield V2 with Lego Servo Moto

by dose13 on Sat Oct 31, 2015 4:49 am

I didn't manage to get the motor work. When I connect my C1 and C2 to port M1, which PINs would that correspond to on the shield? According to this post: http://arduino.stackexchange.com/questi ... tor-9v-pwm the PWM signal should be 1150 Hz. According to the Arduino instruction (http://playground.arduino.cc/Code/PwmFr ... yto2_l5OsQ) each PIN has its own frequency.

The base frequency for pins 3, 9, 10, and 11 is 31250 Hz.
The base frequency for pins 5 and 6 is 62500 Hz.
Divisors:
The divisors available on pins 5, 6, 9 and 10 are: 1, 8, 64, 256, and 1024.
The divisors available on pins 3 and 11 are: 1, 8, 32, 64, 128, 256, and 1024.


Can anyone help me to understand how to get the 1150 Hz PWM signal? My guess was when connecting C1 and C2 to Pins 9 and 10 to divide the 31250 Hz / 27.17 and I am there but "27" is not allowed to be used as a divisor.

Thankś

dose13
 
Posts: 3
Joined: Thu Sep 17, 2015 9:38 am

Please be positive and constructive with your questions and comments.