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

Bytes sent over SerialPort not the same when received on Netduino over Bluetooth

Bluetooth JY-MCU Netduino2 SerialPort

  • Please log in to reply
6 replies to this topic

#1 Tinymacrocosm

Tinymacrocosm

    New Member

  • Members
  • Pip
  • 4 posts

Posted 25 October 2014 - 10:10 PM

I am working on a project and I am using this website as a reference to get my Netduino to communicate with my PC.

I've purchased this Bluetooth transceiver. It seems to be an updated version of the one used by the original post. 1.06 vs 1.04 on his website.

 

I set the Bluetooth's TXD to Pin0, RXD to Pin1, and VCC to 5V.

 

This is my code on the Netduino:

static SerialPort Bluetooth;

public static void Main()
{
    Bluetooth = new SerialPort(SerialPorts.COM1, 9600, Parity.None, 8, StopBits.One);
    Bluetooth.DataReceived += new SerialDataReceivedEventHandler(Bluetooth_DataReceived);

    Bluetooth.Open();

    Thread.Sleep(Timeout.Infinite);
}

static void Bluetooth_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
    byte[] bytes = new byte[1];

    while(Bluetooth.BytesToRead > 0)
    {
        Bluetooth.Read(bytes, 0, bytes.Length);
        Debug.Print(bytes[0].ToString());
    }
}

This is my code on my laptop: (it is a WPF application)

SerialPort serialBT;

private void Connect()
{
    // COM7 is the outgoing port that corresponds to the Bluetooth transceiver
    serialBT = new SerialPort("COM7", 9600, Parity.None, 8, StopBits.One);
    serialBT.Open();

    serialBT.Write(new byte[] { 23, 24, 25, 26 }, 0, 4);
    Debug.Print("Values sent");
}

On the Netduino, when I send the byte array of 23, 24, 25, and 26 (just for testing purposes), the DataReceived event fires. However the values it received and prints out in the debug window are 6, 0, 0, and 248 instead of the 23, 24, 25, and 26 that it should be.

 

Other values I send are also just as mysteriously transformed to completely different ones.

 

I've tripled checked the proper COM settings for the Bluetooth transceiver and those are the correct settings. I've flipped the TXD and RXD pins since the original Arduino expects TXD to be Pin1 and RXD to be Pin0, but that causes no data to be received on the Netduino.

 

Using COM2 and Pin2 and Pin3 yield different values. Instead, I get 0,16,16, and 16.



#2 Jardeth56

Jardeth56

    Member

  • Members
  • PipPip
  • 17 posts

Posted 06 November 2014 - 07:04 PM

Am running in the same issue but with a different Bluetooth module.

No matter what I send the only data I get back 0 0 0 248.

My code is similar to the code above but am using wp8.1 to send the data.

I have been banging my head on this all day!!!

#3 Jardeth56

Jardeth56

    Member

  • Members
  • PipPip
  • 17 posts

Posted 06 November 2014 - 07:08 PM

Also I can send data from the netduino to my phone without a problem its just from the phone to netduino.

#4 Tinymacrocosm

Tinymacrocosm

    New Member

  • Members
  • Pip
  • 4 posts

Posted 07 November 2014 - 03:21 AM

So.... I finally got it working. No change in the code. The answer seemed so simple but no one ever bothered to actually explain it; I just needed to switch the TXD and RXD pins.

 

COM1 for the Netduino means that PIN0 is the RX pin and PIN1 is the TX pin. Its expecting to receive data on PIN0 and send it on PIN1. The Bluetooth component will send data on its TX and the Netduino should receive it on the RX; The Bluetooth TX (send data) should be connected to the Netduino's RX (receive data) and the Bluetooth's RX (receive data) should be connected to the Netduino's TX pin (send data).



#5 Jardeth56

Jardeth56

    Member

  • Members
  • PipPip
  • 17 posts

Posted 07 November 2014 - 02:39 PM

Could you explain your solution a bit more? did u just add a jumper between pin 0 and pin1?



#6 Tinymacrocosm

Tinymacrocosm

    New Member

  • Members
  • Pip
  • 4 posts

Posted 07 November 2014 - 06:15 PM

Could you explain your solution a bit more? did u just add a jumper between pin 0 and pin1?

 

Sure. No jumpers were used. This line of code on the Netduino:

Bluetooth = new SerialPort(SerialPorts.COM1, 9600, Parity.None, 8, StopBits.One);

makes Pin0 and Pin1 defined for serial usage. Pin1 becomes the TX pin (send data) and Pin0 becomes the RX pin (receive data). I needed to connect them to the opposite corresponding pin on the Bluetooth.

 

Netduinotojy-mcubluetoothconnection_zps3

(VCC goes to 5V and GND goes to ground - I'm omitting it in the drawing to just focus on what i changed)

 

The Netduino's send data has to be processed by the Bluetooth's receive data. The Bluetooth's send data has to be processed by the Netduino's receive data.

 

When I connected the RX to the RX and the TX to the TX, I was getting garbage data when it was sent, very similar to yours, with values like 6, 0, 0, 248 regardless of what i sent.



#7 Jardeth56

Jardeth56

    Member

  • Members
  • PipPip
  • 17 posts

Posted 10 November 2014 - 11:17 AM

Thanks for this, It kindy worked I can now send receive data on my neduino when I only have the RX cable in but when I put both in i dont get data or I just get junk data.

 

So am thinking I may need to put a couple of resistors in to clean up the signal as even when I touch the cable I get a junk signal.

 

Thanks for you help.







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.