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

BlueSMiRF Silver (Bluetooth)


  • Please log in to reply
8 replies to this topic

#1 mohammad

mohammad

    Advanced Member

  • Members
  • PipPipPip
  • 79 posts

Posted 10 April 2012 - 07:14 PM

Hi all,

I am working with Netduino Plus with blueSMiRF Silver (a bluetooth module). After spending so much time, I found the following useful links.

1) http://www.sparkfun.com/products/10269
2) http://dlnmh9ip6v2uc...th-RN-42-DS.pdf
3) http://wiring.org.co...ials/bluetooth/
4) http://blog.mark-stevens.co.uk/?p=180

Then, I used Termite 2.9 simulator to connect my Notebook (with bluetooth) to Netduino Plus(with BlueSMiRF).
Now, the connection is establieshed between Netduino and my notebook because the BlueSMiRF LED is on.

My code is as below:
public class Program
    {
        static SerialPort serial;

        public static void Main()
        {
            // initialize the serial port for COM1 (using D0 & D1)
            serial = new SerialPort(SerialPorts.COM1, 115200, 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[32];

            // 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);
            }
        }


    }

My question: How can I transfer data (e.g. some chars) between the 2 mentioned devices?

Thanks for your future replies :rolleyes:

#2 Nevyn

Nevyn

    Advanced Member

  • Members
  • PipPipPip
  • 1072 posts
  • LocationNorth Yorkshire, UK

Posted 10 April 2012 - 08:30 PM

My question: How can I transfer data (e.g. some chars) between the 2 mentioned devices?

The clue can be found in the _bluetoothModule_DataReceived method of the RovingNetworks class. This class receives one or more bytes and then adds them to the buffer. This can then be extracted to return say a string of text. This method is specifically written to process strings of text but could be used to transfer bytes. The general method is:

Attach an event handler to the serial port and add new data to the receive buffer.
Loop
if buffer contains data for processing then
process the data.
end if
while (processing is necessary)

In your case the buffer would contain data for processing when the buffer contained two or more bytes. Also note that as part of the processing you would have to remove the data which has been consumed.

Hope this helps,
Mark

To be or not to be = 0xFF

 

Blogging about Netduino, .NET, STM8S and STM32 and generally waffling on about life

Follow @nevynuk on Twitter


#3 mohammad

mohammad

    Advanced Member

  • Members
  • PipPipPip
  • 79 posts

Posted 18 April 2012 - 09:59 PM

Hi Mark, Thanks for your last reply. I don't know why my Bluetooth module doesn't send anything to Netduino. 1) I connected BlueSMiRF to my notebook. By using Termite 2.9 simulator, I could send some characters and get them from BlueSMiRF. 2) I printed some strings in each method inside the RovingNetworks class. I ran your code and established the connection between BlueSMiRF and Termite (BlueSMiRF LED was green). During the run time, I got unlimited strings, when the program goes to "readLine()" function. By typing some characters in Termite, I didn't receive any response back. I really appreciate if you tell me what is wrong. Cheers, Mohammad

#4 mohammad

mohammad

    Advanced Member

  • Members
  • PipPipPip
  • 79 posts

Posted 19 April 2012 - 08:08 PM

I understood that "_bluetoothModule_DataReceived" function is never called :( In addition, why don't we get any instances from OutputPort or InputPort? I've connected the TX and RX ports of BlueSMiRF to the digital I/O pins 1 and 0 (respectively) of Netduino. According to your code, I just use Serial.Com1 port and pass it to RovingNetworks class. Thanks, Mohammad

#5 ErikN

ErikN

    Advanced Member

  • Members
  • PipPipPip
  • 119 posts
  • LocationNew York, NY

Posted 20 April 2012 - 09:03 PM

I see from the datasheet a couple things. First, it looks like the default software mode speed is indeed 115,200,8,N,1 but there appears to be a dip switch as well that will set the speed to a fixed 9600.


"Baud Rate select - used to configure 9600 or software selected (default=115K ) baudrate. If the switch is
OFF, the stored baudrate setting will be used. When the switch is in the ON position, the baudrate will be set
to 9600 regardless of the software setting."



Can you check this and verify you're using the proper settings? I'd recommend turning this switch on and communicating via 9600 to ensure your code is working and then try again at 115,200 and ensure everything is still working. It might be that 115,200 is just too fast (seems unlikely).

#6 mohammad

mohammad

    Advanced Member

  • Members
  • PipPipPip
  • 79 posts

Posted 20 April 2012 - 10:39 PM

Thanks ErikN. I tried all supported baud rates, but still there is no response.
I don't know whether my attempt for making the connection is right or not. What I do is in this way:

1) I deploy the code from my computer to Netduino Plus (which BlueSMiRF is also connected to).
2) After finishing the deployment, the red LED of BlueSMiRF starts blinking.
3) I pair my notebook (which has bluetooth) to BlueSMiRF.
4) Then, I run the Termite 2.9 simulator or Putty, set the settings (as I set in my code for BlueSMiRF), and send some strings ('$$$', 'a', 'abc', ...) to BlueSMiRF.
5) The green LED of BlueSMiRF is turned on. Thus, I expect to get responses to my posted strings, but nothing happens :( :( :(

#7 mohammad

mohammad

    Advanced Member

  • Members
  • PipPipPip
  • 79 posts

Posted 01 May 2012 - 01:47 AM

I don't know why my SerialDataReceivedEventHandler has never called :(

#8 mohammad

mohammad

    Advanced Member

  • Members
  • PipPipPip
  • 79 posts

Posted 05 July 2012 - 07:33 PM

The best solution to solve the problem: http://mohammad.geoc...ebsite/blog.php

#9 Azazel

Azazel

    Member

  • Members
  • PipPip
  • 28 posts
  • LocationSweden

Posted 30 September 2012 - 01:32 PM

Im trying to setup my BlueSMiRF silver bluetooth to my netduino, got it working. Now im trying to setup the modem for working against a phone (ipone/wp7/android). I dont think i understand this service/device class stuff. Anyone know about these stuff ? I think my service class should be AudioSink (0x110B). But what should device class be ? is this the bluetooth device (my netduino) or the device who is connecting against it (my phone) ?




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.