Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.

enough's Content

There have been 15 items by enough (Search limited from 29-March 23)


By content type

See this member's

Sort by                Order  

#50714 SerialPort / Itead Studio Bluetooth Shield V2.2

Posted by enough on 22 June 2013 - 09:37 AM in Netduino Plus 2 (and Netduino Plus 1)

Hi everyone,

 

My problem:

I cannot receive data using the Itead Studio BT V2.2 on my Netduino Plus 2.

 

My analysis (note that I'm total noob when it comes to electronics):

 

The shield itself seems to be working, I can connect to it using my Windows Phone app, the blinking LED on the shield then switches to the 'connected' blinking mode as expected. I send data to the StreamSocket on my Windows Phone and flush the stream without problems. However, on Netduino I am unable to receive data on the

SerialDataReceivedEventHandler.

 

The shield has a UART Multiplexer, the description from the product shield confuses me a bit (attached).

 

Here's a crude ASCII art of the multiplexer:

 

[font="'courier new', courier, monospace;"]  0  14567[/font]

[font="'courier new', courier, monospace;"]____________[/font]

[font="'courier new', courier, monospace;"]| [] OOOOO | TX[/font]

[font="'courier new', courier, monospace;"]| [] OOOOO | D0 | D1 D4 D5 D6 D7[/font]

[font="'courier new', courier, monospace;"]| [] OOOOO | RX[/font]

[font="'courier new', courier, monospace;"]------------[/font]

 

 

I figured that the TXD side defines the transferring digital port and RX the receiving one.

 

Now typically I would expect to be able to use D0 and D1 (aka "COM1") for the serial communication.

This leads me to believe that I need to set the jumpers like this on the multiplexer (one green, one red):

 

C1:

[font="'courier new', courier, monospace;"]____________[/font]

[font="'courier new', courier, monospace;"]| [color=rgb(0,255,0);][][/color] OOOOO | TX[/font]

[font="'courier new', courier, monospace;"]| [color=rgb(0,255,0);][][/color] [color=rgb(255,0,0);]O[/color]OOOO | D0 | D1 D4 D5 D6 D7[/font]

[font="'courier new', courier, monospace;"]| [] [color=rgb(255,0,0);]O[/color]OOOO | RX[/font]

[font="'courier new', courier, monospace;"]------------[/font]

 

or like this:

 

C2:

[font="'courier new', courier, monospace;"]____________[/font]

[font="'courier new', courier, monospace;"]| [] [color=rgb(255,0,0);]O[/color]OOOO | TX[/font]

[font="'courier new', courier, monospace;"]| [color=rgb(0,255,0);][][/color] [color=rgb(255,0,0);]O[/color]OOOO | D0 | D1 D4 D5 D6 D7[/font]

[font="'courier new', courier, monospace;"]| [color=rgb(0,255,0);][][/color] OOOOO | RX[/font]

[font="'courier new', courier, monospace;"]------------[/font]

 

For the configuration C1 above the description says:

 

You can use the jumper to connect the TXD and RXD pins of HC-05 to D0, D1, D4~D7 pin of Arduino. 
Figure 2 UART Multiplexer When using the connection as Figure C1, the BT shield connects to the ATMega328 chip on board. 

 

For the configuration C2 above the description says:

When using the connection as Figure C2, the HC-05 connects with the FT232RL chip, and the FT232RL connect to PC by USB. Whit this configuration you can use the serial software on PC to control or configure the HC-05 module. 

 

For other jumper configuration the description says:

Except the 2 configurations above, you can connect the TXD and RXD to any other pins from D4-D7, and using the software-serial library to control the HC-05 module.

 

So it seems to me that I cannot use neither C1 nor C2 but instead need to place the jumpers to other configurations. However, I did not figure out a working configuration.

 

When using COM1 I never receive data.

When using COM2 I always receive various length of byte arrays, that's interesting but as the multiplexer does not server D2/D3 at all, I guess that is something completely different going on there (told you I'm a noob).

