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

Driverless PC<->Netduino communication using USB


  • Please log in to reply
79 replies to this topic

#1 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 09 March 2011 - 02:45 PM

With the v4.1.1 beta firmware, you can create a driverless communication channel between your PC and your Netduino...and then send data back and forth.

We have created a sample of how to do this, including a test program. This is a "first cut", and we may be refining this and incorporating it into a future production release.

Please note that this feature requires use of v4.1.1 beta 1 firmware. It is not compatible with the v4.2.0 firmware.

To use this sample:

On Netduino:
1. Make sure you're running the v4.1.1 beta 1 firmware (configured for serial deployment).
2. Open up the UsbHidEchoNetduinoApp project
3. In project settings, select your Netduino's COM port for deployment
4. Make sure your Netduino is plugged in via external power (AC power brick, VIN header, etc.)
5. Deploy the app to your Netduino
6. After the app is running, unplug and reattach the Netduino's USB cable to your PC
7. Windows will discover your "new device" and load the built-in HID drivers

On PC:
1. Open up the UsbHidEchoConsoleApp project
2. Make sure you've started the Netduino's echo project (above) and reattached your USB cable
3. Run the sample. You'll see it discover and connect to the Netduino...and then send a bunch of echo packets back and forth

This echo sample is unoptimized and is designed to give you a "known good" starting point in using the new USB HID comm channel functionality.

To use the comm channel in your own app, just grab the source files from the two projects and incorporate them into your project. They're licensed via Apache 2.0--so you're free to share the source (or use it guilt free in commercial apps).

Enjoy, and please share your feedback in this thread.

Chris

EDIT: updated UsbHidEchoConsoleApp project on 10-March-2011 to fix SafeFileHandle (CloseHandle) issue.

Attached Files


  • Unmalaawale likes this

#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 09 March 2011 - 02:47 PM

A few quick notes: 1. For the v4.1.1 beta, you'll need to debug/deploy over serial to use the USB port in your Netduino app. 2. We're using interrupt USB endpoints in this sample (1ms resolution); we may change to bulk USB endpoints in future revisions. 4. We created a special "lite stream" for this sample. We will probably switch to regular streams once we performance tune. 5. The object model is really simple: creating the object opens the stream; use read() and write() methods to read/write byte data; dispose of the object to close the stream. Chris

#3 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 10 March 2011 - 04:43 PM

One other really cool feature of the HID comm channel... With HID, you can "share" USB pipes between the PC and the Netduino. If you want to have multiple programs read/write to your Netduino _simultaneously_, just modify the "usblitestream" code for both desktop and Netduino apps as follows: On the PC, change the "share" method of the CreateFile call to "share read and share write". This will allow multiple simultaneous connections to the Netduino. If you're just sending data from the Netduino to the PC, that's all you need to do. Packets sent from the Netduino to the PC will go to all programs which are connected to it. If however you want to have multiple bidirectional channels, you can: 1. Create two sets of HID endpoints and two HID connections on the Netduino--for two PC clients. Or... 2. You can simply use the second byte of each USB packet (after the length byte) as a "channel id" byte--and then process that id on either/both sides to filter/process the packets. You could have 256 channels this way. Chris

#4 Dr. Genestealer

Dr. Genestealer

    New Member

  • Members
  • Pip
  • 5 posts
  • LocationEngland, UK

Posted 16 March 2011 - 11:41 PM

Hi everybody, As it currently stands, are we able to program and communicate to the netduino using only the USB cable? Thanks, Richard

#5 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 17 March 2011 - 12:45 AM

As it currently stands, are we able to program and communicate to the netduino using only the USB cable?


Hi Richard,

You can debug with the Netduino via USB and output info to the PC (using Debug.Print) via USB.

You can deploy/debug using serial...and use the USB for a custom feature.

We're working on more options for the future. If you have strong soldering skills, you can always put a jumper wire between D+ and a GPIO (and then control the D+ pullup)...which would technically let you debug/deploy and use the USB feature at the same time. But you'd lose the ESD protection we built into Netduino. And it's very hack-ish, so we normally don't mention that option.

