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

JY-MCU HC-06


  • Please log in to reply
1 reply to this topic

#1 Dolphin_78

Dolphin_78

    New Member

  • Members
  • Pip
  • 3 posts

Posted 23 July 2015 - 05:37 PM

Hi people i m a pleased owner of a netduino plus and recently i bought a bluetooth device JY-MCU HC-06 from dealextreme.

 

I test the device with an arduino nano v3.0 and it works perfect but when i tried with netduino, it has a weird behaviour. Send bytes works perfect but receive data works very bad. I pair it with my phone and with BlueTerm app send some data. When i send "1", byte 49, i receive byte 32.

 

Wired Netduino -> JY-MCU HC-06:

 

COM1 ( Pin 0 / RX - Pin 1 / TX ) -> TX - RX.

 

No resistors between.

 

I tested the serial communication with an arduino. Wiring Arduino serial pins to netduino serial COM1 pins and run a program for send data between both. All works perfect send and receive.

 

Anybody could help me please?.

 

This is the code for Netduino:

 

public class Program
    {
        static SerialPort serial;
        public static void Main()
        {
            serial = new SerialPort(Serial.COM1, 9600Parity.None, 8StopBits.One);
            serial.Open();
            serial.DataReceived += serial_DataReceived;
            Thread.Sleep(Timeout.Infinite);
        }

        static void serial_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            byte[] bytes = new byte[1];
            while (serial.BytesToRead > 0)
            {
                serial.Read(bytes, 0, bytes.Length);
                serial.Write(bytes, 0, bytes.Length);
            }
        }

    }



#2 Dolphin_78

Dolphin_78

    New Member

  • Members
  • Pip
  • 3 posts

Posted 23 July 2015 - 10:48 PM

I tried change parity to EVEN and it begin to work partially.

 

Later i return parity to original and put the initialization of the received bytes buffer out of delegate and recompile the code again and now it works.

 

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.NetduinoPlus;
using System.Text;
using System.IO.Ports;

namespace bluetooth
{
    public class Program
    {
        static byte[] bytes = new byte[1];
        static SerialPort serial;
        public static void Main()
        {
            serial = new SerialPort(Serial.COM1, 9600Parity.None, 8StopBits.One);
            serial.Open();
            serial.DataReceived += serial_DataReceived;
            Thread.Sleep(Timeout.Infinite);
        }

        static void serial_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            while (serial.BytesToRead > 0)
            {
                serial.Read(bytes, 0, bytes.Length);
                /* bytes[0] = 49; */
                serial.Write(bytes, 0, bytes.Length);
            }
        }

    }
}






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.