NETMF SerialPort and "BreakState" - Page 2 - Netduino Plus 2 (and Netduino Plus 1) - Netduino Forums
   
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

NETMF SerialPort and "BreakState"

Serial

Best Answer baxter, 10 July 2014 - 06:07 PM

You are not going to be able to talk to the SRF01 from Netduino without the hardware break. I fired up Fritzing, made a schematic and connected the corresponding breadboard wires. The project is here,
https://www.dropbox....NXj2cVZn8bAJjYa

I am pretty sure it's correct, but no guarantees. Starting from a schematic, ratsnest wires are transfered back to the breadboard and you need to connect them up with wires. Fritzing is a work-in-progress and I find it very limited and cumbersome to use. I use Eagle Cad for all of my work.

 

In any case, you need to develop the capability to transfer a schematic to a breadboard. Here is a nice online free application for electronic design work,

http://easyeda.com/

Go to the full post


  • Please log in to reply
35 replies to this topic

#21 sfx

sfx

    Advanced Member

  • Members
  • PipPipPip
  • 52 posts

Posted 09 July 2014 - 02:22 AM

Hi Baxter,

 

Further to your last response (and in addition to mine), I'm still uncertain as to how to layout a breadboard diagram for the "half duplex" solution that you mentioned - I guess I'm not clear on how both the RX and TX pins from the Netduino will connect to the logical AND gate. I've attached an image as to what I think you mean, but was hoping that you could validate it against the intent of your previous suggestion.

 

I’m wanting to try this out even before your serial adapter advice as I already have the necessary items and will likely have to wait a few days before I can acquire an adapter.

 

Thanks again.

 

Nathan

Attached Files



#22 baxter

baxter

    Advanced Member

  • Members
  • PipPipPip
  • 415 posts

Posted 09 July 2014 - 05:42 AM

Wrong cable ... The one you linked is USB to RS232. I should have been more explicit. What you want is is USB to TTL. Something like this,
(1) http://www.ebay.com/...e-/261101529602
or this,
(2) http://www.mouser.co...j627GFcejHp0Q==
or this,
(3) http://yourduino.com...ct_detail&p=164

 

With the first two, you can plug your jumper wires into the end of the cable and then into the breadboard to bring the signal lines to the breadboard for connections. The third style can plug directly into the breadboard, but be careful that the header pins have enough depth and are not too far offset from the edge of the PCB. Most of my USB to serial TTL are like number (3). The RS232 version you ordered is not of much use for Netduino work. I would cancel your order if you can. The RS232 cable can be used for download with the Netduino Mini.

 

Serial RS232 and TTL are different protocols that are characterized by the logic state voltage. If you measure voltage with no transmission on a TTL TX line, it will be 5V corresponding a logic 1. For RS232, logic 1 will measure at about 2.7V or less. In most cases, USB to RS232 adapters do not conform to the RS232 standard. A further characterization is; TTL idles high and RS232 low..

 

Comment on Fritzing layout
==========================
Last post: Remove the blue wire. Netduino RX doesn't have anything to do with the BREAK.
Next to last post: Correct, but lose the RS232 adapter. See above comments. If you use it, you will need to add add a chip to invert TX and RX from/to the adapter.

 

I will try to dredge up my lost knowledge of Fritzing and try my hand at layout of the breadboard. This is turning into an intriguing problem.



#23 sfx

sfx

    Advanced Member

  • Members
  • PipPipPip
  • 52 posts

Posted 09 July 2014 - 09:45 AM

Hi Baxter,

 

No worries. I've cancelled the order and made another one for item (3) on your list. Hopefully I'll take delivery of it within the next few days.

 

Thanks also for the heads up regarding RS232 and TTL. Your explanation makes a lot of sense.

 

Regarding my Fritzing diagram, I have removed the blue wire as per your instructions but can confirm that this setup does not work using the GPIO with logical AND "break" substitute. More specifically, various commands can be sent without throwing an exception but the SerialPort.BytesToRead property is always zero.

 

Concerning the next to last diagram that I posted, I'll endeavour to build that out once my USB to TTL adapter arrives.

 

In the meantime, however, if you have any further suggestions or recommendations please let me know.

 

Nathan



#24 sfx

sfx

    Advanced Member

  • Members
  • PipPipPip
  • 52 posts

Posted 10 July 2014 - 09:55 AM

Hi Baxter,
 
While I'm waiting on the USB to TTL adapter to arrive, I thought I would try to implement the transistor based half-duplex UART configuration that you mentioned to me earlier:
 
 
I have attached a diagram for the circuit in the above web page, but my circuit reading ability is still in its infancy and so I have a strong hunch that I have got it wrong. When you get a moment, I was hoping you could point out the innacuracies that I have made.
 
As I have each of these parts I'm hoping to be able to test out this configuration using an SRF01 as well.
 
Nathan

Attached Files



#25 baxter

baxter

    Advanced Member

  • Members
  • PipPipPip
  • 415 posts

Posted 10 July 2014 - 06:07 PM   Best Answer

