Welcome Guest! To enable all features please Login or Register.
Options
Go to last post Go to first unread
robert.roffman@gmail.com  
#1 Posted : Sunday, January 10, 2016 10:54:59 AM(UTC)
robert.roffman@gmail.com

Rank: Newbie

Groups: BetaUser, Registered
Joined: 12/25/2015(UTC)
Posts: 2

Was thanked: 2 time(s) in 2 post(s)
Hello. I have an adafruit motorshield that uses a library to run the motor. I can run the motor in an Arduino IDE, but I can't get a custom node to work.

How do I set up the custom node to do the same thing as the Arduino code?

Here's what an Arduino IDE program would look like.

#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"

// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61);

// Select which 'port' M1, M2, M3 or M4. In this case, M1
Adafruit_DCMotor *myMotor = AFMS.getMotor(4);
// You can also make another motor on port M2
//Adafruit_DCMotor *myOtherMotor = AFMS.getMotor(2);

void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Adafruit Motorshield v2 - DC Motor test!");

AFMS.begin(); // create with the default frequency 1.6KHz
//AFMS.begin(1000); // OR with a different frequency, say 1KHz

// Set the speed to start, from 0 (off) to 255 (max speed)
myMotor->setSpeed(150);
myMotor->run(FORWARD);
// turn on motor
myMotor->run(RELEASE);
}

void loop() {
uint8_t i;

Serial.print("tick");

myMotor->run(FORWARD);
myMotor->setSpeed(200);

}

When I try to create a custom node here is what I am putting in.

INCLUDES:
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"

DECLARATIONS:
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// Select which 'port' M1, M2, M3 or M4.
Adafruit_DCMotor *myMotor = AFMS.getMotor(4);

SETUP:

AFMS.begin(); // create with the default frequency 1.6KHz
//AFMS.begin(1000); // OR with a different frequency, say 1KHz
// Set the speed to start, from 0 (off) to 255 (max speed)
myMotor->setSpeed(200);
myMotor->run(FORWARD);
// turn on motor
myMotor->run(RELEASE);

NEW CODE BLOCK:
myMotor->run(FORWARD);
myMotor->setSpeed(200);





thanks 1 user thanked robert.roffman@gmail.com for this useful post.
sample@email.tst on 4/7/2024(UTC)
EmbrioAdmin  
#2 Posted : Sunday, January 10, 2016 5:55:53 PM(UTC)
EmbrioAdmin

Rank: Administration

Groups: Administrators
Joined: 12/11/2014(UTC)
Posts: 661

Thanks: 1 times
Was thanked: 109 time(s) in 104 post(s)
I see a couple things that might be causing issues. Are you getting any errors or is it just not working?

First, leave the serial.begin stuff out. Embrio uses the Serial stuff do communicate while in connection mode, so that could maybe be interfering.

Make sure you're source files (like Adafruit_MotorShield.h and .cpp) are added to the project using the form in view -> Include Files. You might want to either move Adafruit_PWMServoDriver.h to a root folder so you can remove the "utility" part, or add the utility folder using the "Load Folders" button on the include folder.

Once it's working, you'll want to control the speed with an input activation, do that by transforming an activation to the range of 0 to 255.

Below is a quick node I put together. Note that I didn't test this because I don't have the hardware or source files, but I think it should work. You can copy and paste the below XML into a node screen editor in Embrio (an easier way to share than writing out the code again).

Let me know if that works or you're still stuck!

thanks 1 user thanked EmbrioAdmin for this useful post.
sample@email.tst on 4/7/2024(UTC)
robert.roffman@gmail.com  
#3 Posted : Thursday, March 03, 2016 9:26:45 PM(UTC)
robert.roffman@gmail.com

Rank: Newbie

Groups: BetaUser, Registered
Joined: 12/25/2015(UTC)
Posts: 2

Was thanked: 2 time(s) in 2 post(s)
This worked, but I'm now using a different shield and I can't get this to work in embrio.

The connection is good, but the motor won't work even though I included <AFMotor.h> in the view. I also attached a startup trigger, but still not working.

The code works in Arduino. Here's the code in Arduino


#include <AFMotor.h>

AF_DCMotor motor(4);

void setup() {
// turn on motor
motor.setSpeed(200);
motor.run(RELEASE);
}

void loop() {
motor.run(FORWARD);
motor.setSpeed(200);
}


I put in the custom node as follows


#include <AFMotor.h>

Declarations:

AF_DCMotor motor(4);

setup code:

// turn on motor
motor.setSpeed(200);
motor.run(RELEASE);


new code block
motor.run(FORWARD);
motor.setSpeed(200);


thanks 1 user thanked robert.roffman@gmail.com for this useful post.
sample@email.tst on 4/7/2024(UTC)
EmbrioAdmin  
#4 Posted : Friday, March 04, 2016 3:55:12 AM(UTC)
EmbrioAdmin

Rank: Administration

Groups: Administrators
Joined: 12/11/2014(UTC)
Posts: 661

Thanks: 1 times
Was thanked: 109 time(s) in 104 post(s)
I can't see what the problem is from what you posted. Are you getting any errors or the motor doesn't spin after a good upload?

Could you zip the project folder and send it to ezra@embrio.io so I can get a better look?
thanks 1 user thanked EmbrioAdmin for this useful post.
sample@email.tst on 4/7/2024(UTC)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Notification

Icon
Error