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

Could my Netduino COM ports be malfunctioning?

SerialPort COM Bluetooth

Best Answer shiv.kumar, 23 January 2016 - 04:50 PM

Years later....

 

I should have got back here to let folks know that I got this to work (soon after my last post in this thread).

 

Basically, the issue was related to levels. The RX/TX pins need to be level shifted to work with the Netduino. In my case since I'm using the Bluetooth module as a receiver, I've pulled up the TX pin of the Bluetooth module (not the Netduino) with a 10k resistor.

 

That is, the TX pin of the Bluetooth module (in addition to being connected to pin 0 of the Netduino is also connected to 3.3v via a 10k resistor. After doing this, the above test (the very first post in this thread) works as expected. That is, I don't get gibberish and in fact get exactly the data I send via the terminal.

 

I hope this helps.

Go to the full post


  • Please log in to reply
9 replies to this topic

#1 shiv.kumar

shiv.kumar

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts

Posted 22 May 2014 - 11:19 PM

This is on continuation with a previous thread, but because I've changed directions, a quite a bit of debugging in this new direction I felt I should start a new thread since the new stuff can stand independently of the earlier thread.....

 

 For reference, I'm using

I'm using Netduino Plus 2 (Firmware 4.3.1)

I'm using the JY-MCU Bluetooth board (v1.06)

 

The code I'm using is this:

    public class Program
    {
        static ArrayList buffer = new ArrayList();

        public static void Main()
        {
            var bluetoothSerialPort = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
            bluetoothSerialPort.DataReceived += DataReceived;
            bluetoothSerialPort.Open();

            Thread.Sleep(Timeout.Infinite);
        }

        private static void DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            var bluetoothSerialPort = (SerialPort)sender;

            // This code is not "production worthy"
            // But for the purposes of diagnosing the issue it works
            while (bluetoothSerialPort.BytesToRead > 0)
            {
                var byt = (byte)bluetoothSerialPort.ReadByte();
                buffer.Add(byt);
                bluetoothSerialPort.WriteByte(byt);
            }
        }
    }

Some initial findings (The code above is not in play for this)

I've paired the Bluetooth board with my PC

I've powered the board using 5v

I've connected the RX and TX pins of the board to each other. (loop back)

Using Hyper Terminal (or similar) I connected to the correct serial port (the Bluetooth device), set baud rate etc.

 

Sending data from the terminal, results on the bluetooth board receiving and responding (due to RX and TX being connected) and I am able to see the response in the terminal window.

What I send is what I receive.

 

So I know that the bluetooth boards (I have two of them) are working

 

So the next step was to do the "loop back" using software/Netduino (just keeping it simple)

(The code above is now in play)

The TX and RX pins of the Bluetooth board are crossed over and connected to digital pins 0 and 1 (see previous post)

I've powered the bluetooth board via the Netduino 5v and ground.

 

Send data using the Serial Terminal program. What I see in the terminal screen is gibberish. The actual bytes I receive in code (using breaks points and seeing the bytes as they are read:

If I send "Hello" (without the quotes), I get the following bytes (consistently)

0

32

32

56

254

 

I've tried (in Code) using

COM1 with pins 0,1

COM2 with pins 2,3

COM3 with pins 7,8

 

No luck

 

I've also tried using this code in create an instance of a serial port

var bluetoothSerialPort = new SerialPort(SerialPorts.COM1);

Didn't make a difference.

 

So unless something is wrong with the code I've shown (and I've used multiple variations of code with same/similar results) I'm not able to explain/understand why or what.

 

Can someone help?

 



#2 600mL

600mL

    Member

  • Members
  • PipPip
  • 20 posts

Posted 23 May 2014 - 04:27 AM

Hi,

 

You have your serial port baud rate set to 9600. Is this correct? I would reconfigure both devices to work at 115200 and see if you are still receiving gibberish.

 

Usually gibberish is an indication of incompatible baud rates. I know the netduino plus has some issues at lower baud rates, but 9600 should be ok. Give what I suggested a try and let us know how you go.



#3 shiv.kumar

shiv.kumar

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts

Posted 23 May 2014 - 11:11 AM

600mL, thanks for the reply.

 

I tried a baud rate of 115200 and configured and reconnected via RealTerm (Serial Console application) at the same baud rate. Seems to have gotten worse (if that's even possible). Because I'm receiving more bits than I'm sending and they are all 0.

 

Subsequently I've tried various other baud rates including 38400 (the data sheet for CSR BC417143 (BlueCore4 External) mentions setting the baud rate to 38400). Results were pretty much the same as above.

 

I then decided to send data from the Netduino. Not sending what I receive, but rather just send data of my own choosing. The modified code is below

        public static void Main()
        {
            var bluetoothSerialPort = new SerialPort(SerialPorts.COM1, 9600, Parity.None, 8, StopBits.One);
            bluetoothSerialPort.DataReceived += DataReceived;
            bluetoothSerialPort.Open();

            var buffer = new byte[] { 72, 101, 108, 108, 111 }; // Hello
            bluetoothSerialPort.Write(buffer, 0, buffer.Length);
            bluetoothSerialPort.Flush();

            Thread.Sleep(Timeout.Infinite);
        }

What I found is that when I set the baud rate to 9600, I actually do receive the bytes as sent in the serial console. Setting it at 115200 and 38400 did not.

 

So now I know following

1. Data sent from Serial Console to the Bluetooth device works

2. Data sent from the Bluetooth device is received at the Serial Console

3. Data sent from code/Netduino is received at the Serial Console

4. Data sent from the Serial Console and received correctly by the Bluetooth device is not received correctly (gibberish) by the Netduino

 

Anything else I can try?

Is there another way I can test the Serial Port receive capability of the Netduino?



#4 600mL

600mL

    Member

  • Members
  • PipPip
  • 20 posts

Posted 25 May 2014 - 11:29 PM

I can suggest a few things. Make the serial port a static class and place your serialport instantiation outside of the main function and include a serial port timeout. You should also try the other available serial ports if this doesn't work. Example:

public class program
{
   private static SerialPort dataPort = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);

   public static void Main()
   {
      dataPort.ReadTimeout = Timeout.Infinite;
      dataPort.WriteTimeout = Timeout.Infinite;
      dataPort.Open();
      dataPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
   }
}