You are not going to be able to talk to the SRF01 from Netduino without the hardware break. I fired up Fritzing, made a schematic and connected the corresponding breadboard wires. The project is here,
https://www.dropbox....NXj2cVZn8bAJjYa

I am pretty sure it's correct, but no guarantees. Starting from a schematic, ratsnest wires are transfered back to the breadboard and you need to connect them up with wires. Fritzing is a work-in-progress and I find it very limited and cumbersome to use. I use Eagle Cad for all of my work.

 

In any case, you need to develop the capability to transfer a schematic to a breadboard. Here is a nice online free application for electronic design work,

http://easyeda.com/



#26 sfx

sfx

    Advanced Member

  • Members
  • PipPipPip
  • 52 posts

Posted 11 July 2014 - 12:02 AM

Hi Baxter,

 

Wow! Thanks so much for taking the time to diagram that circuit out for me. I really appreciate it.

 

Thanks also for the reference to EasyEDA. I haven’t heard of it before (not surprisingly), but will start playing with it immediately.

 

I’ve created your diagram on my Netduino Plus 2 and attached a picture of the result. I think I have everything in essentially the same order as you.

 

Unfortunately, I’m still not reading anything on the SerialPort.BytesToRead property. It is always zero. This has got me thinking that surely it shouldn’t be as difficult as it has been to set this kind of configuration up on the Netduino. After all, the Arduino can read these sensors without even having to move a circuit out onto a breadboard! As such, I’m left wondering whether there is something wrong with my own hardware or if the NETMF doesn’t play nice with serial communication outside of its standard operational boundaries. I find both of these possibilities quite troubling, but also think that it’s most likely the former rather than the latter.

 

I guess I’m going to have to wait until the USB to TTL adapter arrives in order to see whether my Netduino can operate against the vendor’s PC code.

 

I’m reluctant to have to abandon my venture and admit defeat, but I’m also aware that I might well be out of my depth here. Still, I’m very thankful for all the guidance you have provided over these last few days – I have definitely learned a lot. Nevertheless, I realise that I’m likely stealing your time away from other important matters. Hence, in the event that I can’t get anything working I was wondering if you happen to know of any companies that could prototype the setup that I’m after on the Netduino board? If there are facilities that can offer this kind of service I’d be happy to pay to at least get me a working sample from which I can then build upon.

 

Thanks again.

 

Nathan

Attached Files



#27 baxter

baxter

    Advanced Member

  • Members
  • PipPipPip
  • 415 posts

Posted 11 July 2014 - 09:01 AM

Well I really can't  make out any thing out from your photo. I haven't tested the half-duplex circuit, but it may have problems operating at 3.3V due to the forward voltage drop through the diode and also the resistor value may need to be adjusted. I am pretty certain he designed the circuit for Arduino which has 5V I/O. I suggest you breadboard just the half-duplex circuit. You can then statically test it with your meter. Instantiate COM1 on Netduino and let it idle. You should measure 3.3V on TX and RX. Next, Connect TX and RX of Netduino to TX and RX of the interface circuit.

 

(1) Measure the interface TX/RX; it should be greater than 2.7V.
(2) Apply 0V(GND) to TX/RX. Measure RX; it should be less than 0.5V (0 to 0.5V)
(3) Apply 3.3V to TX/RX. Measure RX; it should be greater than 2.7V.
(4) Disconnect Netduino TX from TX interface. Apply 0V(GND) to TX interface. Measure TX/RX; it should be less than 0.5V (0 to 0.5V)

 

If your measurements do not conform to (1)-(4), then the circuit will not work with 3.3V. The TX line from Netduino will probably need to be level shifted to 5V before connection to the TX interface or the circuit modified.

 

I am more than happy to help you, but if you are just starting out, I would suggest buying a book such as this,
http://www.amazon.co...t/dp/0596153740
This is a very lucid starter book. You don't want to farm your project out to a consultant. Stick with it and you will learn a lot. This is a conceptually simple project; all you are trying to do is talk over a serial line. As I said before, the first step is to get the SRF01 working from your PC with the USB to serial adapter according to the web page instructions.

 

More on logic signal voltage levels:
http://www.allaboutc.../chpt_3/10.html



#28 sfx

sfx

    Advanced Member

  • Members
  • PipPipPip
  • 52 posts

Posted 12 July 2014 - 02:06 PM

Hi Baxter,

 

Sorry for the delay in getting back to you, I’ve been at this thing hammer and tong since we last spoke and wanted to be sure of my findings before I replied to your last post.

 

Thanks for the excellent references too. I’ve had the electronics book you mentioned for a little while now but haven’t acquired the starter kit yet in order to really get the most out of it. I’ve also read the books by Cuno and Chris and have been watching the videos on allaboutcircuits for a couple of weeks now. It’s quite a crash course!

 

Now for finally some good news… Since the last time I discussed this issue with you I went back to my setup (using your diagram) and realised that I had a 1N4001 diode in the place of where the BAT 48 Schottky diode that I had purchased should be. Well, guess what happened when I replaced the diode? It worked! I finally started to receive data back across the wire!! I therefore want to offer you my sincerest thanks as well as hearty congratulations. If it wasn’t for your help, I would never have got this far with my limited hardware experience...

 