Chris

#6 dyadica

dyadica

    Member

  • Members
  • PipPip
  • 17 posts

Posted 17 March 2011 - 11:29 AM

Cool, this is what I have been waiting for :) I'll give it a bash as soon as I get in from work and report back my findings.

#7 Dr. Genestealer

Dr. Genestealer

    New Member

  • Members
  • Pip
  • 5 posts
  • LocationEngland, UK

Posted 17 March 2011 - 01:46 PM

Hi Richard,

You can debug with the Netduino via USB and output info to the PC (using Debug.Print) via USB.

You can deploy/debug using serial...and use the USB for a custom feature.

We're working on more options for the future. If you have strong soldering skills, you can always put a jumper wire between D+ and a GPIO (and then control the D+ pullup)...which would technically let you debug/deploy and use the USB feature at the same time. But you'd lose the ESD protection we built into Netduino. And it's very hack-ish, so we normally don't mention that option.

Chris


Hi Chris,

Thanks for the speedy reply.

What I would like to understand is how I could control the netduino's outputs and read the inputs from and c# or vb application running on a connected pc, via the usb port.

The netduino would, in effect, act as a passive device. Allowing the application on the pc control over the digital i/o and analogue inputs. I was thinking I could load the code to the netduino and then switch it over to allow control over the USB to the app on the pc. (I know to get it back in debug mode I may have to re-load the bootloader)

I currently only have a USB cable and would like to avoid buying a 3.3V USB-to-Serial cable. (Though I do have an old ebay-special USB to RS-232 compatible serial port adaptor, but did I read that standard computer serial com ports are more like +12v to -12v)

Any ideas?

Thanks,
Richard

#8 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 17 March 2011 - 02:15 PM

Hi Richard, You can pick up an inexpensive RS232 shield for Netduino if you'd like to communicate with your USB to RS-232 cable instead. As one example, CuteDigi makes one. You can write a simple "request and response" application on your Netduino that will allow your PC to read/write to its digital ports. We've actually done something similar for the Netduino test jigs (the machines that we use during the production process). Once you're done with your application, remove the RS232 shield and use your Netduino as a USB device. Chris

#9 Michel Trahan

Michel Trahan

    Advanced Member

  • Members
  • PipPipPip
  • 155 posts

Posted 31 March 2011 - 05:36 PM

It made me think ... could it be used to connect multiple netduinos and perform heartbeat check on each other for redundancy ? Mike.
Started with C in 1985, moved to Vb3 ... to vb6 and stopped. Now started with .Net and learning C# and VB.net and wishing VB.net was on MF !

#10 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 31 March 2011 - 06:52 PM

Hi Michel,

could it be used to connect multiple netduinos and perform heartbeat check on each other for redundancy ?


You can absolutely hook up multiple Netduinos to your PC at the same time...and communicate with them using separate HID channels.

Chris

#11 Michel Trahan

Michel Trahan

    Advanced Member

  • Members
  • PipPipPip
  • 155 posts

Posted 27 April 2011 - 09:33 PM

You know ... this is dangerous for someone who reads too fast ... I tried it without having a rs232 shield for the netduino and now it won't communicate with the pc ... What are the steps ? 1- Buy the RS232 Shield 2- Place it on top and connect usb-rs232 cable to it and the computer 3- ReDeploy something else using serial 4- then everything should be back ok ? Mike and his errors ...
Started with C in 1985, moved to Vb3 ... to vb6 and stopped. Now started with .Net and learning C# and VB.net and wishing VB.net was on MF !

#12 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 27 April 2011 - 09:50 PM

What are the steps ?


Hi Mike,

That will work. You can also erase your Netduino using the erase pad...and then redeploy the bootloader using Atmel SAM-BA and the firmware using MFDeploy...all using USB.

Chris
  • Michel Trahan likes this

#13 Michel Trahan

Michel Trahan

    Advanced Member

  • Members
  • PipPipPip
  • 155 posts

