Motor controller dc with trinket

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
blckpstv
 
Posts: 55
Joined: Mon Jan 06, 2014 8:06 pm

Motor controller dc with trinket

Post by blckpstv »

Hi I'm have a code that works on arduino it's a simple motor driver with the tip120.

Now I've put the same code on the trinket. But this doesn't work.
They just arrived today. So don't judge me to quick. And yes I can do a big research on this.
But time is something I don't have at the moment for this project.

this is the code:

Code: Select all

int randNumber; // variable to store the random value
int motor = 11;


 
void setup() {
randomSeed(millis()); // sets millis() as seed
} // no setup needed
void loop()
{
randomSeed(millis()); // sets millis() as seed
randNumber = random(255); // random number from 0-255
analogWrite(motor, randNumber); // outputs PWM signal
delay(3500); // pauses for half a second
}

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor controller dc with trinket

Post by adafruit_support_bill »

A few things:
1. You should only need to call randomSeed once in your setup. You don't need to call it in your loop.
2. Your delay is for 3 1/2 seconds. Not 1/2 second as it says in the comment.
3. There is no pin 11 on a Trinket. Use Pin 0 or 1, since these are the only PWM capable pins on the Trinket.

User avatar
blckpstv
 
Posts: 55
Joined: Mon Jan 06, 2014 8:06 pm

Re: Motor controller dc with trinket

Post by blckpstv »

Yeah sorry, the comments may caused confusion didn't update that, the pwm is set to 0 but still nothing.

But the code else is correct. In the sense it should do what is does on an arduino.
Because I think it's power issues than.

Is there a tip120 possibility or isn't that done on a trinket before?

Kind regards!

Code: Select all

int randNumber; // variable to store the random value
int motor = 0;


 
void setup() {
} 
void loop()
{
randomSeed(millis()); // sets millis() as seed
randNumber = random(255); // random number from 0-255
analogWrite(motor, randNumber); // outputs PWM signal
delay(3500); 
}

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor controller dc with trinket

Post by adafruit_support_bill »

Are you using a 3.3v or a 5v trinket? Post a photo of your wiring.

User avatar
blckpstv
 
Posts: 55
Joined: Mon Jan 06, 2014 8:06 pm

Re: Motor controller dc with trinket

Post by blckpstv »

It's a trinket 5v

Here are the pictures of the connections how I do them with an arduino and works in that way.


http://dewildequinten.be/4.jpg
http://dewildequinten.be/3.jpg
http://dewildequinten.be/2.jpg
http://dewildequinten.be/1.jpg

Battery's are 3.7 volt. Should that cause a problem?

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor controller dc with trinket

Post by adafruit_support_bill »

Running a 5v Trinket on 3.7v is not guaranteed to work. Better to use a 3.3v Trinket.

Also, the output voltage of your PWM pin will be lower than the Arduino, so you probably need to use a lower resistor value on the base of the TIP120 to assure that the base current is sufficient to keep it in saturation. See this page for an example: http://teachmetomake.BANNED.com/how- ... -a-switch/

User avatar
blckpstv
 
Posts: 55
Joined: Mon Jan 06, 2014 8:06 pm

Re: Motor controller dc with trinket

Post by blckpstv »

I gave 5v to the trinket thru usb, and a 9volt battery thru the motor.
But still didn't work?

The resistor value's I don't get? Shouldn't that be the same if I'm working with 5v.
The arduino works on 5v to? And I used the same voltage and it worked?

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor controller dc with trinket

Post by adafruit_support_bill »

And I used the same voltage and it worked?
Maybe you were just lucky. Looks like you are using a 10K ohm resistor which is way too high to work well - even for an Arduino. You need something in the 100-220 ohm range. See the article linked for details.

User avatar
blckpstv
 
Posts: 55
Joined: Mon Jan 06, 2014 8:06 pm

Re: Motor controller dc with trinket

Post by blckpstv »

Yeah suppossedly I was, but I've tried the 100 ohm didn't work eather.

USB powering isn't a problem for the trinket to work?

Yeah I will try to read en search for the correct value of resistor, Is going to be mind bubbling :x .

But otherwise you think the problem resides their?

Anyway, your help is already much appreciated!!!

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor controller dc with trinket

Post by adafruit_support_bill »

Did you set the pinMode to OUTPUT on your motor pin? http://arduino.cc/en/Reference/pinMode
The resistor value does not have to be exact. With 5v logic, 100-220 ohms should be fine.

User avatar
blckpstv
 
Posts: 55
Joined: Mon Jan 06, 2014 8:06 pm

Re: Motor controller dc with trinket

Post by blckpstv »

Strangest thing!

I've did the normal arduino set up again, and it worked?


Now i've got a question for the powering of the trinket and my motors with a same dc adapter (adjustable)


Do I just give it 5v and connect all the positifs to the adapter positif pin, and same for the ground.
And does everything get 5v then?

http://dewildequinten.be/5.jpg UPDATED LINK
Last edited by blckpstv on Thu Jan 09, 2014 9:16 am, edited 1 time in total.

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor controller dc with trinket

Post by adafruit_support_bill »

Your photo link does not work. But your description sounds like it will work.

User avatar
blckpstv
 
Posts: 55
Joined: Mon Jan 06, 2014 8:06 pm

Re: Motor controller dc with trinket

Post by blckpstv »

adafruit_support_bill wrote:Your photo link does not work. But your description sounds like it will work.

Updated!

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor controller dc with trinket

Post by adafruit_support_bill »

Looks good!

User avatar
blckpstv
 
Posts: 55
Joined: Mon Jan 06, 2014 8:06 pm

Re: Motor controller dc with trinket

Post by blckpstv »

Thanks so much for all your help,

Last question, can I give it 6 volt or 7.5 volts because me motor isn't getting enought power I think?
Last edited by blckpstv on Fri Jan 10, 2014 2:20 pm, edited 1 time in total.

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”