tag:blogger.com,1999:blog-70445562121896750782024-03-05T03:00:47.721-08:00MadeInTheUSBAnonymoushttp://www.blogger.com/profile/16516471292134914481noreply@blogger.comBlogger47125tag:blogger.com,1999:blog-7044556212189675078.post-81013460075054581062017-04-22T11:17:00.002-07:002017-06-18T08:47:12.844-07:00Nusbio - UART Api<h2>
Overview</h2>
The Nusbio v1 USB device which offers<br />
<ul>
<li>8 gpios with I2C and SPI support </li>
<li>for Windows programmable in any .NET language </li>
</ul>
is based in the FTDI chip FT232RL. Therefore it can also be used as a UART or serial communication. <br />
This also known as an FTDI friend and can be used to upload code on an Arduino compatible that do not have a UART chip on board like the<br />
<ul>
<li>Diavolino from Evil Mad Scientist</li>
<li>Trinket Pro from Adafruit</li>
<li>Arduino Pro Mini</li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrTPbv1d949ZGiCs5tf9JlmR-TNiHt4E28q7080oDXhGAvamcE38C8NbTx6aROInU5B3VqQ_CfRmXXUdeaYPgj12fcHrNRcPw83uuE8eiDv3FIkEKxJOc3_Zw9BZLtBIGY5suaDjXzBTW8/s1600/FTDI_2_Adapter_01.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="150" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrTPbv1d949ZGiCs5tf9JlmR-TNiHt4E28q7080oDXhGAvamcE38C8NbTx6aROInU5B3VqQ_CfRmXXUdeaYPgj12fcHrNRcPw83uuE8eiDv3FIkEKxJOc3_Zw9BZLtBIGY5suaDjXzBTW8/s200/FTDI_2_Adapter_01.jpg" width="200" /> </a>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijzYgTWpMdTWcx8RUaztt_sNJJftPylPssHfP7J9Bb82n-Nr6bdC3oowP3xyZcZ1KVrbN1YHGrCwZ9yXJ0vFOfbuH2Avc9_GS_QrFCXA1ntYZWYNpEebLXg-C42FwnBFted3CqE61-TKKS/s1600/Nusbio+FTDI+Cable.01.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="149" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijzYgTWpMdTWcx8RUaztt_sNJJftPylPssHfP7J9Bb82n-Nr6bdC3oowP3xyZcZ1KVrbN1YHGrCwZ9yXJ0vFOfbuH2Avc9_GS_QrFCXA1ntYZWYNpEebLXg-C42FwnBFted3CqE61-TKKS/s200/Nusbio+FTDI+Cable.01.jpg" width="200" /></a></div>
<br />
<br />
<h2>
Extension</h2>
We used to sell the following extension which allows to connect some devices using the following UART pins: TX, RX, CTS, RTS, VCC and GND.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNUvzTvnBbjdqjh3Et_1Uw51v3QAMWmitZ8JtPrVEHne2Cp-dFLT0ncNzWfUw4LWWaESO_CjiQNNE53wY88CQv2qZ2u6_uATF18rvfG1OYHkP66d6e4zVkFvUQWjj4xkUnDDjw0nUFcMxS/s1600/FTDI_2_Adapter_03.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="150" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNUvzTvnBbjdqjh3Et_1Uw51v3QAMWmitZ8JtPrVEHne2Cp-dFLT0ncNzWfUw4LWWaESO_CjiQNNE53wY88CQv2qZ2u6_uATF18rvfG1OYHkP66d6e4zVkFvUQWjj4xkUnDDjw0nUFcMxS/s200/FTDI_2_Adapter_03.jpg" width="200" /> </a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
In case you want to use the Nusbio's 8 GPIOs as USART communication here is the mapping.</div>
<div class="separator" style="clear: both; text-align: left;">
</div>
<ul>
<li>GPIO 0 - RI</li>
<li>GPIO 1 - DSR</li>
<li>GPIO 2 - DTR</li>
<li>GPIO 3 - DCD</li>
<li>GPIO 4 - CTS</li>
<li>GPIO 5 - TX</li>
<li>GPIO 6 - RX</li>
<li>GPIO 7 - RTS</li>
</ul>
Remember that<br />
<ul>
<li>The pin 8 is VCC and pin 9 is GROUND. </li>
<li>Most Nusbio can be configured to be 5 volt or 3.3 volt</li>
</ul>
<br />
<h2>
Activation</h2>
<h3>
How do I use the Nusbio as a UART interface ?</h3>
Simply plug the device in the Windows machine and do not run any Nusbio code. Once plugged a COMX port should be available on the PC.<br />
Use the general Serial Port class offered with your programming language<br />
<br />Anonymoushttp://www.blogger.com/profile/16516471292134914481noreply@blogger.com1tag:blogger.com,1999:blog-7044556212189675078.post-41121722447691779282017-04-02T17:11:00.001-07:002017-04-02T19:57:11.419-07:00Nusbio GPIO API<h2>
Overview</h2>
<br />
Nubsio is a Windows plug and play USB interface to connect your PC to the external world and control electronic devices with any .NET languages. <br />
<br />
Nusbio offers:<br />
<ul>
<li>8 digital Input/Output pins (or GPIO) with support of the SPI and I2C protocols </li>
<li>8 analog to digital pins (ADC, with the Analog or Sensor extension) </li>
</ul>
programmable in any .NET languages<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8GvbpBSv5Y0tsilWM8bd74P_8adZfQH7xV2mT1nA2Zc3SJvpTSqrkisKIFEFru1hilgiPPg8nqpYxLksiT_oH_7ZiPw5afu3c_jP6TUgmkqFO2bKQsePF4qzpaN3uR5BvKRzE7oV-FgWi/s1600/Nusbio.Deluxe.01.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="180" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8GvbpBSv5Y0tsilWM8bd74P_8adZfQH7xV2mT1nA2Zc3SJvpTSqrkisKIFEFru1hilgiPPg8nqpYxLksiT_oH_7ZiPw5afu3c_jP6TUgmkqFO2bKQsePF4qzpaN3uR5BvKRzE7oV-FgWi/s320/Nusbio.Deluxe.01.jpg" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5jHpBgIaW7t-JvactIeF3vT35njTob2QT2wnfxtWQRuSpFi-GXHVLhq62vJmPefmP4vW-PiGf_59FzNiXt9_y4F7F07DeB-RtOxSWdmpQvF3j0A8VfbZ185H1-PLZR41_ZKwHfp0Y-4H4/s1600/20160222_204311.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="179" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5jHpBgIaW7t-JvactIeF3vT35njTob2QT2wnfxtWQRuSpFi-GXHVLhq62vJmPefmP4vW-PiGf_59FzNiXt9_y4F7F07DeB-RtOxSWdmpQvF3j0A8VfbZ185H1-PLZR41_ZKwHfp0Y-4H4/s320/20160222_204311.jpg" width="320" /></a></div>
<br />
<h2>
GPIO API</h2>
<br />
<h3>
PinMode </h3>
By default the GPIO pins are initialized as output. To change the direction of an GPIO pin, use the following methods from the Nusbio class.<br />
<pre class="brush:csharp;">public void SetPinMode(NusbioGpio pin, PinMode mode);
public void SetPinMode(int pin, PinMode mode);
// Sample
var serialNumber = Nusbio.Detect();
using (var nusbio = new Nusbio(serialNumber: serialNumber))
{
nusbio.SetPinMode(NusbioGpio.Gpio0, PinMode.Output); // Enum type syntax
nusbio.SetPinMode(1, PinMode.InputPullUp); // Integer syntax
}
</pre>
<br />
The nusbio.GPIOS property allow to access the 8 GPIO pins using the following interface.
<br />
<br />
<pre class="brush:csharp;">public interface GpioPublicApiBase
{
PinMode Mode { get; }
string Name { get; }
PinState PinState { get; }
bool State { get; set; }
PinState DigitalRead();
void DigitalWrite(PinState on);
void DigitalWrite(bool high);
void High();
void Low();
}
// Sample
var serialNumber = Nusbio.Detect();
using (var nusbio = new Nusbio(serialNumber: serialNumber))
{
nusbio.SetPinMode(NusbioGpio.Gpio0, PinMode.Output); // Enum type syntax
nusbio.SetPinMode(1, PinMode.InputPullUp); // Integer syntax
// Turn gpio pin 0 on
nusbio.GPIOS[NusbioGpio.Gpio0].DigitalWrite(PinState.High);
nusbio.GPIOS[NusbioGpio.Gpio0].DigitalWrite(true);
// Read the state for gpio 1
var state = nusbio[1].DigitalRead();
state = nusbio[1].DigitalReadDebounced();
}
</pre>
<br />
<h3>
Code Sample </h3>
For more information on using the GPIO pins in output mode see the following samples:<br />
<ul>
<li>Nusbio.Console <a href="https://github.com/madeintheusb/Nusbio.Samples/tree/master/CS/MadeInTheUSB.Nusbio.Console" target="_blank">Source</a></li>
</ul>
For more information on using the GPIO pins in input mode see the following samples:<br />
<ul>
<li>Nusbio.Buttons <a href="https://github.com/madeintheusb/Nusbio.Samples/tree/master/CS/MadeInTheUSB.Nusbio.Buttons" target="_blank">Source</a></li>
<li>Nusbio.Keypad <a href="https://github.com/madeintheusb/Nusbio.Samples/tree/master/CS/MadeInTheUSB.Nusbio.Keypad" target="_blank">Source</a></li>
</ul>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAEqWEfeuAcp-3VzrNUNz7NepbmI96PfQaAvgIC-ja0bPA7_xhvlUCexVFqPLy4RQbigeb_eAJ4g4oQQ0YDJ5BlFD8CTzqtsg7Y-X3uEOa9qV-j46sY9bpp2Pu23rOY38pINhn46RWtM_G/s1600/Nusbio_Keypad_3x4_00.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="180" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAEqWEfeuAcp-3VzrNUNz7NepbmI96PfQaAvgIC-ja0bPA7_xhvlUCexVFqPLy4RQbigeb_eAJ4g4oQQ0YDJ5BlFD8CTzqtsg7Y-X3uEOa9qV-j46sY9bpp2Pu23rOY38pINhn46RWtM_G/s320/Nusbio_Keypad_3x4_00.jpg" width="320" /></a></div>
<br />
<ul>
</ul>
Anonymoushttp://www.blogger.com/profile/16516471292134914481noreply@blogger.com1tag:blogger.com,1999:blog-7044556212189675078.post-29645686823665612142017-03-19T12:52:00.002-07:002017-05-27T11:00:42.592-07:00Azure Web Site versus GoDaddyOver the years GoDaddy has build a terrible reputation<br />
<ul>
<li><a href="http://science.time.com/2011/04/04/godaddy-ceo-on-shooting-an-elephant-im-not-sorry/">CEO hunt elephants</a></li>
<li><a href="https://www.rt.com/usa/support-sopa-daddy-web-037/">SOPA support</a></li>
</ul>
But I have been with them for years and changing hosting create issues.<br />
<br />
Anyway I was not very happy with the performance of the hosting plan: <br />
<br />
<i>"Economy Windows Hosting with Plesk"</i><br />
It took about 10 seconds to access my web site, when it was shutdown. And it only remains in memory for about 5 minutes. I probably got a good deal for the first year for hosting and 1 domain name.<br />
<br />
But this week it is renewal time and here are the prices<br />
<ul>
<li>Economy Windows Hosting with Plesk $95.88</li>
<li>For the name MadeInTheUSB.net $16.99</li>
</ul>
That is close to $113 per year, for a domain name + hosting that perform really slowly.<br />
<br />
I already use Azure Storage for backup, so I decided to try the <a href="https://azure.microsoft.com/en-us/pricing/details/app-service/" target="_blank">Azure free plan</a> and well it is free, but there is no wait time to access the web site. <br />
Try it.<br />
<ul>
<li><a href="http://www.nusbio.net/" target="_blank">http://www.Nusbio.net</a></li>
<li><a href="http://www.nusbiomcu.com/" target="_blank">http://www.NusbioMCU.com</a></li>
<li><a href="http://madeintheusb.net/" target="_blank">http://www.MadeInTheUSB.net</a></li>
</ul>
There are limits though<br />
<ul>
<li>The free plan is limited to 60 minutes of CPU/Day</li>
<li>The shared plan as I read it should have been: 240 minutes of CPU/Day, cost $0.013/hour, 240/60*0.013*31 == $1.6 per month, <span style="color: red;"><b>Sound great but</b></span>. (Required for SSL and domain name).<br />But in reality you are charged for 24 hour per day, therefore 24*0.013*31 == $9.6 or $116 for the all year.<br />See: <a href="https://azure.microsoft.com/en-us/pricing/calculator/?service=app-service" target="_blank">App Service Pricing</a></li>
<li>So Azure Share Web Site is more expensive than godaddy 'Economy Windows Hosting with Plesk', Azure Share Web Site also perform much much much better.</li>
</ul>
I used the free plan and the shared plan, I am now back on the free plan.<br />
<ul>
</ul>
<h2>
Conclusion </h2>
Now I need to learn if I can find cheaper domain name and how to transfer my domain names.<br />
Capitalism is not about monopoly, it is about competition.<br />
<br />
<br />
<br />Anonymoushttp://www.blogger.com/profile/16516471292134914481noreply@blogger.com2tag:blogger.com,1999:blog-7044556212189675078.post-52184175733773146622017-01-23T20:18:00.002-08:002017-04-11T13:28:09.972-07:00Nusbio I2C<h2>
Overview</h2>
The Inter-Integrated Circuit (<a href="https://en.wikipedia.org/wiki/I%C2%B2C">I²C, i2c</a>) is a multi-master, multi-slave serial communication protocol invented by Philips Semiconductor (now NXP Semiconductors), primarily used in embedded systems.<br />
A lot devices like an EEPROM, LCD, GPIO expander, LED drivers and more support the I2c protocol.<br />
<br />
It is generally not available for Windows easily, though it is available on the Raspberry PI via Python and C.<br />
<br />
That is why I created <a href="http://www.nusbio.net/">Nusbio.net</a> in 2015 that offers in a simple way to talk I2C from Windows and .NET<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimKcELy9Es5B132Cs7LWRk8TKFfNO86kauCI-jymDbJTf3nBAnZol2Ge-K08GUDGeGDoV_2oWdSa8mjFi4YcqVX76CLUxx2j5rFXjy3F3coNxNsCT3bPX5W1A8K7T-wDqmtvwgJ5y9x5Sw/s1600/Img_4795.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimKcELy9Es5B132Cs7LWRk8TKFfNO86kauCI-jymDbJTf3nBAnZol2Ge-K08GUDGeGDoV_2oWdSa8mjFi4YcqVX76CLUxx2j5rFXjy3F3coNxNsCT3bPX5W1A8K7T-wDqmtvwgJ5y9x5Sw/s320/Img_4795.jpg" width="320" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtJUuukBzU2o2X8Fet5theHo6udxKEYI1YtRYytcL5ERP5hlyPSQwcgx8YBQTrBh8Dx3nqlpZNH6xs1rsuXXLfjegqOVAD_simP38OfRVhrrgYNd04gISvwq1K3neXnnzL5ryRpuPSksfW/s1600/Img_4795.jpg" style="margin-left: 1em; margin-right: 1em;">Nusbio extension with I2C EEPROM 24LC256 and GPIO expander MCP23008 on the same bus</a> </div>
<br />
A lot of devices designed by Adafruit use the I2C protocol and are compatibles with Nusbio and any .NET languages.<br />
<br />
<div style="text-align: left;">
Videos:<br />
<ul>
<li><a href="https://www.youtube.com/watch?v=-l8AIY2rEho" target="_blank">Adafruit I2C Devices And Nusbio - Best Of</a> </li>
<li><a href="https://www.youtube.com/watch?v=31QBlvzhxS0" target="_blank">Adafruit 16x9 LED Matrix controlled with Nusbio and some C# code</a> </li>
<li><a href="https://www.youtube.com/watch?v=mdSFkRSMqKQ" target="_blank">Temperature sensor and LCD controlled with some C# or VB.NET code </a></li>
</ul>
<br />
All our C#, VB.NET, Powershell and F# samples source code are open-source and can be found on <a href="https://github.com/madeintheusb/Nusbio.Samples">Nusbio.Samples</a></div>
<h2>
C# Class </h2>
<br />
This post explains the I2CEngine .NET class for the <a href="http://www.nusbio.net/" target="_blank">Nusbio </a>device.
<br />
<br />
<h2>
Wiring</h2>
Since Nusbio has 8 gpio pins, you can technically setup 4 independent I2C buses. But generally one is enough.<br />
I use Gpio0 for SCL and Gpio1 for SDA as convention. Obviously you can connect multiple I2C devices to the bus. <br />
Nusbio does not come with any pull up resistors so it is up you to take care of it.<br />
Generally if you use an I2C breakout it is part of the breakout.<br />
<br />
<h2>
Software</h2>
For each I2C device on the bus you must create an object of the class I2CEngine. After that you call the WriteBuffer() method to initiate an I2C write operation and the method ReadBuffer for a I2C read operation.<br />
The methods takes care of the I2C Control byte. You do not have to pass it as part of the buffer.<br />
The methods return true if the operation succeeded. For the Readxxxx methods, if the operation succeeded you can then read the buffer which will be updated with the data.<br />
<br />
<br />
<pre class="brush:csharp;">public I2CEngine(Nusbio nusbio, NusbioGpio sdaOutPin, NusbioGpio sclPin, byte deviceId);
public bool ReadBuffer(int len, byte[] data);
public bool WriteBuffer(byte[] buffer);
public bool WriteBuffer(byte address8bit, byte[] buffer);
</pre>
<br />
<h2>
Samples</h2>
<br />
<h3>
I2C EEPROM</h3>
<br />
Here is a basic sample reading the first 64 bytes of the I2C EEPROM <a href="http://www.mouser.com/ds/2/268/20001203T-254595.pdf" target="_blank">24LC256</a> which is a 32k bytes EEPROM with a page size of 64 byte.<br />
<br />
<pre class="brush:csharp;">byte EEPROM1_WR = 80; // 0xA0;
var i2c = new I2CEngine(nusbio, NusbioGpio.Gpio1, NusbioGpio.Gpio0, EEPROM1_WR);
var addr = 0;
var buffer = new byte[64];
if (i2c.WriteBuffer(new byte[2] { (byte)(addr >> 8), (byte)(addr & 0xFF) }))
{
var r = i2c.ReadBuffer(64, buffer);
}
</pre>
<br />
We do offer specific classes to handle I2C and SPI EEPROM, see our folder <a href="https://github.com/madeintheusb/Nusbio.Samples/tree/master/MadeInTheUSB.Nusbio.Components/EEPROM" target="_blank">EEPROM </a>on github.<br />
<br />
<br />
<h3>
I2C MCP9808 Temperature Sensor</h3>
Here part of our class <a href="https://github.com/madeintheusb/Nusbio.Samples/blob/master/MadeInTheUSB.Nusbio.Components/Adafruit/MCP9808%20_Temperature%20Sensor.cs" target="_blank">MCP9808 _Temperature Sensor.cs </a>available on Github.<br />
The method Begin will return true if the device is detected on the bus else false.<br />
<br />
<pre class="brush:csharp;">public bool Begin(byte deviceAddress = MCP9808_I2CADDR_DEFAULT)
{
try
{
this._i2c.DeviceId = deviceAddress;
if (read16(MCP9808_REG_MANUF_ID) != MCP9808_REG_MANUF_ID_ANSWER) return false;
if (read16(MCP9808_REG_DEVICE_ID) != MCP9808_REG_DEVICE_ID_ANSWER) return false;
return true;
}
catch (System.Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.ToString());
return false;
}
}
public double GetTemperature(TemperatureType type = TemperatureType.Celsius)
{
uint16_t t = read16(MCP9808_REG_AMBIENT_TEMP);
double temp = t & 0x0FFF;
temp /= 16.0;
if ((t & 0x1000) == 0x1000) temp -= 256;
switch (type)
{
case TemperatureType.Celsius: return temp;
case TemperatureType.Fahrenheit: return CelsiusToFahrenheit(temp);
case TemperatureType.Kelvin: return temp*CELCIUS_TO_KELVIN;
default:
throw new ArgumentException();
}
}
private UInt16 read16(uint8_t reg)
{
UInt16 value = 0;
if (this._i2c.WriteBuffer(new byte[1] { reg }))
{
var buffer = new byte[2];
this._i2c.ReadBuffer(2, buffer);
value = (System.UInt16)((buffer[0] << 8) + buffer[1]);
}
else throw new ArgumentException();
}
</pre>
<br />
We do offer specific classes to handle I2C and SPI EEPROM, see our folder <a href="https://github.com/madeintheusb/Nusbio.Samples/tree/master/MadeInTheUSB.Nusbio.Components/EEPROM" target="_blank">EEPROM </a>on github.<br />
<br />
<br />
<h2>
Advanced Methods</h2>
To improve transfer performance, the class I2CEngine expose the following methods which optimize the number of USB operations to execute the I2C operations (we combine an I2C Read + I2C Write operation in one USB transaction)<br />
<br />
<pre class="brush:csharp;">public bool Send16BitAddressAnd1Byte(int address16bit, byte b);
public bool Send16BitsAddressAndBuffer(int address16bit, int len, byte[] buffer);
public int Send16BitsAddressAndRead1Byte(short address8bit);
public bool Send16BitsAddressAndReadBuffer(int address16bit, int len, byte[] data);
public bool Send1ByteCommand(byte command);
public bool Send2BytesCommand(byte command0, byte command1);
public bool Send3BytesCommand(byte command0, byte command1, byte command2);
public int Send1ByteRead1Byte(byte address8bits);
public _2BytesOrInt16Result Send1ByteRead2Bytes(byte cmd);
</pre>
<br />
<br />
<br />
<h2>
Performance</h2>
Using the EEPROM 24LC256 which is an I2C 32k bytes with a max clock of 400 kHz, we can transfer the 32 k byte of data from the EEPROM to the PC at the rate of <b><i>15 k bytes per second</i></b> in batch mode of 64 page<i>s</i> at a time.<br />
<br />
Transferring one page a the time give a transfer rate of 8 k bytes per second.<br />
<br />
Output or input batch mode is necessary to increase performance for all I2C devices.<br />
<br />
Transfer speed may vary also depending on the speed of the computer.<br />
<br />
<br />
<br />Anonymoushttp://www.blogger.com/profile/16516471292134914481noreply@blogger.com0tag:blogger.com,1999:blog-7044556212189675078.post-16203447274761388472017-01-15T22:04:00.003-08:002017-01-15T22:23:26.185-08:00$0.5 2K EEPROM M93C86 for .NET, CSharp and Nusbio.netI experimented with a cheap EEPROM the M93C86 2k byte of data for $0.5 programmed in C# with Nusbio.net (<a href="http://www.mouser.com/ds/2/389/m93c46-w-955034.pdf" target="_blank">M93C86 datasheet</a>).<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTpi5ailPgWw24FEvmj3EPv6DTDu31hMO2fUT4Y3l6xiEgq74dEJNjZjWQXAL-ifP4wP-tqN0LREhCSNje6EJS3xthC5Mq6yzXE0IAdlDvQpnNL24jvnQZOzGeD6NgTFPsNjj1qGO_AvM0/s1600/M93C86.STMicro.EEPROM.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="225" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTpi5ailPgWw24FEvmj3EPv6DTDu31hMO2fUT4Y3l6xiEgq74dEJNjZjWQXAL-ifP4wP-tqN0LREhCSNje6EJS3xthC5Mq6yzXE0IAdlDvQpnNL24jvnQZOzGeD6NgTFPsNjj1qGO_AvM0/s400/M93C86.STMicro.EEPROM.jpg" width="400" /></a></div>
The EEPROM used the SPI protocol but its API is not as straightforward as the Microchip EEPROMs.<br />
After a day of work it seems that we can only write one byte at the time and for that we need to pass 4 bytes, of protocol. So write speed is very slow.<br />
It does not seems that there is a concept of page per say, but since I want to re use a C# base class, I set up a page to 256 bytes, and the read performance in SPI out of the box is 10 K byte/S with Nusbio v1.<br />
Since it is just an experiment I will not optimize the code to get 28 K byte/S like with the Microchip SPI EEPROM.<br />
As a reminder Nusbio v 2 can transfer at the rate of 1 to 3 M byte/S in SPI and 100 K byte/S in I2C in<br />
any .NET language. Nusbio v 2 is in prototype mode as 2017/01.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2WjsRI-N_9wjGGEyKGIZyvAXpZiR_ktIGhUOsiflE0yEZzWA0E2r8mZo2CDRgxYLotCIc0HWpwXSRgx384qxNFbDVm9s-4TH4gVotJBe3RiuxI8QTh0ldhrVjyI7253AFVbols65LmCVr/s1600/M93C86.STMicro.VisualStudio.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2WjsRI-N_9wjGGEyKGIZyvAXpZiR_ktIGhUOsiflE0yEZzWA0E2r8mZo2CDRgxYLotCIc0HWpwXSRgx384qxNFbDVm9s-4TH4gVotJBe3RiuxI8QTh0ldhrVjyI7253AFVbols65LmCVr/s400/M93C86.STMicro.VisualStudio.jpg" width="400" /></a></div>
<br />
<pre class="brush:csharp;">/*
Copyright (C) 2015, 2016, 2017 MadeInTheUSB LLC
Written by FT for MadeInTheUSB
MIT License (MIT)
*/
using System;
using System.Collections.Generic;
namespace MadeInTheUSB.EEPROM
{
/// <summary>
/// m93c86 is a 2k byte spi cheap eeprom
/// http://www.mouser.com/ds/2/389/m93c46-w-955034.pdf
/// CS(PD-1k)[] [] VCC
/// SCK [] [] Not used
/// MOSI [] [] ORG Leave unconnected for 16kbit orf
/// MISO [] [] GND
/// </summary>
public class EEPROM_M93C86 : EEPROM_25AAXXX_BASE
{
#if NUSBIO2
public EEPROM_M93C86() : base(16)
{
}
#else
public EEPROM_M93C86(Nusbio nusbio,
NusbioGpio clockPin,
NusbioGpio mosiPin,
NusbioGpio misoPin,
NusbioGpio selectPin,
bool debug = false) : base(nusbio, clockPin, mosiPin, misoPin, selectPin, 16,
debug,
chipSelectActiveLow:false // << important
)
{
var b = this.MaxByte;
var p = this.MaxPage;
this.SetWriteRegisterEnable();
//this.SetWriteRegisterDisable();
}
#endif
public override bool Is3BytesAddress
{
get { return false; }
}
public override int PAGE_SIZE
{
get{ return 256; }
}
protected override bool SetWriteRegisterEnable()
{
var r = this.SpiTransfer( new List<byte>(){ 0x98 /*0b10011000*/, 00 } );
return r.Succeeded;
}
protected override bool SetWriteRegisterDisable()
{
var r = this.SpiTransfer(new List<byte>() { 0x80 /*0b10000000*/, 00 });
return r.Succeeded;
}
/// <summary>
/// http://www.mouser.com/ds/2/389/m93c46-w-955034.pdf
/// based on the data sheet in ORG: 8 byte (low)
/// writing one byte require 22 Clock Cycle
/// 1 start bit, 2 bit-opCode, 11-Addr == 2 Clock cycle
/// We send 24 bits the first 2 bits are 00
/// I do not think that this EEPROM support write in bulk mode
/// It does support Read in bulk
/// </summary>
/// <param name="addr" />
/// <param name="buffer" />
/// <returns></returns>
public virtual bool WritePage(int addr, byte[] buffer)
{
int dt1, dt2, ans;
for (var num = 0; num < buffer.Length; num++)
{
//dt1 = 0b00101000 | ((adrs & 0b0000011100000000) >> 8) ;
//dt2 = (adrs & 0b0000000011111111) ;
dt1 = 0x28 | ((addr & 0x700) >> 8);
dt2 = (addr & 0xFF);
var spiBuffer = new List<byte>() { (byte)dt1, (byte)dt2, buffer[num] };
var writeR = this.SpiTransfer(spiBuffer);
var readR = this.SpiTransfer(new List<byte>() { 0 });
ans = readR.Buffer[0];
addr += 1;
}
return true;
}
public override EEPROM_BUFFER ReadPage(int addr, int len = -1)
{
if (len == -1)
len = PAGE_SIZE;
var eb = new EEPROM_BUFFER();
int dt1, dt2;
//dt1 = 0b00110000 | ((adrs & 0b0000011100000000) >> 8) ;
//dt2 = (adrs & 0b0000000011111111) ;
dt1 = 0x30 | ((addr & 0x700) >> 8);
dt2 = (addr & 0xFF);
var spiBufferWrite = new List<byte>() { (byte)dt1, (byte)dt2 };
var spiBufferRead = GetEepromApiDataBuffer(len);
var buffer = new List<byte>();
buffer.AddRange(spiBufferWrite);
buffer.AddRange(spiBufferRead);
var r = this.SpiTransfer(buffer);
if (r.Succeeded)
{
eb.Succeeded = true;
eb.Buffer = r.Buffer.GetRange(spiBufferWrite.Count, r.Buffer.Count - spiBufferWrite.Count).ToArray();
}
return eb;
}
}
}
</byte></byte></byte></byte></byte></byte></pre>
Anonymoushttp://www.blogger.com/profile/16516471292134914481noreply@blogger.com0tag:blogger.com,1999:blog-7044556212189675078.post-30890804346167406712016-12-31T17:32:00.001-08:002017-04-11T13:28:51.335-07:00External Keypad For Windows controlled by .NET code<br />
<h2>
Overview</h2>
This keypad below is very cheap, so i bought 2 just to try them with <a href="http://nusbio.net/">Nusbio.net</a>. Though it is a very simple device, it is not easy to explain how this work and moreover the theory behind the source code.<br />
It is a little bit tricky and requires to understand <a href="http://digital.ni.com/public.nsf/allkb/A10122C63A7F5CFE86256B4C007491DD" target="_blank">sourcing and sinking current</a>.<br />
If you do not get it right away it is normal.<br />
But you should be able to understand the basic idea just by reading the source code and my comments below.<br />
With an Arduino you will find tutorial and library already made, but for .NET and Nusbio I had to write my own class (that is part of the open source samples that come with the <a href="http://www.nusbio.net/" target="_blank">Nusbio </a>device). <br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGR_1oXar5FPrrvOBLjL_QQBBTHLC5aQK8BvAoR1X4MJpU680C_2Z0G9gyK6HM2461AoFDD_II57z-WH0yu-2iVUwW7vJEtr8f4FnxuPBB9A_rUhrjyPn1THTteNEiN0pgMbWLn6kfidPq/s1600/KeyPadAlone.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGR_1oXar5FPrrvOBLjL_QQBBTHLC5aQK8BvAoR1X4MJpU680C_2Z0G9gyK6HM2461AoFDD_II57z-WH0yu-2iVUwW7vJEtr8f4FnxuPBB9A_rUhrjyPn1THTteNEiN0pgMbWLn6kfidPq/s320/KeyPadAlone.jpg" width="213" /> </a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<h3 class="separator" style="clear: both; text-align: left;">
<b>First</b></h3>
There are plenty of tutorial on the internet about it, here is one I like the most to read first <a href="http://www.electroschematics.com/12446/arduino-with-keypad/" target="_blank">Arduino with Keypad Tutorial</a><br />
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<h2 class="separator" style="clear: both; text-align: left;">
Here is my take on it for software developers. </h2>
<div class="separator" style="clear: both; text-align: left;">
We have a grid of 4 rows and 3 colums. Each rows and columns connect to each other when one of the 12 buttons is pressed. We are going use 4+3 == 7 GPIO pins and monitor the connection between rows and the columns.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
From a software point of view we have to constantly polled the state of the 12 buttons. </div>
<br />
<h3>
Initialization</h3>
<br />
<div class="separator" style="clear: both; text-align: left;">
The 4 GPIO pins connected to the 4 rows are open in input pull up mode, simply said this mean that the state of the pin is Readable (Input) and default state value is HIGH (AKA 1 or 5 Volts) and could be come a LOW (AKA 0 or 0 Volt) if there is a path to ground.</div>
<div class="separator" style="clear: both; text-align: left;">
The 3 GPIO pins connected to the 3 columns are open in output mode, (the state can be set to HIGH or LOW programmatically) and set first to HIGH (1).</div>
<div class="separator" style="clear: both; text-align: left;">
In this state nothing will happen, no current flow even if one button is pressed because current only flow from HIGH to LOW.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
For one specific column if one button is pressed a connection is made
between the column and the row and the state of the row will change from
HIGH to LOW.</div>
<div class="separator" style="clear: both; text-align: left;">
</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
In a function called constantly we going one at time </div>
<ol>
<li>Change the state of one the column GPIO pin to LOW (so now we know the column)</li>
<li>Then we are going to read the state of the 4 GPIO pins rows one after the other, <br />if the state is HIGH the button matching the current column and row is not pressed, <br />but if the state is LOW, then this mean there is a connection because the button is pressed and the current flowing from HIGH to LOW changing the state of the row GPIO pins (which is readable, because it was open as input) </li>
</ol>
<h2 class="separator" style="clear: both; text-align: left;">
Source Code</h2>
<h4 class="separator" style="clear: both; text-align: left;">
Initialization</h4>
<pre class="brush:csharp;">private List<nusbiogpio> _gpioRow;
private List<nusbiogpio> _gpioCol;
private Nusbio _nusbio;
private List<List<char>> _keys;
private void Init()
{
for (var r = 0; r < this._gpioRow.Count; r++)
{
this._nusbio.SetPinMode(this._gpioRow[r], PinMode.Input);
}
for (var c = 0; c < this._gpioCol.Count; c++)
{
this._nusbio.SetPinMode(this._gpioCol[c], PinMode.Output);
_nusbio.GPIOS[this._gpioCol[c]].High();
}
}
</nusbiogpio></nusbiogpio></pre>
<br />
<h4 class="separator" style="clear: both; text-align: left;">
Check() function</h4>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<pre class="brush:csharp;">public KeypadPressedInfo Check()
{
KeypadPressedInfo rr = null;
var found = false;
for (var c = 0; c < this._gpioCol.Count; c++)
{
_nusbio.GPIOS[this._gpioCol[c]].Low();
for (var r = 0; r < this._gpioRow.Count; r++)
{
var pressed = _nusbio.GPIOS[this._gpioRow[r]].DigitalRead() == PinState.Low;
if (pressed)
{
rr = new KeypadPressedInfo {
Row = r, Col = c, Key = this._keys[r][c]
};
break;
}
}
_nusbio.GPIOS[this._gpioCol[c]].High();
if (rr!=null)
break;
}
return rr;
}
</pre>
<div class="separator" style="clear: both; text-align: left;">
</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
See on github the <a href="https://github.com/madeintheusb/Nusbio.Samples/tree/master/CS/MadeInTheUSB.Nusbio.Keypad" target="_blank">C# project</a>. and the <a href="https://github.com/madeintheusb/Nusbio.Samples/blob/master/MadeInTheUSB.Nusbio.Components/Buttons/Keypad.cs" target="_blank">Keypad.cs</a> class.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<h2 class="separator" style="clear: both; text-align: left;">
About the Wiring</h2>
<div class="separator" style="clear: both; text-align: left;">
One electricity rule that you may know is that if the + touch the - directly, you create a short circuit and it is not good. In between the + and - you must have a load, something that consume current. Therefore in between the 3 GPIO pins column and the 3 wires of the keypad I inserted 3 10 K Ohm resistor.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKyNwQiN7EKW0UsF2Rbom-Afsg3Y_i2fncm-9JPnCUvrVacNIdcOKnUhUW5n58UhIphyotBbR3JQseCCrwPFASteb6gGMKUoWSYBdtl4o47iSejuo-VnD94eJ1oHQK050quiw3T8pKlmA2/s1600/Nusbio_Keypad_3x4_01.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="145" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKyNwQiN7EKW0UsF2Rbom-Afsg3Y_i2fncm-9JPnCUvrVacNIdcOKnUhUW5n58UhIphyotBbR3JQseCCrwPFASteb6gGMKUoWSYBdtl4o47iSejuo-VnD94eJ1oHQK050quiw3T8pKlmA2/s400/Nusbio_Keypad_3x4_01.jpg" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<br />Anonymoushttp://www.blogger.com/profile/16516471292134914481noreply@blogger.com1tag:blogger.com,1999:blog-7044556212189675078.post-17348275421819652802016-11-05T20:39:00.004-07:002016-11-07T15:42:03.552-08:00How to make an LED fade in, fade out with 1 Nusbio GPIO<h2>
Overview</h2>
With one GPIO (General Purpose Input Output) from an Arduino, Raspberry PI or Nusbio you can easily turn one LED on or off.<br />
But making the LED fade in and fade out is a little bit more complicated. With a micro-controller like an Arduino you can use a GPIO with PWM (Pulse with modulation) and call the method analogWrite(pin, value). The value defines what is called the duty cycle, in simple term this will be the intensity of the LED.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhz0vtSQnxpfZMTr6mmTHC-gFPaa8azN_d8xvf2yg31bZlb7PYmUhjkp3g_91oAzL9Zu1xdAoRh7Vz__0atsuPo5gbCGRkwEzRVZ1PVb9R4m2ZjsQFoMIy4bRzL3XEt2dD-iWsnB69FDOhA/s1600/LedFadeInFadeOutWithGpio.0.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="180" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhz0vtSQnxpfZMTr6mmTHC-gFPaa8azN_d8xvf2yg31bZlb7PYmUhjkp3g_91oAzL9Zu1xdAoRh7Vz__0atsuPo5gbCGRkwEzRVZ1PVb9R4m2ZjsQFoMIy4bRzL3XEt2dD-iWsnB69FDOhA/s320/LedFadeInFadeOutWithGpio.0.jpg" width="320" /></a></div>
<br />
<div style="text-align: center;">
<span style="font-size: large;"><a href="https://www.youtube.com/watch?v=370ddyA3rio" target="_blank">Video</a></span></div>
<span style="font-size: large;"></span><br />
But with a Raspberry PI linked to Linux or Nusbio linked to Windows, there is no PWM (PWM is a hardware function, not available on PC and not managed by the OS).<br />
<br />
So for this post I used an good old analog solution:<br />
<br />
<ul>
<li>1 transistor <a href="https://www.sparkfun.com/datasheets/Components/2N3904.pdf">2N3904</a></li>
<li>1 100mF capacitor</li>
<li>1 220k Ohm resistor</li>
<li>1 1k Ohm resistor</li>
</ul>
Wired as follow:<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJKl3BRtR-GSPS6jcRIBMbR8ZhdACKnmscQ-eY2w2YVyjf70k2sKY5Kq-hUu338-cV_RGVMMGzF-xNAwYuKnbyNmgrzkbd6Ysmo0TIPqizvwI5CmQwS2eXRevwXOOvTYWPQf-mju-qoFd3/s1600/LedFadeInFadeOutWithGpio.Schema.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="317" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJKl3BRtR-GSPS6jcRIBMbR8ZhdACKnmscQ-eY2w2YVyjf70k2sKY5Kq-hUu338-cV_RGVMMGzF-xNAwYuKnbyNmgrzkbd6Ysmo0TIPqizvwI5CmQwS2eXRevwXOOvTYWPQf-mju-qoFd3/s400/LedFadeInFadeOutWithGpio.Schema.jpg" width="400" /></a></div>
<div style="text-align: center;">
</div>
<br />
This circuit looks simple, but it is not easy to understand how it works, though it does work as shown in the <a href="https://www.youtube.com/watch?v=370ddyA3rio" target="_blank">video</a>. <br />
And I will not try to explain it today.<br />
If you are like me a software developer interested in learning analog electronic, it is a good example to start with because there are so many concepts involved to understand before you can picture how the all thing works:<br />
<ul>
<li>LED voltage drop</li>
<li>Capacitor</li>
<li>Transistor</li>
<li>Sourcing and sinking current</li>
</ul>
The first step is to try it on a bread board. <br /><br />Use a red LED because the LED voltage drop makes a different, a blue LED would require different resistors.<br />
<br />
<h2>
Programming</h2>
The programming on the other side is simple, turn the LED on and wait for the LED to fade in,<br />
then the LED off and wait for the LED to fade out.<br />
The speed of the fade in fade out is controlled by the size of the capacitor and the resistance in between the GPIO and the base of the transistor (in my case a 220K Ohm).<br />
<br />
<br />
<pre class="brush:csharp;">var serialNumber = Nusbio.Detect();
if (serialNumber == null) // Detect the first Nusbio available
{
Console.WriteLine("Nusbio not detected");
return;
}
Console.Clear();
using (var nusbio = new Nusbio(serialNumber: serialNumber))
{
ConsoleEx.WriteMenu(0, 1, "Q)uit");
while (true)
{
Console.Write("On ");
nusbio.GPIOS[0].High();
Thread.Sleep(1000 * 3);
Console.Write("Off ");
nusbio.GPIOS[0].Low();
Thread.Sleep(1000 * 3);
if (Console.KeyAvailable && Console.ReadKey().Key == ConsoleKey.Q)
break;
}
}
</pre>
Anonymoushttp://www.blogger.com/profile/16516471292134914481noreply@blogger.com1tag:blogger.com,1999:blog-7044556212189675078.post-70322610425605539882016-07-31T11:24:00.000-07:002017-02-13T19:33:17.123-08:00Nusbio SPI<h2>
Overview</h2>
<br />
The Serial Peripheral Interface (SPI) bus is a communication protocol primarily in embedded systems.<br />
A lot devices like an EEPROM, SD card reader, graphic screen (AKA OLED) and more support the SPI protocol.<br />
It is generally not available for Windows easily, though it is available on the Raspberry PI via Python and C.<br />
That is why I created <a href="http://www.nusbio.net/">Nusbio.net</a> that offers in a simple way to talk SPI from Windows and .NET.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3xXFYPxR7frDXNOG0K7MP6cByFwmFTeM8U9BQn8yaUP4Tn3n8B_0rGPAH6eOPIGtaNiBxWqFTV1YdrspSwQQZtUy7MqNYL541ZTEfAbCEi6n_mVvoB_6lbmkGdieVoA3C9m-Ox81ozPJE/s1600/Oled128x64_WrittenInCS.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3xXFYPxR7frDXNOG0K7MP6cByFwmFTeM8U9BQn8yaUP4Tn3n8B_0rGPAH6eOPIGtaNiBxWqFTV1YdrspSwQQZtUy7MqNYL541ZTEfAbCEi6n_mVvoB_6lbmkGdieVoA3C9m-Ox81ozPJE/s320/Oled128x64_WrittenInCS.jpg" width="320" /> </a></div>
<br />
<br />
For more information see the<br />
<ul>
<li><a href="http://madeintheusb.net/TutorialSpi/Index" target="_blank">Our SPI Tutorial</a> </li>
<li><a href="https://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus" target="_blank">Wiki page</a></li>
</ul>
<br />
<h2>
C# Class</h2>
This post explains the SPIEngine .NET class for the <a href="http://www.nusbio.net/" target="_blank">Nusbio </a>device.
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1JiYazzyhgfVuryhyphenhyphenN0QU_R820q7LSEa06KAdqOhegIiNPicPQqSK66Kbl7pcYUDLNLNUqPGnQinitjK9SD7M-mzF8lyPqDxJbGUxuIyxdhQWBEW_y1DvD70KXjbfHbfKrHBSe5I_gq5K/s1600/SensorExtensionBoard_small.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="225" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1JiYazzyhgfVuryhyphenhyphenN0QU_R820q7LSEa06KAdqOhegIiNPicPQqSK66Kbl7pcYUDLNLNUqPGnQinitjK9SD7M-mzF8lyPqDxJbGUxuIyxdhQWBEW_y1DvD70KXjbfHbfKrHBSe5I_gq5K/s400/SensorExtensionBoard_small.jpg" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtJUuukBzU2o2X8Fet5theHo6udxKEYI1YtRYytcL5ERP5hlyPSQwcgx8YBQTrBh8Dx3nqlpZNH6xs1rsuXXLfjegqOVAD_simP38OfRVhrrgYNd04gISvwq1K3neXnnzL5ryRpuPSksfW/s1600/Img_4795.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><br />The Nusbio sensor extension uses an SPI bus to control the TC77 temperature sensor and the ADC MCP3008 </a></div>
<br />
<h2>
Wiring</h2>
Since Nusbio has 8 gpio pins, you can setup an SPI bus and control up to 5 SPI devices. I generally use the following:<br />
<ul>
<li>Gpio0 - CLOCK</li>
<li>Gpio1 - MOSI</li>
<li>Gpio2 - MISO</li>
<li>Gpio3 - CS 1</li>
<li>Gpio4 - CS 2</li>
<li>Gpio5 - CS 3</li>
<li>Gpio6 - CS 4</li>
<li>Gpio7 - CS 5 </li>
</ul>
<br />
Controlling more than 5 SPI devices is for now not possible due to a software limitation in the class SPIEngine, which will be fixed by the end of 2017.<br />
<br />
Note that you could use Gpio6 and Gpio7 to setup an I2C bus and therefore control for example<br />
<ul>
<li>3 SPI devices</li>
<li>127 I2C devices</li>
<li>Using the SPI bus you could add an analog to digital converter (ADC) like the MCP3008 and therefore also add 8 ADCs (<a href="http://madeintheusb.net/TutorialAnalogConverter/Index" target="_blank">ADC Tutorial</a>, <a href="https://squareup.com/market/madeintheusb-dot-net/item/combo-nusbio-board-sensors-extension" target="_blank">Sensors Extension</a>).</li>
</ul>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhthi-ysjDzKNSi9Ds1v0uJHNwfzodaGExoZyCSSpffpit0jQ50iiSMHm5yCzgBifvcC2bfxY86aMQym2UeYBJTzNPgOc4wjuzf58WeYzyWkIRo-rukM_iMoWi1LvHu8W3ac84ovbMd8ECL/s1600/20160602_211517.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="225" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhthi-ysjDzKNSi9Ds1v0uJHNwfzodaGExoZyCSSpffpit0jQ50iiSMHm5yCzgBifvcC2bfxY86aMQym2UeYBJTzNPgOc4wjuzf58WeYzyWkIRo-rukM_iMoWi1LvHu8W3ac84ovbMd8ECL/s400/20160602_211517.jpg" width="400" /><br />Nusbio controlling 4 SPI MAX7219 chained driving 4 8x8 LED matrix</a></div>
<br />
<ul>
</ul>
<h2>
<br /><div class="separator" style="clear: both; text-align: center;">
<br /></div>
</h2>
<h2>
Software</h2>
For each SPI device on the bus you must create an object of the class <b><i>SPIEngine</i></b>. After that you call the <br />
the method <b><i>Transfer</i></b>() to send or receive data. You do <b>not need</b> to call the method <b><i>Select</i></b>() and <b><i>Unselect</i></b>()<i> </i>when calling <b><i>Transfer</i></b>().<br />
<br />
<pre class="brush:csharp;">public SPIEngine(Nusbio nusbio,
NusbioGpio selectGpio,
NusbioGpio mosiGpio,
NusbioGpio misoGpio,
NusbioGpio clockGpio,
NusbioGpio resetGpio = NusbioGpio.None);
public SPIResult Transfer(byte b);
public SPIResult Transfer(List<byte> bytes,
bool select = true,
bool optimizeDataLine = false);
public SPIMode Mode;
public enum SPIMode
{
MODE_CPOL0_CPHA0 = 0,
MODE_CPOL1_CPHA0 = 1,
MODE_CPOL0_CPHA1 = 2,
MODE_CPOL1_CPHA1 = 3
}
public void Select()
public void Unselect()
</pre>
<br />
<h2>
Samples</h2>
<br />
<h3>
I2C EEPROM</h3>
<br />
Here is a basic sample reading the first 4 pages of the SPI EEPROM <a href="http://www.mouser.com/ds/2/268/21836H-76424.pdf" target="_blank">25AA1024</a> which is a 128 k bytes EEPROM with a page size of 256 bytes (20 mHz). We are therefore transferring 1 k bytes of data from the EEPROM to the PC.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFs0XkrxZWx6s5xhXFiEhDFBomuuxnnyZV1SHy9KMQKsz57qib81nISHAu_rcUQRkq0iJfi7HzF1RaAOqJwk8z9wCzWzQu8nBPWcKyI4Eb2K_XBAa88HrutalhvC98ruociYDX1cdgi_Un/s1600/20160306_172359.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="225" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFs0XkrxZWx6s5xhXFiEhDFBomuuxnnyZV1SHy9KMQKsz57qib81nISHAu_rcUQRkq0iJfi7HzF1RaAOqJwk8z9wCzWzQu8nBPWcKyI4Eb2K_XBAa88HrutalhvC98ruociYDX1cdgi_Un/s400/20160306_172359.jpg" width="400" /></a></div>
<br />
<br />
<br />
<pre class="brush:csharp;">var _eeprom = new EEPROM_25AA1024(
nusbio : nusbio,
clockPin : NusbioGpio.Gpio0,
mosiPin : NusbioGpio.Gpio1,
misoPin : NusbioGpio.Gpio2,
selectPin: NusbioGpio.Gpio3
);
var r = _eeprom.ReadPage(0, _eeprom.PAGE_SIZE * 4);
if(r.Succeeded)
{
var data = r.Buffer;
}
// ...
// Class 25AA1024
// ...
public override EEPROM_BUFFER ReadPage(int addr, int len = -1)
{
if (len == -1)
len = PAGE_SIZE;
var eb = new EEPROM_BUFFER();
int byteSent = 0;
var spiBufferWrite = GetEepromApiReadBuffer(addr);
var spiBufferRead = GetEepromApiDataBuffer(len);
var buffer = new List<byte>();
buffer.AddRange(spiBufferWrite);
buffer.AddRange(spiBufferRead);
var r = this._spi.Transfer(buffer);
if (r.Succeeded)
{
eb.Succeeded = true;
eb.Buffer = r.ReadBuffer.GetRange(spiBufferWrite.Length, r.ReadBuffer.Count - spiBufferWrite.Length).ToArray();
}
return eb;
}
</pre>
<br />
See full source code of class <a href="https://github.com/madeintheusb/Nusbio.Samples/blob/master/MadeInTheUSB.Nusbio.Components/EEPROM/SPI/EEPROM_25AAXXX_BASE.cs" target="_blank">EEPROM_25AAXXX_BASE.cs</a>.<br />
<br />
<br />
<h2>
Performance Improvement</h2>
By default the SPI transfer rate using Nusbio and a Windows machine is limited around 15 Kb/s.<br />
There are 3 ways improve performance transfer giving from 20 Kb/s to 28 Kb/s depending of what type of SPI device your are controlling<br />
<i></i><br />
<ol>
<li>If there is no MISO (Master In Slave Out) needed or in other way if we only send data from the PC to the SPI device. In the constructor pass the miso parameter as <i><b>None</b></i>, and when calling the method <b><i>Transfer</i></b>() set the paramter optimizeDataLine to true. This will increase the output speed by about 33%.</li>
<li>To force an SPI EEPROM to send the next 64 bytes of data from an EEPROM to the PC, EEPROMs generally require that the master send 64 0 as byte. 64 0 is equal to 64 x 8 (512) bit set to 0. There is no need to set the data line to 0, 512 times, once is enough. Based on this concept the class<a href="https://github.com/madeintheusb/Nusbio.Samples/blob/master/MadeInTheUSB.Nusbio.Components/EEPROM/SPI/EEPROM_25AAXXX_BASE.cs" target="_blank"> EEPROM_25AAXXX_BASE.cs</a> contains the method ReadPageOptimized(), which implement the optimization. It is open source and complicated. But this increase the performance from 15 k byte/s to 28 k byte/s.</li>
<li>This third way only works for control APA 102 RGB LED and is kind a pushy. It consist to use the same cycle to set the data and to set the clock data line high. It gives a transfer rate up to 20 Kb/S.<br />See the our Github C# project on Github <a href="https://github.com/madeintheusb/Nusbio.Samples/tree/master/Extensions/CS/MadeInTheUSB.Nusbio.Extension.APA102_2_StripAdapter">Extension.APA102_2_StripAdapter</a>.</li>
</ol>
<h2>
</h2>
<h2>
OLED, Data Command Pin and SPI</h2>
Some SPI OLED driver may requires an extra pin called DataOrCommand (D/C). This is not par per say part of the SPI protocol, but it is needed, to achieve better performance the SPIEngine class offers the following methods. The methods allow to package buffers of type <b>Data </b>and buffers of type <b>Command </b>and then send the buffers as SPI buffers with limited USB operations.<br />
<br />
<pre class="brush:csharp;">public void TransferNoMiso(bool reverse, List<byte> buffer);
public void TransferNoMiso(byte dataOrCommandBit, bool reverse, List<packagedbuffer> PackagedBuffers);
public void TransferNoMiso(int dataOrCommand, byte dataOrCommandBit, bool reverse, List<byte> buffer);
</byte></packagedbuffer></byte></pre>
<complete id="goog_1374425757">See our folder <a href="https://github.com/madeintheusb/Nusbio.Samples/tree/master/MadeInTheUSB.Nusbio.Components/Oled" target="_blank">Oled </a>on Github for more information. We do support the SH1106 and SSD1306 OLED driver.</complete><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSRpdHUjpua4mg22ileMwYQcPSojBumz_SSwtMuts14cDxJWUuEJObB5xLdcRdryWeerZ54K36yPsU0BEKHpXOSxWLmcvgYi7RbWcPWzyjyyZZ5jCwwIq0cr6symA1S2-68w6aHPl_mxBW/s1600/Oled128x64_WrittenInCS.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSRpdHUjpua4mg22ileMwYQcPSojBumz_SSwtMuts14cDxJWUuEJObB5xLdcRdryWeerZ54K36yPsU0BEKHpXOSxWLmcvgYi7RbWcPWzyjyyZZ5jCwwIq0cr6symA1S2-68w6aHPl_mxBW/s400/Oled128x64_WrittenInCS.jpg" width="400" /></a></div>
<br />
<br />
<br />
<h2>
APA 102 RGB LED and SPI</h2>
The RGB LED (multi color LED) of type APA 102 use the SPI protocol and are supported by Nusbio.<br />
See our <a href="http://madeintheusb.net/TutorialRgbLedStrip/Index" target="_blank">Tutorial page</a>.<br />
See the our Github C# project on Github <a href="https://github.com/madeintheusb/Nusbio.Samples/tree/master/Extensions/CS/MadeInTheUSB.Nusbio.Extension.APA102_2_StripAdapter">Extension.APA102_2_StripAdapter</a>. <br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTP0fXcM-Yygf7i7Tnq-4RjZuM2Q7CFDsmpdLy_q2oCdocBTtpmbfwFRQ4BW2xQGcMe-D-VSDgyMrMeK6ZIQwhwP_b9-501YuMFeqJUScFB6JnR1Es3FnaVZuKDP4HzKoTXiRgQlOdDkDv/s1600/Nusbio_APA102_2_Strips_Adapter.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTP0fXcM-Yygf7i7Tnq-4RjZuM2Q7CFDsmpdLy_q2oCdocBTtpmbfwFRQ4BW2xQGcMe-D-VSDgyMrMeK6ZIQwhwP_b9-501YuMFeqJUScFB6JnR1Es3FnaVZuKDP4HzKoTXiRgQlOdDkDv/s400/Nusbio_APA102_2_Strips_Adapter.jpg" width="206" /></a></div>
<br />
<br />
<h2>
SPI Modes</h2>
<br />
The 4 spi modes have been implemented, but only the first mode has been tested.<br />
<br />
<ul>
<li>MODE_CPOL0_CPHA0</li>
<li>MODE_CPOL1_CPHA0</li>
<li>MODE_CPOL0_CPHA1</li>
<li>MODE_CPOL1_CPHA1</li>
</ul>
Anonymoushttp://www.blogger.com/profile/16516471292134914481noreply@blogger.com0tag:blogger.com,1999:blog-7044556212189675078.post-33910286025013795122016-07-30T22:31:00.001-07:002016-11-29T19:15:16.428-08:00Nusbio I2C<h2>
Overview</h2>
The Inter-Integrated Circuit (<a href="https://en.wikipedia.org/wiki/I%C2%B2C">I²C, i2c</a>) is a multi-master, multi-slave serial communication protocol invented by Philips Semiconductor (now NXP Semiconductors), primarily used in embedded systems.<br />
A lot devices like an EEPROM, LCD, GPIO expander, LED drivers and more support the I2c protocol.<br />
<br />
It is generally not available for Windows easily, though it is available on the Raspberry PI via Python and C.<br />
<br />
That is why I created <a href="http://www.nusbio.net/">Nusbio.net</a> that offers in a simple way to talk I2C from Windows and .NET<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhC6upFbV65woD3J8-5mXVTAkvC6XGmLd1hhisPsiNkAseWjyGuPdHlhu5064W-LISLHLcBVJjjsPEFOY6_c6L_nASUaB8Jx6pEEToJt3rHW2jD9kwORbewALsvBUR8dhdpX763f99guR52/s1600/Img_4795.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhC6upFbV65woD3J8-5mXVTAkvC6XGmLd1hhisPsiNkAseWjyGuPdHlhu5064W-LISLHLcBVJjjsPEFOY6_c6L_nASUaB8Jx6pEEToJt3rHW2jD9kwORbewALsvBUR8dhdpX763f99guR52/s320/Img_4795.jpg" width="320" /> </a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtJUuukBzU2o2X8Fet5theHo6udxKEYI1YtRYytcL5ERP5hlyPSQwcgx8YBQTrBh8Dx3nqlpZNH6xs1rsuXXLfjegqOVAD_simP38OfRVhrrgYNd04gISvwq1K3neXnnzL5ryRpuPSksfW/s1600/Img_4795.jpg" style="margin-left: 1em; margin-right: 1em;">Nusbio extension with I2C EEPROM 24LC256 and GPIO expander MCP23008 on the same bus</a> </div>
<br />
A lot of devices designed by Adafruit use the I2C protocol and are compatibles with Nusbio and any .NET languages.<br />
<br />
<div style="text-align: left;">
Videos:<br />
<ul>
<li><a href="https://www.youtube.com/watch?v=-l8AIY2rEho" target="_blank">Adafruit I2C Devices And Nusbio - Best Of</a> </li>
<li><a href="https://www.youtube.com/watch?v=31QBlvzhxS0" target="_blank">Adafruit 16x9 LED Matrix controlled with Nusbio and some C# code</a> </li>
<li><a href="https://www.youtube.com/watch?v=mdSFkRSMqKQ" target="_blank">Temperature sensor and LCD controlled with some C# or VB.NET code </a></li>
</ul>
<br />
All our C#, VB.NET, Powershell and F# source code is open-source and can be found on <a href="https://github.com/madeintheusb/Nusbio.Samples">Nusbio.Samples</a></div>
<h2>
C# Class </h2>
<br />
This post explains the I2CEngine .NET class for the <a href="http://www.nusbio.net/" target="_blank">Nusbio </a>device.
<br />
<br />
<h2>
Wiring</h2>
Since Nusbio has 8 gpio pins, you can technically setup 4 independent I2C buses. But generally one is enough.<br />
I use Gpio0 for SCL and Gpio1 for SDA as convention. Obviously you can connect multiple I2C devices to the bus. <br />
Nusbio does not come with any pull up resistors so it is up you to take care of it.<br />
Generally if you use an I2C breakout it is part of the breakout.<br />
<br />
<h2>
Software</h2>
For each I2C device on the bus you must create an object of the class I2CEngine. After that you call the WriteBuffer() method to initiate an I2C write operation and the method ReadBuffer for a I2C read operation.<br />
The methods takes care of the I2C Control byte. You do not have to pass it as part of the buffer.<br />
The methods return true if the operation succeeded. For the Readxxxx methods, if the operation succeeded you can then read the buffer which will be updated with the data.<br />
<br />
<br />
<pre class="brush:csharp;">public I2CEngine(Nusbio nusbio, NusbioGpio sdaOutPin, NusbioGpio sclPin, byte deviceId);
public bool ReadBuffer(int len, byte[] data);
public bool WriteBuffer(byte[] buffer);
public bool WriteBuffer(byte address8bit, byte[] buffer);
</pre>
<br />
<h2>
Samples</h2>
<br />
<h3>
I2C EEPROM</h3>
<br />
Here is a basic sample reading the first 64 bytes of the I2C EEPROM <a href="http://www.mouser.com/ds/2/268/20001203T-254595.pdf" target="_blank">24LC256</a> which is a 32k bytes EEPROM with a page size of 64 byte.<br />
<br />
<pre class="brush:csharp;">byte EEPROM1_WR = 80; // 0xA0;
var i2c = new I2CEngine(nusbio, NusbioGpio.Gpio1, NusbioGpio.Gpio0, EEPROM1_WR);
var addr = 0;
var buffer = new byte[64];
if (i2c.WriteBuffer(new byte[2] { (byte)(addr >> 8), (byte)(addr & 0xFF) }))
{
var r = i2c.ReadBuffer(64, buffer);
}
</pre>
<br />
We do offer specific classes to handle I2C and SPI EEPROM, see our folder <a href="https://github.com/madeintheusb/Nusbio.Samples/tree/master/MadeInTheUSB.Nusbio.Components/EEPROM" target="_blank">EEPROM </a>on github.<br />
<br />
<br />
<h3>
I2C MCP9808 Temperature Sensor</h3>
Here part of our class <a href="https://github.com/madeintheusb/Nusbio.Samples/blob/master/MadeInTheUSB.Nusbio.Components/Adafruit/MCP9808%20_Temperature%20Sensor.cs" target="_blank">MCP9808 _Temperature Sensor.cs </a>available on Github.<br />
The method Begin will return true if the device is detected on the bus else false.<br />
<br />
<pre class="brush:csharp;">public bool Begin(byte deviceAddress = MCP9808_I2CADDR_DEFAULT)
{
try
{
this._i2c.DeviceId = deviceAddress;
if (read16(MCP9808_REG_MANUF_ID) != MCP9808_REG_MANUF_ID_ANSWER) return false;
if (read16(MCP9808_REG_DEVICE_ID) != MCP9808_REG_DEVICE_ID_ANSWER) return false;
return true;
}
catch (System.Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.ToString());
return false;
}
}
public double GetTemperature(TemperatureType type = TemperatureType.Celsius)
{
uint16_t t = read16(MCP9808_REG_AMBIENT_TEMP);
double temp = t & 0x0FFF;
temp /= 16.0;
if ((t & 0x1000) == 0x1000) temp -= 256;
switch (type)
{
case TemperatureType.Celsius: return temp;
case TemperatureType.Fahrenheit: return CelsiusToFahrenheit(temp);
case TemperatureType.Kelvin: return temp*CELCIUS_TO_KELVIN;
default:
throw new ArgumentException();
}
}
private UInt16 read16(uint8_t reg)
{
UInt16 value = 0;
if (this._i2c.WriteBuffer(new byte[1] { reg }))
{
var buffer = new byte[2];
this._i2c.ReadBuffer(2, buffer);
value = (System.UInt16)((buffer[0] << 8) + buffer[1]);
}
else throw new ArgumentException();
}
</pre>
<br />
We do offer specific classes to handle I2C and SPI EEPROM, see our folder <a href="https://github.com/madeintheusb/Nusbio.Samples/tree/master/MadeInTheUSB.Nusbio.Components/EEPROM" target="_blank">EEPROM </a>on github.<br />
<br />
<br />
<h2>
Advanced Methods</h2>
To improve transfer performance, the class I2CEngine expose the following methods which optimize the number of USB operations to execute the I2C operations (we combine an I2C Read + I2C Write operation in one USB transaction)<br />
<br />
<pre class="brush:csharp;">public bool Send16BitAddressAnd1Byte(int address16bit, byte b);
public bool Send16BitsAddressAndBuffer(int address16bit, int len, byte[] buffer);
public int Send16BitsAddressAndRead1Byte(short address8bit);
public bool Send16BitsAddressAndReadBuffer(int address16bit, int len, byte[] data);
public bool Send1ByteCommand(byte command);
public bool Send2BytesCommand(byte command0, byte command1);
public bool Send3BytesCommand(byte command0, byte command1, byte command2);
public int Send1ByteRead1Byte(byte address8bits);
public _2BytesOrInt16Result Send1ByteRead2Bytes(byte cmd);
</pre>
<br />
<br />
<br />
<h2>
Performance</h2>
Using the EEPROM 24LC256 which is an I2C 32k bytes with a max clock of 400 kHz, we can transfer the 32 k byte of data from the EEPROM to the PC at the rate of <b><i>15 k bytes per second</i></b> in batch mode of 64 page<i>s</i> at a time.<br />
<br />
Transferring one page a the time give a transfer rate of 8 k bytes per second.<br />
<br />
Output or input batch mode is necessary to increase performance for all I2C devices.<br />
<br />
Transfer speed may vary also depending on the speed of the computer.<br />
<br />
<br />
<br />Anonymoushttp://www.blogger.com/profile/16516471292134914481noreply@blogger.com0tag:blogger.com,1999:blog-7044556212189675078.post-56429132351188555992016-07-16T19:34:00.003-07:002017-03-18T17:49:11.773-07:00Faster serial port communication from .NET to Arduino<h2>
Overview</h2>
I was for a long time thinking that serial port communication on Windows and/or .NET was limited to 115 200 bauds, which translate to 11Kb/s at the most ( 115200 / 10 (8 bit-data + 2 (1-start-bit 1-stop-bit )) ).<br />
<br />
In reality it is possible to use faster transfer rate, but there are a few things to know and it can be a little bit convoluted.<br />
<br />
I am currently working on my "device" <b><a href="http://www.nusbiomcu.com/" target="_blank">NusbioMCU</a></b>, which use an Arduino Nano compatible (ATmega328),<br />
so I will focus in this post on communication from Windows+.NET to different Arduino and compatibles. <br />
But this can be applied to any serial communication from Windows and .NET.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
This post should be taken with some grains of salt, because I am not an expert. I am just a guy that would like to do faster serial communication from Windows and .NET. This post is the fruit of my research and experimentation.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<img border="0" height="180" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijWnFM8qvYXOp4m038KGSVE-_cFkdrjHxiIGcytJ8H7pXXPPFVQPHvjz29H26sLzE1cBmDInnGoLVyb2gkCaQ5-nO7eg2OTc_YZD4Y5Py3hY62CpS5oGhUs0Or0JNP3bFoh2Lgd4CmgUo0/s320/NusbioMCU_Square.2017.Rainbow.01.jpg" width="320" /> </div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<h2>
<div class="separator" style="clear: both; text-align: center;">
</div>
</h2>
<h2>
What do you need to know?</h2>
<ul>
<li><b>Hardware</b>: You must know what UART chip is used in your MCU board. Different chip will support different baud rates, and the values may not be as expected. <br /><br />Popular UART chip:<br /><ul>
<li>FTDI <a href="http://www.ftdichip.com/Support/Documents/DataSheets/ICs/DS_FT232R.pdf" target="_blank">FT232RL</a> or <a href="http://www.ftdichip.com/Support/Documents/DataSheets/ICs/DS_FT231X.pdf" target="_blank">FT231X</a></li>
<li>Atmel <a href="http://www.atmel.com/images/doc7799.pdf" target="_blank">Atmega16U2</a></li>
<li>Cypress <a href="https://www.silabs.com/Support%20Documents/TechnicalDocs/CP2130.pdf" target="_blank">CP2130</a> </li>
<li><a href="http://wch.cn/" target="_blank">WCH</a> <a href="https://www.olimex.com/Products/Breadboarding/BB-CH340T/resources/CH340DS1.PDF" target="_blank">CH340</a> </li>
</ul>
<br />The Windows Device Manager program can help you figure this out. Below is the list of baud rate supported by the FT231X UART.</li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMdRZpzPbGdIvT89uGfQBJKx3nwa8z-D0YOvdG3An2rUNe8zThUt9qn1OaAoM_RTWyL-RXHmcEtcE0RuRpZJDB9nXqr2pKGYMnVq4JO-rwYt3dR4Ez4K2Qiflt5DIVePgo1aZcttBFq_0v/s1600/FT231X_Metro_BaudList.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="291" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMdRZpzPbGdIvT89uGfQBJKx3nwa8z-D0YOvdG3An2rUNe8zThUt9qn1OaAoM_RTWyL-RXHmcEtcE0RuRpZJDB9nXqr2pKGYMnVq4JO-rwYt3dR4Ez4K2Qiflt5DIVePgo1aZcttBFq_0v/s400/FT231X_Metro_BaudList.jpg" width="400" /></a></div>
<br />
As shown in the image above, the FT231X UART which comes with the <a href="https://www.adafruit.com/products/2488" target="_blank">Adafruit Metro</a> (a compatible Arduino UNO) support the 460 800 and 921 600 baud rates (Same for the FT232RL). <br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjeLYDekmqnm3Ea_m83a1VGz72l2W2ii4tP-KOeQIjQDH9n5VbkRFx21P1wpYEEzySTGzjKJ6O4MBKi1WvryZXXFxZnjH2OIxnJmP9QatluxnTRgClVNcxacar-pvrdgptK0YfS-Ue7_YFo/s1600/Adafruit+Metro.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="298" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjeLYDekmqnm3Ea_m83a1VGz72l2W2ii4tP-KOeQIjQDH9n5VbkRFx21P1wpYEEzySTGzjKJ6O4MBKi1WvryZXXFxZnjH2OIxnJmP9QatluxnTRgClVNcxacar-pvrdgptK0YfS-Ue7_YFo/s400/Adafruit+Metro.jpg" width="400" /><br />Adafruit Metro, FT231X UART</a></div>
<br />
The Atmega16U2 UART which comes with a real Arduino UNO R3, will only display up to 128 000,<br />
but multiplying this value by 2, 4 or 8 works.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiorZkQAHI4e6zfI_vcsgQ9VloH18sGxkDBmGu4ishn1eAgERv0f3IPUr1rqVSQdnCr12vN52oFomqNw2qvuHu82LhT9P0n1ptaZTkr64F7WoKLzLpr7NoBptzTQSyplo6mjoujuudYzC4_/s1600/ArduinoUno.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="298" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiorZkQAHI4e6zfI_vcsgQ9VloH18sGxkDBmGu4ishn1eAgERv0f3IPUr1rqVSQdnCr12vN52oFomqNw2qvuHu82LhT9P0n1ptaZTkr64F7WoKLzLpr7NoBptzTQSyplo6mjoujuudYzC4_/s400/ArduinoUno.jpg" width="400" /><br />Arduino UNO R3, ATmega16U2 UART </a> </div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
Regarding the CH340, Chinese Arduino UNO or Nano compatibles comes with a CH340 UART which is limited to 115 200 bauds. That said based on information from <a href="https://ryanteck.uk/" target="_blank">RyanteckLTD and their device the RTK.Gpio</a>, it could be possible that if the CH340 has its own 12 Mhz clock, it then can support faster transfer rates.<br />
<br />
<ul>
<li><b>USB 2.0 Full Speed</b>. The FTDI FT232RL or FT231X UART chips implement serial communication over USB 2.0 Full Speed. In USB 2.0 Full Speed there is a 1 ms latency to access the USB and transfer data. So if we transfer data in a 64 byte or less buffer, we cannot expect a transfer rate greater then 64 x 1000 == 53K b/s. <br />There are 2 transfer phases:</li>
<ol>
<li>From the PC to the UART at USB 2.0 Full Speed, dependent on the data buffer size</li>
<li>From the UART to the MCU based on the baud rate. UART generally have an output buffer that allow to receive byte faster that they can sent according to the baud rate, but they are limted to 128 or 512 bytes</li>
</ol>
</ul>
For example if we transfer data in buffer of 256 bytes at the USB level we can reach 212 Kb/s (256 * 1000 / 1024), that said since the max baud rate is 921 600 or 90 Kb/s I think the FTDI driver will stop the communication until the UART buffer is empty.<br />
So for now I am only focusing on reaching 64 Kb/s. <br />
<br />
<ul>
<li><b>Sofware</b>: </li>
<ul>
<li>The SerialPort class available in .NET <b>does not</b> support transfer speed greater than 115 200 bauds. The Windows low level API does support it, but the .NET implementation does not.<br />See blog post <a href="http://www.sparxeng.com/blog/software/must-use-net-system-io-ports-serialport" target="_blank">If you *must* use .NET System.IO.Ports.SerialPort</a>.<br />Though is his blog post Ben Voigt gave some code small snippet that could work.</li>
<li>I did not find another open source and/or free library on the internet</li>
<li>With the <a href="https://www.marshallsoft.com/serial-communication-library.htm" target="_blank">Windows Serial Communication Component Library</a> from Marshallsoft, I was able to achieve greater transfer speed.<br /> </li>
</ul>
</ul>
<h2>
</h2>
<h2>
Transfer Test</h2>
To test the transfer speed I am sending from the PC to the MCU 640 times, 4 buffers containing 33 bytes of data (82.5 Kb). Each buffer is processed by the MCU and the data is sent to a 32x8 LED matrix driven by 4 MAX7219 chips chained using the SPI protocol at 10Mhz (about 1 Mb/s). <br />
<br />
There is no acknowledgment from MCU to the PC. I am visually testing the result for now, when there are issues the expected images is not display correctly on the matrix. When there is no issue I see a slight flickering of the expected images (see picture below).<br />
<br />
The processing time by the MCU of one buffer takes less than 1 ms, and since there is a know 1 ms overhead when using USB 2.0 full speed, the PC is always working on sending the next buffer while the MCU is processing the current one. That said this will be an issue when the MCU take more than 1 ms to process the data. I did verified that the processing by the MCU does not affect the transfer in my case.<br />
<br />
With that configuration I reached 33 Kb/s at 500 000 bauds. At 1 000 000 bauds no improvement.<br />
<br />
Realizing that to get more transfer speed I needed to send more data I changed buffer size to 41 bytes of data (for total of 102.5 Kb) and reached 41Kb/s. <br />
<br />
<b>RTS/CTS</b><br />
According to the schematic of the <a href="https://www.arduino.cc/en/uploads/Main/arduino-uno-schematic.pdf" target="_blank">Arduino Uno R2</a> or <a href="https://github.com/adafruit/Adafruit-METRO-328-PCB" target="_blank">Adafruit Arduino Metro</a>, it looks like the RST/CTS pin are not wired to the MCU. So I guess there is no hardware control flow.<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<h2>
Summary</h2>
Here are my results using the Marshallsoft WSC library called from a C# program.<br />
<br />
<table border="1" cellpadding="4" cellspacing="0">
<tbody>
<tr>
<th>MCU</th>
<th>UART</th>
<th>Max Baud Rate</th>
<th>Expected Kb/S</th>
<th>Measured Kb/S</th>
</tr>
<tr>
<td>Arduino UNO R3 </td>
<td>Atmega16U2</td>
<td>512 000</td>
<td>50 Kb/s</td>
<td>41 Kb/s</td>
</tr>
<tr>
<td>Adafruit Arduino Metro </td>
<td>FT231X</td>
<td>500 000</td>
<td>48 Kb/s</td>
<td>41 Kb/s</td>
</tr>
<tr>
<td>Adafruit Trinket Pro + FTDI Cable</td>
<td>FT232RL</td>
<td>500 000</td>
<td>48 Kb/s</td>
<td>41 Kb/s</td>
</tr>
<tr>
<td>Arduino Nano Compatible Chinese </td>
<td>CH340</td>
<td>115 200</td>
<td>11 Kb/s</td>
<td>11 Kb/s</td>
</tr>
<tr>
</tr>
</tbody></table>
<br />
Note that the baud rates for the Atmega16U2 and FT231X are different, this is not a typo.<br />
<br />
I do see a transfer speed increase from 115200 to 230400 and from 230400 to 460800. <br />
But at 460800 or 500000 I do measure a transfer rate lower than expected.<br />
And at 1 024 000 baud there is no improvement so far, with the FT231X, FT232RL and the Atmega16U2.<br />
<br />
I think the issue here is that I need be able to send bigger buffer, but for that the Arduino need to be able to handle it, up to 41 Kb/s it is ok, after that it does not work (yet). The Arduino serial library only use a 64 bytes buffer and I think this is my problem. I would need to increase this buffer to 128 bytes and and send 64 bytes buffer to achieve 64 Kb/s. Well at least that is my expectation.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVDdj7M_hiInNQrD9kno6PQ1rPLsx2P4qIFhoE98_vARucPGn222Far_kN2U7_DGcwU0Gdh7pac8doXcrmurb98qaJeX9ylA9nr5I7mxEv_umviShlGrHm6_XDEirHZGa9Uhn1UG8awPOi/s1600/TrinketPro+FTDI+Cable.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="298" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVDdj7M_hiInNQrD9kno6PQ1rPLsx2P4qIFhoE98_vARucPGn222Far_kN2U7_DGcwU0Gdh7pac8doXcrmurb98qaJeX9ylA9nr5I7mxEv_umviShlGrHm6_XDEirHZGa9Uhn1UG8awPOi/s400/TrinketPro+FTDI+Cable.JPG" width="400" /><br />Trinket Pro with FTDI Cable (FT232RL UART)</a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<h2>
To-Do</h2>
<ul>
<li>Optimize processing and serial communication on the Arduino side to support buffer of 64 bytes </li>
<li>Test CH340 with its own 12 Mhz clock </li>
<li>Test Cypress <a href="https://www.silabs.com/Support%20Documents/TechnicalDocs/CP2130.pdf" target="_blank">CP2130</a></li>
</ul>
To be continued. <br />
<h2>
Contact</h2>
<br />
<br />
To contact me see my web site <a href="http://madeintheusb.net/">MadeInTheUSB.net</a><span id="goog_272903750"></span><a href="https://www.blogger.com/"></a><span id="goog_272903751"></span>.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhhvNUNImhgzS1U8JODu29uEYT5xbzA1U8sRQchnz_Iib90VqjBN6cajQJ4RUZzvCY9eaD6UBUjtgd_WRcI5FfatqoCvPYcB6MYju1cspVi-GKnKzBmfOwjyFP-1KLBP5dBqSaPRdaz49U/s1600/NusbioMCU.207.02.Strip.02.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="225" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhhvNUNImhgzS1U8JODu29uEYT5xbzA1U8sRQchnz_Iib90VqjBN6cajQJ4RUZzvCY9eaD6UBUjtgd_WRcI5FfatqoCvPYcB6MYju1cspVi-GKnKzBmfOwjyFP-1KLBP5dBqSaPRdaz49U/s400/NusbioMCU.207.02.Strip.02.jpg" width="400" /> </a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0K8-uuKwb67yFzyOoOFfK4-hQdKfqyqKth0jIzddfV7HIaBt4GErbVgZJeNI8PwRqH05y1gu_PXI_2eHOboigEXxhT2JKqlqtqWVL_hSR0-RHxvwQXbnqzqesvYF8kfj7v71i_BAdQ0Rb/s1600/NusbioMCU_2017-02.00.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="225" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0K8-uuKwb67yFzyOoOFfK4-hQdKfqyqKth0jIzddfV7HIaBt4GErbVgZJeNI8PwRqH05y1gu_PXI_2eHOboigEXxhT2JKqlqtqWVL_hSR0-RHxvwQXbnqzqesvYF8kfj7v71i_BAdQ0Rb/s400/NusbioMCU_2017-02.00.jpg" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br />
<br />
<br />
<br />
<br />
<br />Anonymoushttp://www.blogger.com/profile/16516471292134914481noreply@blogger.com0tag:blogger.com,1999:blog-7044556212189675078.post-91092704492995015062016-07-01T18:43:00.002-07:002016-07-02T20:13:21.563-07:00Controlling one 110 volts appliance safely with .NET (C#, VB.NET, F# or PowerShell)<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<h2>
Overview</h2>
Turning on and off an 110 volts appliance from a computer like a Raspberry PI/Python or a PC with an our device <a href="http://nusbio.net/">Nusbio.net</a> using any .NET language, is not per say difficult.<br />
<br />
You need one GPIO (General Purpose Input/Output) connected to what is called a Relay. A Relay looks like that.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKPZcr5q42teb5BEZGZdF6FtOFRSk2Tz3qOV2a2loFODbZEzLpCY_2vPNQ3KB_zj7G4QyeUPEdKOwPEwriVgowTiGzFHRsNe3va9-mSTSXpS_ffhbGViVyxA9MSZFIIS4LfUFsjn86pExi/s1600/RegularRelay.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="257" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKPZcr5q42teb5BEZGZdF6FtOFRSk2Tz3qOV2a2loFODbZEzLpCY_2vPNQ3KB_zj7G4QyeUPEdKOwPEwriVgowTiGzFHRsNe3va9-mSTSXpS_ffhbGViVyxA9MSZFIIS4LfUFsjn86pExi/s320/RegularRelay.jpg" width="320" /> </a></div>
<div class="separator" style="clear: both; text-align: left;">
The issue is that you must make the wiring yourself and this can be slightly dangerous. </div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<h2 class="separator" style="clear: both; text-align: left;">
Solution</h2>
<div class="separator" style="clear: both; text-align: left;">
The company <a href="http://www.digital-loggers.com/" target="_blank">Digital-loggers</a> introduced recently the <a href="http://www.digital-loggers.com/iot.html" target="_blank">IOTRelay</a>. The IOTRealy takes care of every thing, it is safe, solid, easy to connect to and affordable $20.</div>
<ul>
<li>On the side connect the cable to one of your outlet.</li>
<li>On the top you have 4 outlets</li>
<ul>
<li>2 are labelled normally ON, this is the one you will use to plug into your lamp, <br />fan or toaster. Though we have 2 outlets, they are not independent.</li>
<li>2 are labelled normally OFF, and turn the appliances when the IOTRelay is programmed to be off. I am not sure that this will be very useful.</li>
</ul>
</ul>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMbuwBcGDbp3_IJbXJ9591Qa0KLWGki-ml9nmygvCtkTHUDoxsAx6ZtEQK83UoulCqQxZCUOCdUYU72h-Vk72LZQzBmRyVytulgC7rE0ZuopbfB-Ep_h9HGL_OAMdR6uWHgyZrmTCoTa-g/s1600/IORelay_01.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="360" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMbuwBcGDbp3_IJbXJ9591Qa0KLWGki-ml9nmygvCtkTHUDoxsAx6ZtEQK83UoulCqQxZCUOCdUYU72h-Vk72LZQzBmRyVytulgC7rE0ZuopbfB-Ep_h9HGL_OAMdR6uWHgyZrmTCoTa-g/s640/IORelay_01.jpg" width="640" /></a></div>
<h3 class="separator" style="clear: both; text-align: center;">
<b> </b></h3>
<h2 class="separator" style="clear: both; text-align: center;">
<b><a href="https://www.youtube.com/watch?v=TfoSoSGG-h0" target="_blank">Video</a></b></h2>
<h3 class="separator" style="clear: both; text-align: center;">
<b> </b></h3>
<div class="separator" style="clear: both; text-align: left;">
</div>
<div class="separator" style="clear: both; text-align: left;">
The wiring is simple:</div>
<ul>
<li>Connect any of the 8 Nusbio's GPIO to the positive of the IOT Relay. </li>
<li>Connect the negative of the IOT Relay to Nusbio's Ground.</li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCc1D0BQsVwVKXtB5f6N1fEHrgYARhcEzQSv6cayuOCi4sFbomT-kGawcEhj65SMcFUg6DFjYzgnbGHX3AMl_ilY4kVN3eUzsHmYRVOlVZgCMD4dL9ZXfi-1Qq8J21LaOSSy-6GXAjVZTQ/s1600/IORelay_00.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="360" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCc1D0BQsVwVKXtB5f6N1fEHrgYARhcEzQSv6cayuOCi4sFbomT-kGawcEhj65SMcFUg6DFjYzgnbGHX3AMl_ilY4kVN3eUzsHmYRVOlVZgCMD4dL9ZXfi-1Qq8J21LaOSSy-6GXAjVZTQ/s640/IORelay_00.jpg" width="640" /></a></div>
<br />
<br />
<h2 style="text-align: center;">
<a href="http://squ.re/28YnTTn" target="_blank">Nusbio board + IOTRelay $36</a></h2>
<br />
<h2>
Programming</h2>
<br />
From a software point of view all you have to do is turn the GPIO on or off to power your appliances.<br />
Nusbio is compatible with C#, VB.NET, F# and PowerShell.<br />
<br />
<pre class="brush:csharp;" id=""> nusbio[0].High(); // Turn appliance on
nusbio[0].Low(); // Turn appliance off
</pre>
Anonymoushttp://www.blogger.com/profile/16516471292134914481noreply@blogger.com1tag:blogger.com,1999:blog-7044556212189675078.post-86182664931870740902016-05-27T20:31:00.000-07:002016-06-08T03:31:57.387-07:00Digital To Analog Converter For .NET, C# and VB.NET.<h2>
Introduction</h2>
The world of Raspberry PI and Arduino offers<br />
<ul>
<li>GPIO pins (General Purpose Input Output) </li>
<li>ADC (Analog To Digital converter)</li>
<li>DAC (Digital To Analog Converter)</li>
</ul>
But what you may not know is that you can have these directly programmable to your Windows machine with any .NET languages using the USB device Nusbio.<br />
<h2>
DAC - Digital To Analog Converter</h2>
A DAC offers the ADC reverse function, that is to say starting with a integer range of values for example from 0 to 4097 (12 bits), output voltage between 0 and 5 volt, or 0 or 3.3 volt.<br />
<br />
The MCP4725 is a 12 bit, 5 volts digital to analog converter that use the I2C protocol.<br />
Adafruit offer a <a href="https://www.adafruit.com/products/935" target="_blank">break out</a>.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjbb5j5PsfqHFENV7LR_PmfcqjnVu3Fq8LCmfgZV8VscQ-dl1T7-5ig-rSL3XgpfzzLWzszreyPrhiBKIsQ5I6z17sHeBvkkU-Wifw-BIxCIEFRCTJw2XnRXUbyBpEGexYefVihyphenhyphenwojtFoo/s1600/Adafruit+MCP4525+DAC.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="233" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjbb5j5PsfqHFENV7LR_PmfcqjnVu3Fq8LCmfgZV8VscQ-dl1T7-5ig-rSL3XgpfzzLWzszreyPrhiBKIsQ5I6z17sHeBvkkU-Wifw-BIxCIEFRCTJw2XnRXUbyBpEGexYefVihyphenhyphenwojtFoo/s400/Adafruit+MCP4525+DAC.jpg" width="400" /></a></div>
<br />
<br />
Here are 2 videos:<br />
<br />
<ul>
<li><a href="https://www.youtube.com/watch?v=yJbxXnyzp6w" target="_blank">Nusbio - Digital To Analog Converter</a> </li>
<li><a href="https://www.youtube.com/watch?v=ao87ho9jOTc" target="_blank">Nusbio - LED fade in and fade out with DAC </a></li>
</ul>
<br />Anonymoushttp://www.blogger.com/profile/16516471292134914481noreply@blogger.com0tag:blogger.com,1999:blog-7044556212189675078.post-3291289543259018942016-05-27T20:15:00.001-07:002016-06-08T03:32:09.348-07:00Analog To Digital Converter For .NET (C#, VB.NET, F#, PowerShell)<h2>
Introduction</h2>
The world of Raspberry PI and Arduino offers<br />
<ul>
<li>GPIO pins (General Purpose Input Output) </li>
<li>ADC (Analog To Digital converter)</li>
<li>DAC (Digital To Analog Converter)</li>
</ul>
But what you may not know is that you can have these directly programmable to your Windows machine with any .NET languages using the USB device <a href="http://www.nusbio.net/" target="_blank">Nusbio</a>.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijOdgXm-mSbXppwno5X8BrqtzRKzkVrcPrjKm4MYbODIn8WfL3QxWK1CUu1ZWy4jP_vjggtfsYUN3uuHi6gTqOa4uogB3p-gMqUlZBgSde_NB2dr3tpVJAoAIi8m3EPLg3mELTAA8sjfWx/s1600/20160222_215025.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="179" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijOdgXm-mSbXppwno5X8BrqtzRKzkVrcPrjKm4MYbODIn8WfL3QxWK1CUu1ZWy4jP_vjggtfsYUN3uuHi6gTqOa4uogB3p-gMqUlZBgSde_NB2dr3tpVJAoAIi8m3EPLg3mELTAA8sjfWx/s320/20160222_215025.jpg" width="320" /></a></div>
<b>Videos</b><br />
<div style="text-align: center;">
<a href="https://www.youtube.com/watch?v=LP3nwIzAiTw" target="_blank">Light Sensor </a></div>
<div style="text-align: center;">
<a href="https://www.youtube.com/watch?v=o0GFyDnX9NY" target="_blank">Nusbio - Analog To Digital Converters + Sensors - Part I </a> </div>
<div style="text-align: center;">
<a href="https://www.youtube.com/watch?v=83_imLFF2fM" target="_blank">Nusbio - Analog To Digital Converters + Sensors - Part II</a><br />
<br />
<div style="text-align: left;">
<b>Source Code</b> </div>
<div style="text-align: center;">
<a href="https://github.com/madeintheusb/Nusbio.Samples/tree/master/Extensions/CS/MadeInTheUSB.Nusbio.Extension.Analog" target="_blank">Analog Extension</a> </div>
</div>
<h2>
Analog Sensors </h2>
The analog extension offer 8 10 bits analog to digital converter similar as the one found on an Arduino UNO.<br />
Any 5 or 3 volts analog sensor could be plugged into the extension and their values read from any .NET language.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgluH-_E2O7CcgxOCKYDK6T8JD0y14gIv1y1rJs7cmwHFdKoGNlOrxxtmO6BamkNHykMQLnIs4nTKWMWwd6HXW-oFqGbcVqJoX4nW9qENdpUMBqLoSUw5GgC8xEwhWf6miXtBKCsxDtpBGV/s1600/Vibrator+Sensor.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="223" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgluH-_E2O7CcgxOCKYDK6T8JD0y14gIv1y1rJs7cmwHFdKoGNlOrxxtmO6BamkNHykMQLnIs4nTKWMWwd6HXW-oFqGbcVqJoX4nW9qENdpUMBqLoSUw5GgC8xEwhWf6miXtBKCsxDtpBGV/s400/Vibrator+Sensor.jpg" width="400" /> </a></div>
<div class="separator" style="clear: both; text-align: center;">
Vibrator Sensor </div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijOdgXm-mSbXppwno5X8BrqtzRKzkVrcPrjKm4MYbODIn8WfL3QxWK1CUu1ZWy4jP_vjggtfsYUN3uuHi6gTqOa4uogB3p-gMqUlZBgSde_NB2dr3tpVJAoAIi8m3EPLg3mELTAA8sjfWx/s1600/20160222_215025.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="225" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijOdgXm-mSbXppwno5X8BrqtzRKzkVrcPrjKm4MYbODIn8WfL3QxWK1CUu1ZWy4jP_vjggtfsYUN3uuHi6gTqOa4uogB3p-gMqUlZBgSde_NB2dr3tpVJAoAIi8m3EPLg3mELTAA8sjfWx/s400/20160222_215025.jpg" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
One TMP36 temperature sensor, one light sensor and one motion sensor plugged into the Analog Extension.</div>
The source code to deal with the 3 sensors:<br />
<br />
<pre class="brush:csharp;">while (nusbio.Loop())
{
if (halfSeconds.IsTimeOut())
{
const int lightSensorAnalogPort = 6;
const int motionSensorAnalogPort = 2;
const int temperatureSensorAnalogPort = 0;
ConsoleEx.WriteLine(0, 2, string.Format("{0,-20}", DateTime.Now, lightSensor.AnalogValue), ConsoleColor.Cyan);
lightSensor.SetAnalogValue(ad.Read(lightSensorAnalogPort));
ConsoleEx.WriteLine(0, 4, string.Format("Light Sensor : {0} (ADValue:{1:000.000}, Volt:{2:000.000}) ",
lightSensor.CalibratedValue.PadRight(18),
lightSensor.AnalogValue,
lightSensor.Voltage), ConsoleColor.Cyan);
analogTempSensor.SetAnalogValue(ad.Read(temperatureSensorAnalogPort));
ConsoleEx.WriteLine(0, 6, string.Format("Temperature Sensor : {0:00.00}C, {1:00.00}F (ADValue:{2:0000}, Volt:{3:000.000}) ",
analogTempSensor.GetTemperature(AnalogTemperatureSensor.TemperatureType.Celsius),
analogTempSensor.GetTemperature(AnalogTemperatureSensor.TemperatureType.Fahrenheit),
analogTempSensor.AnalogValue,
analogTempSensor.Voltage), ConsoleColor.Cyan);
analogMotionSensor.SetAnalogValue(ad.Read(motionSensorAnalogPort));
var motionType = analogMotionSensor.MotionDetected();
if (motionType == DigitalMotionSensorPIR.MotionDetectedType.MotionDetected || motionType == DigitalMotionSensorPIR.MotionDetectedType.None)
{
ConsoleEx.Write(0, 8, string.Format("Motion Sensor : {0,-20} (ADValue:{1:000.000}, Volt:{2:000.000})", motionType, analogMotionSensor.AnalogValue, analogMotionSensor.Voltage), ConsoleColor.Cyan);
}
}
} </pre>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTSsSuRTiCKQAn8fjgmh0qMfXJAyK2kYFhTCnSVq7hLZNMU5ByKURRn9DvOwXHjpjXaFSW9dgiZVMDOa58uHFarhPTNXl52xuo6YGfvFZ_-Yt5u7yKTUSVZXhoQbOrADG0k6ss37bV7JsE/s1600/TouchSensor.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="223" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTSsSuRTiCKQAn8fjgmh0qMfXJAyK2kYFhTCnSVq7hLZNMU5ByKURRn9DvOwXHjpjXaFSW9dgiZVMDOa58uHFarhPTNXl52xuo6YGfvFZ_-Yt5u7yKTUSVZXhoQbOrADG0k6ss37bV7JsE/s400/TouchSensor.jpg" width="400" /></a></div>
This touch sensor only require a digital GPIO, when you finger touch the panel the value at the gpio is a 1.<br />
It could also be plugged into the analog extension.<br />
<br />
<h2>
DAC - Digital To Analog Converter</h2>
A DAC offers the ADC reverse function, that is to say starting with a
integer range of values for example from 0 to 4097 (12 bits), output
voltage between 0 and 5 volt, or 0 or 3.3 volt.<br />
<br />
The MCP4725 is a 12 bit, 5 volts digital to analog converter that use the I2C protocol.<br />
Adafruit offer a <a href="https://www.adafruit.com/products/935" target="_blank">break out</a>.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjbb5j5PsfqHFENV7LR_PmfcqjnVu3Fq8LCmfgZV8VscQ-dl1T7-5ig-rSL3XgpfzzLWzszreyPrhiBKIsQ5I6z17sHeBvkkU-Wifw-BIxCIEFRCTJw2XnRXUbyBpEGexYefVihyphenhyphenwojtFoo/s1600/Adafruit+MCP4525+DAC.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="233" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjbb5j5PsfqHFENV7LR_PmfcqjnVu3Fq8LCmfgZV8VscQ-dl1T7-5ig-rSL3XgpfzzLWzszreyPrhiBKIsQ5I6z17sHeBvkkU-Wifw-BIxCIEFRCTJw2XnRXUbyBpEGexYefVihyphenhyphenwojtFoo/s400/Adafruit+MCP4525+DAC.jpg" width="400" /></a></div>
<br />
<br />
Here are 2 videos:<br />
<br />
<ul>
<li><a href="https://www.youtube.com/watch?v=yJbxXnyzp6w" target="_blank">Nusbio - Digital To Analog Converter</a> </li>
<li><a href="https://www.youtube.com/watch?v=ao87ho9jOTc" target="_blank">Nusbio - LED fade in and fade out with DAC </a></li>
</ul>
<br />Anonymoushttp://www.blogger.com/profile/16516471292134914481noreply@blogger.com0tag:blogger.com,1999:blog-7044556212189675078.post-5988227061574305202016-05-22T19:23:00.004-07:002016-05-23T05:37:54.767-07:00Controller Extension Tutorial - Part II<h2>
Overview</h2>
You can read part I at of this post at <a href="http://madeintheusb.blogspot.com/2016/05/controller-extension-tutorial-part-i.html" target="_blank">Controller Extension Tutorial - Part I</a>.<br />
<br />
<div style="text-align: center;">
<a href="https://www.youtube.com/watch?v=JSbiJ_-s8_Y" target="_blank">Video</a>
<a href="http://madeintheusb.blogspot.com/2016/05/controller-extension-tutorial-part-ii.html" target="_blank">Part II - Beyond 5 volts</a><br />
<a href="https://squareup.com/store/madeintheusb-dot-net" target="_blank">Store</a> -<a href="http://www.nusbio.net/" target="_blank"> www.Nusbio.net </a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<h2>
Beyond 5 volt</h2>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCzuxzRz21ZFDDCDZ799qz9wx1_8ArL_2Hepm2XUs-HYiq7XvKCA8A8tpNKrvnrwnjooCKKrQlpkSR_19yu1YnRlLlwsbm1K0mR5gAeJcu4hckUAq1121LQ31bs2cVOeg7Dg_reLZA5tPB/s1600/EX_CT_14_Bat.On.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="223" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCzuxzRz21ZFDDCDZ799qz9wx1_8ArL_2Hepm2XUs-HYiq7XvKCA8A8tpNKrvnrwnjooCKKrQlpkSR_19yu1YnRlLlwsbm1K0mR5gAeJcu4hckUAq1121LQ31bs2cVOeg7Dg_reLZA5tPB/s400/EX_CT_14_Bat.On.jpg" width="400" /></a></div>
Some devices will require 8 or 12 volt, therefore we offer a second extension which allow to plug an external source of power like a 9 volt battery. <br />
Both extension use the transistor <a href="https://www.sparkfun.com/datasheets/Components/2N3904.pdf" target="_blank">2N3904 </a>which support 12 volt, but the current is still limited to 200 mA per external device controlled.<br />
<br />
<h2>
Beyond the USB 500 milliamp</h2>
<br />
Note that if each device controlled are 5 volts but require 200 mA each, we cannot use the USB to provide the 600 mA. USB 2.0 only allow to consume 500 mA. In this case we need a 5 volt power adapter providing 600 mA or more.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhqpFXfhez9SGblzlBw0rI9IE2w7p7yABRzECiGC3adRknfrbBaZ_d0HU5U-xOVfosbhUIEKqPYUcbQOolq8mfduXLBjHsEj573ZBsjUtxncm9IIKoGhaiBv6eLQ_acXd1rxHM-m-D4FJA/s1600/EX_CT_02_HackLamp.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><br /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhlnEwx4GRFjcO0-Jrtzal0IWYRRK8nrGkzGe8HwwlqXMlmPPJHlq5dIzHLq9aMmFI1w4A04_LjCjE_QzDhUVZhO3vb6cyBald_cLlz7hyphenhyphen74I_9RXVedGAqrcPhyphenhyphenR_dggz_Nr0H98jPgvng/s1600/EX+Controller+12Volts.01.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhlnEwx4GRFjcO0-Jrtzal0IWYRRK8nrGkzGe8HwwlqXMlmPPJHlq5dIzHLq9aMmFI1w4A04_LjCjE_QzDhUVZhO3vb6cyBald_cLlz7hyphenhyphen74I_9RXVedGAqrcPhyphenhyphenR_dggz_Nr0H98jPgvng/s320/EX+Controller+12Volts.01.jpg" width="320" /></a></div>
The extension is configured to use an external source of power by default. But we can revert it back to use the USB power, by de-soldering the connection EX_PWR_ON and solder the connection USB_PWR_ON.<br />
<br />
<h2>
Connecting all the pieces</h2>
Now, we have 4 items<br />
<ol>
<li>The Nusbio board</li>
<li>The Controller Extension</li>
<li>The 9 volts lamp</li>
<li>An external source of power, here a 9 volt battery </li>
</ol>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2EcT-loInDQlOKzcqvvYX8eloh9qW6iC5Lmh6EUr-gxgdEwetzhYPfMzHomCh-oCf2CvcxHDXCL0Eh7WmO-s63pKvZAIrO2FTduwm1thQDn3EyXeyaghhSGYMGJYKUe5E1jdU-0imZEOx/s1600/EX_CT_10_Bat.AllSeparate.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2EcT-loInDQlOKzcqvvYX8eloh9qW6iC5Lmh6EUr-gxgdEwetzhYPfMzHomCh-oCf2CvcxHDXCL0Eh7WmO-s63pKvZAIrO2FTduwm1thQDn3EyXeyaghhSGYMGJYKUe5E1jdU-0imZEOx/s400/EX_CT_10_Bat.AllSeparate.jpg" width="225" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVhxe1xxGzMmxK3QlM23lDNzAO8qhpk_eJbTd4vj9TbhXG3qWQo3oOFpzCUPJ9Hs_QQkZiqJ1aIcSNtb-s5Dpmvl-8sCFFcR8T6DZrpLW4x68IbZM2oJs7nNpg16Yk2Tq7HTmmZukHupAT/s1600/EX_CT_10_Bat.AllSeparate.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><br /></a></div>
Plug the extension into Nusbio and<br />
<ul>
<li>The black wire from the device must be plugged into the G0 pin (Ground 0)</li>
<li>The red wire from the device must be plugged into the V0 pin (VCC 0, in short VCC mean +)</li>
<li>The black wire or negative from the battery into the EX_POWER_PIN negative pin</li>
<li>The red wire or positive from the battery into the EX_POWER_PIN positive pin</li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKV9LRoNK7gxS7DIs1iiBIGE51d019v84LpTIOoWdhjLvNxy55xeqQktY-CzaEqIjfnqV6WdOVdF3h0d3RMWkHDw_Hn12PXMovsFSU6nykILeslQjadbtvpgcOrXZkXYw4UzpgJNqAsURy/s1600/EX_CT_13_Bat.Together.Closer.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="225" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKV9LRoNK7gxS7DIs1iiBIGE51d019v84LpTIOoWdhjLvNxy55xeqQktY-CzaEqIjfnqV6WdOVdF3h0d3RMWkHDw_Hn12PXMovsFSU6nykILeslQjadbtvpgcOrXZkXYw4UzpgJNqAsURy/s400/EX_CT_13_Bat.Together.Closer.jpg" width="400" /> </a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEVX459NpMV5xuPeI2a9zEL09-7r55epmM3iH_eLb2lyritUMn3NvhWk0Y_Zpfx2nT-TPd0D_C7KNdGwBr5-vRPA5bo6EG4ytnSs5BQdOP-0SWCElGZ19WR5WV_VUWP9siJJECTobisTeX/s1600/EX_CT_11_Bat.Together.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEVX459NpMV5xuPeI2a9zEL09-7r55epmM3iH_eLb2lyritUMn3NvhWk0Y_Zpfx2nT-TPd0D_C7KNdGwBr5-vRPA5bo6EG4ytnSs5BQdOP-0SWCElGZ19WR5WV_VUWP9siJJECTobisTeX/s400/EX_CT_11_Bat.Together.jpg" width="225" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br />
<h2>
Programming</h2>
The change of voltage from 5 to 9 volt does not affect the programming.<br />
The shortest code would look like this and will turn on the device for 500 ms and turn it off for another 500 ms.<br />
<br />
<pre class="brush:csharp;">var serialNumber = Nusbio.Detect();
if (serialNumber == null) // Detect the first Nusbio available
{
Console.WriteLine("Nusbio not detected"); return;
}
using (var nusbio = new Nusbio(serialNumber)
{
while(true) {
nusbio.GPIOS[NusbioGpio.Gpio0].DigitalWrite(true);
Thread.Sleep(500);
nusbio.GPIOS[NusbioGpio.Gpio0].DigitalWrite(false);
Thread.Sleep(500);
}
}</pre>
<h2>
To learn more</h2>
<a href="http://madeintheusb.blogspot.com/2016/04/transistor-crash-course-for-software.html" target="_blank">Transistor Crash Course For Software Developer - PART I - Transistor As Switch </a><br />
<a href="https://www.youtube.com/watch?v=P660hTqkGiY" target="_blank">Measuring Current with a Digital Multimeter</a><br />
YouTube is your friend, if you want to learn electricityAnonymoushttp://www.blogger.com/profile/16516471292134914481noreply@blogger.com0tag:blogger.com,1999:blog-7044556212189675078.post-3333939593876278502016-05-21T16:17:00.001-07:002016-05-23T05:55:06.020-07:00Controller Extension Tutorial - Part I<h2>
Overview</h2>
<br />
The Nusbio's Controller Extension allows to turn on and off programmatically using any .NET language up to 3 devices.<br />
<br />
<div style="text-align: center;">
<a href="https://www.youtube.com/watch?v=JSbiJ_-s8_Y" target="_blank">Video</a><br />
<a href="http://madeintheusb.blogspot.com/2016/05/controller-extension-tutorial-part-ii.html" target="_blank">Part II - Beyond 5 volts</a><br />
<a href="https://squareup.com/store/madeintheusb-dot-net" target="_blank">Store</a> -<a href="http://www.nusbio.net/" target="_blank"> www.Nusbio.net </a></div>
<br />
In this part I, I will use the simple version of the extension which automatically provide current to power the devices and therefore each device must be 5 volts.<br />
The limit of current per device is 200 milli-amp (mA) because this is the limit of the 2N3904 transistor used by the extension.<br />
Also the total consumption must be less than 500 milli-amp, because this is the USB limit and the devices are really powered by the USB of the computer. <br />
<br />
The rule of thumb is that an LED use 20 mA and this lamp has 3 so 60 mA. Simple motor found in printer will use 100 mA. To learn how to measure current consumption, see links at the end of this post.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYPZVI4rJN7qxxFhW9XZGJvtfcoZBDBuEuJhng-5faH9bNRJrQ3BN8w9KwvaffIvfb59v5CPGjelTkVUaGHTQ_ED_tskniTDMBGoiHb_bBN8AZ1qAEWxpwMinRQ5XIvYhm8Cbb6l53OV2O/s1600/EX_CT_07_On.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYPZVI4rJN7qxxFhW9XZGJvtfcoZBDBuEuJhng-5faH9bNRJrQ3BN8w9KwvaffIvfb59v5CPGjelTkVUaGHTQ_ED_tskniTDMBGoiHb_bBN8AZ1qAEWxpwMinRQ5XIvYhm8Cbb6l53OV2O/s400/EX_CT_07_On.jpg" width="225" /></a></div>
<br />
<h2>
Where to start?</h2>
Pick a 5 volts device like this lamp, even if the device is powered with battery like 3 AA battery (3 x 1.5 ~= 4.5 ~= 5 Volts ) and attach or solder a black wire to the negative and a red wire to the positive. Just follow the current black and red wire currently hooked from the batteries to the device.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhqpFXfhez9SGblzlBw0rI9IE2w7p7yABRzECiGC3adRknfrbBaZ_d0HU5U-xOVfosbhUIEKqPYUcbQOolq8mfduXLBjHsEj573ZBsjUtxncm9IIKoGhaiBv6eLQ_acXd1rxHM-m-D4FJA/s1600/EX_CT_02_HackLamp.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="225" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhqpFXfhez9SGblzlBw0rI9IE2w7p7yABRzECiGC3adRknfrbBaZ_d0HU5U-xOVfosbhUIEKqPYUcbQOolq8mfduXLBjHsEj573ZBsjUtxncm9IIKoGhaiBv6eLQ_acXd1rxHM-m-D4FJA/s400/EX_CT_02_HackLamp.jpg" width="400" /></a></div>
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJmJOJzhK_G4YMFSTofXHvKGGu4OTgEf3VO5l8tG-LBVH3BBk0i3fETGRy3V3OdpG5OxJGlxHzwoY5L3T4tmeI62-5B7tBx6LKbiUeAzNnIp0Qbaa86tNz0u8dWfYSzOLYPGobc4qU_1S0/s1600/EX_CT_03_HackLamp.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;">a<img border="0" height="225" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJmJOJzhK_G4YMFSTofXHvKGGu4OTgEf3VO5l8tG-LBVH3BBk0i3fETGRy3V3OdpG5OxJGlxHzwoY5L3T4tmeI62-5B7tBx6LKbiUeAzNnIp0Qbaa86tNz0u8dWfYSzOLYPGobc4qU_1S0/s400/EX_CT_03_HackLamp.jpg" width="400" /></a></div>
<br />
<br />
Now, we have 3 items<br />
<ol>
<li>The Nusbio board</li>
<li>The Controller Extension</li>
<li>The 5 volts lamp</li>
</ol>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi80h8S0xOaCrpP9JBCNNBmp2VNhygemIoDxMTk7sxYbpfPcF6NSMuz9RzXR3GR7lYxkSUu6KJCM0OGJsanX5Sk5z4zFIhY2wzGn6exFRDk9kem6NodwM2_AWXmdcPlKOeYM-3mzlGmxjKy/s1600/EX_CT_04_AllSeparate.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi80h8S0xOaCrpP9JBCNNBmp2VNhygemIoDxMTk7sxYbpfPcF6NSMuz9RzXR3GR7lYxkSUu6KJCM0OGJsanX5Sk5z4zFIhY2wzGn6exFRDk9kem6NodwM2_AWXmdcPlKOeYM-3mzlGmxjKy/s320/EX_CT_04_AllSeparate.jpg" width="180" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVhxe1xxGzMmxK3QlM23lDNzAO8qhpk_eJbTd4vj9TbhXG3qWQo3oOFpzCUPJ9Hs_QQkZiqJ1aIcSNtb-s5Dpmvl-8sCFFcR8T6DZrpLW4x68IbZM2oJs7nNpg16Yk2Tq7HTmmZukHupAT/s1600/EX_CT_10_Bat.AllSeparate.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><br /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVhxe1xxGzMmxK3QlM23lDNzAO8qhpk_eJbTd4vj9TbhXG3qWQo3oOFpzCUPJ9Hs_QQkZiqJ1aIcSNtb-s5Dpmvl-8sCFFcR8T6DZrpLW4x68IbZM2oJs7nNpg16Yk2Tq7HTmmZukHupAT/s1600/EX_CT_10_Bat.AllSeparate.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><br /></a></div>
Plug the extension into Nusbio and<br />
<ul>
<li>The black wire from the device must be plugged into the G0 pin (Ground 0)</li>
<li>The red wire from the device must be plugged into the V0 pin (VCC 0, in short VCC mean +)</li>
<li>Turning on or off Nusbio GPIO 0 programmatically will power or not the device</li>
</ul>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXS1BvbU8TIhPGT2q5MZhynqeH9qybocPAMAmPj3pvj6Sijr-ciMlsPZej-L0ta4szTgUhwXn00e4fArZ9_TMB8gbofq1zxdDyNqvT4lJ9ib9Qiar58YgaFtPqXK_L0wCOEzYUzQ4TiSZS/s1600/EX_CT_06_Close.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="360" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXS1BvbU8TIhPGT2q5MZhynqeH9qybocPAMAmPj3pvj6Sijr-ciMlsPZej-L0ta4szTgUhwXn00e4fArZ9_TMB8gbofq1zxdDyNqvT4lJ9ib9Qiar58YgaFtPqXK_L0wCOEzYUzQ4TiSZS/s640/EX_CT_06_Close.jpg" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzSynO1fclrWJ6oQ-rbzjIhZ4sEHUhGfm_iXOF24guCpo7qIGqojNy50b-wctQ6k53GGNbtqQLxS6gxDatmtcGrvR5y9vX2OIjy1XNnmIAMCyCtTwkASXZnShgb453j6W-rgFVbmpFP7_L/s1600/EX_CT_07_On.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzSynO1fclrWJ6oQ-rbzjIhZ4sEHUhGfm_iXOF24guCpo7qIGqojNy50b-wctQ6k53GGNbtqQLxS6gxDatmtcGrvR5y9vX2OIjy1XNnmIAMCyCtTwkASXZnShgb453j6W-rgFVbmpFP7_L/s400/EX_CT_07_On.jpg" width="225" /></a></div>
<br />
<h2>
Programming</h2>
The shortest code would look like this and will turn on the device for 500 ms and turn it off for another 500 ms. The Nusbio .NET library is written in C# compiled as .NET 4.0 and therefore compatible with VB.NET, F#, PowerShell and IronPython.<br />
<br />
<pre class="brush:csharp;">var serialNumber = Nusbio.Detect();
if (serialNumber == null) // Detect the first Nusbio available
{
Console.WriteLine("Nusbio not detected"); return;
}
using (var nusbio = new Nusbio(serialNumber)
{
while(true) {
nusbio.GPIOS[NusbioGpio.Gpio0].DigitalWrite(true);
Thread.Sleep(500);
nusbio.GPIOS[NusbioGpio.Gpio0].DigitalWrite(false);
Thread.Sleep(500);
}
}</pre>
<pre class="brush:csharp;"> </pre>
<h2>
To learn more</h2>
<a href="http://madeintheusb.blogspot.com/2016/04/transistor-crash-course-for-software.html" target="_blank">Transistor Crash Course For Software Developer - PART I - Transistor As Switch </a><br />
<a href="https://www.youtube.com/watch?v=P660hTqkGiY" target="_blank">Measuring Current with a Digital Multimeter</a><br />
YouTube is your friend, if you want to learn electricity<br />
<pre class="brush:csharp;"></pre>
Anonymoushttp://www.blogger.com/profile/16516471292134914481noreply@blogger.com0tag:blogger.com,1999:blog-7044556212189675078.post-15622403722476831782016-04-16T09:45:00.000-07:002016-05-20T07:08:46.210-07:00Transistor Crash Course For Software Developer - PART I - Transistor As Switch<div class="separator" style="clear: both; text-align: center;">
</div>
<h2>
Overview</h2>
<br />
If you are a software developer that started making hardware experiment with an Arduino, Raspberry PI, BeagleBone or our USB device <a href="http://www.nusbio.net/">Nusbio</a>, You probably learn by now about GPIO (General Purpose Input Ouput).<br />
These pins with which we can programmatically send a 1 or 0 or read a 1 or 0 when connected to another device.<br />
A 1 also called high (pulling the wire high) is materialized by sending<br /> some voltage/current (3 or 5 volts generally) and a 0 also called a low materialized by sending no voltage/current.<br />
<br />
Though we can turn on and off device with a GPIO, a GPIO generally can only provide a limited amount of current. An Arduino Uno GPIO can provide up to 40 mA of current (<a href="http://playground.arduino.cc/Main/ArduinoPinCurrentLimitations">ArduinoPinCurrentLimitations</a>).<br />
<a href="http://www.nusbio.net/" target="_blank">Nusbio</a>'s GPIO are configured by default to provide 4 mA and can be configured to provide up to 16 mA.<br />
<br />
Therefore when you want to control a device like a simple motor or an LED using 60 mA, you should not connect the GPIO directly to the positive of the device. It may work, but the motor may go very slow or the LED will not be very bright.<br />
<br />
If the device is 5 or 12 volts, you can use a transistor. If the device is 110 volts, you need a relay.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIezTrS3hlUscJWerp_-C8GJSVvo_d0HCzvx40t47a3_0SvC8vkJCbpE4BOzI4OaikoCuughdS8YUfBEdM25suANKcRvVaj4ghZmSQcVtDisL8njIIlHLnDHx0mEBJi4BJ-S0G9LzuF0kS/s1600/DesktopLamp5V.VisualStudio.WinFormEditing.Combined.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="222" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIezTrS3hlUscJWerp_-C8GJSVvo_d0HCzvx40t47a3_0SvC8vkJCbpE4BOzI4OaikoCuughdS8YUfBEdM25suANKcRvVaj4ghZmSQcVtDisL8njIIlHLnDHx0mEBJi4BJ-S0G9LzuF0kS/s400/DesktopLamp5V.VisualStudio.WinFormEditing.Combined.jpg" width="400" /></a></div>
<br />
<br />
<h2>
Transistors </h2>
<h2>
</h2>
<br />
<b><i>Disclaimer</i></b>: <i>This is a very quick introduction to <a href="https://en.wikipedia.org/wiki/Transistor">transistor </a>to be used as switch. My goal is to get you enough information so you can turn on and off devices that require between 40 and 400 mA of current with <a href="http://www.nusbio.net/" target="_blank">Nusbio</a>'s GPIOS.</i><br />
<br />
<h3>
Usage</h3>
<h3>
</h3>
<a href="https://en.wikipedia.org/wiki/Transistor">Transistor </a>can be used as<br />
<ul>
<li>Switch</li>
<li>Amplifier</li>
<li>Binary logic</li>
</ul>
<h3>
Type</h3>
There are multiples types of transistor, if you just need to remember 2 types<br />
<ol>
<li>BJT (Bipolar junction transistor)</li>
<ul>
<li>Activated by sending some current to the base (more on this later) </li>
</ul>
<ul>
<li>NPN, default off, activated when current is sent to base</li>
<li>PNP, default on, de-activated when current is sent to base</li>
</ul>
<li>MOSFET (metal–oxide–semiconductor field-effect transistor)</li>
<ul>
<li>Activated by sending some voltage at the gate (<a href="https://en.wikipedia.org/wiki/MOSFET">more on MOSFET</a>)</li>
<li>N-Chanel, default off, activated when voltage is sent to base</li>
<li>P-Chanel default on, de-activated when voltage is sent to base</li>
</ul>
</ol>
<h3>
Switch Configuration</h3>
In this paragraph we are going to use a BJT transistor and configure it as a Switch. A BJT transistor has 3 pins C, B , E.<br />
<br />
<ul>
<li>The C stand for Collector. Remember the following:<br /> <i>In a Switch mode configuration the Collector collect the load.</i><br />What that mean is in a electrical circuit one component is consuming current (a light or motor), that is the load. The transistor Collector should be plugged just after the component creating the load.<br />The negative of the controlled device should be connected the collector and the positive of the controlled device should connected to the source of power. As a software developer I would call it the input.</li>
</ul>
<ul>
<li>E stands for Emitter which in a Switch mode should be connected to ground, as a software developer I would call it the output.</li>
</ul>
<ul>
<li>B stands for base which is connected to for example a GPIO, as a software developer I would call it the API. Don't forget to add in between the GPIO and the base a resistor (for now let's say 1k).</li>
</ul>
In short the current will flow from C to E, if a small amount of current is sent to B (for NPN transistor)<br />
<ol><ul>
</ul>
</ol>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZV8fCaAU-gYAndAivdTLYUfgDLAaY5XCDPydyVpDsYh29pKuIJWnEdmjM8X02NC7mis8UMWQc_KUbipomkDnZodiED_UZi2JhTfutjYGZAsFBe3xaJA0c_4ZqvkFYrsItA2GkwI_9ffXp/s1600/BJT_NPN_Transistor_Motor.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZV8fCaAU-gYAndAivdTLYUfgDLAaY5XCDPydyVpDsYh29pKuIJWnEdmjM8X02NC7mis8UMWQc_KUbipomkDnZodiED_UZi2JhTfutjYGZAsFBe3xaJA0c_4ZqvkFYrsItA2GkwI_9ffXp/s320/BJT_NPN_Transistor_Motor.jpg" width="300" /></a></div>
<h3>
Datasheet</h3>
Double check the transistor datasheet to know the maximum voltage and current supported by the transistor.<br />
<br />
I often use the <a href="https://www.sparkfun.com/datasheets/Components/2N3904.pdf">2N3904</a>, it is a BJT NPN. In datasheet I found the following<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEig7anyv7-qJ7ZyH4KAT8uBl6uXbHxS8fIRm7rQ062MnaoSQyUrjDLYMz4DCTtFWPkZC1KuwHxP4F52MGE-nzLkgExbGL3D_CxR2CgeQ-P1TU9S8nbCORoFApquqC8txfiYc9k52dn6_HOv/s1600/BJT_NPN_Transistor_2N3904_MaxRating.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="141" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEig7anyv7-qJ7ZyH4KAT8uBl6uXbHxS8fIRm7rQ062MnaoSQyUrjDLYMz4DCTtFWPkZC1KuwHxP4F52MGE-nzLkgExbGL3D_CxR2CgeQ-P1TU9S8nbCORoFApquqC8txfiYc9k52dn6_HOv/s400/BJT_NPN_Transistor_2N3904_MaxRating.jpg" width="400" /></a></div>
The maximum voltage supported is 40 (Vceo) and the maximum current that can flow throw the transistor is 200 mA (Ic). Nusbio power comes from the USB and is 5 volts.<br />
<br />
<h2>
Eat Big Cookie</h2>
How do I find which pin is which? Turn the flat face toward you and say out load Eat Big Cookie.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJ5bUZ1mbJvVLlTLDPdNMLlD70RDxd5RYn1lIjcOSWzf2F8mKBoCe__Szb588H4I_-LSA-50UBqQf7rAAV8Xddmpnx34rVBO7zv-qJEkoK-Eqq25rm8kPEtswe8A9ptUKzRX7k3bn4onkM/s1600/BJT_NPN_Transistor_EatBigCookie.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJ5bUZ1mbJvVLlTLDPdNMLlD70RDxd5RYn1lIjcOSWzf2F8mKBoCe__Szb588H4I_-LSA-50UBqQf7rAAV8Xddmpnx34rVBO7zv-qJEkoK-Eqq25rm8kPEtswe8A9ptUKzRX7k3bn4onkM/s320/BJT_NPN_Transistor_EatBigCookie.jpg" width="311" /></a></div>
<br />
<br />
<h2>
Nusbio + Transistor</h2>
<br />
Wiring a BJT to <a href="http://www.nusbio.net/" target="_blank">Nusbio </a>on a breadboard should look like that (it would be the same with an Arduino or Raspberry PI)<br />
<br />
<h3>
</h3>
<h3>
</h3>
<h3>
</h3>
<h3>
</h3>
<h3>
</h3>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbC_BUyfK89ddEvKdnXlHWhMXe8fFd9z3_qqlKYgRXRP_bv3cubscXsqMW3JMypsUtW16fUio6gMAdaPV43GpHXOgnBF6LKQbiFrEBTtWnPXjKDk52_QC7_Znb27JRXpqHsn3U8NFoibo-/s1600/DesktopLamp5V.Diagram.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbC_BUyfK89ddEvKdnXlHWhMXe8fFd9z3_qqlKYgRXRP_bv3cubscXsqMW3JMypsUtW16fUio6gMAdaPV43GpHXOgnBF6LKQbiFrEBTtWnPXjKDk52_QC7_Znb27JRXpqHsn3U8NFoibo-/s400/DesktopLamp5V.Diagram.jpg" width="342" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYav5GKUW91skqQTg1XbSAFses1iH_bjIDmsj7f_ukKFhnkjrIbTaqDBYdUxPalAX14p2Ie8z6hEA4PB3-nLjygrTaW30EB6Z4cCUIxrHa8HHbdGhhjmRJfBpiAdgE75dWFYfz2vz-hLdg/s1600/DesktopLamp5V_CloseView_00_S6.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYav5GKUW91skqQTg1XbSAFses1iH_bjIDmsj7f_ukKFhnkjrIbTaqDBYdUxPalAX14p2Ie8z6hEA4PB3-nLjygrTaW30EB6Z4cCUIxrHa8HHbdGhhjmRJfBpiAdgE75dWFYfz2vz-hLdg/s640/DesktopLamp5V_CloseView_00_S6.jpg" width="358" /> </a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<h2>
Videos</h2>
<div class="separator" style="clear: both; text-align: left;">
A video from MAKE and Collin Cunningham: MAKE presents: <a href="https://www.youtube.com/watch?v=-td7YT-Pums" target="_blank">The Transistor </a></div>
<h3>
</h3>
Anonymoushttp://www.blogger.com/profile/16516471292134914481noreply@blogger.com1tag:blogger.com,1999:blog-7044556212189675078.post-44054597901949899562016-02-21T19:59:00.000-08:002016-10-25T21:37:45.461-07:00Configuring Nusbio GPIO to drive up to 16 mA of current<h2>
Overview</h2>
All Nusbio's 8 GPIOs are configured to source/sink 4 mA of current.<br />
<br />
If you need the 8 gpios to source or sink 16 mA of current if possible to activate this mode using the Nusbio Console application.<br /><br /><b><span style="color: red;">We noticed that in 16mA of current mode I2C bus does not work.</span></b><br />
<ol>
<li>Execute the console</li>
<li>Select the C)onfiguration option</li>
<li>Verify that the setting ADDriveCurrent is set to 4 </li>
<li>Hit the enter key</li>
<li>Answer Y)es at the question: <b><i>Increase GPIO current drive/sink to 16 mA Y)es N)o</i></b></li>
<li>Once the operation is done, unplug Nusbio, wait 5 seconds and plug back Nusbio</li>
</ol>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2TXar-uALJlXQkoz_3kPuvdK0zW_X-AWGUuHUuZ8mLQCxdAeWbjKpc1p2SatJZm-NzTYQOYCxqdkdynvedzQGb6G8p7xNLw2OzxPvhUdaii_SQbOMg0i1J95eD7vZuINQ_CHmoqURCyl1/s1600/Image1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="267" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2TXar-uALJlXQkoz_3kPuvdK0zW_X-AWGUuHUuZ8mLQCxdAeWbjKpc1p2SatJZm-NzTYQOYCxqdkdynvedzQGb6G8p7xNLw2OzxPvhUdaii_SQbOMg0i1J95eD7vZuINQ_CHmoqURCyl1/s400/Image1.jpg" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgx10T0nUYxlprTAgZky4Gx5Yq5Q16C3wFFXBypTZ-icl30cVDXnETTbHSUeD_Ct5zs0uGt_A-6UxQOzrVha-_HDCChRPMgkH76-cXi0yIxD2tlKaSa_X8Cl3ORpvAlewpvO35Cug3RAu7M/s1600/Image2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="267" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgx10T0nUYxlprTAgZky4Gx5Yq5Q16C3wFFXBypTZ-icl30cVDXnETTbHSUeD_Ct5zs0uGt_A-6UxQOzrVha-_HDCChRPMgkH76-cXi0yIxD2tlKaSa_X8Cl3ORpvAlewpvO35Cug3RAu7M/s400/Image2.jpg" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNd8kti_Vr2MWK4V5LSqIyY24YlT_W32Hd3VesXN-6fWvRSOz4aLOltoJhfzh1hkcB0g0QmVtFL28QOhl4Abxw0huIeq1C7bGlwEfQX0sJSGA1p06bj1j3r8oivBt4pNKdpEnATUKF3yg-/s1600/Image3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="267" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNd8kti_Vr2MWK4V5LSqIyY24YlT_W32Hd3VesXN-6fWvRSOz4aLOltoJhfzh1hkcB0g0QmVtFL28QOhl4Abxw0huIeq1C7bGlwEfQX0sJSGA1p06bj1j3r8oivBt4pNKdpEnATUKF3yg-/s400/Image3.jpg" width="400" /> </a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiByxkzngni4i78DzdChbvmAWBje7WDxrwpcj1FnaKBEoMr-vu0THaAUP-W67VTdlvog55T_K4PmdbKRx36ic8Or56ARv7GEopPHmGdeDNXgAFXMN76eL-_Gquir7vypSxSuO9I4AbQrQ4L/s1600/Image4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="267" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiByxkzngni4i78DzdChbvmAWBje7WDxrwpcj1FnaKBEoMr-vu0THaAUP-W67VTdlvog55T_K4PmdbKRx36ic8Or56ARv7GEopPHmGdeDNXgAFXMN76eL-_Gquir7vypSxSuO9I4AbQrQ4L/s400/Image4.jpg" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br />
<ol>
</ol>
Anonymoushttp://www.blogger.com/profile/16516471292134914481noreply@blogger.com0tag:blogger.com,1999:blog-7044556212189675078.post-8399365793780491802016-02-15T08:36:00.001-08:002016-02-28T17:43:47.323-08:00FT232 versus FT231<h2>
Overview</h2>
<br />
In his Adafruit <a href="https://blog.adafruit.com/2016/02/08/exclusive-interview-with-fred-dart-ceo-of-ftdi-ftdichip-ftdi-adafruit/">interview </a>Fred Dart, the CEO of FTDI, talked about the differences between the UART FT232 and FT231.<br />
<br />
For the design of the Nusbio, I started with the FT232R and later switched to the FT231X.<br />
I spent a good amount of time studying the 2 chips.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQT-S2PPibezfvuCft_WhoYPHuIkSU00LBNY5znwXtw0L0g2zVHV0AXzrjv4-ra18GwbrC_eCyByt4kW684JmrLnmQvoGeBawIL1zIJkpf0XvCJmZLmhHz7IVnOyCx2_8qw6QX8-YHnldb/s1600/%2540Nusbio.Board.1.Small.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="243" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQT-S2PPibezfvuCft_WhoYPHuIkSU00LBNY5znwXtw0L0g2zVHV0AXzrjv4-ra18GwbrC_eCyByt4kW684JmrLnmQvoGeBawIL1zIJkpf0XvCJmZLmhHz7IVnOyCx2_8qw6QX8-YHnldb/s400/%2540Nusbio.Board.1.Small.jpg" width="400" /><br />Nusbio G1 - Early version based on the FT232R</a></div>
<br />
<a href="http://www.mouser.com/ProductDetail/FTDI/FT221XS-U/?qs=sGAEpiMZZMtv%252bwxsgy%2fhiIaF6qCroMVRWHZIHX%2fcBkM%3d" id="ctl00_ContentMain_bc_rptrBreadcrumbs_ctl04_lnkPartNumberBreadcrumb" style="font-size: 9pt; font-weight: bold;"></a><br />
I was surprise to hear that:<br />
<blockquote class="tr_bq">
<i>"it can only drive out at 3.3V max though it has 5V tolerant inputs"</i></blockquote>
and also in the interview it was not mentioned that the FT231X has a 1024 bytes (512+512) transfer buffer, versus the FT232 which only has a 384 bytes transfer buffer (128 + 256). The buffer size in synchronous bit banging mode makes a big difference in terms of byte/second transferred.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvQ65tPfanCNdm29qaVL1HjedgiaaTYtAgWDenrUC9g-lGqf7QDO8_21Orr__KkDFPdZwcvWiShHJ6awT50nvpybEW_V-pepj36CJdWAlsDPccwwmPByRc-2FWVimiCofK2e1FM3bkcd_-/s1600/Nusbio.Board.FreshFromTheOven.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvQ65tPfanCNdm29qaVL1HjedgiaaTYtAgWDenrUC9g-lGqf7QDO8_21Orr__KkDFPdZwcvWiShHJ6awT50nvpybEW_V-pepj36CJdWAlsDPccwwmPByRc-2FWVimiCofK2e1FM3bkcd_-/s400/Nusbio.Board.FreshFromTheOven.jpg" width="300" /><br />Nusbio G1 - Based on the FT231X</a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br />
<br />
The FT231X has multiple advantages over the FT232R <br />
<ol>
<li><b>Price</b><br />$2.12 over $4.50<b> </b>for one chip<b>.</b></li>
<li><b>Buffer size</b> 1024 over 384. A larger buffer increase the transfer performance when using the synchronous or asynchronous bit banging mode. I do not know if this make a difference in UART mode (I supposed it should) but with Windows the serial port are limited 128 000 bauds.</li>
<li><b>Package</b> <br />SSOP-20 over SSOP-28, easier to solder. For both I would <b><i>not</i></b> use a regular solder iron. I recommend to use an "electric skillet"or toaster. Obviously the FT231X take less space on the board.</li>
<li><b>Voltage</b><br />Based on the FT231X datasheet the 3.3 Volt out should feed VCCIO, therefore all 8 GPIO would output 3.3V. Making it a 3.3V devices. <br />For now in Nusbio I feed VCCIO with the USB 5V or 3.3V configurable with a jumper or a soldered connector. By default it is set to 5V, making Nusbio a 5V device. <br /><br />I need to check with FTDI if that is ok, though it seems to work and
Fred Dart confirmed the input are 5V tolerant. The question is the
output and VCCIO are 5V tolerant.<br /><br />At the URL http://www.ftdichip.com/Products/ICs/FT231X.html, I found this<br /><blockquote class="tr_bq">
<i> True 3.3V CMOS drive output and TTL input.<br /> (operates down to 1V8 with external pull ups and is also 5V tolerant)</i></blockquote>
From Twitter @FTDICHIP sent me back the following:<i><br /></i><a class="twitter-atreply pretty-link js-nav" data-mentioned-user-id="3161901251" dir="ltr" href="https://twitter.com/MadeInTheUSB"><s>@</s><b>MadeInTheUSB</b></a> the VCCIO is really meant to be 3.3V Absolute max ratings as quoted are this. It will withstand a 5V input but output at 3.3V.<br /><br />I am going to update Nusbio board to send 3.3V to VCCIO, this mean the 8 GPIOs will send 3.3V. Nusbio VCC will remains 5V with up to 500 mA.<br /><br />
</li>
<li><b>Clock</b><br />With the FT232R, there is an issue with the internal clock in bit banging mode. It can only be viewed with an Oscilloscope. The clock is not stable. If you bit bang 1 0 1 0 1 0, you would expect a stable 50% duty cycle what ever the baud rate. But what I saw on the Oscilloscope was all over the place. I found one person on the FTDI forum that remarked the same problem. Adding an external clock fixed the problem (Adding an external clock does not increase performance).</li>
</ol>
The FT231X has multiple disadvantages over the FT232R.<br />
<ol>
<li>The USB data lines require each a 27Ohm resistor and a 47pF capacitor.<br />More work to build a device</li>
<li>FT232R is definitely 5 or 3.3 volts chip, where the FT231X is a 3.3V chip (though the gpio input are 5V tolerant. And gpio can be configured to 5V, but not "recommended" by FTDI)</li>
</ol>
<ol>
</ol>
Anonymoushttp://www.blogger.com/profile/16516471292134914481noreply@blogger.com1tag:blogger.com,1999:blog-7044556212189675078.post-12279971106597505162016-02-15T06:14:00.001-08:002016-02-28T17:46:50.044-08:00Temperature Sensor For .NET<h2>
Overview</h2>
<br />
Do you want to know the temperature around your laptop in your .NET app?<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7LnZGdsW_hWr8iCXVt89j6SzLIs7UI2MHoH30UxQ4fKCPjTL15VfLfNsB2xC3SlSDhH1N24fSLQH-Z7X6SvN8UDfn54_Hl5vbwHw5Q4K6Cxl1OGcm1X7oP7aJ58HW0bPMkZBS8p6QIOs5/s1600/AdaFruit+MCP9808+Board+Plus+I2C+Adapter.02.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7LnZGdsW_hWr8iCXVt89j6SzLIs7UI2MHoH30UxQ4fKCPjTL15VfLfNsB2xC3SlSDhH1N24fSLQH-Z7X6SvN8UDfn54_Hl5vbwHw5Q4K6Cxl1OGcm1X7oP7aJ58HW0bPMkZBS8p6QIOs5/s400/AdaFruit+MCP9808+Board+Plus+I2C+Adapter.02.jpg" width="400" /><br />Adafruit MCP9808 Breakout plugged directly into Nusbio</a></div>
<br />
<a href="http://www.nusbio.net/">Nusbio </a>is a USB device that can talk the different protocols to query temperature sensors.<br />
<a href="http://www.nusbio.net/">Nusbio </a>is fully programmable in any .NET languages.<br />
<br />
<h2>
Communication Protocols </h2>
<br />
There are 3 protocols supported<br />
<ul>
<li>SPI</li>
<li>I2C</li>
<li>Analog</li>
</ul>
Temperature using the 1 Wire protocol like sensor family of DHT XXX are not supported.<br />
<ul>
</ul>
<br />
<h2>
Temperature sensors tested </h2>
<ul>
<li>MCP9808 - I2C</li>
<ul>
<li>Very accurate ±0.25 (typical) from -40°C to +125°C </li>
<li><a href="http://www.mouser.com/ds/2/268/25095A-15487.pdf">Datasheet</a></li>
<li>Price for one: $1.22</li>
<li>Package <span id="ctl00_ContentMain_Specifications_dlspec_ctl14_lblName">MSOP-8</span></li>
<ul>
<li>A little bit challenging to solder manually, but possible</li>
</ul>
<ul>
<li>Adafruit has a <a href="https://www.adafruit.com/products/1782">breakout </a>(breadboard compatible)</li>
</ul>
<li>We have an adapter for Adafruit I2C device (see photo above)</li>
</ul>
</ul>
<ul>
<li>TC77 - SPI</li>
<ul>
<li>Accurate 1°C (max.) accuracy from +25°C to +65°C </li>
<li><a href="http://www.mouser.com/ds/2/268/20092a-72501.pdf">Datasheet</a></li>
<li>Price for one: $1</li>
<li>Package <span id="ctl00_ContentMain_Specifications_dlspec_ctl15_lblName">SOIC-8</span></li>
<ul>
<li>Easy to solder manually on a adapter (See picture below)</li>
</ul>
<li>We are working on an extension for it that will be plug and play</li>
</ul>
</ul>
<ul>
<li>TMP36 - Analog</li>
<ul>
<li>Not very accurate. ±2°C accuracy over temperature.</li>
<li><a href="http://www.mouser.com/ds/2/609/TMP35_36_37-246343.pdf">Datasheet</a></li>
<li>Price for one: $1.36</li>
<li>Can be plugged into a breadboard</li>
<li>This temperature sensor requires an ADC (Analog to Digital Converter)</li>
<li>We have noticed that the TMP36 does not perform correctly with our Analog Extension</li>
</ul>
</ul>
<ul></ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGWdbhBD-yUj73H9TZu5Mf2L7rG5Gc8Ci8TTamKNbuwH2c9n-AVjwXZ6j7pezJncCxJ3z43KwkbaepdwvE1ieHJBpPUxDAQsa8JgvH3HkobbKjjyHYSFkccvQtdNUEudwEHo72dsANUxti/s1600/TC77_OnABreadBoard.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGWdbhBD-yUj73H9TZu5Mf2L7rG5Gc8Ci8TTamKNbuwH2c9n-AVjwXZ6j7pezJncCxJ3z43KwkbaepdwvE1ieHJBpPUxDAQsa8JgvH3HkobbKjjyHYSFkccvQtdNUEudwEHo72dsANUxti/s400/TC77_OnABreadBoard.jpg" width="300" /><br />TC77 SPI Temperature Sensor</a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZisvsltXcVFkLCZk9wVlerAhsegHZ61orB8EpdkZbSs63SkVGa43SoJi38xRWMRWaIywg0InjA9kJfzyLcHBm3jTfh11oaV7fIQmL0WlrQ5JXHu4cR7-9j0QalvUGyTigMdhc6mdv_3gz/s1600/AnalogEx_Temp_Light_Motion_Sensor_3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZisvsltXcVFkLCZk9wVlerAhsegHZ61orB8EpdkZbSs63SkVGa43SoJi38xRWMRWaIywg0InjA9kJfzyLcHBm3jTfh11oaV7fIQmL0WlrQ5JXHu4cR7-9j0QalvUGyTigMdhc6mdv_3gz/s320/AnalogEx_Temp_Light_Motion_Sensor_3.jpg" width="320" /></a></div>
<div style="text-align: center;">
TMP36 analog temperature sensor (in black) <br />plugged into the Nusbio Analog Extension</div>
<h2>
Conclusion</h2>
<br />
If you need to query for temperature in your .NET app in an easy to assemble solution we recommend the<br />
<ul>
<li>Adafruit MCP9808 breakout + Nusbio adapter for Adafruit I2C device</li>
<li>Coming soon our own plug and play extension for the TC77 </li>
</ul>
<ul><ul>
</ul>
</ul>
Anonymoushttp://www.blogger.com/profile/16516471292134914481noreply@blogger.com0tag:blogger.com,1999:blog-7044556212189675078.post-10290781634007058312016-02-13T17:30:00.000-08:002016-02-24T17:28:12.436-08:00USB to SPI for .NET - EEPROM<br />
<h2>
EEPROM and Nusbio G1</h2>
The Nusbio library supports the following EEPROMs<br />
<br />
<ul>
<li>SPI 128k 25AA1024</li>
<ul>
<li>Transfer the 128k in 5.8s 22Kb/SS </li>
<li>Transfer the 128k in 89ms with <b>Nusbio G2 prototype</b> 1438 Kb/s 15Mhz </li>
</ul>
<li>SPI 32k 25AA256</li>
<ul>
<li>Transfer the 32k in 1.5s 21Kb/SS </li>
</ul>
<li>I2C 32k 24LC256</li>
<ul>
<li>Transfer the 32k in 4.5s 7Kb/SS </li>
</ul>
</ul>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIMMch4ESBrsw0iWLsLEuTCc1hg3UOjGKbk7rCEbvtSvWX86w3U0jQQZ17D7sBt0_dHyx-yuASqSWnNj0yvDKFHHTiEelJPuchvij-tXHndIUjTscIt3l_ScL_cO6YHD0H-kL_ogDnvnf8/s1600/20160213_200039.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="225" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIMMch4ESBrsw0iWLsLEuTCc1hg3UOjGKbk7rCEbvtSvWX86w3U0jQQZ17D7sBt0_dHyx-yuASqSWnNj0yvDKFHHTiEelJPuchvij-tXHndIUjTscIt3l_ScL_cO6YHD0H-kL_ogDnvnf8/s400/20160213_200039.jpg" width="400" /></a></div>
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLSIDxQ6k3Y_7V-yIAxmtilEmImZz02VepgMFXMdaK89Y3zoJeOOcZ6IEtQwivlD2P26Ac5w5QZxOpUenT6h3PPCm6F8cJDRZVyw_60Dtt6lB5eA2PcH2vcLfAIBNN9t5c7Bm68CeRuhCv/s1600/EEPROM_TD_ExtensionAlone.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="225" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLSIDxQ6k3Y_7V-yIAxmtilEmImZz02VepgMFXMdaK89Y3zoJeOOcZ6IEtQwivlD2P26Ac5w5QZxOpUenT6h3PPCm6F8cJDRZVyw_60Dtt6lB5eA2PcH2vcLfAIBNN9t5c7Bm68CeRuhCv/s400/EEPROM_TD_ExtensionAlone.jpg" width="400" /> </a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVUVxjMNcrxLLVLZcaUNlM3TrMvAw5tinK_jusQPfz3mhW8Yj_zAYwnMzzTHA3XMigTPIP4jYp7gwX5YIV4kYjS0IHfrH7KEe8Qrph8ZhxBnfF9lusL2Rs8_BWbRq5BCng4w8VsL4HEbOx/s1600/EEPROM_TD_ExtensionWithNusbio_02.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="225" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVUVxjMNcrxLLVLZcaUNlM3TrMvAw5tinK_jusQPfz3mhW8Yj_zAYwnMzzTHA3XMigTPIP4jYp7gwX5YIV4kYjS0IHfrH7KEe8Qrph8ZhxBnfF9lusL2Rs8_BWbRq5BCng4w8VsL4HEbOx/s400/EEPROM_TD_ExtensionWithNusbio_02.jpg" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br />Anonymoushttp://www.blogger.com/profile/16516471292134914481noreply@blogger.com0tag:blogger.com,1999:blog-7044556212189675078.post-76310451704294008482016-02-12T20:00:00.002-08:002016-02-12T20:01:23.336-08:00USB to SPI for .NET (performance)<h2>
USB to SPI performance</h2>
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:<br />
<ul>
<li>Let's pick the <b>MAX7219 </b>(10Mhz) an LED driver used to control 7-Segment display or 8x8 LED matrix.<br />The communication protocol is : <br /><br /><span style="font-family: "courier new" , "courier" , monospace;"> SELECT Byte0:Command, Byte1:Data, UNSELECT</span><br /><br />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.<br />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.</li>
<li>An <b>EEPROM </b>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.</li>
<li>A third case is for example the SPI OLED <b>SH1106 </b>or <b>SSD1306 </b>driver (128x64 monochrome pixel), which requires also extra GPIO named D/C (Data or Command). <br />The communication protocol is : <br /><br /><span style="font-family: "courier new" , "courier" , monospace;">SELECT, DC=C, Cursor Position 3 bytes, UNSELECT, SELECT, DC=D, 128 data bytes, UNSELECT</span><br /><br />We need 8 times this sequence to send a full refresh of the display. <br />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. <br />So it depends on the hardware and software feature of the chip.<br />I am going to call this feature: USB to SPI Low Level Optimization. <br /><br />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.<br /><br />The FTDI FT232H is the only chip so I tested that support SPI Low Level Optimization. <br />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.</li>
<li>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.</li>
</ul>
<br />Anonymoushttp://www.blogger.com/profile/16516471292134914481noreply@blogger.com0tag:blogger.com,1999:blog-7044556212189675078.post-24850564467736383572016-02-12T19:20:00.002-08:002016-02-12T20:03:58.597-08:00Digital Potentiometer SPI AD5290 and Nusbio<h2>
Overview</h2>
<br />
The Digital Potentiometer AD5290 is not a regular one.<br />
<ol>
<li>It provides 2 supply modes</li>
<ol>
<li>Single supply, Positive voltage </li>
<li>Dual supply, Positive voltage and negative voltage<br />You need to provide the positive and negative voltage (pin 1 and 2)</li>
</ol>
<li>In mode 1, the current can be between 20 and 30 Volts.<br />In mode 2, the current +-10 to +- 15 volts</li>
<li>It is only available in MSOP-10</li>
</ol>
<b><a href="http://www.mouser.com/ds/2/609/AD5290-246554.pdf">Datasheet</a></b><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRCZiK_Iaavlpn_1U9T7Fb6GNXym0Dr8GQ5hcDyEVYQ4yuVHh2_mayM-gOwjQuxzr0-ruzWn_-MzfF9p2xnnYtmAm00JDOdNxLAQecNEmNXxGEvSTOl40IhSXTu3KcbbePoktIURbU6zZN/s1600/Img_4288.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="225" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRCZiK_Iaavlpn_1U9T7Fb6GNXym0Dr8GQ5hcDyEVYQ4yuVHh2_mayM-gOwjQuxzr0-ruzWn_-MzfF9p2xnnYtmAm00JDOdNxLAQecNEmNXxGEvSTOl40IhSXTu3KcbbePoktIURbU6zZN/s400/Img_4288.jpg" width="400" /></a></div>
<br />
<b> </b> <br />
<h2>
SPI</h2>
<h2>
</h2>
<br />
The AD5290 is an SPI chip which does not use MISO (The chip does not send information back).<br />
Be care full, the SDO pin is used for daisy-chaining<br />
<br />
The recommended wiring with Nusbio is a follow<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;">GPIO 0 - CLOCK<br />GPIO 1 - MOSI<br />GPIO 2 - CS</span><br />
<ol>
</ol>
<b><a href="https://github.com/madeintheusb/Nusbio.Samples/tree/master/VB/MadeInTheUSB.Nusbio.DigitalPot.AD5290.VB">VB.net Code</a></b><br />
<br />
<h2>
Wiring</h2>
<h2>
</h2>
<h3>
5 Volts from the USB</h3>
In this wiring, we use the Single supply, positive 5 volts mode from Nusbio and therefore from the USB. <br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicj9vn0DPkjfZKy2k7o2BKLx5DJfzb_YSi544zZYqiJ4aKAkpssqJNMjsuUJR_3h2HkKv7P0xMDKQAJoAcw1hv_V9R_7yO_fflUC9L7mlI6N6bkwC02citcRRdeOORG8wWJNvv1kFVkQxL/s1600/AD5290_DigitalPotentiometer_Nusbio_5VoltSupply.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicj9vn0DPkjfZKy2k7o2BKLx5DJfzb_YSi544zZYqiJ4aKAkpssqJNMjsuUJR_3h2HkKv7P0xMDKQAJoAcw1hv_V9R_7yO_fflUC9L7mlI6N6bkwC02citcRRdeOORG8wWJNvv1kFVkQxL/s400/AD5290_DigitalPotentiometer_Nusbio_5VoltSupply.jpg" width="400" /></a></div>
<br />
<h3>
9 Volts from a battery</h3>
In this wiring, we use the Single supply, positive 9 volts mode from a battery.<br />
<span style="color: red;"><i><b>Nusbio GPIO 0,1,2 should never be in contact with the 9 Volts from the battery.</b></i></span><br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiX_63y7SpxALUI-8ws9wl2wrUEovCbXEBDSnwjcjD3waQt-PRw5S6UUCvWx_sfvFVdmPkONJ2OK_UNl1MIQDFMN3rE6svU_tXVxJLANhhXO9RAyfg1a8Wqai2zhyphenhyphenYfcu8hV37anesHHEoQ/s1600/AD5290_DigitalPotentiometer_External12VoltsPower_bb.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="302" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiX_63y7SpxALUI-8ws9wl2wrUEovCbXEBDSnwjcjD3waQt-PRw5S6UUCvWx_sfvFVdmPkONJ2OK_UNl1MIQDFMN3rE6svU_tXVxJLANhhXO9RAyfg1a8Wqai2zhyphenhyphenYfcu8hV37anesHHEoQ/s400/AD5290_DigitalPotentiometer_External12VoltsPower_bb.png" width="400" /></a></div>
<br />
<ol>
</ol>
Anonymoushttp://www.blogger.com/profile/16516471292134914481noreply@blogger.com0tag:blogger.com,1999:blog-7044556212189675078.post-36031964880873685402016-02-11T19:56:00.004-08:002016-02-11T19:57:04.879-08:00SPI digital potentiometer AD5290Y 10k with some vb.net code SPI digital potentiometer AD5290Y 10k with some <a class="twitter-timeline-link" data-expanded-url="http://vb.net" dir="ltr" href="https://t.co/gKLZjDLnux" rel="nofollow" target="_blank" title="http://vb.net"><span class="invisible"></span><span class="js-display-url">vb.net</span><span class="invisible"></span><span class="tco-ellipsis"><span class="invisible"> </span></span></a> code and Nusbio <br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDSz-09UNPyHjoWeYiughrtJ9pGIYtVQ5U134i5bByKeUsgKsduK8KsmundCss5s6nG6tEa1usKGWexb7XurzTeTBDJATEKSsYR9aH3sdrrJCytHJbXmeRnUC1pxenIm2Ze2AaTHTLS0VQ/s1600/Img_4288.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="225" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDSz-09UNPyHjoWeYiughrtJ9pGIYtVQ5U134i5bByKeUsgKsduK8KsmundCss5s6nG6tEa1usKGWexb7XurzTeTBDJATEKSsYR9aH3sdrrJCytHJbXmeRnUC1pxenIm2Ze2AaTHTLS0VQ/s400/Img_4288.jpg" width="400" /></a></div>
<br />
<br />
<br />
<br />
<br />
<a class="twitter-timeline-link" data-expanded-url="http://bit.ly/20PkDkl" dir="ltr" href="https://t.co/gsDnSzvJkG" rel="nofollow" target="_blank" title="http://bit.ly/20PkDkl"><span class="tco-ellipsis">Video </span><span class="invisible">http://</span><span class="js-display-url">bit.ly/20PkDkl</span><span class="invisible"></span><span class="tco-ellipsis"><span class="invisible"> </span></span></a><br />
<br />
<br />
<span class="tco-ellipsis"><span class="invisible">Source Code: https://github.com/madeintheusb/Nusbio.Samples/tree/master/VB/MadeInTheUSB.Nusbio.DigitalPot.AD5290.VB</span></span> Anonymoushttp://www.blogger.com/profile/16516471292134914481noreply@blogger.com0tag:blogger.com,1999:blog-7044556212189675078.post-8458300679365991202016-02-08T11:38:00.001-08:002017-04-03T20:35:30.946-07:00USB to SPI for .NET<h2>
Overview</h2>
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.<br />
(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) <br />
<br />
I most likely will use a USB 2.0 to SPI chip and add a micro-controller like the ATiny84 to provide<br />
<ul>
<li>More GPIOs</li>
<li>PWM</li>
<li>ADC</li>
<li>EEPROM storage</li>
</ul>
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<span style="background-color: white; color: #333333; display: inline; float: none; font-family: "arial" , "helvetica" , sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 15.5844px; text-align: center; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;">.</span><br />
<br />
In this post, I will summarize my findings regarding the chips I tested. Obviously my end goal is to create a .NET compatible device.<br />
<br />
<h2>
USB to SPI performance</h2>
See blog: <a href="http://madeintheusb.blogspot.com/2016/02/usb-to-spi-for-net-performance.html">USB to SPI for .NET (performance) </a><br />
<br />
<br />
<h2>
Test Scenarios</h2>
<ol>
<li>Test1 - Transfert 32 K byte of data from EEPROM 25AA256 (support SPI 10MHz) to computer in C#.</li>
<li>Test2 - Transfert 128 K byte of data from EEPROM 25AA1024 (support SPI 10MHz) to computer in C#.</li>
</ol>
<h2>
<br />USB to SPI Chip</h2>
<ul>
<li>MicroChip - MCP2210 <a href="http://ww1.microchip.com/downloads/en/DeviceDoc/22288A.pdf" target="_blank">Datasheet </a><a class="lnkDatasheet" href="http://www.microchip.com/mymicrochip/filehandler.aspx?ddocname=en556791" rel="nofollow" style="-webkit-text-stroke-width: 0px; display: inline-block; font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px;" target="_blank"><br /></a></li>
<ul>
<li>Evaluation board <a href="https://www.digikey.com/product-detail/en/ADM00419/ADM00419-ND/3046570" target="_blank">ADM00419 </a>$15</li>
<li>USB 2.0 Full speed </li>
<li>SPI Bitrate 3 Mbps</li>
<li>128 byte buffer</li>
<li>GPIO for select: 8</li>
<li>Packages: 20-lead QFN, 20-lead SOIC, 20-lead SSOP</li>
<li>Price: $1.98 for one</li>
<li>.NET samples: Yes</li>
<li> SPI Low Level Optimization: Most likely No</li>
</ul>
</ul>
<ul>
<li>Cypress - CY7C65211 <a href="http://www.mouser.com/ds/2/100/001-82042_CY7C65211_CY7C65211A_USB-SERIAL_SINGLE-C-369290.pdf" target="_blank">Datasheet </a><a class="lnkDatasheet" href="http://www.microchip.com/mymicrochip/filehandler.aspx?ddocname=en556791" rel="nofollow" style="-webkit-text-stroke-width: 0px; display: inline-block; font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px;" target="_blank"><br /></a></li>
<ul>
<li>Evaluation board <a href="https://www.digikey.com/product-detail/en/CY8CKIT-049-42XX/428-3344-ND/4805328" target="_blank">CY8CKIT-049-42XX</a> $4</li>
<li>USB 2.0 Full speed </li>
<li>Bitrate 3 Mhz</li>
<li>256 byte buffer</li>
<li>GPIO for select: 5 </li>
<li>Packages: 24-lead QFN </li>
<li>Price: $2.61 for one</li>
<li>.NET samples: No. C code.</li>
<li> SPI Low Level Optimization: Most likely No</li>
<li>Remark: Can be configured as UART, SPI or I2C</li>
</ul>
</ul>
<ul>
<li>FTDI - FT232H <a href="http://www.mouser.com/ds/2/163/DS_FT232H-11324.pdf" target="_blank">Datasheet </a><a class="lnkDatasheet" href="http://www.microchip.com/mymicrochip/filehandler.aspx?ddocname=en556791" rel="nofollow" style="-webkit-text-stroke-width: 0px; display: inline-block; font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px;" target="_blank"><br /></a></li>
<ul>
<li>Evaluation board <a href="http://www.mouser.com/Search/ProductDetail.aspx?qs=rzPzygjq8vJshyX0tvqkbA%3d%3d">UM232H</a> $20</li>
<li>USB 2.0 High speed</li>
<li>Bitrate 30 Mhz for SPI</li>
<li>64k byte buffer</li>
<li>GPIO for select: 5 </li>
<li>Packages: 48-lead QFN </li>
<li>Price: $4.25 for one</li>
<li>.NET samples: Partially, Require C DLL.</li>
<li> SPI Low Level Optimization: Yes</li>
<li>Remark: Can be configured as UART, SPI, I2C, JTAG, FIFO, Bit banging.</li>
<br />
</ul>
<li>SILICON LABS - CP2130 <a href="http://www.mouser.com/ds/2/368/CP2130-272405.pdf" target="_blank">Datasheet </a><a class="lnkDatasheet" href="http://www.microchip.com/mymicrochip/filehandler.aspx?ddocname=en556791" rel="nofollow" style="-webkit-text-stroke-width: 0px; display: inline-block; font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px;" target="_blank"><br /></a></li>
<ul>
<li>Evaluation board <a href="http://www.mouser.com/ProductDetail/Silicon-Laboratories/CP2130EK/?qs=%2fha2pyFadui3GQI3uPiFbEVg5mjfuIiXTMr%2fIkayo5I%3d">CP2130EK</a> $20</li>
<li>USB 2.0 High speed</li>
<li>6.6 Mb/s for SPI (844Kbyte/S, <a href="https://www.youtube.com/watch?v=hJfyJUlSuvA">Video</a>)</li>
<li>xx byte buffer</li>
<li>GPIO for select: 11 </li>
<li>Packages: 24-lead QFN </li>
<li>Price: $2.16 for one</li>
<li>.NET samples:?</li>
<li> SPI Low Level Optimization:?</li>
</ul>
</ul>
<br />
<h2>
Test Result</h2>
<ul>
<li>MicroChip - MCP2210</li>
<ul>
<li>At the SPI Bitrate 3 Mhz (which cannot be increased)</li>
<li>Downloading the 32k of data in chunk of 32 pages of 64 bytes (2k)</li>
<li>4.559s 7.02 K byte/S</li>
<li>Conclusion: Really <b><i>bad performance.</i></b></li>
</ul>
<li>Cypress - CY7C65211 </li>
<ul>
<li>At the SPI Bitrate 3 Mhz </li>
<li>Downloading the 32k of data in chunk of 16 pages of 64 bytes (1k)</li>
<li>12 K byte/S</li>
<li>I asked on the Cypress forum for help - <a href="http://www.cypress.com/forum/usb-full-speed-peripherals/better-throughput-cy7c65211-spi-eeprom#comment-325806">Page</a>. So far no real help from the Indian support.<br /> </li>
</ul>
<li>FTDI - FT232H </li>
<ul>
<li>At the SPI Bitrate 10 Mhz (Max supported by the EEPROM)</li>
<li>Downloading the 32k of data in chunk of 256 pages of 64 bytes (16k) </li>
</ul>
<ul>
<li> 0.03s 1066.67 K byte/S</li>
<li>Conclusion: Really <i><b>very nice performance. and the FT232H can goes up to 30 Mhz.</b></i><b><i></i></b></li>
</ul>
<li>SILICON LABS - CP2130</li>
</ul>
<br />
<h2>
More About The MCP2210</h2>
<ul>
<li> Kerry Wong, blogged a lot about the MCP2210 at <a href="http://www.kerrywong.com/">http://www.kerrywong.com.</a></li>
<li>In his post "<a href="http://www.kerrywong.com/2012/09/15/finicky-mcp2210-oscillator/">Finicky MCP2210 Oscillator</a>", John Davis added the following comment, which explain a lot.<br /><br /><div style="-webkit-text-stroke-width: 0px; background-color: #fafafa; color: #444444; font-family: Verdana, 'Lucida Grande', Arial, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px;">
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!</div>
</li>
</ul>
<br />
<br />
<ul><ul>
</ul>
<ul>
</ul>
</ul>
<br />Anonymoushttp://www.blogger.com/profile/16516471292134914481noreply@blogger.com3tag:blogger.com,1999:blog-7044556212189675078.post-68419181732594775162016-02-02T19:19:00.000-08:002016-11-12T21:12:40.104-08:00Technical Precisions About The Nusbio Device<h2>
What is <a href="http://www.nusbio.net/" target="_blank">Nusbio</a>?</h2>
Nusbio is USB device that bring the following to a Windows machine and the Microsoft .NET Runtime:<br />
<br />
<h2>
Device</h2>
<ul>
<li><h3>
Gpios</h3>
</li>
<ul>
<li>8GPIO pins</li>
<li>3 or 5 volts </li>
<ul>
<li>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.</li>
<li>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.</li>
</ul>
<li>Modes: OUTPUT or INPUT PULL UP.</li>
<li>Maximum current per GPIO pin default 4 mA .<br />The Console application allows to switch from 4 to 16 mA.<br />In 16 mA of current mode we noticed that the I2C protocol does not work.</li>
</ul>
</ul>
Powering devices connected to Nusbio<br />
<ul><ul>
<li>
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.</li>
<li>The VCC output can be used to power other devices connected to Nusbio.</li>
<li>Some Nusbio version based on the FT231X have a fuse that will limit the consumption to 500 mA of current.</li>
</ul>
<ul>
<li>The voltage can be changed depending on the version as follow:</li>
<ul>
<li>De-soldering the 5 volts connector and soldering the 3 volts connector.</li>
<li>Or switch the jumper between 5 volts and 3 volts </li>
</ul>
</ul>
</ul>
<ul>
<li><h3>
SPI Protocol </h3>
</li>
<ul>
<li><h4>
Mode </h4>
</li>
<ul>
<li>Clock MODE_CPOL0_CPHA0 supported and tested</li>
</ul>
<ul>
<li>The other 3 modes have been implemented but not tested.</li>
</ul>
<li><h4>
Tested Devices</h4>
</li>
<ul>
<li>MCP3008 - 8 DAC </li>
<li>MAX7219 - 7-Segment Driver</li>
<li>25AA256 - 32k EEPROM</li>
<li>25AA1024 - 128k EEPROM </li>
<li>MCP23S08 - 8 Gpio Expander </li>
<li>OLED drivers</li>
<ul>
<li>SD1306 </li>
<li>SH1106</li>
</ul>
<li>SPI Compatible Devices </li>
<ul>
<li>74HC595 - Shift register</li>
<li>APA102 RGB LED</li>
</ul>
</ul>
<li><h4>
SPI Slave</h4>
</li>
<ul>
<li>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. </li>
</ul>
<li><h4>
Transfert Speed</h4>
</li>
<ul>
<li>When data in and data out communication is needed (MOSI and MISO) the maximum transfer rate is around 15 k byte/s <b><i>with no optimization</i></b>.</li>
<li>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.</li>
<li>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.</li>
<li>Transfer speed vary depending on the SPI device and the Windows PC.</li>
<li>Nusbio and the C# class SPIEngine can transfer in one USB operation multiple SPI buffer (Select + Data + UnSelect + Select + Data + UnSelect).</li>
<li>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).</li>
</ul>
</ul>
<li><h3>
I2C Protocol </h3>
</li>
<ul>
<li>Tested Devices:</li>
<ul>
<li>24LC256 32k EEPROM</li>
<li>MCP2308 - 8 Gpio Expander </li>
<li>MCP9808 - Temperature sensor</li>
<li>MCP4725 - 12Bit DAC </li>
<li>HT16K33 - Matrix Driver </li>
<li>Adafruit I2C LED Matrix devices</li>
</ul>
<li>Transfer Speed </li>
<ul>
<li>The tests were performed by downloading 32k from the I2C EEPROM 24LC256 . </li>
</ul>
<ul>
<li>Transfer speed around 7.5K byte/s. </li>
<li>Transfer speed vary depending on the device and the Windows PC.</li>
</ul>
</ul>
<li><h3>
SPI and I2C Protocol Combined</h3>
With Nusbio it is possible to control SPI and I2C devices from the same configuration. For example<br />
<div style="margin-left: 40px;">
<br /></div>
<ul>
<li>GPIO 0,1,2 would be reserved for SPI BUS: CLOCK, MOSI and MISO</li>
<li>GPIO 3,4,5 would be used as SELECT for 3 SPI Devices</li>
<li>GPIO 6,7 would be used as SDA and SCK for the I2C bus, allow to control up to 127 devices</li>
</ul>
<div style="margin-left: 40px;">
</div>
<div style="margin-left: 40px;">
<br /></div>
</li>
<ul><ul>
</ul>
</ul>
</ul>
<ul>
<li><h3>
UART</h3>
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.<br />
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.<br /><h4>
Videos</h4>
<ul>
<li>Nusbio - <a href="https://www.youtube.com/watch?v=EfR4Jw36rQw" target="_blank">Nusbio As a FTDI Cable Adapter - PART I</a> </li>
<li>Nusbio - <a href="https://www.youtube.com/watch?v=8PeGCCNqqWc" target="_blank">Nusbio As a FTDI Cable Adapter - PART II </a></li>
</ul>
<h2>
</h2>
<ul>
</ul>
</li>
<li><h3>
Library/Assembly</h3>
<ul>
<li>The MadeInTheUSB.Nusbio.Lib .NET assembly give access to the Nusbio device to any .NET language.</li>
<li>The MadeInTheUSB.Nusbio.Components assembly contains classes for specific components including the one used in the Nusbio's extensions.</li>
<li>Github <a href="https://github.com/madeintheusb/Nusbio.Samples" target="_blank">Source</a></li>
</ul>
<br />
<ul>
</ul>
<ul>
</ul>
</li>
<li><h3>
Internal EEPROM
</h3>
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.</li>
</ul>
<ul>
<li><h3>
Unique Serial Number</h3>
Each Nusbio device is initialized with a unique Serial Number. See property SerialNumber.</li>
</ul>
<br />
<ul>
</ul>
<h2>
Chip</h2>
Nusbio is based on the FTDI FT231X chip (<a href="http://www.mouser.com/ds/2/163/DS_FT231X-13571.pdf" target="_blank">Datasheet</a>) or the FT232RL.<br />
In 2017 only the FT232RL chip is used.<br />
<br />
<ul><ul><ul>
</ul>
</ul>
</ul>
Anonymoushttp://www.blogger.com/profile/16516471292134914481noreply@blogger.com0