I am trying to achieve that my arduino-built device connects automatically to a device after it is switched on. The board is an Arduino Mini Pro and the bluetooth module is the Bluetooth Mate Silver (RN42). The devices are already paired, the bluetooth module is in slave mode, the remote device (in this case a normal laptop) is discoverable. I am using the SoftwareSerial library provided with the Arduino software.
Here is my setup:
void setup()
{
Serial.begin(9600); // Begin the serial monitor at 9600bps
// bluetooth
// set baud rate to 9600
bluetooth.begin(9600);
// start command mode
bluetooth.print("$$$");
// reply delay
delay(100);
// set to slave mode
bluetooth.println("SM,0");
// reply delay
delay(100);
// set device pin to 0403
bluetooth.println("SP,0403");
// reply delay
delay(100);
// connect to pixelsense
bluetooth.println("C," + remoteMAC); // remoteMAC is a string with the mac address
// reply delay
delay(2500);
// leave command mode
bluetooth.println("---");
// reply delay
delay(100);
}
I read the command set of the RN42 and I think the commands are correct. I can connect to Arduino via bluetooth but the other direction isn't working. I also tried using the master mode or storing the remote mac in the flash instead of using a string. From the documentation it should be possible to initiate connections from the RN42, but I haven't quite found out how this works in details. Can anyone provide any help to solve my issue?
EDIT: The device does not seem to enter command mode at all. At least the flash lights don't indicate that. Is there anything wrong with the commands so that the command mode cannot be accessed?
After nearly a week, I came across a solution. Actually it seems to be important that there is any program that accepts a bluetooth connection. I tried it the whole time with the Windows 7 Bluetooth dialog menu entry "Receive a file" but that did not work. So I used a third party program that listens for incoming connections and that actually worked. Basically everything I did was fine except for the missing connection listener.
Sometimes if I upload new code to the Arduino there is the problem that the connection cannot be established. This can be solved by removing and readding the bluetooth device.
The code for the RN42 Bluetooth Client above works. The library SoftwareSerial provided with the Arduino software is used.
I think you may need to put some delay after bluetooth.begin(9600), to let set its baudrate and then issue print command.
You can enter into the command mode only in 60s after the module is powered on. You can see if the timer is still counting using the status LED(if it blink 2 per second). Sorry for my bad english.
On startup the RN-42 needs 500ms before it can enter command mode try 'delay(500);' before 'bluetooth.begin(115200);' and that should get you there. Also CTS should be tied low
as can be seen on page 45 of the document found at the link below.
https://cdn.sparkfun.com/assets/1/e/e/5/d/5217b297757b7fd3748b4567.pdf
PG 45
"3.3 INTERFACING TO A MICROPROCESSOR
Roving Networks Bluetooth devices can connect to 3.3-V (only) microprocessors using
the UART interface. When interfacing with a microprocessor, use the following guidelines:
• The Bluetooth device power, ground, RX, and TX signals must be connected and
CTS should be held low or tied to RTS.
• The Bluetooth device can go into command mode 500 ms after booting.
• The microprocessor should send $$$ with no carriage return or line feed to enter
command mode.
3.3.0.1 HOW DO I KNOW THE MODULE IS READY FOR COMMAND MODE?
500 ms after rebooting, the module is ready for command mode. You send $$$with no
carriage return.
3.3.0.2 WHICH HARD SIGNALS SHOULD I CONNECT?
You should connect power, ground, RX, and TX. CTS should be low or you can connect
or tie it to RTS."
Related
Hi I am trying to give a website direct on/off control of a usb relay on a chrome os device. In the past I just used some terminal scripts to run on start-up on a ubuntu device but chrome os is giving me a hard time making this work.
Based on the sample Linux code it looks like these devices are using an FTDI USB serial chip and support a very simple set of commands to turn the relays on and off. The FTDI chips are supported by ChromeOS and so you can use the Web Serial API to control the device like this:
let port = navigator.serial.requestPort();
await port.open({ baudRate: 9600 });
let writer = port.writable.getWriter();
writer.write(new Uint8Array([0xff, 0x01, 0x01]); // Turn relay on command.
await writer.close();
await port.close();
This is a very minimal example. You can improve this by passing a filter to requestPort() to select only the USB devices you want. You also don't need to request permission every time. You can call navigator.serial.getPorts() to get a list of ports that your site already has permission to access.
See https://web.dev/serial and https://wicg.github.io/serial for more information about how to use this API.
I'm trying to connect to a BTLE device from Linux from C++ with BlueZ.
Connecting to most devices works fine, but there is a special device which times out with 90% probability. From a standard Android smartphone the connection to this particular device works as intended.
For #Emil's advice in my other question (thanks!) I've setup a Link Layer sniffer tool for further investigation.
During the sniff period I tried connecting to the device(Destination) from both device(Good) and device(Bad).
Device(Good) is working perfectly - it connected
Device(Bad) is not working - timed out
Now I have a Link Layer data of both device connection trials and there is one significant difference between their trials:
Device(Good)'s LL Data for its CONNECT_REQ uses 500 for Timeout value (which is 625ms) while Device(Bad)'s LL Data in CONNECT_REQ uses 42 (which is 52.5ms).
I think Device(Destination)'s response is normally (mostly) arriving between those two, ie after 52.5ms and below 625ms, but sometimes it arrives in less than 52.5ms, and then also BlueZ can connect to it finally.
Is there any possibility to change this Timeout property for CONNECT_REQ in BlueZ? Maybe with setsockopt by any chance?
Or this is something hardcoded into kernel, even for bluetooth adapters attached to USB?
I followed this tutorial for emulating my Raspberry pi model B as a bluetooth Keyboard. I am able to identify the pi as a keyboard when searching for connection.
The pairing part is working fine also, I am using the following command for pairing:
sudo blue-simple-agent hci0 <mac address>
The tutorial asks to run the PiTooth code in one terminal and it will initialise the required ports (control and interrupt ports), read the SDP record, advertise the sdp record and it will listen for connection in the control and interrupt port. Then open another terminal and use the above command to pair with the client.
It is getting paired but it not reflected in the other terminal, which is still like "waiting for connection. The following is the part of the python code where it is listening for connection and connecting:
class Bluetooth:
HOST = 0 # BT Mac address
PORT = 1 # Bluetooth Port Number...
def listen(self):
# Advertise our service record
self.service_handle = self. service.AddRecord(self.service_record)
print “Service record added”
# Start listening on the server sockets
self.scontrol.listen(1) # Limit of 1 connection
self.sinterrupt.listen(1)
print “Waiting for a connection”
self.ccontrol, self.cinfo = self.scontrol.accept()
print “Got a connection on the control channel from “ + self.cinfo[Bluetooth.HOST]
self.cinterrupt, self.cinfo = self.sinterrupt.accept()
print “Got a connection on the interrupt channel from “ + self.cinfo[Bluetooth.HOST]
The whole code is really big and I don't like to enlarge the question. Please view this google doc for the code:
https://docs.google.com/document/d/1hEyprvN1MyFqyczL9Qh07_-pJjRvBIEkomiJhLHcXiQ/edit?usp=sharing
Can anyone help me solve this issue. Or is there any problem with the code. Is there any alternative ways to listen for connection.
The issue is resolved. It was an out-of-box solution actually. The problem was with the operating power of the pi. The pi was powered from my laptop's USB port and it's voltage was about 4.4V. USB ports usually provide only 500 mA, 5 V. Raspberry pi need a voltage source of about 4.75 to 5.25V and current in range of 700 to 1000 mA for optimum performance. Exactly how much current (mA) the Raspberry Pi requires is dependent on what you connect to it. For reference about power supply. I just changed the source, I fetched power via a 1000 mA 5v adapter and checked the voltage in the pi, it was about 4.64V and it worked fine.
I am curently looking to find out wheter it is possible to Bluetooth connect an arduino or similar micro controller to the pebble watch using the RN-42 Sparkfun RN-42 adapter
I currently am having difficulty connecting to the pebble, as the board just times out.
Thanks
The RN-42 can, using bluetooth. The following will get you paired, and the watch MAY accept a ping:
SF,1 //factory reset
SP,9999 //takes care of the pairing code
SM,6 //pairing
SA,4
SY,0000 //power
SW,0640 //sniff mode
R,1 //reset so settings are saved/active and pebble should ask to connect
To pass app messages you need to pass some information to the watch, see http://dexwatch.blogspot.com/2015/12/more-on-pebble.html for the full details.
I want to send some commands to my RN42 Bluetooth Module over the serial port using hterm. But i does not respond. I can connect to the bluetooth modul and the status LED blinks right.
I tried to send $$$ to change to command mode (modul should respond with cmd but does nothing) and 0x00 to disconnect.
Do you guys know what could be wrong?
A couple things that I have run into that you could try:
Ensure that the baud rate of hterm is set to the default 115k
Depending on the firmware version of the RN42 you may have to enter command mode within a one minute time frame. Try power cycling the module and sending the $$$ as soon as possible