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.

Kirk K

Member Since 18 Apr 2012
Offline Last Active Jun 14 2013 02:03 AM
-----

Posts I've Made

In Topic: NetduinoGo Shieldbase SPI hookup

10 June 2013 - 02:19 PM

Thanks for all the input guys. I will be shelving the NGO for the time being I am leaning towards a +2. While the GO has the potential to be a great device, it is beginning to fall behind the other development boards. I was an earlier adapter of this board because of the potential, but I am now sadden by the fact that this board is going nowhere fast and it seems to be losing traction. Maybe if I understand the concept of building modules the NoGO will be interesting again. 

 

@NooM

Thanks I will try the provided code tonight and keep you guys posted.

 

 

Thanks,

Kirk


In Topic: Hardware Details: Shield Base

29 June 2012 - 02:49 PM

I have few couple question. Does the ShieldBase currently support I2CDevices and SPI devices? If not, will there be an updated driver coming out soon? Base on the pinout of the ShieldBase, which headers would I connect a I2CDevice to that of PIN_A4/PIN_A5 or that of SCL/SDA? Thanks, Kirk

In Topic: ShieldBase Threading

28 June 2012 - 01:45 AM

Hi Kirk,


If you can create a ~10 line repro, we'd love to test it out. I'll put this on our short list, to address with the UART->SPI update. We'll be updating the C# class drivers anyway, so this is a good issue to work out :)

Chris


Here goes
 public class Program
    {
        private static ShieldBase _ShieldBase;
        private static InputPort _Pin1;
        private static InputPort _Pin2;
        public static void Main()
        {
            // write your code here
            _ShieldBase = new ShieldBase(GoSockets.Socket4);
            _Pin1 = new InputPort(_ShieldBase.Pins.GPIO_PIN_A4, false, Port.ResistorMode.Disabled);
            _Pin2 = new InputPort(_ShieldBase.Pins.GPIO_PIN_A5, false, Port.ResistorMode.Disabled);
            Program prog = new Program();
            Thread sec1 = new Thread(prog.ReadPin1);
            sec1.Start();
            prog.ReadPin2();
        }
        public void ReadPin1()
        {
            while(true)
            {
                var ret = _Pin1.Read();
                Thread.Sleep(500);
            }
        }
        public void ReadPin2()
        {
            while(true)
            {
                _Pin2.Read();
                Thread.Sleep(50); 
            }
            
        }

    }

In Topic: ShieldBase Threading

27 June 2012 - 09:08 PM

Hi Kirk,

Very interesting. We use the Shield Base with multiple threads regularly and haven't seen this issue. But we may not have created enough work to trigger a thread switch :)

To confirm -- when you use the lock mechanism then it works fine for you? But when you don't use the lock mechanism, you get exceptions?

If that's the case, we can fix that in an update. Virtual IO resources should have the same thread safety as physical IO resources...you shouldn't have to worry about it.

Chris


Thanks Guys,

The locking mechanism does work fine as presented in the code. Without it, as soon as a secondary thread starts a read/write operation on another pin while another thread read/write is in process, the ShieldBase throws an exception. I can easily reproduce the exceptions with the above locking mechanism removed.

In Topic: Shield Base Firmware v4.2.0.1 (beta 1)

23 June 2012 - 05:44 AM

This is my first go at any *duino boards. I have a background in C# and after watching the webcast, became very interested in the Netduino Go. So I purchased one along with two shieldbases, how my excitement was short lived as the project that I am planning on working on requires multiple servos. To make matters worst, I could not get my sheildbase to properly pulse my servo.

After updating my shield base firmware I am smiling again. So here is my first go:


public class Program
    {
        public static bool IsClosing = false;
         public static void Main()
        {
            Thread[] servoThreads = new Thread[4]; //Create an array to hold servo threads
            // write your code here
            using(ShieldBase sb = new ShieldBase(GoSockets.Socket5)) //Create the ShieldBase instance
            {
                Servo _Servo1 = new Servo(sb.PWMChannels.PWM_0); //Create the servo1 object. This is connected to Digital I/O PIN 5
                Thread t1 = new Thread(new ThreadStart(_Servo1.ActivateServo)); //Create the child thread to run the first servo
                t1.Start(); //Starts the thread
                servoThreads[0] = t1;
                //Do some work
                Thread.Sleep(1000);
                _Servo1.Degree = 180;
                Thread.Sleep(1000);
                _Servo1.Degree = 0.1;
                Thread.Sleep(1000);
                _Servo1.Degree = 90;
                Thread.Sleep(1000);
                IsClosing = true;

                bool isChildThreadAlive = true;
                while(isChildThreadAlive) //Ensure that the child thread(s) have fully exited before closing parent
                {
                    for(int i = 0; i < servoThreads.Length; i++)
                    {
                        if(servoThreads[i] == null)
                            continue;
                        if(servoThreads[i].IsAlive)
                        {
                            isChildThreadAlive = servoThreads[i].IsAlive;
                            break;
                        }
                        isChildThreadAlive = false; //Go ahead and exit no active servo threads found 
                    }
                    Thread.Sleep(500);
                }
            }
        }


    }

    public class Servo
    {
        uint _Duration = 0;
        public double Degree
        {
            set
            {
                _Duration = CalculatePulseFromDegrees(value);
            }
        }
        private Microsoft.SPOT.Hardware.Cpu.PWMChannel _Channel;
        public Servo(Microsoft.SPOT.Hardware.Cpu.PWMChannel pwmChannel)
        {
            _Channel = pwmChannel;
            _Duration = CalculatePulseFromDegrees(90);
        }

        private uint CalculatePulseFromDegrees(double degree)
        {
            uint neutralPulse = 1500; //This represent the neutral pulse time (in microsecond) of the servo typically when the servo is at 90 degrees. ;
            float factor = neutralPulse / 90; //This value represent pulse time when the servo is at 1 degree;
            uint outPulse = (uint)(factor * degree);
            return outPulse;
        }
        public void ActivateServo()
        {
            using(PWM pwm = new PWM(_Channel, 20000, _Duration, PWM.ScaleFactor.Microseconds, false)) //Initializes PWM port
            {
                pwm.Start(); //Start the PWM port
                while(!Program.IsClosing) //Loop until we get a signal to exit
                {
                    pwm.Duration = _Duration; //Sets the duration. This value tells the servo how far to move
                    Thread.Sleep(10); //Sleep for 10ms. 
                }
                pwm.Stop();
            }
           
        }
    }

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.