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

NoobShield on Shield Base


  • Please log in to reply
9 replies to this topic

#1 Arron Chapman

Arron Chapman

    Advanced Member

  • Members
  • PipPipPip
  • 289 posts
  • LocationOregon, USA

Posted 08 April 2012 - 08:00 AM

Just a quick test I wrote up using a PWM pin on the Shield Base to play a song on the NoobShield's buzzer.

http://www.youtube.com/watch?v=3iVuuBZACP0

The code for this is fairly straight forward.

using System.Threading;
using NetduinoGo;
using SecretLabs.NETMF.Hardware.NetduinoGo;
using PWM = Microsoft.SPOT.Hardware.PWM;

namespace NetduinoGo_ShieldBase
{
    public class Program
    {
        public static void Main()
        {
			//No auto detection for the port
            ShieldBase sb = new ShieldBase(GoSockets.Socket2);
			
			//PWMCHannles.PWM_3 is Digital 10
            PWM speaker = new PWM(sb.PWMChannels.PWM_3, 50, .5, false);

			//Old McDonald code is taken from Chris Walker's book "Getting Started with Netduino"
            System.Collections.Hashtable scale = new System.Collections.Hashtable
                                                     {
                                                         {"c", 1915u},
                                                         {"d", 1700u},
                                                         {"e", 1519u},
                                                         {"f", 1432u},
                                                         {"g", 1275u},
                                                         {"a", 1136u},
                                                         {"b", 1014u},
                                                         {"C", 956u},
                                                         {"D", 851u},
                                                         {"E", 758u},
                                                         {"h", 0u}
                                                     };

            int beatsPerMinute = 90;
            int beatTimeInMilliseconds =
            60000 / beatsPerMinute; // 60,000 milliseconds per minute
            int pauseTimeInMilliseconds = (int)(beatTimeInMilliseconds * 0.1);

            // define the song (letter of note followed by length of note)
            string song = "C1C1C1g1a1a1g2E1E1D1D1C2";

            while (true)
            {
                for (int i = 0; i < song.Length; i += 2)
                {
                    // extract each note and its length in beats
                    string note = song.Substring(i, 1);
                    int beatCount = int.Parse(song.Substring(i + 1, 1));
                    uint noteDuration = (uint) scale[note];

                    speaker.Duration = noteDuration;
                    speaker.Period = noteDuration*2;

                    speaker.Start();

                    Thread.Sleep(beatTimeInMilliseconds*beatCount - pauseTimeInMilliseconds);

                    speaker.Stop();

                    Thread.Sleep(pauseTimeInMilliseconds);
                }
            }

            Thread.Sleep(Timeout.Infinite);
        }

    }
} 

When you talk EE use small words, I'm just a Software Developer :)
My Blog/Site and Everything Else

If my post helped you please consider pressing the "Like This" button in the bottom right-hand corner.

 

Oh my. So many things, so little money!!

 


#2 Gutworks

Gutworks

    Advanced Member

  • Members
  • PipPipPip
  • 363 posts
  • LocationOttawa, Ontario

Posted 11 April 2012 - 04:16 PM

Hi Arron,

I have tried your code this morning but had little success. It would seem the reference to the Microsoft.Hardware.PWM is causing troubles. If I run any code with that reference it seems freeze. In a couple of cases it crashed my computer.

For example if I used this code without the PWM reference everything works fine. However when I add the reference nothing seems to happen and VS stops debugging and even skips the while loop. What could I be missing?

I have the following reference added to my project when it crashes, and am using .NETMF 4.2:
GoBus
Microsoft.SPOT.Hardware
Microsoft.SPOT.Hardware.PWM
Microsoft.SPOT.Native
mscorlib
NetduinoGo.Shieldbase
Secretlabs.NETMF.Hardware.NetduinoGo

using System.Threading;
using NetduinoGo;
using SecretLabs.NETMF.Hardware.NetduinoGo;
using Microsoft.SPOT;

namespace NetduinoGo_ShieldBasePiezo
{
    public class Program
    {
        public static void Main()
        {
            ShieldBase sb = new ShieldBase(GoSockets.Socket2);
            Microsoft.SPOT.Hardware.OutputPort ledPort = new Microsoft.SPOT.Hardware.OutputPort(sb.Pins.GPIO_PIN_A5, false);
            ledPort.Write(false);
            while (true)
            {
                ledPort.Write(!ledPort.Read());
                System.Threading.Thread.Sleep(250);

            }            
        }
    }
}


#3 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 11 April 2012 - 08:16 PM

Hi Gutworks, Can you build a new basic project and then add one thing at a time until it breaks? For instance, just blink an LED. Then add the PWM reference and redeploy. Then try to create a PWM object, etc. If we can narrow down the action or line of code that's causing this for you, we can debug and then update the Shield Base beta firmware (if we can fix the issue there). Chris
  • Arron Chapman likes this

