
Nubsio GPIO API – A Windows USB interface for controlling external devices - madeintheusb
http://madeintheusb.blogspot.com/2017/04/nusbio-gpio-api.html
======
NinoScript
Please change the default direction to input (high-z). You could potentially
fry some sensor or make a short circuit if they start in output before the
code changes them to input.

~~~
Animats
Agreed. Power up sequencing on dumb low-level interfaces has to be thought
through carefully. You may turn on something you don't want to turn on.

I have a device which controls an antique Teletype machine from a USB port. It
uses the request to send signal on a USB-simulated serial port to start the
Teletype motor. This works fine on Linux. On Windows, the motor starts and
stops several times when the USB device is plugged in or Windows starts up.
That's because an old Windows feature is probing the serial port for a serial
mouse. Annoying.

~~~
fest
It's even more annoying when Windows does succeed interpreting data coming
from device and cursor starts moving around and clicking randomly.

------
keithnz
I don't get it, why is this even high up on HN? There's a ton of similar
products, many which do a lot more than this that can be controlled using .net

~~~
nitrogen
Link to some of them maybe?

\---

 _Edit:_ some I have used or heard of that may or may not have .net support:

USB Bit Whacker -
[http://www.schmalzhaus.com/UBW/](http://www.schmalzhaus.com/UBW/)

Ultimarc control interfaces (haven't tried them) -
[http://www.ultimarc.com/](http://www.ultimarc.com/)

~~~
tyingq
An FTDI FT232H is popular in this space as well. You can get one already on a
breakout board for $15.
[https://www.digikey.com/products/en?mpart=2264&v=1528](https://www.digikey.com/products/en?mpart=2264&v=1528)

Tutorials, etc, here: [https://learn.adafruit.com/adafruit-
ft232h-breakout](https://learn.adafruit.com/adafruit-ft232h-breakout) Includes
some python code that works on Windows, Linux, etc.

~~~
fredericaltorre
Adafruit does not support .NET on Windows.

~~~
tyingq
Adafruit just put the chip on a breakout board. There's .net support for it.

A couple of sources:

[http://www.ftdichip.com/Support/SoftwareExamples/MPSSE/FTCSP...](http://www.ftdichip.com/Support/SoftwareExamples/MPSSE/FTCSPI.htm)

[https://github.com/zhelnio/MPSSELight](https://github.com/zhelnio/MPSSELight)

~~~
madeintheusb
You are right there is .NET support, I used it the SPI library. I think there
one library for I2C and one for SPI. I settled on the FTDI ft4222 which is
somehow easier to program and can only do SPI and I2C (no IO, no UART). The
FT232H could be faster in SPI.

------
kenz0r
Serial interface, and GPIO reads are polled. Its a good first or second year
uni project, but its not a product.

~~~
rattray
Sorry, just a curious passerby - why are those things bad?

~~~
jjcc
Polling usually is not considered to be a real time method. To reduce latency
it will consume unnecessary CPU cycle, I think

~~~
Matthias247
it actually is, as long as your polling interval is deterministic and meets
the requirements of your target application (polling interval < state change
interval).

If you look at real hardware (or FPGAs) they will basically do polling: The
input gets sampled at each clock cycle and will then get processed. And
hardware is definitely realtime :)

The downside of polling is that you burn CPU resources when actually nothing
happens. Interrupt driven designs help there.

~~~
sokoloff
> If you look at real hardware (or FPGAs) they will basically do polling: The
> input gets sampled at each clock cycle and will then get processed. And
> hardware is definitely realtime :)

Smiley noted; I think we can agree that "polling at 10s of MHz on an input
pin" becomes something quite different than "polling at 10s of kHz on the
other side of a USB link".

------
jacquesm
I would caution against trying to drive anything serious from an IO solution
whose inputs are not interrupt driven. Please use a real time operating system
for jobs like these and communicate with your windows box on a higher
abstraction level than directly driving outputs.

If you don't do that you risk your machinery not responding to critical inputs
resulting in machine damage or worse.

If all you want to do is play around with lights and switches then this is
fine.

------
molticrystal
I think it would be more interesting to take ports found on many computers
that aren't being used and turn them into GPIO.

There are Ethernet to Serial adapters [1] [2], I wonder if it could go
further. There is also dvi, hdmi, displayport with lots of wires and a chip
behind them. Displayport even has " A bi-directional, half-duplex auxiliary
channel" [3] , though I'd want to look at the spec to see how that could be
used, or if it could be contorted to a GPIO purpose.

[1]
[https://en.wikipedia.org/wiki/PHY_%28chip%29](https://en.wikipedia.org/wiki/PHY_%28chip%29)

[2] [https://electronics.stackexchange.com/questions/24588/is-
the...](https://electronics.stackexchange.com/questions/24588/is-there-any-
way-to-send-serial-data-over-physical-ethernet-layer-with-no-encaps)

[3]
[https://en.wikipedia.org/wiki/DisplayPort](https://en.wikipedia.org/wiki/DisplayPort)

------
yitchelle
Using a i7 with Win10 just to get the blink LEDs application going is a bit
over the top :-)

Joking aside, having one of these for a kid to play with is a good way to
introduce them to world of controls. They are some areas to work through
(polled inputs, default pin configuration etc) but it is a good start. Hoping
that v2.0 will be more bespoked.

~~~
madeintheusb
I designed Nusbio 1 to be cheap and a first USB device for .NET developers
with little knowledge in electricity to start playing with IO, I2C, SPI, ADC
directly from Windows and .NET languages.

It has some limitations in terms of IO default state, IO polling or speed of
transfer (I2C:15Kbyte/S, SPI:15KBytes/S To 28KBytes/S). Samples in C#, VB.NET
or Powershell codes are available on github.

Regarding the IO polling issue, I do not think this can be address with a
Windows PC or Linux on the Raspberry PI. I tested the USB interrupt for the
FTDI FT4222 and this is not very impressive.

Nusbio v2 coming sometime this year will address some of these issues, IO
default state as input, increase in speed transfer (I2C:Up to 128Kbyte/S,
SPI:Up to 2.4 Mbyte/S), 10 bit ADC. But unfortunately will be more expensive.
Therefore not a device for beginner or small project.

see
[https://twitter.com/MadeInTheUSB/status/848013033335029761](https://twitter.com/MadeInTheUSB/status/848013033335029761)

~~~
LeifCarrotson
First, love your username. And it's impressive to get this level of a product
together!

> Regarding the IO polling issue, I do not think this can be address with a
> Windows PC or Linux on the Raspberry PI. I tested the USB interrupt for the
> FTDI FT4222 and this is not very impressive.

Yeah, that's not the right approach. As a controls engineer who builds PC-
based test and manufacturing equipment, this is your competition:

[http://www.ni.com/pdf/manuals/374369a.pdf](http://www.ni.com/pdf/manuals/374369a.pdf)

[http://www.ni.com/pdf/manuals/374566d.pdf](http://www.ni.com/pdf/manuals/374566d.pdf)

These can be programmed with .NET languages and C/C++ using Measurement
Studio, or graphically through LabView.

I think the critical differences are (1) using USB directly, rather than a
serial emulator, enabling much higher data rates - you don't necessarily need
this yet, low-speed is probably fine and (2) using internal FIFOs and Tasks to
control IO instead of handling each bit over the connection.

Essentially, what you want to do is push all the real-time stuff off to the
microcontroller on the peripheral, and only synchronize every couple hundred
milliseconds with the PC, which will essentially take in a large buffer with
the history of the inputs at 1 kHz or more, and output a similarly sized
buffer with the data to be encoded on the outputs until the next
synchronization. Anything that needs to happen faster than that needs to be
set up before hand.

------
kodfodrasz
It is not clear to me if this is a product anouncement, or a blog article
about something you made using a product.

If the former, then why should anyone choose this over Netduino? If the
latter: why have you chosen this product?

edit: by browsing the page I saw it is the former.

------
nimish
Why not just use [https://developer.microsoft.com/en-
us/windows/iot/docs/wra](https://developer.microsoft.com/en-
us/windows/iot/docs/wra) ?

------
sigmaprimus
What makes this anything more than an arduino in a box?

[http://playground.arduino.cc/Interfacing/Csharp](http://playground.arduino.cc/Interfacing/Csharp)

~~~
mbanzi
Depends on the protocol they use on the USB connection. Serial over USB has
its quirks. Using a Leonardo, a Due or a SAMD21 based Arduino allows you to
implement something like HID which should give you better latency

~~~
madeintheusb
You are right though I do think HID is limited to 64 Kbytes/S. But an SAMD21
or 32U4 could allow me to build a cheaper product. I have to think about it
now.

What I am currently achieving is

\- 100Kbytes/S in I2C with a 10Mhz I2C EEPROM and \- 2.4 Mbytes/S in SPI with
a NOR FLASH at 103Mhz

using the FTDI FT4222 and the FT232H should the same or better.

------
Animats
There's tons of those things. Adafruit has one.[1] They're useful, but if
you're doing something with critical timing, you usually don't want a Windows
machine on the other end.

[1]
[https://www.adafruit.com/product/2264](https://www.adafruit.com/product/2264)

~~~
pjmlp
Or UNIX for that matter, both don't play on the same league as high integrity
OS, if that is what you mean.

[http://www.ghs.com/products/rtos/integrity.html](http://www.ghs.com/products/rtos/integrity.html)

------
dheera
How is this better than an Arduino and just serial communication, which all of
these languages support?

~~~
mbanzi
Check out [https://microsoft.hackster.io/en-US/windowsiot/basic-
windows...](https://microsoft.hackster.io/en-US/windowsiot/basic-windows-
remote-arduino-47eeb9) from microsoft. As I wrote in another comment Serial
over USB is not great if you want to contain latency. Something like HID or a
custom protocol using the Leonardo or the Zero would give you much better
results

------
ngcc_hk
wonder (i) anything for mac and xcode based trial and (ii) any programmer
suggested.

all just for hobby and my attempt to understand. have beadboard exprience and
follow a course that use windows xp and M3 and a propeiority tool from TI.