Now for some not so good news… The code samples that I’ve worked on that were taken from the vendor’s website, as well as others that I’ve attempted to port from different platforms, don’t seem to work on the Netduino. The problem appears to be in how data is waited upon as well as how echo transmissions get discarded before any relevant bytes can be parsed – I just couldn’t get the Netduino to read anything but junk using the code samples I found online... And so...

 

Now for some interesting news... I did finally manage to get the range bytes by using the DataReceived event of the serial port, but only after what I consider to be a bit of a hack; or more specifically, by collaborating with the number of times the received event gets raised and then parsing the relevant bytes accordingly. It seems to work, but it’s definitely a code smell.

 

Due to all of these issues, I’m not certain I will settle on the SRF01 as the range finder I want to use on the Netduino. Nevertheless, it’s only because of your assistance that I’m even able to consider this option.  More importantly, your solution has not only helped me, but it will aid anyone who is searching online for how they can connect a SRF01 to the current release Netduino hardware.

 

Well done!

 

Nathan



#29 baxter

baxter

    Advanced Member

  • Members
  • PipPipPip
  • 415 posts

Posted 12 July 2014 - 09:54 PM

Success is sweet after a round of failures ...

 

My measurements with a BAT42 diode:

(1) Measure the interface TX/RX; it should be greater than 2.7V. ---> 3.0V
(2) Apply 0V(GND) to TX/RX. Measure RX; it should be less than 0.5V (0 to 0.5V) ---> 0.05V
(3) Apply 3.3V to TX/RX. Measure RX; it should be greater than 2.7V. ---> 2.9V
(4) Disconnect Netduino TX from TX interface. Apply 0V(GND) to TX interface.
     Measure TX/RX; it should be less than 0.5V (0 to 0.5V) ---> 0.03V

There is not a lot of margin on the high side when working with 3.3V, but enough.

 

Here is a Netduino VB 2010 simple serial text terminal I wrote to interact with something connected to the COM port. It's nothing fancy, but it works
https://www.dropbox....al Terminal.zip
You can translate it to C# with one of the online translators,
http://www.developer...t/vb-to-csharp/

 

You might consider the HC-SR04. It will probably be easier to work with than the SRF01 (no Break and no COM port, just an echo line)
https://www.dropbox..../HC-SR04_V1.zip
I translated the original C# to VB. The original link is in the program. I added some smoothing and statistics on the measurements.

 

I am glad that you are finally getting some hardware interaction. If nothing seems to work, it can lead to mountain of frustration.



#30 sfx

sfx

    Advanced Member

  • Members
  • PipPipPip
  • 52 posts

Posted 13 July 2014 - 10:11 AM

Hi Baxter,

 

Sweet indeed.

 

As usual, thanks for the great references. Thanks also for your code samples. I’ve put them in a folder called “Baxter Serial”. Now there’s a name for a new design!

 

I’m going to purchase the HR-SR04, but I’m ideally on the lookout for a single transducer range finder so I’ll probably purchase something from MaxBotix as well (though I’m not sure about the connections on these since I’ll probably have to solder [something new again] wires to them).

 

Of course, I’m open to any further suggestions you have. Hopefully I’ll be able to build something out with these that doesn’t cost me my sanity.

 

Nathan



#31 jrlyman3

jrlyman3

    Advanced Member

  • Members
  • PipPipPip
  • 67 posts
  • LocationNorth St Paul. MN

Posted 13 July 2014 - 07:50 PM

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



#32 sfx

sfx

    Advanced Member

  • Members
  • PipPipPip
  • 52 posts

Posted 14 July 2014 - 05:34 AM

Hi jrlyman3,

 

Thanks for the feedback. I'm definitely going to test out a HC-SR04 now.

 

Nathan



#33 jrlyman3

jrlyman3

    Advanced Member

  • Members
  • PipPipPip
  • 67 posts
  • LocationNorth St Paul. MN

Posted 16 July 2014 - 02:54 AM

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



#34 sfx

sfx

    Advanced Member

  • Members
  • PipPipPip
  • 52 posts

Posted 16 July 2014 - 04:57 AM

Hi jrlyman3,

 

Am I interested? Of course!

 

When you get a moment, I'd welcome any samples that you think might be of some help.

 

Nathan



#35 jrlyman3

jrlyman3

    Advanced Member

  • Members
  • PipPipPip
  • 67 posts
  • LocationNorth St Paul. MN

Posted 20 July 2014 - 03:14 PM

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



#36 sfx

sfx

    Advanced Member

  • Members
  • PipPipPip
  • 52 posts

Posted 20 July 2014 - 11:52 PM

Hi jrlyman3,

 

This is fantastic! Thanks for posting this for me. My HC-SR04 has not arrived yet, but your code will give me something to work with out of the gate. Much appreciated!

 

Nathan







Also tagged with one or more of these keywords: Serial

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.