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.

jrlyman3's Content

There have been 65 items by jrlyman3 (Search limited from 28-April 23)


By content type

See this member's


Sort by                Order  

#56901 I2C Bus Problem - Debugging

Posted by jrlyman3 on 19 March 2014 - 02:14 AM in General Discussion

Hard to say without a logic analyzer ... but, it sounds like the I2C lines are in a bad state when the board initializes and after the first operation the I2C lines are left in the correct state so that the subsequent operations all work.  It seems to me there is another topic where this is discussed, I think that they set the pins to "1" before using them as I2C ...

 

Glad that that you found a work around.




#59243 NETMF SerialPort and "BreakState"

Posted by jrlyman3 on 16 July 2014 - 02:54 AM in Netduino Plus 2 (and Netduino Plus 1)

If you're interested I could dig up the software I was testing with.

 

It may be a bit messy,  But it's not too complex.  I think that I ported it from an Arduino library ...




#59314 NETMF SerialPort and "BreakState"

Posted by jrlyman3 on 20 July 2014 - 03:14 PM in Netduino Plus 2 (and Netduino Plus 1)

I thought that I ported this, but it wasn't me.  This code uses interrupts and seems to be fairly accurate if I remember correctly.   One thing that I changed was the SecretLabs.NETFM.Hardware.Netduino using statement since I'm using a Netduino Plus.  Enjoy.

 

John

 

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

namespace HC_SR04
{
    /// <summary>
    /// Class for controlling the HC-SR04 Ultrasonic Range detector
    /// Written by John E. Wilson
    /// Version 1.1 - 2012/04/03 - Corrected constructor pin documentation
    /// Free to use, please attribute credit
    /// </summary>
    public class HC_SR04
    {
        private OutputPort portOut;
        private InterruptPort interIn;
        private long beginTick;
        private long endTick;
        private long minTicks;  // System latency, subtracted off ticks to find actual sound travel time
        private double inchConversion;
        private double version;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="pinTrig">Netduino pin connected to the HC-SR04 Trig pin</param>
        /// <param name="pinEcho">Netduino pin connected to the HC-SR04 Echo pin</param>
        public HC_SR04(Cpu.Pin pinTrig, Cpu.Pin pinEcho)
        {
            portOut = new OutputPort(pinTrig, false);
            interIn = new InterruptPort(pinEcho, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeLow);
            interIn.OnInterrupt += new NativeEventHandler(interIn_OnInterrupt);
            minTicks = 6200L;
            inchConversion = 1440.0;
            version = 1.1;
        }

        /// <summary>
        /// Returns the library version number
        /// </summary>
        public double Version
        {
            get
            {
                return version;
            }
        }

        /// <summary>
        /// Trigger a sensor reading
        /// Convert ticks to distance using TicksToInches below
        /// </summary>
        /// <returns>Number of ticks it takes to get back sonic pulse</returns>
        public long Ping()
        {
            // Reset Sensor
            portOut.Write(true);
            Thread.Sleep(1);

            // Start Clock
            endTick = 0L;
            beginTick = System.DateTime.Now.Ticks;
            // Trigger Sonic Pulse
            portOut.Write(false);

            // Wait 1/20 second (this could be set as a variable instead of constant)
            Thread.Sleep(50);

            if (endTick > 0L)
            {
                // Calculate Difference
                long elapsed = endTick - beginTick;

                // Subtract out fixed overhead (interrupt lag, etc.)
                elapsed -= minTicks;
                if (elapsed < 0L)
                {
                    elapsed = 0L;
                }

                // Return elapsed ticks
                return elapsed;
            }

            // Sonic pulse wasn't detected within 1/20 second
            return -1L;
        }

        /// <summary>
        /// This interrupt will trigger when detector receives back reflected sonic pulse      
        /// </summary>
        /// <param name="data1">Not used</param>
        /// <param name="data2">Not used</param>
        /// <param name="time">Transfer to endTick to calculated sound pulse travel time</param>
        void interIn_OnInterrupt(uint data1, uint data2, DateTime time)
        {
            // Save the ticks when pulse was received back
            endTick = time.Ticks;
        }

        /// <summary>
        /// Convert ticks to inches
        /// </summary>
        /// <param name="ticks"></param>
        /// <returns></returns>
        public double TicksToInches(long ticks)
        {
            return (double)ticks / inchConversion;
        }

        /// <summary>
        /// The ticks to inches conversion factor
        /// </summary>
        public double InchCoversionFactor
        {
            get
            {
                return inchConversion;
            }
            set
            {
                inchConversion = value;
            }
        }

