Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Circuit works on Arduino but not on my Netduino 2

dc motor netduino 2

  • Please log in to reply
5 replies to this topic

#1 kumaichi

kumaichi

    New Member

  • Members
  • Pip
  • 3 posts

Posted 23 April 2014 - 03:15 AM

Hi All,

 

New to the Netduino and excited to get started.  I'm having a bit of trouble though.  I already had a Arduino UNO and decided to go with a Netduino 2.  The problem I'm having is, my circuit to run a dc motor works fine on the Arduino but when I hook it up to my Netduino it doesn't work.  I think it's either my code is incorrect or maybe it's a power issue?  I originally followed this tutorial for setting up my circuit for the Arduino, https://www.youtube....h?v=sOz41WQF7wE which works great.

 

I then hooked up my Netduino using the same pins, ground and +5v and here is my code:

public static void Main()
{
    AnalogInput hall = new AnalogInput(Cpu.AnalogChannel.ANALOG_0);
    OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
    InputPort switchPin = new InputPort(Pins.GPIO_PIN_D2, false, Port.ResistorMode.Disabled);
    OutputPort motor = new OutputPort(Pins.GPIO_PIN_D9, false);
    
    double value = 0.0;

    while (true)
    {
        //Do calculation to get the actual volts for an analog input
        value = ((hall.Read() * 1000) / 1023) * 3.3;
        //Take into account north/south pole magnets
        if (value <= 0.01 || value >= 3.17)
            led.Write(true);
        else
            led.Write(false);
        
        Debug.Print(value.ToString("f02"));

        if (switchPin.Read())
        {
            motor.Write(true);
            led.Write(true);
        }
        else
        {
            motor.Write(true);
            led.Write(false);
        }
    }
}

My led lights up when I press the button but my motor never runs.

 

Thanks for any suggestions :).



#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 23 April 2014 - 01:22 PM

Hi kumaichi,

The digital outputs on Netduino are 3.3V (rather than 5V) and they're designed for digital IO--not for driving motors. Whether on Netduino or Arduino, you really want to be using an H-Bridge (see: motor shield) to provide current for your motor; we highly recommend that you don't drive motors using digital IO pins.

Unrelated to this, but just FYI...the code above is doing "motor.Write(true)" whether the switch is pressed or not. You may want to tweak one of those to false, for the expected behavior, once you have an H-Bridge acting as the motor driver.

Does that get you pointed in the right direction?

Chris

#3 kumaichi

kumaichi

    New Member

  • Members
  • Pip
  • 3 posts

Posted 23 April 2014 - 06:44 PM

Hi Chris,

 

Thanks for the response.  I set the "motor.Write(true)" for both cases in case the button wasn't hooked up right, gotta love those beginning hardware guys ;)

 

If I understood the video correctly, using the MOSFET actually opens up the gate that allows the power from the 9v battery to run the motor right?  That way it doesn't cause any issues on the Netduino board.  Just trying to understand this correctly is all.

 

Thanks again,

 

Craig



#4 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 23 April 2014 - 07:14 PM

Hi Craig,

Using a FET will let you turn power on/off to the motor using your digital IO pin...and even control speed via PWM.

Even better...if you use an H-Bridge then you can drive the motor in either direction, do advanced braking, etc.

In both cases, you're effectively controlling power delivery from a power source...rather than providing power directly from your digital IO pins.

Chris

#5 kumaichi

kumaichi

    New Member

  • Members
  • Pip
  • 3 posts

Posted 23 April 2014 - 07:17 PM

I think I'll go the H-Bridge route, I'll have to see what Spark Fun has in that area. 

 

It seems kind of odd though that the circuit works on the Arduino but doesn't work for the Netduino.

 

Thanks again,

 

Craig



#6 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 23 April 2014 - 08:27 PM

Hi Craig,

It seems kind of odd though that the circuit works on the Arduino but doesn't work for the Netduino.

A bit of insight on that: 8-bit AVRs run at 5V (higher electric pressure)...and AVR pins are rated to deliver up to 40mA. I really wouldn't recommend driving a motor off of an AVR pin either, but both the electric pressure and current are quite a bit higher on those pins (generally for direct-driving of LEDs and such).

Chris





Also tagged with one or more of these keywords: dc motor, netduino 2

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.