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.

Omar (OZ)

Member Since 11 Aug 2010
Offline Last Active Nov 18 2016 09:24 PM
****-

#32833 Seven Segment Display Demos

Posted by Omar (OZ) on 28 July 2012 - 03:51 AM

First the odd public embarrassment... Matt did an awesome job with this module! Both the hardware and drivers are very very nice. Edit: I will add videos as I make more, to avoid spamming the forum with random little videos :) subscribe on youtube to catch them all! Code - Attached File  ComboLock.zip   119.74KB   16 downloads Code - http://sdrv.ms/MUeRa3 Let me know if i can clear something up, I'd be happy to help.


#16883 Netduino USB HID Touch Screen Keyboard

Posted by Omar (OZ) on 20 August 2011 - 07:20 PM

This is a touch screen keyboard with most keys found on a regular keyboard. It is a USB touch screen keyboard powered by 4DGL code, .netmf USB HID code (uses my USB HID Keyboard class). This runs on the 32PT touch screen from 4D Systems, and a netduino. You can use the keyboard class without the screen. Attached File  Netduino Touch Keyboard.zip   165.82KB   211 downloads Here is the screen's code: Attached File  screen 4DGL code.txt   8.84KB   69 downloads Let me know if you find bugs.


#16311 Netduino USB HID Keyboard - Updated code

Posted by Omar (OZ) on 04 August 2011 - 09:04 AM

Here is a quick video of it in action.



This will make the netduino a USB HID, so the netduino will simulate a keyboard in this case.
To get your netduino ready for this:
1 Install firmware 4.1.1 http://forums.netdui...re-v411-beta-1/
2. Transfer to Serial deployment http://forums.netdui...b-and-com1com2/
3. Create a project and put the class in it, add the test code to your program's main method
4. Hook up a usb to serial like this: http://www.sparkfun.com/products/9873 to your netduino's com1 or 2, which ever you chose while setting serial deployment
5. Change deployment in VS to Serial, select your com port
6. Power your netduino with a 9V battery or whatever, except usb. Deploy.
7. You need the code to run and set up the usb stream first, then connect your usb cable.

Class: Attached File  Keyboard.cs   16.63KB   241 downloads

Add a reference to:
Microsoft.SPOT.Hardware.Usb

Sample use. As in the video.
            string setupResult = Keyboard.SetUp();

            Debug.Print(setupResult);

            if (setupResult != "Success")
                return;

            while (true)
            {
                led.Write(true);
                if (button.Read())
                    Keyboard.SendString("/*\n" +
         "* Supported Characters (with this method):\n" +
         "* abcdefghijklmnopqrstuvwxyz\n" +
         "* ABCDEFGHIJKLMNOPQRSTUVWXYZ\n" +
         "* 0123456789\n" +
         "* enter escape backspace deletethis\b\b\b\b\b\b\b\b\b\b \ttab   space\n" +
         "* - = [ { ] } \\ | , > . < / ? ! @ # $ % ^ & * ( )\n" +
         "*/");
                led.Write(false);
                Thread.Sleep(2000);
            }

Projects using the netduino as a keyboard coming sometime soon. I want to make a mouse class next.

I found this:
/* Custom USB HID Communication Device
* Copyright © Secret Labs LLC. All Rights Reserved.
*
*
* Licensed under the Apache 2.0 open source license
*/
in the original code from the USB HID example. I added that I expanded it. I am not big on licenses, but I think I must add it to my code as well. License info here: http://www.apache.or...ICENSE-2.0.html


#14360 VB Example - Analog Inputs and PWM

Posted by Omar (OZ) on 16 June 2011 - 02:29 AM

In this example I use two analog inputs and 4 PWM outputs. The purpose of this code is to show the values of the two light sensors (analog inputs) in a creative-ish manner.

First the schematic and breadboard image!
* If anyone notices an error in the schematic please inform me, I might have done it wrong when look at the actual physical breadboard and transferring it to fritzing.

Attached File  schem2.PNG   57.03KB   217 downloads

Attached File  schem.PNG   59.6KB   203 downloads

Code!

Option Strict Off

Imports Microsoft.SPOT
Imports Microsoft.SPOT.Hardware
Imports SecretLabs.NETMF.Hardware
Imports SecretLabs.NETMF.Hardware.Netduino

