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 29-April 23)


By content type

See this member's


Sort by                Order  

#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.




#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 :-).




#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.




#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




#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 ...




#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);
                }
            }
        }
    }
}




#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.
}



#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 ...




#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




#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.




#57620 13.56Mhz RFID module - IOS/IEC 14443 type a

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

The link you supplied doesn't seem to work.  If your device is: http://www.seeedstud...KHz_RFID_Reader then it looks pretty simple, ground, +5, transmit, and receive.  You would use some code like:

 

       using System.IO.Ports;

    m_SerialPort = new SerialPort(port, 9600, Parity.None, 8, StopBits.One);

 

You can find information on SerialPort here: http://netmf.codeplex.com/ or just search on the web.

 

Have fun.

 

--John




#57665 13.56Mhz RFID module - IOS/IEC 14443 type a

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

If you look at the spec sheet http://www.netduino....plus2/specs.htm you'll see

that there are 4 serial ports.  "COM1" ... "COM4".  Since each pin has multiple functions but

can only do one at a time, it all depends on what functions you're using.  I suggest you start

with "COM1" and hook:

 

    NP2 Pin D0 (RX)  --->  RFID  J2  Pin3 (TX)

    NP2 Pin D1 (TX)  --->  RFID  J2  Pin2 (RX)

    Hook up Gnd and +5 on J1

 

And you should be ready to go.  You will have to translate the Arduino example to C#.  Here

are couple hints, more information is at http://arduino.cc/en...erence/HomePage :

 

     Arduino uses the Serial object to talk to the host computer.  Since they only have a single

     serial port (in hardware) they use the SoftwareSerial  class (mySerial) to talk to the device.

     So convert:

         Serial.println  --> Debug.Print

         mySerial.print  -->  m_SerialPort.Write

 

Of, course they're not one-for-one but we have to leave a little fun for you :) .

 

Enjoy,

 

-- John




#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




#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.




#58756 Pushover or Pushbullet Notifications from Netduino Plus 2

Posted by jrlyman3 on 17 June 2014 - 03:40 PM in Netduino Plus 2 (and Netduino Plus 1)

I think that you're stuck with some kind of server because: 1) your phone is not always connected to the internet, and 2) it's IP address will change based on how you're connected.  Even if that were not true the available apps are setup to work that way so you would have to write your own app otherwise.

 

If you're OK with writing your own app then I think you want your phone to poll your Netduino when it's connected to see if there is anything to notify you about.  That would require your Netduino to have a fixed IP address, or you have to use a server to get the IP address ...

 

If you're on your local WiFi then you could use a discovery protocol to find the Netduino.

 

Looks, like you've already got a good solution (except maybe privacy) ...

 

Email was too slow ... Mmmm, I guess I might have to learn more about these new methods :).

 

John




#59652 Trying to recreate Arduino Code for Netduino, running into issues.

Posted by jrlyman3 on 11 August 2014 - 02:31 AM in Netduino Plus 2 (and Netduino Plus 1)

I took a quick look and I think that you're missing:

        

IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, port);

 

before listener.Bind(localEndPoint);

 

Also, you should use listener.RecieveFrom() which will receive the data and tell you who it came from.  This works best with UDP since you can receive data from multiple hosts on the same socket (no connection).

 

John




#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.




#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.

 




#56633 How to convert hex value stored in string to binary in string?

Posted by jrlyman3 on 04 March 2014 - 11:13 PM in Visual Studio

There are a number of useful string functions that are missing ... not to mention the StringBuilder class ... I would use some code like:

        String smsData = "31584C1E8bC160";
        String data = "";
        int bytePos;
        int charPos;
        int nibble0, nibble1, byteVal;
        int carryBits = 0;

        smsData = smsData.ToUpper();   // Not needed if digits will always be uppercase.

        for (bytePos = 0; bytePos < 7; bytePos++) {
            charPos = bytePos * 2;
            nibble0 = smsData[charPos] - '0' - ((smsData[charPos] >> 6) * 7);
            nibble1 = smsData[charPos + 1] - '0' - ((smsData[charPos + 1] >> 6) * 7);
            byteVal = (((nibble0 << 4) + nibble1) << bytePos) | carryBits;
            carryBits = (byteVal & 0x7F80) >> 7;
            data += ((char)(byteVal & 0x7F));
        }
        data += ((char)carryBits);
        Debug.Print("SMS Data = " + data + "\n");

--John




#56637 How to convert hex value stored in string to binary in string?

Posted by jrlyman3 on 05 March 2014 - 03:27 AM in Visual Studio

I'm curious to see how you did that ... I'm always looking for a better way to do things ... could you post the code?




#55412 Clean way to interrupt Socket.Accept()?

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

Yup.  That's how I do it.





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.