Posted 28 April 2011 - 02:10 AM

You can also erase your Netduino using the erase pad...and then redeploy the bootloader using Atmel SAM-BA and the firmware using MFDeploy...all using USB.

Should I install v4.1.1 beta firmware even if I only have an ordinary netduino ?
Started with C in 1985, moved to Vb3 ... to vb6 and stopped. Now started with .Net and learning C# and VB.net and wishing VB.net was on MF !

#14 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 28 April 2011 - 03:02 AM

Should I install v4.1.1 beta firmware even if I only have an ordinary netduino ?


Sure, if you'd like to use some of the new features (enhanced I2C/SPI features).

Just to be sure to flash it with the Netduino bootloader/firmware instead of the Netduino Plus bootloader/firmware.

Chris

#15 Michel Trahan

Michel Trahan

    Advanced Member

  • Members
  • PipPipPip
  • 155 posts

Posted 28 April 2011 - 12:52 PM

You can also erase your Netduino using the erase pad...and then redeploy the bootloader using Atmel SAM-BA and the firmware using MFDeploy...all using USB.

Great News everyone, Terry Massey found a new way to get out of this mess. FOLLOW THIS PROCEDURE TO THE LETTER :

Prepare everything since time is of the essence.

1- Have your netduino with the mini usb connected to it but not to the computer (leave the usb connection near the ports)
2- Start MFDeploy.exe, select USB as the transport (the combobox will be empty, and that is ok)
3- Put the mouse over the "erase" button on MFDeploy.exe

Once you are ready do this :

1- Press and hold the push button on the netduino for the whole procedure (leave it pushed at all times)
2- Plug the USB to the computer
3- You should see the combobox in MFDeploy.exe contain your usb port
4- Press as fast as you can the "erase" button on MFDeploy.exe
5- You can now release the push button on the netduino

If it worked, you should get a message asking if you are sure you want to erase the software on the netduino. This will only delete de software, not the bootloader :)

You can now deploy some other application while waiting for you RS232 shield and try the HID again :)

THANKS TERRY !
Started with C in 1985, moved to Vb3 ... to vb6 and stopped. Now started with .Net and learning C# and VB.net and wishing VB.net was on MF !

#16 Luca Monaco

Luca Monaco

    New Member

  • Members
  • Pip
  • 3 posts

Posted 07 May 2011 - 10:14 AM

Hi, Can I use USB port for read/write data from another device? I need read/write data from a Photovoltaic Inverter by USB interface. If I link the Inverter with my Windows PC, it install a virtual COM Driver.

#17 Jay Beavers

Jay Beavers

    New Member

  • Members
  • Pip
  • 6 posts

Posted 12 May 2011 - 02:16 PM

Any updated news on shared debugging/deployment/communications over a single USB channel? I'm very excited by this new capability and very much looking forward to starting a new project once I have firmware with this capability.

#18 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 12 May 2011 - 02:43 PM

Any updated news on shared debugging/deployment/communications over a single USB channel?

I'm very excited by this new capability and very much looking forward to starting a new project once I have firmware with this capability.

Working on a few options... No news to share quite yet.

Chris

#19 Mati

Mati

    New Member

  • Members
  • Pip
  • 9 posts
  • LocationIsrael

Posted 30 May 2011 - 01:10 PM

Hey, Why an AC Brick / External power is required? Though the USB cable should provide the voltage. I am planning to implement a custom HID device. My question is, will I require an external power source to run my device in order to enjoy USB communication? When I attach the Netduino, it won't recognize the device unless it's plugged to an AC brick, the echo console app tells me the same
Windows XP SP3, Q6600.

#20 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 30 May 2011 - 04:34 PM

Hi Mati,

Why an AC Brick / External power is required?
Though the USB cable should provide the voltage.


At this time, the external power is required. This is because the device can't enumerate until the "custom USB" feature is started up--and the "custom USB" feature isn't started until after the board is powered.

Chris
  • Phillip Brooks likes this




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.