Module Module1
    Sub Main()
        Dim led1 As PWM = New PWM(Pins.GPIO_PIN_D5)
        Dim led2 As PWM = New PWM(Pins.GPIO_PIN_D6)
        Dim led3 As PWM = New PWM(Pins.GPIO_PIN_D9)
        Dim led4 As PWM = New PWM(Pins.GPIO_PIN_D10)

        Dim lightSensor0 As AnalogInput = New AnalogInput(Pins.GPIO_PIN_A0)
        Dim lightSensor1 As AnalogInput = New AnalogInput(Pins.GPIO_PIN_A1)

        Dim val1 As Integer = 0
        Dim val2 As Integer = 0

        lightSensor0.SetRange(0, 50)
        lightSensor1.SetRange(0, 50)

        Do While True
            val1 = lightSensor0.Read()
            val2 = lightSensor1.Read()

            led1.SetDutyCycle(val1)
            led2.SetDutyCycle(val2)

            led3.SetDutyCycle(val1 + val2)
            led4.SetDutyCycle(val1 * val2)
        Loop


    End Sub

End Module

Hope that helps the VB users out. Feel free to ask any questions.


#12490 Force Sensor - Easy Example and Special Class

Posted by Omar (OZ) on 26 April 2011 - 01:02 AM

I know some people wanted more analog examples and here it is! This was much easier than I thought, force sensors are not that complicated. These are called force sensitive resistors as well. Here is is:

*Always use a resistor! Dont imitate my bad habit!
Attached File  force sensor schem.PNG   103.22KB   179 downloads

Attached File  force sensor schem 2.PNG   41.62KB   188 downloads

Attached File  force sensor test.jpg   790.22KB   138 downloads

Magic! Oh right the code....

            AnalogInput input = new AnalogInput(Pins.GPIO_PIN_A0);
            PWM led = new PWM(Pins.GPIO_PIN_D10);

            input.SetRange(0, 100);

            while (true)
            {
                led.SetDutyCycle((uint)input.Read());
                Thread.Sleep(1);
            }

To enable event firing use this class I created [since analog port doesnt have built in event stuff]

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

namespace Sensors
{
    public delegate void ChangedValue(int oldValue, int newValue, DateTime time);

    public class Force
    {
        public event ChangedValue ValueChanged;
        Thread updater;
        AnalogInput input;
        int oldVal = -1;
        public int ignoreChangeLessThan = 0;

        public Force(Cpu.Pin analogPin)
        {
            input = new AnalogInput(analogPin);
        }

        public void SetRange(int min, int max)
        {
            input.SetRange(min, max);
        }

        public int Read()
        {
            return input.Read();
        }

        public void UpdateConstantly(bool update)
        {
            if (update)
            {
                updater = new Thread(new ThreadStart(Update));
                oldVal = input.Read();
                updater.Start();
            }
            else
            {
                if (updater != null)
                    updater.Suspend();
            }
        }

        private void Update()
        {
            while (updater.IsAlive)        // as long as we havent stoped the thread...
            {
                int newVal = input.Read(); // get the current value

                if ((newVal < oldVal - ignoreChangeLessThan) || (newVal > oldVal + ignoreChangeLessThan))
                {
                    if(ValueChanged != null)
                        ValueChanged(oldVal, newVal, DateTime.Now); // if the value has changed more than the filter value then fire the event

                    oldVal = newVal;                                // now this is the new value to base a change off of.
                }
            }
        }
    }
}

Use:

static Force f = new Force(Pins.GPIO_PIN_A0);

        public static void Main()
        {
            f.ValueChanged += new ChangedValue(f_ValueChanged);
            f.UpdateConstantly(true);

            Thread.Sleep(Timeout.Infinite); // just keep on waiting... forever
        }

        static void f_ValueChanged(int oldValue, int newValue, DateTime time)
        {
            Debug.Print("Old: " + oldValue + " || New: " + newValue);
            //f.UpdateConstantly(false); // stop  the updating using that line
        }

When ignoreChangeLessThan is 0 you'll get tons of fires, i suggest a setting of 3 depending on your range or sensor you'll have to fiddle with values.
Sample output (tiny part of it) with ignoreChangeLessThan being 0:

Old: 810 || New: 823
Old: 823 || New: 836
Old: 836 || New: 847
Old: 847 || New: 855
Old: 855 || New: 865
Old: 865 || New: 873
Old: 873 || New: 878
Old: 878 || New: 886
Old: 886 || New: 892
Old: 892 || New: 899
Old: 899 || New: 903
Old: 903 || New: 907
Old: 907 || New: 911