#4 Gutworks

Gutworks

    Advanced Member

  • Members
  • PipPipPip
  • 363 posts
  • LocationOttawa, Ontario

Posted 11 April 2012 - 08:47 PM

Hi Chris, I did that and it seems to fail the moment I add the reference to the Microsoft.SPOT.Hardware.PWM, regardless if I add using PWM = Microsoft.SPOT.Hardware.PWM; to the source code. I have also tried replicating the SparkFun Inventor's Kit / CIRC-10 | Temperature tutorial, but have been having some errors using the AnalogInputs. I will post that elsewhere though. Thank you for the help and all the time you put into these boards. Though I must say that even though your a hero in this fantastic community, my wife doesn't "appreciate" you as much ;) Thanks, Steve

#5 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 11 April 2012 - 08:51 PM

Hi Steve, Oh, this will be important... Are you using the .NET MF 4.2 QFE1 SDK? The "QFE1" part is important. Microsoft updated the PWM to v4.2.0.1. If you're using the older 4.2 SDK, Visual Studio won't be able to deploy your project successfully. Chris

#6 Gutworks

Gutworks

    Advanced Member

  • Members
  • PipPipPip
  • 363 posts
  • LocationOttawa, Ontario

Posted 11 April 2012 - 09:08 PM

Hi Steve,

Oh, this will be important...

Are you using the .NET MF 4.2 QFE1 SDK? The "QFE1" part is important. Microsoft updated the PWM to v4.2.0.1. If you're using the older 4.2 SDK, Visual Studio won't be able to deploy your project successfully.

Chris


Hmm, I installed this past weekend the SDK 4.2 (RTM QFE1), but the version shown in VS is Microsoft .NET Micro Framework SDK Version 4.2.0.0. I was confused on which I should download. Should I be installing the Porting Kit instead of the SDK? I just 'assumed' the SDK was the latest and greatest.

#7 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 11 April 2012 - 09:14 PM

Hi Gutworks, Hmm, if you just downloaded it then it should be the QFE1 SDK. If you right-click on Microsoft.SPOT.Hardware.PWM.dll in your references and click "properties" what is its version number? If it's 4.2.0.0 instead of 4.2.0.1, please uninstall your current .NET MF 4.2 SDK and grab the QFE1 version instead. You can also download the PK if you want--but that's meant for compiling your own firmware. Chris

#8 Gutworks

Gutworks

    Advanced Member

  • Members
  • PipPipPip
  • 363 posts
  • LocationOttawa, Ontario

Posted 12 April 2012 - 03:47 AM

Hi Gutworks,

Hmm, if you just downloaded it then it should be the QFE1 SDK.

If you right-click on Microsoft.SPOT.Hardware.PWM.dll in your references and click "properties" what is its version number? If it's 4.2.0.0 instead of 4.2.0.1, please uninstall your current .NET MF 4.2 SDK and grab the QFE1 version instead.

You can also download the PK if you want--but that's meant for compiling your own firmware.

Chris

Well, I installed the SDK and PK, re-installed (after realizing that it is only the PWM that is 4.2.0.1 and not the entire framework :)), but still had some issues. At first it would only play the first few notes. Then it wouldn't play anything. I added some Debug statements and saw that it was iterating through the loop, and so I added the Led (from your Shield sample code) and flashed it on every note change. The Led flashed successfully but the piezo didn't make a peep. I checked the wires and even tried a couple of other piezos.

The last time I tried it, the code froze, as it has a few times in other shield tests, and I was unable to stop the debug process. When I pulled out the USB cable my computer crashed. Then low and behold while rebooting, in a mocking tone, Old McDonald chirped away with a flashing LED.

It does seem to be working consistently right now, however I wonder if there is some sort of issue with the PWM? However it is much more likely it's my innate ability to crash the code. :D

I really appreciate the help Chris. Thanks.

Steve

#9 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 12 April 2012 - 04:25 AM

Hi Gutworks, There could be a glitch in the PWM. We'll try to repro. Is anyone else getting intermittent reliability with the PWM feature on the Shield Base (beta)? Using it as a shield base -- or deploying code straight to the board? Chris

#10 izuino

izuino

    New Member

  • Members
  • Pip
  • 3 posts

Posted 30 April 2012 - 04:03 PM

Is anyone else getting intermittent reliability with the PWM feature on the Shield Base (beta)? Using it as a shield base -- or deploying code straight to the board?

Hi Chris,

Just got my N-Go with its shield base (beta), and I am having pretty much the same trouble with it as Gutworks. Using either the code you or he had provided, the program seems to work perfectly fine (the loop is looping) but the led is not turning off even though !ledPort.Read() changes value at each turn.

I am using the 4.2.0.1 of the Microsoft.SPOT.Hardware.PWM. I installed everything in the right order.

Please let me know if you have any idea about this problem.

Cheers.




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.