Netduino home hardware projects downloads community

Jump to content


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

SerialPort / Itead Studio Bluetooth Shield V2.2

serial serialport bluetooth

  • Please log in to reply
4 replies to this topic

#1 enough

enough

    Member

  • Members
  • PipPip
  • 15 posts
  • LocationBremen, Germany

Posted 22 June 2013 - 09:37 AM

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



#2 ziggurat29

ziggurat29

    Advanced Member

  • Members
  • PipPipPip
  • 244 posts

Posted 22 June 2013 - 01:48 PM

you're not doomed, you can make it work, though it will have to be on COM1 since for some reason they didn't bring out D2/D3, and as you observed only the one D0-7 header (and so don't have a complete COM3).

 

First, I have not used this shield.  But, I have used the underlying BT module, the HC-05, and with it connected to the netduino.  So it is doable.

 

NB datasheet:

ftp://imall.iteadstudio.com/IM120417010_BT_Shield_v2.2/DS_BluetoothHC05.pdf

p2 indicates:  "Default Baud rate: 38400, Data bits:8, Stop bit:1,Parity:No parity"

 

your code shows 9600.

 

However the various ITead docs are inconsistent, so take them with appropriate salt.  For example one says the PIN code is 0000, and another says it is 1234.  They also state that Vih is 4.5v, which you will not get out of a 3.3v board, but I suspect that rating is actual Vimax instead of Vih.

 

You netduino code at first glance looks like an OK 'loopback' test.  But I havent' run it so thats just a desk check.  I can say that I have had problems with SerialDataReceivedEventHandler, but those are sporadic, so let's not worry about that now.

 

You are wise to do a loopback test as a sanity check.  If you like, you can loopback even closer by connecting the TX to the RX of the radio, bypassing the netduino.  You can do that either by removing all the jumpers, and connecting the TX to the RX with a jumper wire; or by temporarily removing all your code in main (thereby leaving the netduino pins in high-impedance) and jumpering at the header.  You should be able to connect to the radio as you have been, and see data sent comes right back.  This will verfify from the radio to your windows phone code, and take com configuration out of the equation.

 

Next I suspect you just have to configure your jumpers correctly.  I love the ascii art but I confess I got confused by the [] and the colors, so let me just say that the way it is shown in your datasheet's 'figure 3', is probably the way you want.  I.e. the TX of the board to D0 (rx of netduino) and the RX of the board to D1 (tx of netduino).  Depending on their sense of RX and TX you might reverse that, but I think that is it.

 

Keep at it, it will (probably!) work.



#3 enough

enough

    Member

  • Members
  • PipPip
  • 15 posts
  • LocationBremen, Germany

Posted 28 June 2013 - 10:07 PM

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



#4 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 29 June 2013 - 11:06 PM

did you test it with your pc?

 

your connecttodrive function looks very strange to me, but ive never worked with windows phone.

doesent it have a normal serialport class?

 

also, before you use the drive, you have to pair it first (at least on my pc, i search for device once, enter the pairing code, than i can open to serialport of it)



#5 enough

enough

    Member

  • Members
  • PipPip
  • 15 posts
  • LocationBremen, Germany

Posted 01 July 2013 - 10:06 AM

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.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

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