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.

deashute

Member Since 07 Oct 2013
Offline Last Active Dec 06 2013 07:36 PM
-----

Topics I've Started

Understanding I2C

30 October 2013 - 10:36 PM

Hi all,

 

I am a relative beginner when it comes to Netduino programming. I am attempting to use an Adafruit Motor Shield v2 with my Netduino Plus 2 to control two stepper motors. I've done a bit of research into the I2C protocol, but find myself somewhat confused about it's implementation, and how I can directly use it to control the steppers. Does anyone out there think they can help me to understand I2C's implementation?

 

Thanks,

Dean

 

 

I suppose I should also mention that I have, in searching the forums, found many an example of how to initialize an I2C device, however I am unsure of how to directly communicate with said device once initialized.


Netduino, AdaFruit Motor Shield, and Stepper Motors

21 October 2013 - 10:32 PM

Hello all,

 

I am fairly new to Netduino programming, and am trying to work specifically with a project using stepper motors. I have:

 

  • a Netduino Plus 2
  • 2 Stepper Motors
  • 1 AdaFruit Motor Shield v2.0

 

I have been trying to use a variant of the code from this blog post to program my Netduino and run the stepper motors, but currently am striking out.

http://blog.codeblac...ppermotors.aspx

 

I have looked through the forums, and found this topic here. It has been very helpful so far, but I have a new problem.

 

The first thing I realize was that the SecretLabs.NETMF.hardware references were defaulting to version 4.1, which I resolved fairly quickly by updating those references. Now that I've changed that though, I have been receiving an error on the Motorshield.cs file.

 

Lines 12 and 13 have been returning an error stating that "The expression being assigned to 'Codeblack.Micro.GettingStarted.MotorShield.MotorShield.PWM_0A' must be constant". Prior to updating the references, I received no such errors. Does anyone have any idea why this could have changed?
 

 

"public const Cpu.Pin PWM_0A = Pins.GPIO_PIN_D6; // M4
public const Cpu.Pin PWM_0B = Pins.GPIO_PIN_D5; // M3"

using System;using Microsoft.SPOT;using Microsoft.SPOT.Hardware;using SecretLabs.NETMF.Hardware.NetduinoPlus;namespace Codeblack.Micro.GettingStarted.MotorShield{    public class MotorShield    {        #region Constants        public const Cpu.Pin PWM_0A = Pins.GPIO_PIN_D6; // M4        public const Cpu.Pin PWM_0B = Pins.GPIO_PIN_D5; // M3        #endregion        #region Private fields        private static MotorShield instance = new MotorShield();        private byte latchState = 0x00;        private OutputPort motorLatch;        private OutputPort motorClock;        private OutputPort motorEnable;        private OutputPort motorData;        #endregion        #region Properties        public byte LatchState        {            get { return this.latchState; }        }        #endregion        #region Static properties        public static MotorShield Instance        {            get { return instance; }        }        #endregion        #region Constructor        private MotorShield()        {            this.motorLatch = new OutputPort(Pins.GPIO_PIN_D12, false);            this.motorClock = new OutputPort(Pins.GPIO_PIN_D4, false);            this.motorEnable = new OutputPort(Pins.GPIO_PIN_D7, false);            this.motorData = new OutputPort(Pins.GPIO_PIN_D8, false);        }        #endregion        #region Methods        internal void LatchTx(byte latchState)        {            this.latchState = latchState;            //LATCH_PORT &= ~_BV(LATCH);            this.motorLatch.Write(false);            //SER_PORT &= ~_BV(SER);            this.motorData.Write(false);            for (int i = 0; i < 8; i++)            {                //CLK_PORT &= ~_BV(CLK);                this.motorClock.Write(false);                int mask = (1 << (7 - i));                if ((this.latchState & mask) != 0)                {                    //SER_PORT |= _BV(SER);                    this.motorData.Write(true);                }                else                {                    //SER_PORT &= ~_BV(SER);                    this.motorData.Write(false);                }                //CLK_PORT |= _BV(CLK);                this.motorClock.Write(true);            }            //LATCH_PORT |= _BV(LATCH);            this.motorLatch.Write(true);        }        #endregion    }}

Thanks in advance,

Dean


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.