I am using two Arduino BT. It works fine and I can upload programs from my Laptop on both of them. They are connected to some circuits and they function properly. Circuits do what they are supposed to do. I see four virtual ports for Rx/Tx.
Now I have two questions:
-1) I am going to connect one Arduino BT to a sensor. I would like to get the data from this Arduino BT which is connected to the sensor back to my Laptop. Do some processing and based on some criteria let a circuit that is connected to the other Arduino BT be on or off.
How can get the data from the sensor back to my Laptop? There is virtual port for the receiving, so I should be capable of receiving the data of the sensor? But I do not know how. It should be wireless.
-2) in the first case the program on my Laptop behaves as a Master. Can I not use my Laptop and let the two Arduino BT communicate together without my Laptop interfering? If yes how (do you have program for it), if this is not possible then why not.
How can get the data from the sensor back to my Laptop?
We'd need to know something about what is paired with what. If the PC and Arduino BT 1 are paired, and the PC and Arduino BT 2 are paired, then Serial.print() on Arduino BT 1 should show up in the Serial Monitor that is paired to the correct COM port.
You can send data to Arduino BT 2 using the Serial Monitor that is paired to the other COM port.
Can I not use my Laptop and let the two Arduino BT communicate together without my Laptop interfering?
You should be able to. I've never used a Arduino BT, but somehow you must have to tell it what to pair with. I presume that now you are telling it to pair with your PC. Tell each Arduino BT to pair with the other one, instead.
I see the four ports on my Laptop.
So in this case I can never read a sensor data from on Arduino BT and after some processing to generate my criteria to turn on a Led on other Arduino board?
Let me make my question simpler. I have first paired with an Arduino BT. This Arduino BT is connected to a simple circuit containing a switch and a Led for indicator. I have uploaded my program. The program works fine since I see the LED turns off and on based on the state of the switch.
I have another Arduino board (no BT). I have connected this board to a simple led circuit. The led get his voltage from a digital pin on the board. My question is now how can I read the state of the switch from Arduino BT and turns on the Led on the second Arduino.
Maybe I cannot do that since I have already lost the paring with original one. So my wireless sensor network does not work?
They jump up and start dancing around on your keyboard, like little fairies?
So in this case I can never read a sensor data from on Arduino BT and after some processing to generate my criteria to turn on a Led on other Arduino board?
Did I say that? I think that you should be able to. It might involve writing an application on the PC that connects the two COM ports that the two Arduino BTs are on.
I thought that the BT link simply replaced the USB cable between the Arduino and the PC (or wires between one Arduino and another). I see no reason why an Arduino BT can not send serial data to a PC on one port, or why the PC couldn't talk to another Arduino (BT or not) on another COM port.
I meant that I see the four virtual ports on the Arduino software environment.
The wireless link between the two Arduino BT is my next project. Let me first get the data on my PC from one Arduino BT which is accessible on virtual serial port.
This is my first program to get the state of the switch; however I do not see anything. As I mentioned the program works fine. It is not surprising since when I activate the Serial Monitor, the monitor shows the virtual port 13 while the incoming data from Arduino BT is from virtual port 14. So I am missing the controlling of the ports somehow.
void loop()
{
Value = digitalRead(Switch);
if(Value == LOW) {
digitalWrite(led, HIGH);
} else {
digitalWrite(led, LOW);
}
delay(1000); // waits for a second
if(Serial.available() > 0) {
Val = Serial.read();
Serial.println('The value of value is');
Serial.println(Val);
}
}
So the problem is that I do not know how to the control these virtual ports in my programs.
Regards
Moody Blues
so this means you have an external pull-up resistor, right? Yes, I have an external circuit which is combination of a switch, and 10k resistor. The state of the pull down resistor is read by digital pin 2.
What is sending this serial data? I thought that the data assigned to Value (state of switch read by digital pin 2) is automatically and already available on the outgoing virtual port of Arduino BT to be read. So maybe this is my mistake. So how can I read the data back to my laptop?
You mean that you don't know how to push the Serial Monitor icon to open the serial monitor? No. I mean I do not know how can I make the data (state of switch available on outgoing virtual port) to be read back to Laptop.
The code you posted sends data back to the PC only when it receives something from the PC first.
Open the Serial Monitor, and type something. Anything. Press send. The Arduino should then start replying with whatever you send.
If you want the Arduino to send the switch state, make it send Value, not Val.
There is really no reason why the PC needs to send anything to the Arduino. Get rid of the Serial.available() test and the Serial.read() call. Just use Serial.print().
I have changed the code. However the Serial Monitor does not display any data.
After uploading the program I have also change virtual port to incoming port (in Arduino editor, under tools) to see if the Serial Monitor display anything. It simply does not. The code looks like this now:
You mentioned that there are 4 serial ports involved when the two Arduino BTs are talking. I'd set each one in turn as the active port, and open the serial monitor for that port. You should end up with 4 of them open. Data should appear in at least one of them.
As I have mentioned before the communication between two Arduino BTs would be my next project.
First step is to try to get data from one Arduino BT on my laptop. I have to build this handshaking first. When BT on laptop is paired with Arduin BT two virtual ports in window is assigned, i.e. one for outgoing- and the other one for incoming data respectively. I have chosen the incoming port and there is no data displayed on Serial Monitor. Two questions:
Is the data assigned to Value in my program available on outgoing virtual port?
If yes then it should be displayed, if not I have to somehow in my program make it available. Do you know how?
Communication between the BT module and the computer can be temperamental. You might want to open the serial monitor a couple of seconds after resetting the board.
I have done the following knowing that virtual ports 13 (outgoing) and 14 (incoming) are assigned by window.
Choose port 13, upload my program. It works fine.
Choose port 14 to display data. He gives me now error that COM14 is already in use. Quit any program that is using it. I have no idea which program is using COM14. The only one is the one that is running. I have also quit that and start new Arduino session; it still gives the same error messages.
He gives list of processes that might be using COM14. such as:
at processing.app.Serial.(Serial.java:144)
** at processing.app.Serial.(Serial.java:91)**
** atprocessing.app.SerialMonitor.openSerialPort(SerialMonitor.java:204)**
** at processing.app.Editor.handleSerial(Editor.java:2415)**
** at processing.app.EditorToolbar.mousePressed(EditorToolbar.java:352)**
** at java.awt.Component.processMouseEvent(Component.java:6260)**
** at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)**
** at java.awt.Component.processEvent(Component.java:6028)**
** at java.awt.Container.processEvent(Container.java:2041)**
** at java.awt.Component.dispatchEventImpl(Component.java:4630)**
** at java.awt.Container.dispatchEventImpl(Container.java:2099)**
** at java.awt.Component.dispatchEvent(Component.java:4460)**
** at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)**
** at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4235)**
** at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)**
** at java.awt.Container.dispatchEventImpl(Container.java:2085)**
** at java.awt.Window.dispatchEventImpl(Window.java:2475)**
** at java.awt.Component.dispatchEvent(Component.java:4460)**
** at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)**
** at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)**
** at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)**
** at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)**
** at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)**
** at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)**
** at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)**
This is very new to me. I have not had this before.