Kalix - Viewing Profile: Posts - Netduino Forums
   
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.

Kalix

Member Since 23 Jan 2013
Offline Last Active Private
-----

Posts I've Made

In Topic: Compatible Shields and Accessories

19 February 2013 - 07:26 AM

Hi all!

I´m an absolutely newbie to .NETMF programming and love to spent some time as a hobbyist on this platform. To be honest my personal programming experience lasts back to my university time when I was programming in Turbo Pascal and a little assembler... (which is more than 25 years ago)

I have some understanding of the C, C++ and even C#, read some books, did some small practice (and forgot many things, as I didn´t find the time to consecutively follow my trail aside of my job).

I bought a Netduino 2+ and for some trials a Nootropic design 4 digit shield, a Adafruit Motorshield and a luminosity sensor. Thanks to you guys I already found some porting for the motor control, but I´m struggling with the digit shield. It uses 4 pins and uses a timer interrupt controlled multiplexing. What I´ve understood so far from the Arduino library provided by Nootropic, is that the concept is based on using a shift register for the data (taking 1 pin), a clock pin, a latch pin and a control pin for decimal point on/off. Many of the inherited methods appear quite simple, but especially this timer issue is giving me headache. I have tried to figure out, whether and how this ISR concept could be ported ....but to be honest: I HAVE GOT NO CLUE

Has anyone played around with this shield yet?

Thx in advance from a desperate bloodie newbie.......

Hi Vol_Del,

First of all, I do not have the [color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]Nootropic design 4 digit shield you are talking about, however the technique used to write to the 4 digit shield is the same used in the Motor driver above your post. Both shields use a 74HC595 serial to parallel latch. Take a look at the: [/color]latch_tx(); method and the assignment: latch_state [color=rgb(102,102,0);]=[/color] [color=rgb(102,102,0);]([/color][color=rgb(0,0,136);]byte[/color][color=rgb(102,102,0);])(([/color]latch_state [color=rgb(102,102,0);]&[/color] [color=rgb(0,102,102);]0xBE[/color][color=rgb(102,102,0);])[/color] [color=rgb(102,102,0);]|[/color] [color=rgb(102,102,0);]([/color]direction [color=rgb(102,102,0);]?[/color] [color=rgb(0,102,102);]1[/color] [color=rgb(102,102,0);]:[/color] [color=rgb(0,102,102);]64[/color][color=rgb(102,102,0);]));[/color]

If you use a windows calculator (set to programmer mode) you will find that 0xBE translates into the bit pattern 10111110 in the code above either the first bit or the seventh bit is set. The latch_tx method is all you need to write the 8 bits to the 74HC595. For more information about the 74HC595 I recommend reading this article: http://arduino.cc/en/Tutorial/ShiftOut .

The other IC on the Nooptric shield will translate the binary pattern of the 74HC595 to the 7-segment display so you do not have to do that yourself.

 

Hope this helps you a bit.

 

One more thing to keep in mind is the use of pins when stacking shields on top of each other.

The Adafruit Motor shield uses quite a lot of pins. The information below might help you:

 

 
What pins can be used for external components on the Arduino with Ladyada's Motor Shield?
 
Answer:
 