:D enjoy

Attached Files




#12254 TED Talk, interesting Video...

Posted by Omar (OZ) on 19 April 2011 - 08:27 PM

Just a quick post... check this out. I think you guys might like it.


#11773 Extending pins through the 74hc595 shift register

Posted by Omar (OZ) on 07 April 2011 - 08:56 PM

Hey guys, I run a site called bildr that documents electronics know-how.
Our goal is to have all of our code examples written for the most popular microcontrollers.


Recently we did an article on extending the pins on your arduino using the 74hc595 shift register http://bildr.org/2011/02/74hc595/

I wrote arduino code that will allow you to directly call digital pins on the shift register (even dozens chained together) like so: setRegisterPin(147, HIGH); and register pin number 147 (if you had 20 chained together) would go high.

Im looking for anyone who could help translate this very simple arduino code for the netduino.


First of all welcome to the community!
Very nice post you made there, if you could tell us what you used to make the schematics/diagrams that would be awesome, I really liked those.
Now to what came for :) : http://forums.netdui...gister-example/ there is some code I posted to show how to use a shift register with the netduino, I hope that helps... let me know if you require more assistance.


#10640 GPIO pin for both input and output

Posted by Omar (OZ) on 07 March 2011 - 03:04 PM

I suggest you use the TristatePort class. It is faster than creating an output and disposing then creating an input. Here is an example of how I used it http://forums.netdui...de-is-included/ and http://forums.netdui...ch__1#entry6511


#6593 Quick & Simple Shift-register Example

Posted by Omar (OZ) on 28 December 2010 - 01:42 AM

I was going to make a video for this, but it isn't really needed. This is just a simple shift register example use. I made a fun little class that will help all of you that like things that make sense visually.

I bought my shift register here: http://www.sparkfun.com/products/733 bu there are many different places to shop, so buy it from your favorite place.

Code:
public class ShiftRegister
    {
        private SPI _dataPort;
        private byte[] bitsStorage;
        public ShiftRegister(Cpu.Pin latch = Pins.GPIO_PIN_D10)
        {
            SPI.Configuration spiConfig = new SPI.Configuration(
                latch,
                false, // active state
                0,     // setup time
                0,     // hold time
                false, // clock idle state
                true,  // clock edge
                1000,   // clock rate
                SPI.SPI_module.SPI1);

            _dataPort = new SPI(spiConfig);
        }

        public void WriteByteArray(byte[] byteArray)
        {
            _dataPort.Write(byteArray);
        }

        public void StoreBits(string eightBits)
        {
            if (bitsStorage == null)
                bitsStorage = new byte[1]; // Start the storage
            else
            {
                byte[] temp = bitsStorage; // save it temporarily
                bitsStorage = new byte[bitsStorage.Length + 1]; // make room for another eight bits

                for (int i = 0; i < temp.Length; i++)
                    bitsStorage[i] = temp[i];
            }

            while (eightBits.Length < 8)
                eightBits = "0" + eightBits;

            byte data = 0x00;
            char[] chars = eightBits.Substring(0, 8).ToCharArray();

            for (int i = 0; i < 8; i++)
                data += (byte)((chars[System.Math.Abs(i - 7)] == '1') ? System.Math.Pow(2, i) : 0);

            bitsStorage[bitsStorage.Length-1] = data;
        }

        public void SendBits(bool eraseAfterSend = true)
        {
            WriteByteArray(bitsStorage); // send sotred bits

            if (eraseAfterSend)
                bitsStorage = null; // erase all the stored bits if told to.
        }
    }

The new and improved bit writting system is now designed to work with multiple shift registers. Although it is nice for me because I like binary and stuff... its not the way to go if you're looking for speed. Its best to use the WriteByteArray(byte[] byteArray) method instead.

If you don't have the time or brain power (like me ;) ) to memorize/learn bits to bytes to hex char and all that mess then use this: http://home2.paulsch...et/tools/xlate/

All off and on example:
            ShiftRegister shifty = new ShiftRegister();

            byte[] allOn = new byte[]{0xff, 0xff}; // two bytes because we got two shift registers
            byte[] allOff = new byte[]{0x00, 0x00};

            while (true)
            {
                shifty.WriteByteArray(allOn);
                Thread.Sleep(1000);
                shifty.WriteByteArray(allOff);
                Thread.Sleep(1000);
            }


