Monday, February 15, 2016

Temperature Sensor For .NET

Overview


Do you want to know the temperature around your laptop in your .NET app?


Nusbio is a USB device that can talk the different protocols to query temperature sensors.
Nusbio is fully programmable in any .NET languages.

Communication Protocols 


There are 3 protocols supported
  • SPI
  • I2C
  • Analog
Temperature using the 1 Wire protocol like sensor family of DHT XXX are not supported.

Temperature sensors tested

  • MCP9808 - I2C
    • Very accurate ±0.25 (typical) from -40°C to +125°C 
    • Datasheet
    • Price for one: $1.22
    • Package MSOP-8
      • A little bit challenging to solder manually, but possible
      • Adafruit has a breakout (breadboard compatible)
    • We have an adapter for Adafruit I2C device (see photo above)
  • TC77 - SPI
    • Accurate 1°C (max.) accuracy from +25°C to +65°C
    • Datasheet
    • Price for one: $1
    • Package SOIC-8
      • Easy to solder manually on a adapter (See picture below)
    • We are working on an extension for it that will be plug and play
  • TMP36 - Analog
    • Not very accurate. ±2°C accuracy over temperature.
    • Datasheet
    • Price for one: $1.36
    • Can be plugged into a breadboard
    • This  temperature sensor requires an ADC (Analog to Digital Converter)
    • We have noticed that the TMP36 does not perform correctly with our Analog Extension

    TMP36 analog temperature sensor (in black)
    plugged into the Nusbio Analog Extension

    Conclusion


    If you need to query for temperature in your .NET app in an easy to assemble solution we recommend the
    • Adafruit MCP9808 breakout + Nusbio adapter for Adafruit I2C device
    • Coming soon our own plug and play extension for the TC77

    Saturday, February 13, 2016

    USB to SPI for .NET - EEPROM


    EEPROM and Nusbio G1

    The Nusbio library supports the following EEPROMs

    • SPI 128k 25AA1024
      • Transfer the 128k in 5.8s 22Kb/SS 
      • Transfer the 128k in 89ms with Nusbio G2 prototype 1438 Kb/s 15Mhz
    • SPI 32k 25AA256
      • Transfer the 32k in 1.5s 21Kb/SS 
    • I2C 32k 24LC256
      • Transfer the 32k in 4.5s 7Kb/SS  






    Friday, February 12, 2016

    USB to SPI for .NET (performance)

    USB to SPI performance

    Getting good performance with a USB to SPI with a USB 2.0 full speed also depend also on what slave chip you are controlling, for example:
    • Let's pick the MAX7219 (10Mhz) an LED driver used to control 7-Segment display or 8x8 LED matrix.
      The communication protocol is :

          SELECT Byte0:Command, Byte1:Data, UNSELECT

      It does not really matter the speed at which the 2 bytes are transferred, after the 2 bytes, the MAX7219 required the UNSELECT. Most USB to SPI chip will therefore end the USB operation. With each USB operation there is a penalty at least of 1 Milli-second.
      If the USB to SPI chip (Software and hardware) allows to package multiple SELECT, Data, UNSELECT in one USB operation, then we will get good performance.
    • An EEPROM are generally more forgiving because we generally transfer pages of bytes. So for the cost of one USB operation we can transfer 64, 128, 256, ... bytes. But then it also depend on how much buffer the chip has.
    • A third case is for example the SPI OLED SH1106 or SSD1306 driver (128x64 monochrome pixel), which requires also extra GPIO named D/C (Data or Command).
      The communication protocol is :

      SELECT, DC=C, Cursor Position 3 bytes, UNSELECT, SELECT, DC=D, 128 data bytes, UNSELECT

      We need 8 times this sequence to send a full refresh of the display.
      If we cannot combine in one USB operation multiple sequences SELECT, DC, Data, UNSELECT. We will not get good performance even with a clock at 12Mhz.
      So it depends on the hardware and software feature of the chip.
      I am going to call this feature: USB to SPI Low Level Optimization.

      For example Nusbio G1 library (FT231X Chip) do support this mode and this allow to support the devices mentioned above with acceptable performance. That said the USB Buffer of the FT231X is 1k, so we can only package the bit banging in batch of 1024 and then we hit the USB operation penalty. That is why Nusbio G1 performance depending on the SPI slave device are between 10 K byte/s and 20 K byte/s.

      The FTDI FT232H is the only chip so I tested that support SPI Low Level Optimization.
      In FTDI world it is called MPSSE (Multi Protocol Synchronous Serial Engine). All FTDI chips supporting this mode can do SPI, I2C in very optimized way. This FT232H is High speed, the FT2232 is Full speed. More on the FT232H later.
    • USB 2.0 Highspeed. In Highspeed mode the cost (latency) of an USB operation is 100 nano second (I think). Therefore we can get better performance without SPI Low Level Optimization. Though it is preferable to have access to it.

    Digital Potentiometer SPI AD5290 and Nusbio

    Overview


    The Digital Potentiometer AD5290 is not a regular one.
    1. It provides 2 supply modes
      1. Single supply, Positive voltage
      2. Dual supply, Positive voltage and negative voltage
        You need to provide the positive and negative voltage (pin 1 and 2)
    2. In mode 1, the current can be between 20 and 30 Volts.
      In mode 2, the current +-10 to +- 15 volts
    3. It is only available in MSOP-10
    Datasheet


     

    SPI


    The AD5290  is an SPI chip which does not use MISO (The chip does not send information back).
    Be care full, the SDO pin is used for daisy-chaining

    The recommended wiring with Nusbio is a follow

    GPIO 0 - CLOCK
    GPIO 1 - MOSI
    GPIO 2 - CS

    VB.net Code

    Wiring

    5 Volts from the USB

    In this wiring, we use the Single supply, positive 5 volts mode from Nusbio and therefore from the USB.


    9 Volts from a battery

    In this wiring, we use the Single supply, positive 9 volts mode from a battery.
    Nusbio GPIO 0,1,2 should never be in contact with the 9 Volts from the battery.



    Thursday, February 11, 2016

    SPI digital potentiometer AD5290Y 10k with some vb.net code

    SPI digital potentiometer AD5290Y 10k with some  code and Nusbio










    Monday, February 8, 2016

    USB to SPI for .NET

    Overview

    I started investigating the hardware architecture for Nusbio 2. With the new device I would like to achieve a transfer of at least 100 K byte /s and target 1 M byte/s.
    (Update: 2017.04.02 with the FTDI FT4222 I achieved 100 Kbyte/S in I2C using a 32k byte EEPROM and 2.4 MebaByte/S using a NOR FLASH at 100Mhz)

    I most likely will use a USB 2.0 to SPI chip and add a micro-controller like the ATiny84 to provide
    • More GPIOs
    • PWM
    • ADC
    • EEPROM storage
    I may select a Full speed or High speed. High speed is faster, but more expensive and most likely does not exist in package SSOP-20, but rather LQFP-48 or QFN-48.

    In this post, I will summarize my findings regarding the chips I tested. Obviously my end goal is to create a .NET compatible device.

    USB to SPI performance

    See blog: USB to SPI for .NET (performance)


    Test Scenarios

    1. Test1 - Transfert 32 K byte of data from EEPROM 25AA256 (support SPI 10MHz) to computer in C#.
    2. Test2 - Transfert 128 K byte of data from EEPROM 25AA1024 (support SPI 10MHz) to computer in C#.


    USB to SPI Chip

    • MicroChip - MCP2210 Datasheet
      • Evaluation board ADM00419 $15
      • USB 2.0 Full speed
      • SPI Bitrate 3 Mbps
      • 128 byte buffer
      • GPIO for select: 8
      • Packages: 20-lead QFN, 20-lead SOIC, 20-lead SSOP
      • Price: $1.98 for one
      • .NET samples: Yes
      • SPI Low Level Optimization: Most likely No
    • Cypress - CY7C65211 Datasheet
      • Evaluation board  CY8CKIT-049-42XX $4
      • USB 2.0 Full speed
      • Bitrate 3 Mhz
      • 256 byte buffer
      • GPIO for select: 5 
      • Packages: 24-lead QFN
      • Price: $2.61 for one
      • .NET samples: No. C code.
      • SPI Low Level Optimization: Most likely No
      • Remark: Can be configured as UART, SPI or I2C
    • FTDI - FT232H Datasheet
      • Evaluation board  UM232H $20
      • USB 2.0 High speed
      • Bitrate 30 Mhz for SPI
      • 64k byte buffer
      • GPIO for select: 5
      • Packages: 48-lead QFN
      • Price: $4.25 for one
      • .NET samples: Partially, Require C DLL.
      • SPI Low Level Optimization: Yes
      • Remark: Can be configured as UART, SPI, I2C, JTAG, FIFO, Bit banging.

    • SILICON LABS - CP2130 Datasheet
      • Evaluation board  CP2130EK $20
      • USB 2.0 High speed
      • 6.6 Mb/s for SPI (844Kbyte/S, Video)
      • xx byte buffer
      • GPIO for select: 11
      • Packages: 24-lead QFN
      • Price: $2.16 for one
      • .NET samples:?
      • SPI Low Level Optimization:?

    Test Result

    • MicroChip - MCP2210
      • At the SPI Bitrate 3 Mhz (which cannot be increased)
      • Downloading the 32k of  data in chunk of 32 pages of 64 bytes (2k)
      • 4.559s 7.02 K byte/S
      • Conclusion: Really bad performance.
    • Cypress - CY7C65211 
      • At the SPI Bitrate 3 Mhz  
      • Downloading the 32k of  data in chunk of 16 pages of 64 bytes (1k)
      • 12 K byte/S
      • I asked on the Cypress forum for help - Page. So far no real help from the Indian support.
    • FTDI - FT232H 
      • At the SPI Bitrate 10 Mhz (Max supported by the EEPROM)
      • Downloading the 32k of  data in chunk of 256 pages of 64 bytes (16k)
      •  0.03s  1066.67 K byte/S
      • Conclusion: Really very nice performance. and the FT232H can goes up to 30 Mhz.
    • SILICON LABS - CP2130

    More About The MCP2210

    •  Kerry Wong, blogged a lot about the MCP2210 at http://www.kerrywong.com.
    • In his post "Finicky MCP2210 Oscillator", John Davis added the following comment, which explain a lot.

      WARNING: According to our trouble ticket interactions with Microchip technical support, the MCP2210 is “throttled” internally with a mininum SPI inter-byte spacing of about 45uS REGARDLESS of SPI clock frequency (we got 12 MHz working on our board.) That limits the byte data rate to about 23KBytes/second max. However, the performance is still limited further by the fact that it is an HID device with a HID-limit 64KByte/second interface. Two USB 128 byte transactions of 3mS each with a wait in between are required for a transfer, so the effective data rate using full 60 byte packets works out to slightly less than 8KBytes/second (Verified with ‘scope.) THIS IS NOT A HIGH THROUGHPUT PART!



    Tuesday, February 2, 2016

    Technical Precisions About The Nusbio Device

    What is Nusbio?

    Nusbio is USB device that bring the following to a Windows machine and the Microsoft .NET Runtime:

    Device

    • Gpios

      • 8GPIO pins
      • 3 or 5 volts 
        • Nusbio version based on the chip FT232RL can be changed between 3.3 and 5 volts (GPIO and VCC). In 2017 only the version based on the FT232RL will be sold.
        • Nusbio version based on the chip FT231X only the VCC can be changed between 3.3 and 5 volts. The GPIO are always 3.3 volts.
      • Modes: OUTPUT or INPUT PULL UP.
      • Maximum current per GPIO pin default 4 mA .
        The Console application allows to switch from 4 to 16 mA.
        In 16 mA of current mode we noticed that the I2C protocol does not work.
     Powering devices connected to Nusbio
      • The VCC output from Nusbio provides 5 or 3.3 volts and up to 500 mA of current as defined by the USB 2.0 standard.
      • The VCC output can be used to power other devices connected to Nusbio.
      • Some Nusbio version based on the FT231X have a fuse that will limit the consumption to 500 mA of current.
      • The voltage can be changed depending on the version as follow:
        • De-soldering the 5 volts connector and soldering the 3 volts connector.
        • Or switch the jumper between 5 volts and 3 volts
    • SPI Protocol

      • Mode

        • Clock MODE_CPOL0_CPHA0 supported and tested
        • The other 3 modes have been implemented but not tested.
      • Tested Devices

        • MCP3008 - 8 DAC
        • MAX7219 - 7-Segment Driver
        • 25AA256 - 32k EEPROM
        • 25AA1024 - 128k EEPROM
        • MCP23S08 - 8 Gpio Expander 
        • OLED drivers
          • SD1306
          • SH1106
        • SPI Compatible Devices
          • 74HC595 - Shift register
          • APA102 RGB LED
      • SPI Slave

        • Number of devices on an SPI bus. Since Nusbio comes with 8 gpios, we can control 5 (8-3 (clock, miso, mosi)) SPI devices on the same bus.
      • Transfert Speed

        • When data in and data out communication is needed (MOSI and MISO) the maximum transfer rate is around 15 k byte/s with no optimization.
        • With specific optimization for EEPROM downloading in batch of 128 pages of 64 bytes, the transfer rate can go up to 28 k byte/s.
        • Generally speaking when only data out communication is needed (no MISO) the transfer rate can go up to 20 k byte/s by using the class GpioSequence rather than the class SPIEngine. The class GpioSequence offers a way to optimize the bit banging.
        • Transfer speed vary depending on the SPI device and the Windows PC.
        • Nusbio and the C# class SPIEngine can transfer in one USB operation multiple SPI buffer (Select + Data + UnSelect + Select + Data + UnSelect).
        • Some SPI device like the OLED driver SH1106 or SSD1306, required on top of the Select pin (CS) another pin named D/C (Data or Command). Nusbio and the C# class SPIEngine can transfer in one USB operation multiple SPI buffer (Select + D/C + Data + UnSelect + Select + D/C + Data + UnSelect. (See our source code on GitHub).
    • I2C Protocol

      • Tested Devices:
        • 24LC256 32k EEPROM
        • MCP2308 - 8 Gpio Expander 
        • MCP9808 - Temperature sensor
        • MCP4725 - 12Bit DAC 
        • HT16K33 - Matrix Driver 
        • Adafruit I2C LED Matrix devices
      • Transfer Speed 
        • The tests were performed by downloading 32k from the I2C EEPROM 24LC256 . 
        • Transfer speed around 7.5K byte/s. 
        • Transfer speed vary depending on the device and the Windows PC.
    • SPI and I2C Protocol Combined

      With Nusbio it is possible to control SPI and I2C devices from the same configuration. For example

      • GPIO 0,1,2 would be reserved for SPI BUS: CLOCK, MOSI and MISO
      • GPIO 3,4,5 would be used as SELECT for 3 SPI Devices
      • GPIO 6,7 would be used as SDA and SCK for the I2C bus, allow to control up to 127 devices

    • UART

      Nusbio can also play the role of an UART (FTDI cable, FTDI Friend) to upload data into an micro-controller like an Adafruit Trinket or Diavolino.
      The .NET library MadeInTheUSB.Lib.dll does not support this mode. The Arduino IDE will support Nusbio to upload code into an micro-controller with no UART.

      Videos

    •  Library/Assembly

      • The MadeInTheUSB.Nusbio.Lib .NET assembly give access to the Nusbio device to any .NET language.
      • The MadeInTheUSB.Nusbio.Components assembly contains classes for specific components including the one used in the Nusbio's extensions.
      • Github Source

    • Internal EEPROM

      Nusbio can store up to 32 bytes of data into the Description field. Though the Description property is a .NET string, the EEPROM only support ASCII string.
    • Unique Serial Number

      Each Nusbio device is initialized with a unique Serial Number. See property SerialNumber.

    Chip

    Nusbio is based on the FTDI FT231X chip (Datasheet) or the FT232RL.
    In 2017 only the FT232RL chip is used.