        /// <summary>
        /// The system latency (minimum number of ticks)
        /// This number will be subtracted off to find actual sound travel time
        /// </summary>
        public long LatencyTicks
        {
            get
            {
                return minTicks;
            }
            set
            {
                minTicks = value;
            }
        }
    }

    public class Program
    {
        public static void Main()
        {
            HC_SR04 sensor = new HC_SR04(Pins.GPIO_PIN_D6, Pins.GPIO_PIN_D7);

            while (true)
            {
                long ticks = sensor.Ping();
                if (ticks > 0L)
                {
                    double inches = sensor.TicksToInches(ticks);
                }
            }
        }
    }
}




#59197 NETMF SerialPort and "BreakState"

Posted by jrlyman3 on 13 July 2014 - 07:50 PM in Netduino Plus 2 (and Netduino Plus 1)

Hi Nathan,

 

I've played with the HC-SR04 and it seems to work pretty good, no soldering required :).

 

I haven't had time to put my project together yet ...




#55902 Automated Urban Garden

Posted by jrlyman3 on 06 February 2014 - 02:19 PM in Project Showcase

That is a great project!  I've been working on a similar project, so far I'm just monitoring the moisture level of the plant, but I got the pump this week and hope to get it hooked up soon :-).




#59196 Automated Urban Garden

Posted by jrlyman3 on 13 July 2014 - 07:28 PM in Project Showcase

Wow that looks great!  What type of moisture sensor are you using?  How's it been working?

 

My PlantNanny (http://www.lymantech...nanny-part-one/) started giving me noise for the moisture level last week.  I pulled out the moisture sensor (a two prong fork like thing) and when I cleaned it off I found that the metal plating (probably copper) was completely corroded away.

 

Instead of buying a new one I took two pieces of #12 gauge copper electrical wire, secured them to the fork by wrapping some hookup wire around them, and soldered them to the sensor at the top of the fork.  It seems to be working, I guess we'll see how it goes.




#56323 My daydream - FPGA/ARM platform

Posted by jrlyman3 on 24 February 2014 - 02:57 AM in General Discussion

Wow, this does look pretty cool.  I'm a lot like you and I'm tempted to drop what I'm doing and get one of these eval kits ... but I'm trying really hard not to start any more projects until I get some finished and written up ... I guess I'll just save this link and hope to have time later this year :) .




#56285 A problem with VS Express for C#

Posted by jrlyman3 on 22 February 2014 - 10:58 PM in Visual Studio

Kenny,

 

You should consider upgrading to the 4.2 (or 4.3) framework on your Netduino. It will be harder to upgrade later as they seem to like changing stuff in the interfaces.  Like for example in 4.1 analog ports return an integer with a range that you specify, in 4.2 you get a float between 0.0 and 1.0 which indicates the percentage of the reference voltage ... I like 4.2 but I should upgrade to 4.3.

 

BTW, be careful about the versions in use when you read posts in the forum :).

 

John




#57674 Bizarre Behavior with N2 with Events, Interrupts, and other peripherals. Need...

Posted by jrlyman3 on 22 April 2014 - 01:34 AM in General Discussion

Well, in both cases you want to keep the PWM wires / traces away from the other wires / traces.  In a fancy multi-layer PCB you would put those signals on a separate plane and put a ground or DC power plane on each side.  In the proto case just use wires that are long enough to keep them away from everything else.  When you do a PCB you could try to put the PWM traces on the back side of the board and keep most of the rest on the top side of the board (or the other way around).

 

Good luck.  Sounds like a fun project.

 




#57667 Bizarre Behavior with N2 with Events, Interrupts, and other peripherals. Need...

Posted by jrlyman3 on 21 April 2014 - 02:07 AM in General Discussion

Gismo,

 

We have this sort of problem all the time at work, but we work at much higher speeds.

I don't think that I've ever read about this on a Netduino.  Sounds like you're just going

to need to isolate those two circuits :).  Great work tracking that down.




#55411 Future PoE support (Netduino Plus 3?)

Posted by jrlyman3 on 16 January 2014 - 02:53 AM in Netduino Plus 2 (and Netduino Plus 1)

After researching POE options for my Netduino projects I went in a different direction.  You can see in the photos I attached, that I'm using a Passive PoE Injector/Splitter.  Right now I have one Netduino plugged into a gigabit Ethernet switch and the normal 9v power supply, it works great.  Since the Netduino only has 10Mb Ethernet there is no need for the more complex 1Gb PoE.  When I add more Netduino devices in the future I'm going to buy a 9v 4A power supply and use a 4-way splitter to send that power to 4 of these PoE splitter pairs. 

 

PowerOverEthernet-1.jpg   PowerOverEthernet-2.jpg

 

