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; } }
BTShieldV2.2_DS.pdf 644.68KB 11 downloads