#5 600mL

600mL

    Member

  • Members
  • PipPip
  • 20 posts

Posted 26 May 2014 - 04:44 AM

Also, can you provide a link to the datasheet of the bluetooth device you are using?

 

Perhaps your module uses a different interface to communicate with the Netduino

 

EG. Netduino <-- SPI/I2C --> Bluetooth <---- RS232 ----> Device ????



#6 shiv.kumar

shiv.kumar

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts

Posted 27 May 2014 - 11:00 AM

Don't see why making the variable static would make a difference :) But I tried that and your suggestion about Timeout as well. No difference and same gibberish as well. In earlier posts you'll see that I've tried the other COM ports as well with no difference.

 

Well, the Bluetooth module definitely communicates using Serial as you can see from my previous posts while using Hyper Terminal. The chip (CSR BC417143) is a UART chip.

http://www.digikey.c.../bc417143/21102

 

This is the vendor I bought mine from

http://www.amazon.co...0?ie=UTF8&psc=1

 

On the bottom of the board mine says v1.06.

 

Thanks for your help.



#7 600mL

600mL

    Member

  • Members
  • PipPip
  • 20 posts

Posted 27 May 2014 - 11:41 PM

Don't see why making the variable static would make a difference :) But I tried that and your suggestion about Timeout as well. No difference and same gibberish as well. In earlier posts you'll see that I've tried the other COM ports as well with no difference.

 

Well, the Bluetooth module definitely communicates using Serial as you can see from my previous posts while using Hyper Terminal. The chip (CSR BC417143) is a UART chip.

http://www.digikey.c.../bc417143/21102

 

This is the vendor I bought mine from

http://www.amazon.co...0?ie=UTF8&psc=1

 

On the bottom of the board mine says v1.06.

 

Thanks for your help.

 

That was just some example code that worked for me, making it static probably makes no difference.

 

Are you powering the module from the 3.3V or the 5V pin? You need to connect it to 5V pin apparently.

 

Have a look at this tutorial: http://homepages.ihu...o/GUIDE_2BT.pdf

 

Check out page two, there is a wiring diagram that shows a pair of resistors connected from txd to gnd. Have a read through that pdf, it looks well written and informative.



#8 shiv.kumar

shiv.kumar

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts

Posted 03 June 2014 - 10:31 PM

Hey 600ml,

 

Sorry for not responding earlier. I've only just been able to get back to this. I'll try the voltage diver mentioned on the PDF you've linked to. However, since that document is geared towards the Arduino UNO and the UNO is a 5v device. I'll have to think about what is relevant to my Netduino Plus 2 and what's not.

 

I've also bought an FTDI board from SparkFun. The aim to communicate with the NP2 via USB leaving the code I currently have to see if I things work as expected. That is use the Terminal server to talk to the Netduino via USB/COM port and I should get back what I sent in.



#9 shiv.kumar

shiv.kumar

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts

Posted 05 June 2014 - 11:06 AM

So the FTDI works as expected. Using the same code but swapping out the Bluetooth module for the FTDI module. I'm able to send serial data from the terminal via the FTDI module to the Netduino and the code in the Netduino echos the data back and all works as expected.

 

So the Netduino code is OK

The serial ports function as expected

With the Buletooth module I can send data to the Terminal but I can't receive data via Bluetooth.

 

Seems to be a levels issue on the bluetooth module. I have an Arduino Uno and I'll try the Bluetooth module with this using the voltage divider as shown in the document you linked to once I get some time.



#10 shiv.kumar

shiv.kumar

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts

Posted 23 January 2016 - 04:50 PM   Best Answer

Years later....

 

I should have got back here to let folks know that I got this to work (soon after my last post in this thread).

 

Basically, the issue was related to levels. The RX/TX pins need to be level shifted to work with the Netduino. In my case since I'm using the Bluetooth module as a receiver, I've pulled up the TX pin of the Bluetooth module (not the Netduino) with a 10k resistor.

 

That is, the TX pin of the Bluetooth module (in addition to being connected to pin 0 of the Netduino is also connected to 3.3v via a 10k resistor. After doing this, the above test (the very first post in this thread) works as expected. That is, I don't get gibberish and in fact get exactly the data I send via the terminal.

 

I hope this helps.







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.