The splitter on the left plugs into the switch and a power supply the Ethernet plugs into the socket.  Then on the right the splitter plugs into the Ethernet and power connectors of the Netduino and the Ethernet cable plugs in the socket.  Simple, cheap ($6), and easy to install.




#58732 obstacle detection

Posted by jrlyman3 on 16 June 2014 - 12:11 AM in General Discussion

If you're saying that you haven't been able to hook up both the LCD and the sensor because there is only one socket on the shield connector for 5V, then I've had the same problem.  My solution was to create a couple "Y" cables.  They allow me to connect multiple devices to the 5V, 3.3V and/or GND pins.

 

If that;s not what you're saying ... then say more ...

 

John




#58746 obstacle detection

Posted by jrlyman3 on 17 June 2014 - 02:32 AM in General Discussion

I like to use "breadboard jumper wires".  They come in M/F, F/F, and even M/M configurations.  You can get them from a bunch of vendors on Amazon for a few dollars.  One way to do a "Y" cable would be to cut a couple M/F cables in half, strip the ends, twist them together, solder it together, and shrink wrap it.  Use one male end (to plug into the Netduino) and 2 or more female ends to receive the wires from your devices.

 

Another way that I've done it is to solder a jumper wire with a male end to a piece of female header with 3 or 4 sockets.  Solder all the pins together and put some shrink wrap on it if you want.

 

Do you have a soldering iron?  I took a quick look on Amazon and I don't see any premade jumpers.

 

John




#55228 I2C Bus not working

Posted by jrlyman3 on 07 January 2014 - 04:42 AM in Netduino Plus 2 (and Netduino Plus 1)

I compared your code to mine and I don't see much difference, I used a timeout of 1000 on the execute function, but that should not be an issue.  I know that I had a issue when I went back to a NetduinoPlus1 which uses A4/A5, but I don't see how you would mistake the SCL/SDA pins on the NetduinoPlus2 board.  I also ran into a problem with bus contention (I have another microcontroller on the bus) but that doesn't apply to this.  So, other than to say it seems to work for me, I guess I can't be much help.  I did notice one other thing, you're using the Netduino library instead of the NetduinoPlus library you might want to try changing that.

 

Sorry I can't be more help.

 

John




#55123 I2C Bus not working

Posted by jrlyman3 on 02 January 2014 - 03:10 AM in Netduino Plus 2 (and Netduino Plus 1)

Are you sure you're hooked up to the right pins? So which pins are you connecting to?




#57599 Need a bit of help, Netduino Plus

Posted by jrlyman3 on 17 April 2014 - 12:47 AM in Netduino 2 (and Netduino 1)

I've seen this before (just this morning in fact) and I usually just pull down the build menu and stop the "build", unplug the USB cable, plug it back in, and try again.  If that doesn't work then I bring up the project properties and reset the .NET Micro Framework Device, that usually solves the problem.




#57698 Hang on socket connect

Posted by jrlyman3 on 23 April 2014 - 03:14 AM in Netduino Plus 2 (and Netduino Plus 1)

Chris,

 

I haven't started a list yet, but off the top of my head I miss:

 

  • StringBuilder class
  • Blocking and Connected properties of Socket class
  • List<> class and templates in general

My only other complaint is the lack of coherent documentation.

 

On the plus side the forums are great!

 

Thanks,

 

John




#57598 Hang on socket connect

Posted by jrlyman3 on 16 April 2014 - 11:33 PM in Netduino Plus 2 (and Netduino Plus 1)

This turns out to be harder than I expected, due to the fact that the .Net Micro Framework does not include everything from the full framework.

 

If you try to connect to a host on the network that doesn't exist, or just isn't responding, your thread will lock up until the host responses (which may be never).  Although the .Net Framework theoretically handles all of this with no problem, the 4.2 version of the .Net Micro Framework is missing a number of important properties and methods.

 

According to the documentation the normal way to handle this situation is to set the Blocking socket option to false, then the Connect() method will throw an exception because it can't connect immediately (the TCP connect protocol takes some time). You catch the expection and wait for the connection to be be completed, and if it doesn't complete quick enough then you return an error. No hang.

 

Unfortunately, the 4.2 .Net Micro Framework is missing the Blocking and Connected properties, and the Send() method does not work as documented. The following code shows how to get around this ... but it's a kludge. 

 

using System.Net.Sockets;
using System.Reflection;

int TIME_PORT = 37;
IPEndPoint iep = new IPEndPoint(
    IPAddress.Parse("192.168.3.3"), TIME_PORT);