Single Shift register:
Attached File  Shiftregister.png   177.05KB   443 downloads

Double shift register all the way across the breadboard (I hope you got that reference):
Attached File  doubleshiftregister.PNG   175.4KB   371 downloads
Note that there are no LEDs or other outputs on that schematic, I just wanted to keep things as neat as possible.

To make it a little more clear (hopefully):


Netduino | SR 1 | SR2
---------------------
GND | 13 | 13
GND | 8 | 8
3V3 | 16 | 16
3V3 | 10 | 10
10 | 12 | 12
13 | 11 | 11
14 | 14 | X
X | 9 | 14


Datasheet for the shift register I am using: http://www.sparkfun....C/SN74HC595.pdf


#6511 Parallax Ping))) Sensor Code

Posted by Omar (OZ) on 25 December 2010 - 06:26 AM

Hello there!
I made some c sharp drivers for the Ping))) Sensor from parallax (http://www.parallax....92/Default.aspx). These are pretty nice I think. I took a look at this: http://forums.netdui...ch__1#entry4555

I then decided to use the TristatePort class (previously used in my charlieplexing code). I also got started with the math behind it from someone else's code.. if you are the one who wrote some code on the speed of sound conversion let me know and I'll post a link to your thread. Sorry I forgot who it was :unsure:

What I basicly did was a lot of optimization (other programmer friends of mine hate this, i love it) and cleaning up, also nice commented code makes for happy you and me! Also added a few new features like the Units enum and the math is optimized as well.

I'll make a video soon. Let me know if you have any questions or issues. Little note, the port that connects to the Ping))) does not need to be a PWM!

Enjoy :)

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

namespace Parallax.Sensors.Ping
{
    public enum DistanceUnits
    {
        mm,
        cm,
        dm,
        m,
        feet,
        inch,
        yard
    }

    public class Ping
    {
        TristatePort _port;
        DistanceUnits _unit = DistanceUnits.mm;

        double _soundSpeed = 343, _convertion = (10000 / 343) * 2; // default values
 
        public Ping(Cpu.Pin pin)
        {
            _port = new TristatePort(pin, false, false, ResistorModes.Disabled);
        }

        /// <summary>
        /// Automaticly adjust the convertion factor depending on air temperature.
        /// </summary>
        /// <param name="degC">The temperature in degrees celsius</param>
        public void AdjustSoundSpeed(double degC)
        {
            /* Speed of Sound (at 20 degrees celsius): 343 m/s
             * or
             * _soundSpeed = 331.4 + 0.6 * degC
             * 
             * There are 10,000,000 ticks per second.
             * 10,000,000 / _soundSpeed * 1000 can be simplyfied into:
             * 10,000 / _soundSpeed
             * times it by 2 because of round trip
             * then you get about 58.309 ticks per mm
             * 
             * then multiply if other unit is needed
             * 
             */
            _soundSpeed = 331.4 + 0.6 * degC;
            _convertion = (10000 / _soundSpeed) * 2;
        }

        /// <summary>
        /// Return the Ping))) sensor's reading in millimeters.
        /// </summary>
        /// <param name="usedefault">Set true to return value in the unit specified by the "Unit" property.
        /// Set false to return value in mm.</param>
        public double GetDistance()
        {
            bool low = true, high = true;
            long t1, t2;

            // Set it to an putput
            _port.Active = true;

            //Send a quick HIGH pulse
            _port.Write(true);
            _port.Write(false);

            // Set it as an input
            _port.Active = false;  

            while (low) 
                low = !_port.Read(); 
            t1 = System.DateTime.Now.Ticks;

            while (high) 
                high = _port.Read(); 
            t2 = System.DateTime.Now.Ticks;

            return Convert(((t2 - t1) / _convertion), _unit);
        }