From this post: http://forums.netdui...opic/4999-com3/ I think that COM3 uses D7/D8 which is a bit of shame, as I only have D4 - D7 available above.

 

So, am I doomed? Can anyone recommend a stackable shield that works fine with my Netduino Plus2?

 

Thanks in advance,

Robert

 

 

My Netduino code:

 

using SecretLabs.NETMF.Hardware.Netduino;using System.IO.Ports;using System.Threading;public class Program{    static SerialPort serial;    public static void Main()    {        // initialize the serial port for COM1 (using D0 & D1)        serial = new SerialPort(SerialPorts.COM1, 9600, Parity.None, 8, StopBits.One);        // open the serial-port, so we can send & receive data        serial.Open();        // add an event-handler for handling incoming data        serial.DataReceived += new SerialDataReceivedEventHandler(serial_DataReceived);        // wait forever...        Thread.Sleep(Timeout.Infinite);    }    static void serial_DataReceived(object sender, SerialDataReceivedEventArgs e)    {        // create a single byte array        byte[] bytes = new byte[1];        // as long as there is data waiting to be read        while (serial.BytesToRead > 0)        {            // read a single byte            serial.Read(bytes, 0, bytes.Length);            // send the same byte back            serial.Write(bytes, 0, bytes.Length);        }    }}

The sending part of my Windows Phone code:

private async void ConnectToDevice(PeerInformation peer)        {            if (_socket != null)            {                // Disposing the socket with close it and release all resources associated with the socket                _socket.Dispose();            }            try            {                _socket = new StreamSocket();                string serviceName = "1";                 await _socket.ConnectAsync(peer.HostName, serviceName);                DataWriter writer = new DataWriter(_socket.OutputStream);                string data = "hello world";                writer.WriteString(data);                await writer.FlushAsync();                //writer.DetachStream();                DataReader reader = new DataReader(_socket.InputStream);                await reader.LoadAsync((uint)data.Length);                reader.ReadString((uint)data.Length);                // If the connection was successful, the RemoteAddress field will be populated               MessageBox.Show(String.Format(AppResources.Msg_ConnectedTo, _socket.Information.RemoteAddress.DisplayName));            }            catch (Exception ex)            {                // In a real app, you would want to take action dependent on the type of                 // exception that occurred.                MessageBox.Show(ex.Message);                _socket.Dispose();                _socket = null;            }        }

Attached File  BTShieldV2.2_DS.pdf   644.68KB   11 downloads




#50908 SerialPort / Itead Studio Bluetooth Shield V2.2

Posted by enough on 28 June 2013 - 10:07 PM in Netduino Plus 2 (and Netduino Plus 1)

Hey ziggurat29 and all,

 

many thanks for your response - and sorry for my late feedback - family and work take their toll.  

 

I changed my code to 38400 baud but still the SerialPort.DataReceived callback is never called (meaning that the debugger never stops at the corresponding breakpoint). I tried that again with both jumper configurations.

 

I was considering upgrading my plus2 to 4.3 beta, but I think it's not worth the trouble now that the .NET MF 4.3 QFE1 release seems to be close.

 

I also tried your suggestion to get a direct 'netduino-less' loopback test. This did not work out but I am not sure if I understood your correctly:

 

> "or by temporarily removing all your code in main (thereby leaving the netduino pins in high-impedance) and jumpering at the header."

 

What I did was to remove all code in the main loop (even the Thread.Sleep(Timeout.Inifinite)) and then tried different jumper configuration for PINs D0/D1 at the multiplexer (a) no jumper, B) Figure 3 and c) Figure 4 of the manual). This didn't work out neither; when debugging my WP app I am passing the "await writer.FlushAsync()" bit without a problem but I'm getting stuck at the "await reader.LoadAsync(..)" part. I also tried to use a jumper cable between the RX and the DX side, but taking my non-existing electronics expertise I am not sure if I did that right (I squeezed the cables with the jumpers on those PINs).

 

So naturally I started to suspect my code on my Windows Phone. For fun I changed the 'await writer.FlushAsync()' part with an 'await writer.StoreAsync()' call, but that yielded the same result.

 

So right now I'll be probably looking for another Bluetooth solution for my Netduino - if I get that one working, I will be revisiting this Idead BT shield once again. Any suggestion for a (preferably stackable) BT shield?

 

Thanks again,

  Robert




#50977 SerialPort / Itead Studio Bluetooth Shield V2.2

Posted by enough on 01 July 2013 - 10:06 AM in Netduino Plus 2 (and Netduino Plus 1)

Hi NooM,

 

Thanks for your feedback! Windows Phone does not have direct Serial Port access and yes, the phone and the shield have been paired successfully, the connection is successfully established and I can send bytes to it.




#53689 Release Dates of Netduino Boards

Posted by enough on 27 October 2013 - 09:20 PM in General Discussion

Many thanks!




#53538 Release Dates of Netduino Boards

Posted by enough on 24 October 2013 - 08:50 PM in General Discussion

Hi everyone,

 

for an article I'd like to know the release dates of the Netduino boards, more specifically for the Netduino 2, the Netduino Plus 2 and the Netduino Go boards.

 

Thanks in advance,

yours

  Robert




#51738 No 'List(T)' in Microframework?

Posted by enough on 28 July 2013 - 12:23 PM in Visual Basic Support

Hey GFC,

 

you can use System.Collections.ArrayList, for example. Generics are not supported by the Microframework afaik. So if you do not want to cast a lot you can either use an array or subclass a collection class such as the above mentioned ArrayList.

 

Hope this helps,

Robert




#51172 Netduino and Bluetooth

Posted by enough on 07 July 2013 - 09:54 AM in Netduino 2 (and Netduino 1)

For anyone else interested in the Seeedstudio Bluetooth Shield:

You need to configure the shield first to make it discoverable to other Bluetooth devices. This shield is also very chatty, it confirms every configuration and let's you know when a connection is made, lost, etc. Sounds good in theory but it means that you need to parse received data to strip out the chatter from the shield.

 

Here's the relevant bit of the configuration code:

// initialize the serial port for COM2 (using D2 & D3)_serial = new SerialPort(SerialPorts.COM2, 38400, Parity.None, 8, StopBits.One);// open the serial-port, so we can send & receive data_serial.Open();// add an event-handler for handling incoming data_serial.DataReceived += new SerialDataReceivedEventHandler(serial_DataReceived);// configure seeedstudio:write("rn+STWMOD=0rn", _serial); //set the bluetooth work in slave modewrite("rn+STNA=SeeedBTSlavern", _serial); //set the bluetooth name as "SeeedBTSlave"write("rn+STOAUT=1rn", _serial); // Permit Paired device to connect mewrite("rn+STAUTO=0rn", _serial); // Auto-connection should be forbidden hereThread.Sleep(2000); // This delay is required.write("rn+INQ=1rn", _serial); //make the slave bluetooth inquirable

Here's the write method:

private static void write(string command, SerialPort serial){    byte[] buffer = System.Text.Encoding.UTF8.GetBytes(command);    serial.Write(buffer, 0, buffer.Length);}

To strip out the data send by the shield (like "+BTSTATE:4", "CONNECT:OK", etc) I first try to load the data completely - I am not sure, if this works in all circumstances, though. I just read the data until nothing more is available. Then I'm discarding all lines but the last one (this assumes that no line breaks are send) and do a sanity check on that line. You might want to add some magic value or so in the data send to the shield to make this one easier.

static void serial_DataReceived(object sender, SerialDataReceivedEventArgs e){    byte[] bytes = null;    int destinationIndex = 0;    int read = 0;    while (_serial.BytesToRead > 0)    {        int expected = _serial.BytesToRead;        byte[] data = new byte[expected];        int currentRead = _serial.Read(data, 0, expected);        read += currentRead;        if (bytes == null)        {            bytes = data;            destinationIndex = read;        }        else        {            byte[] intermediate = new byte[read];            System.Array.Copy(bytes, intermediate, read - currentRead);            System.Array.Copy(data, 0, intermediate, destinationIndex, currentRead);            bytes = intermediate;            destinationIndex += currentRead;        }    }    if (!_isInitialized)    {        // just chatter from the shield        return;    }    char[] chars = new char[read];    for (int i = 0; i < read; i++)    {        char c = (char)bytes[i];        chars[i] = c;    }    string result = new string(chars);    string[] lines = result.Split('r', 'n');    string receivedData = lines[lines.Length - 1];    if (receivedData.Length > 1)    {        if ((receivedData[0] == '+') || "CONNECT:OK".Equals(receivedData))        {            // that's just chatter from the shield like +BTSTATE:4            return;        }        processReceivedData(receivedData);    }}

The shield is documented quite poorly in my opinion, I haven't found a list of configuration options, for example.

 

Here's the complete Program.cs - have fun hacking!

Robert

using System;using System.Net;using System.Net.Sockets;using System.Threading;using Microsoft.SPOT;using Microsoft.SPOT.Hardware;using SecretLabs.NETMF.Hardware;using SecretLabs.NETMF.Hardware.Netduino;using System.IO.Ports;using System.Text;namespace robert_netduino_seeedstudio_bluetooth{    public class Program    {        private static SerialPort _serial;        private static bool _isInitialized;        public static void Main()        {            Thread.Sleep(2000); // not sure if this delay is required.            // initialize the serial port for COM2 (using D2 & D3)            _serial = new SerialPort(SerialPorts.COM2, 38400, Parity.None, 8, StopBits.One);            // open the serial-port, so we can send & receive data            _serial.Open();            // add an event-handler for handling incoming data            _serial.DataReceived += new SerialDataReceivedEventHandler(serial_DataReceived);            // configure seeedstudio:            write("rn+STWMOD=0rn", _serial); //set the bluetooth work in slave mode            write("rn+STNA=SeeedBTSlavern", _serial); //set the bluetooth name as "SeeedBTSlave"            write("rn+STOAUT=1rn", _serial); // Permit Paired device to connect me            write("rn+STAUTO=0rn", _serial); // Auto-connection should be forbidden here            Thread.Sleep(2000); // This delay is required.            write("rn+INQ=1rn", _serial); //make the slave bluetooth inquirable            Thread.Sleep(2000); // not sure if this delay is required.            _isInitialized = true;            // wait forever...            Thread.Sleep(Timeout.Infinite);        }        private static void write(string command, SerialPort serial, bool addLength = false)        {            byte[] buffer = System.Text.Encoding.UTF8.GetBytes(command);            if (addLength)            {                int length = buffer.Length;                serial.WriteByte((byte)(length >> 24));                serial.WriteByte((byte)((length >> 16) & 0x00ff));                serial.WriteByte((byte)((length >> 8) & 0x0000ff));                serial.WriteByte((byte)((length & 0x000000ff)));            }            serial.Write(buffer, 0, buffer.Length);        }        static void serial_DataReceived(object sender, SerialDataReceivedEventArgs e)        {            byte[] bytes = null;            int destinationIndex = 0;            int read = 0;            while (_serial.BytesToRead > 0)            {                int expected = _serial.BytesToRead;                byte[] data = new byte[expected];                int currentRead = _serial.Read(data, 0, expected);                read += currentRead;                if (bytes == null)                {                    bytes = data;                    destinationIndex = read;                }                else                {                    byte[] intermediate = new byte[read];                    System.Array.Copy(bytes, intermediate, read - currentRead);                    System.Array.Copy(data, 0, intermediate, destinationIndex, currentRead);                    bytes = intermediate;                    destinationIndex += currentRead;                }            }            if (!_isInitialized)            {                // just chatter from the shield                return;            }            char[] chars = new char[read];            for (int i = 0; i < read; i++)            {                char c = (char)bytes[i];                chars[i] = c;            }            string result = new string(chars);            string[] lines = result.Split('r', 'n');            string receivedData = lines[lines.Length - 1];            if (receivedData.Length > 1)            {                if ((receivedData[0] == '+') || "CONNECT:OK".Equals(receivedData))                {                    // that's just chatter from the shield like +BTSTATE:4                    return;                }                processReceivedData(receivedData);            }        }        private static void processReceivedData(string receivedData)        {            // okay, we have real data. Just send a confirmation back:             // an int32 that describes the length of our feedback and then the received data plus something            string responseStr = receivedData + " from netduino";            write(responseStr, _serial, addLength: true);        }    }}



#51195 Netduino and Bluetooth

Posted by enough on 08 July 2013 - 08:31 AM in Netduino 2 (and Netduino 1)

Yes, that's exactly the model I'm referring to.

 

Please also note that I adapted the serial_DataReceived method a bit - I had to sleep for a short while so that the serial interface was able to pump out more data. This is done in the while (_serial.BytesToRead > 0)  loop, this loop is now:

            byte[] bytes = null;            int destinationIndex = 0;            int read = 0;            while (_serial.BytesToRead > 0)            {                int expected = _serial.BytesToRead;                byte[] data = new byte[expected];                int currentRead = _serial.Read(data, 0, expected);                read += currentRead;                if (bytes == null)                {                    bytes = data;                    destinationIndex = read;                }                else                {                    byte[] intermediate = new byte[read];                    System.Array.Copy(bytes, intermediate, read - currentRead);                    System.Array.Copy(data, 0, intermediate, destinationIndex, currentRead);                    bytes = intermediate;                    destinationIndex += currentRead;                }                if (_isInitialized)                {                    // give serial a chance to add more data                    Thread.Sleep(5);                }            }

Have fun,

  Robert




#51197 Netduino and Bluetooth

Posted by enough on 08 July 2013 - 08:36 AM in Netduino 2 (and Netduino 1)

Oh, and there's a list of configuration commands here:

 

http://www.seeedstud...t_configuration




#52551 Generating own NuGet packages

Posted by enough on 04 September 2013 - 07:07 PM in General Discussion

I have created a .NET MF class library and want to publish that on NuGet.

Creating the NuGet seems to work fine, but when I integrate the NuGet package (it's called Enough.MF.Connectivity) I get the following errors in Visual Studio: Could not copy the file "[...]ProjectsLightOMatorpackagesEnough.MF.Connectivity.1.0.1libnetmfleLEEnough.MF.Connectivity.pe" because it was not found. Could not copy the file "[...]ProjectsLightOMatorpackagesEnough.MF.Connectivity.1.0.1libnetmfleLEEnough.MF.Connectivity.pdbx" because it was not found. Could not copy the file "[...]ProjectsLightOMatorpackagesEnough.MF.Connectivity.1.0.1libnetmfleBEEnough.MF.Connectivity.pe" because it was not found. Could not copy the file "[...]ProjectsLightOMatorpackagesEnough.MF.Connectivity.1.0.1libnetmfleBEEnough.MF.Connectivity.pdbx" because it was not found.

I can fix that error by moving the files from packagesEnough.MF.Connectivity.1.0.1libnetmfle to packagesEnough.MF.Connectivity.1.0.1libnetmfleLE, etc.

Comparing that to other Microframework NuGet packages (that work flawlessly out of the box) I can't really find any substantial difference other than those packages being tailored for specific .NET MF versions (with folders such as netmf42, etc).

Something seems to point to the libnetmfle folder as the root, but I don't know what.

I have attached the NuGet file, you can also download it under the ID Enough.MF.Connectivity.

I create the NuGet package with following psake script:

1. building:   Exec { msbuild "/t:Clean;Build" /p:Configuration=Release /p:OutDir=$tempBinariesDir /p:GenerateProjectSpecificOutputFolder=true /p:StyleCopTreatErrorsAsWarnings=false /m "$solution" } "Error building $solutionFile" 2. NuGet packaging:   Exec { .$nuget pack $projectNugetFolder$projectNuspec -Output $nupkgDir } "Error packaging $name"

When I unpackage the generated nupgk file, I get following folder structure:

+ _rels   .rels + lib   + netmf   Enough.MF.Connectivity.dll  Enough.MF.Connectivity.pdb  SecretLabs.NETMF.Hardware.dll  SecretLabs.NETMF.Hardware.Netduino.dll  SecretLabs.NETMF.Hardware.Netduino.pdb  SecretLabs.NETMF.Hardware.pdb  + be Enough.MF.Connectivity.dll Enough.MF.Connectivity.pdb Enough.MF.Connectivity.pdbx Enough.MF.Connectivity.pe SecretLabs.NETMF.Hardware.dll SecretLabs.NETMF.Hardware.Netduino.dll SecretLabs.NETMF.Hardware.Netduino.pdb SecretLabs.NETMF.Hardware.pdb SecretLabs.NETMF.Hardware.pdbx SecretLabs.NETMF.Hardware.pe  + le Enough.MF.Connectivity.dll Enough.MF.Connectivity.pdb Enough.MF.Connectivity.pdbx Enough.MF.Connectivity.pe SecretLabs.NETMF.Hardware.dll SecretLabs.NETMF.Hardware.Netduino.dll SecretLabs.NETMF.Hardware.Netduino.pdb SecretLabs.NETMF.Hardware.pdb SecretLabs.NETMF.Hardware.pdbx SecretLabs.NETMF.Hardware.pe + package   + services   + metadata + core-properties 407e9cf4968540ff98272fc0fb2a98a8.psmdcp [Content_Types].xml Enough.MF.Connectivity.nuspec

 

 

 

Thanks in advance for any pointers, Robert

Attached Files




#52552 Generating own NuGet packages

Posted by enough on 04 September 2013 - 07:10 PM in General Discussion

Forgot to mention that I created two Windows 8 packages using the same scripting commands which resulted in working NuGet packages.




#48695 Controlling Lights with Netduino Go

Posted by enough on 24 April 2013 - 06:24 PM in Netduino Go

Forgot to mention that I do not need to control each light singly - however, that would also be nice (just imagining my own massive RGB LED powered display, hehe).




#48691 Controlling Lights with Netduino Go

Posted by enough on 24 April 2013 - 02:24 PM in Netduino Go

Hi everyone,

since yesterday I'm a proud owner of a Netduino Go starter kit, hooray!
I have set up VS2012 along with the .NET MF and Netduino SDK. Then I successfully created a couple of test apps that use the RGB LED light - so everything's pretty cool.
My problem is that I have no clue about hardware, this was one of the main reasons to use the Netduino Go board - it's just to amazingly simple!

 

Now I wonder how to start my actual idea: I want to control lights according to the time of the day (e.g. having more blue light in the morning, but more red light in the evening),
but also control it from my mobile phone. For that I _think_ I need basically 3 things:

  • Netduino Go
  • Some Wifi extension
  • Some lights with a connection

Wifi is discussed in several threads here, so I guess that can be solved. About the light I am not so sure - I am thinking about RGB LED arrays such as the
"ITeadstudio 8x8 LED Matrix RGB" (e.g. http://www.exp-tech....B--circle-.html ).
I assume that I would need a proto board to connect the lights and then the shield base to connect the proto board - is that correct?


How would you tackle such a problem? How could I control a big collection of RGB LEDs, e.g. to lid a complete office?


I am ready to learn, and yes, even to solder - but I want some guidance before galloping into a completely wrong direction.

 

Thanks for you help,
Robert




#48697 Controlling Lights with Netduino Go

Posted by enough on 24 April 2013 - 07:59 PM in Netduino Go

Just a short update - went to the chat room I was told that the Netduino 2 Plus might be a better option (thanks, Arron!). Placed an order and now wait for the stuff to arrive. I will post updates if and when I succeed :-)




#51739 Anyone tried XMarine?

Posted by enough on 28 July 2013 - 12:28 PM in General Discussion

<shamelessselfplug>

The Mobile Developer's Guide to the Galaxy has a dedicated chapter for cross platform tools, there are lots out there:

You can download it for free here:

http://enough.de/mdgg/

</shamelessselfplug>





home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.