What pins are not used on the motor shield?
All 6 analog input pins are available. They can also be used as digital pins (pins #14 thru 19)
 
Digital pin 2, and 13 are not used.
 
Digital pin 11: DC Motor #1 / Stepper #1 (activation/speed control)
Digital pin 3: DC Motor #2 / Stepper #1 (activation/speed control)
Digital pin 5: DC Motor #3 / Stepper #2 (activation/speed control)
Digital pin 6: DC Motor #4 / Stepper #2 (activation/speed control)
These pins are in use only if the DC/Stepper noted is in use
 
Digital pin 4, 7, 8 and 12 are used to drive DC motors and Stepper motors via the 74HC595 
serial-to-parallel latch
All these pins are in use if any DC motors or steppers are used
 
Digitals pin 9: Servo #1 control
Digital pin 10: Servo #2 control
These pins are used only if that particular servo is in use
These pins are used only if that particular servo is in use

In Topic: Compatible Shields and Accessories

10 February 2013 - 10:05 PM

Just got the  http://learn.adafrui...shield/overview shield working on a Netduino plus 2 with 4 DC motors (Have not tested servos or steppers yet).

Did have to modify some of the codesamples I found because of difference in PWM classes. (Code now only supports 4 DC motors all PWM controlled).

using System;using System.Threading;using Microsoft.SPOT.Hardware;using SecretLabs.NETMF.Hardware;using SecretLabs.NETMF.Hardware.Netduino;namespace Robot.Drivers.Adafruit{    public class MotorShield : IDisposable    {        public enum Drivers : byte        {            None = 0,            Driver1,            Driver2,            Both        }        public enum Motors : byte        {            M1 = 0,            M2,            M3,            M4        }                private Drivers UsedDriver;        private PWM Motor1;        private PWM Motor2;        private PWM Motor3;        private PWM Motor4;        private OutputPort MotorLatch, MotorEnable, MotorClk, MotorData; // 74HCT595 commands        byte latch_state; // Actual 74HCT595 output state        double MaxSpeed;        /// <summary>        /// Constructor        /// </summary>        /// <param name="driver"> Which driver to initialize : 1=driver 1, 2=driver 2, 3=both</param>        public MotorShield(Drivers driver = Drivers.Both, double pwmfrequency = 20000, double maxspeed = 255D)        {            UsedDriver = driver;            if (driver == Drivers.Driver1 || driver == Drivers.Both)            {                Motor1 = new PWM(PWMChannels.PWM_PIN_D11, pwmfrequency, 0, false);                Motor1.Start();                Motor2 = new PWM(PWMChannels.PWM_PIN_D3, pwmfrequency, 0, false);                Motor2.Start();            }            if (driver == Drivers.Driver2 || driver == Drivers.Both)            {                Motor3 = new PWM(PWMChannels.PWM_PIN_D6, pwmfrequency, 0, false);                Motor3.Start();                Motor4 = new PWM(PWMChannels.PWM_PIN_D5, pwmfrequency, 0, false);                Motor4.Start();            }            MotorLatch = new OutputPort(Pins.GPIO_PIN_D12, true);            MotorEnable = new OutputPort(Pins.GPIO_PIN_D7, false);            MotorClk = new OutputPort(Pins.GPIO_PIN_D4, true);            MotorData = new OutputPort(Pins.GPIO_PIN_D8, true);            MaxSpeed = maxspeed;            latch_state = 0;            latch_tx();        }        #region IDisposable Members        public void Dispose()        {            latch_state = 0;            latch_tx();            if (UsedDriver == Drivers.Driver1 || UsedDriver == Drivers.Both)            {                Motor1.Dispose();                Motor2.Dispose();            }            if (UsedDriver == Drivers.Driver2 || UsedDriver == Drivers.Both)            {                Motor3.Dispose();                Motor4.Dispose();            }            MotorLatch.Dispose();            MotorEnable.Dispose();            MotorClk.Dispose();            MotorData.Dispose();        }        #endregion IDisposable Members                // Send byte to the 74HCT595 demux        private void latch_tx()        {            MotorLatch.Write(false);            MotorData.Write(false);            for (int i = 0; i < 8; i++)            {                MotorClk.Write(false);                bool bitdata = (latch_state & (1 << (7 - i))) > 0;                MotorData.Write(bitdata);                MotorClk.Write(true);            }            MotorLatch.Write(true);        }                /// <summary>        /// Control a motor; Non-blocking call. Set speed to 0 to stop.        /// Frequency might need to be adjusted deppending on motor, or to match other PWMs        /// </summary>        /// <param name="which">Which motor to drive</param>        /// <param name="speed">Speed, between 0 and MaxSpeed supplied in Constructor (0 to stop)</param>        /// <param name="direction">True = foward, False = backward</param>        public void MotorControl(Motors which, int speed, bool direction)        {            switch (which)            {                case Motors.M1: // This motor can have its speed controlled through PWM                    if (speed == 0)                    {                        Motor1.DutyCycle = 0;                    }                    else                    {                        latch_state = (byte)((latch_state & 0xF3) | (direction ? 4 : 8));                        latch_tx();                        uint duration = (uint)(Motor1.Period * (double)speed / MaxSpeed);                        Motor1.Duration = duration;                    }                    break;                case Motors.M2: // This motor can have its speed controlled through PWM                    if (speed == 0)                    {                        Motor2.DutyCycle = 0;                    }                    else                    {                        latch_state = (byte)((latch_state & 0xED) | (direction ? 2 : 16));                        latch_tx();                        uint duration = (uint)(Motor2.Period * (double)speed / MaxSpeed);                        Motor2.Duration = duration;                    }                    break;                case Motors.M3: // This motor can have its speed controlled through PWM                                      if (speed == 0)                    {                        Motor3.DutyCycle = 0;                    }                    else                    {                        latch_state = (byte)((latch_state & 0xBE) | (direction ? 1 : 64));                        latch_tx();                        uint duration = (uint)(Motor3.Period * (double)speed / MaxSpeed);                        Motor3.Duration = duration;                    }                    break;                case Motors.M4: // This motor can have its speed controlled through PWM                                      if (speed == 0)                    {                        Motor4.DutyCycle = 0;                    }                    else                    {                        latch_state = (byte)((latch_state & 0x5F) | (direction ? 32 : 128));                        latch_tx();                        uint duration = (uint)(Motor4.Period * (double)speed / MaxSpeed);                        Motor4.Duration = duration;                    }                    break;            }        }    }}

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.