        /// <summary>
        /// Convert the millimeters into other units.
        /// </summary>
        /// <param name="millimeters">The Ping))) sensor's mm reading.</param>
        /// <param name="outputUnit">The desired output unit.</param>
        public double Convert(double millimeters, DistanceUnits outputUnit)
        {
            double result = millimeters;

            switch (outputUnit)
            {
                case DistanceUnits.cm:
                    result = millimeters * 0.1F;
                    break;
                case DistanceUnits.dm:
                    result = millimeters * 0.01F;
                    break;
                case DistanceUnits.m:
                    result = millimeters * 0.001F;
                    break;
                case DistanceUnits.inch:
                    result = millimeters * 0.0393700787;
                    break;
                case DistanceUnits.feet:
                    result = millimeters * 0.0032808399;
                    break;
                case DistanceUnits.yard:
                    result = millimeters * 0.0010936133;
                    break;
            }

            return result;
        }

        public DistanceUnits Unit
        {
            get { return _unit; }
            set { _unit = value; }
        }
    }
}



#5424 Getting Weather Data for your zip-code.

Posted by Omar (OZ) on 27 November 2010 - 07:26 PM

This is a little class I started making, right now it fetches the current weather data and in the future I will add code to get the forecast. I wanted to make it into a project that shows it on a 16x2 LCD, but I couldn't keep this fun little code from you guys! I hope you can find some use for it.

using System;
using Microsoft.SPOT;
using System.Net;
using System.Text;
using System.IO;

namespace NPlus_Ethernet_Testing
{
    public class WebRetrieve
    {
        public WebRetrieve()
        {

        }

        public string GetCurrentConditions(string zipcode)
        {
            Uri address = new Uri("http://xml.weather.yahoo.com/forecastrss?p=" + zipcode);

            // Create the web request  
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(address);

            // Get response  
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            
            // Get the response stream  
            StreamReader reader = new StreamReader(response.GetResponseStream());
            
            string newLine = reader.ReadLine();
            int lineNumber = 0;

            while (newLine != "") // While we still got data
            {
                if (lineNumber == 32) // The Current weather data seems to be on line 32 always.
                    return newLine.Split('<')[0]; // The line also has a <BR/> at the end, get rid of that by spliting it and using the first part.

                newLine = reader.ReadLine(); // Read next line
                lineNumber++; // Update line number
            }

            return "Could Not Get Data"; // In case that we dont get to line # 32 for some odd reason
        }
    }
}



#2959 Netduino Plus Ethernet and LED

Posted by Omar (OZ) on 26 September 2010 - 10:00 PM

First of all I would like to thank all of the members of the community that have posted ethernet code and questions! Your code and thoughts helped me a lot so thanks again. Video: This is really buggy code so I won't post it for your own good... I had to reset my netduino 3 times because of the sockets not closing properly or some other wierd stuff. This is just to show people what the awewsome Netduino Plus can do! If you will not get mad at me if your netduino flips out on ya when you run my code, email me and I will send it to you personally. You guys at Secret Labs have done a wonderful job with the netduino plus, I hope you had a good day at the MakerFaire!


#2413 OZ-Solutions - Sheet Music

Posted by Omar (OZ) on 18 September 2010 - 05:35 AM

Sources (Places I copied a little from ;) ):
Piezo Buzzer (Netduino Forums)
Notes to Frequencies and Mario Song



If you need help with the implementation of this ask right here.

UPDATE
--------------------------------------------------------------------------

Fixed the Play method - correction provided by Robert Echten (http://forums.netdui...-robert-echten/)

Attached Files

  • Attached File  Sound.cs   5.68KB   165 downloads



#1830 PWM Timer Access

Posted by Omar (OZ) on 06 September 2010 - 03:06 AM

OK, asking in a purely informational way, how would someone that just purchased a Netduino know this?



Forget the text, start putting it online as you write it, print it off when it's done. Just 1 suggestion....


I guess both sides aren't fully documented, sorry for the 'trolling' post, I just had good stuff in mind and got a little carried away. I am planing on posting a new video soon, featuring your shield as always.

Question... What do you suggest I do to protect the light sensor from the rgb light's awesome brightness? It isn't too bad but the less interference the better.


#1821 PWM Timer Access

Posted by Omar (OZ) on 06 September 2010 - 02:13 AM

Just a reminder that we should all be civil here :)

OZ, let's see if we can figure out what support that Rugged Circuits needs to enhance Netduino support for their platform--and then go from there. Thanks for continuing to push the limits of the platform, and for all your efforts...

Chris

Alright, I am a total newb so I don't think I can help much, other than testing alpha stuff.

I am sorry that I reacted badly RuggedCircuits, I am just upset that I couldn't do what I was expecting.




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.