Socket socket = new Socket(AddressFamily.InterNetwork,
    SocketType.Stream, ProtocolType.Tcp);

Type sType = Type.GetType("System.Net.Sockets.Socket");
FieldInfo blockingInfo = sType.GetField("m_fBlocking",
    BindingFlags.NonPublic | BindingFlags.Instance);
blockingInfo.SetValue(socket, false);

try {
    socket.Connect(iep);
} catch (SocketException se) {
    // Ignore this exception, it takes time to complete the connection.
}

This code uses reflection to access the blocking property which is not publicly available to us.  It catches the exception during Connect() and ignores it.

 

The problem is how to we know if the connect completes.?The documentation says that you should get an exception if  you call Send() with a zero length and  the socket hasn't finished connecting, but it doesn't.  If you call Send() with a non-zero length then it hangs whether blocking is true or false.  And if you call Receive() it just returns 0 bytes.

 

The good news is that the SendTimeout property does work.  If you set it to 300 the send will wait for 300 milliseconds and then throw an exception (might as well set the ReceiveTimeout value to 300 too).

 

So add the following code and you should be good to go.  There is a slight chance that you'll need to wait a little bit for the connection to complete, or maybe retry the first send a few times before giving up.

socket.SendTimeout = 300;
socket.ReceiveTimeout = 300;

byte[] cmd = new byte[1];
try {
    int xx = socket.Send(cmd, 1, SocketFlags.None);
} catch (SocketException se) {
    // Unable to send data - probably no connection.
}



#57697 Hang on socket connect

Posted by jrlyman3 on 23 April 2014 - 03:09 AM in Netduino Plus 2 (and Netduino Plus 1)

Steve,

 

Glad that helped.  It turned out to be much more of a problem than I expected and it didn't fix my random freeze problem :( either.

 

If you are repeatedly creating and closing sockets on a Netduino it could be running out of socket resources, each closed socket hangs around for a while to support the TCP CloseWait time.  I haven't explored this on a Netduino, but it's one theory.  Have you tried keeping the socket to each peer open?  Do they need to be fully connected, or could connect them in a ring?  Or have one as the master?

 

I've read some posts that indicate some issues with the network, especially if there is a lot of traffic.  I'm thinking that a marginal power supply might also cause hang conditions.  If I come up with a solution I'll post it.

 

Good luck.

 

John




#57245 Hang on socket connect

Posted by jrlyman3 on 01 April 2014 - 02:47 AM in Netduino Plus 2 (and Netduino Plus 1)

After you create the socket you need to set the Blocking property to false.  Now when you connect you get an exception (you'll need to put it into a try/catch block) which just says the connection couldn't be completed immediately.  You can then call Socket.Poll to wait for the connect to finish, and then check if the socket is connected.  I know this is probably not enough, I haven't found a good example, I'll try to come up with a simple example ...




#57266 Help with netduino Networking

Posted by jrlyman3 on 01 April 2014 - 02:22 PM in Netduino Plus 2 (and Netduino Plus 1)

I'm guessing that your NP2 server code is closing the socket after it sends the HTTP reponse.




#56121 Is data lost when UDP socket receive buffer is too small?

Posted by jrlyman3 on 16 February 2014 - 02:36 PM in Netduino Plus 2 (and Netduino Plus 1)

Hey, Paul,

 

Thanks for taking the time to report this.  I would have expected the second read to get the remaining 3 bytes of the first packet.

 

It's nice to learn something the easy way for a change :).




#56126 Is data lost when UDP socket receive buffer is too small?

Posted by jrlyman3 on 16 February 2014 - 04:03 PM in Netduino Plus 2 (and Netduino Plus 1)

Yes, TCP sockets are different, they work the way we would expect.

 

Except that I've found that they don't always return the number of bytes that I request ... even if I sent more than that.  I always do the reads in a loop to verify that I get all of the data I need for each read ...

 

That's what makes programming fun (and frustrating) - John




#56833 Emulator, can it handle OneWire ?

Posted by jrlyman3 on 16 March 2014 - 12:30 AM in General Discussion

I thought that the address was printed on the device, but I looked at a DS1820 and the numbers on the device do not have any correlation with the address (so I guess not).  The way I got the address was to add the new device to the 1-wire network and use the FindAllDevices() function to get all the addresses.  The one I didn't know is the new device's address.  You could also choose to make it the only device on the net.




#58745 Pushover or Pushbullet Notifications from Netduino Plus 2

Posted by jrlyman3 on 17 June 2014 - 02:13 AM in Netduino Plus 2 (and Netduino Plus 1)

Why don't you use SMTP to send an email?  You could use email direct to your cellphone or use it to send the phone a text message.





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.