hey all;
i ve created a code that connects web-server to arduino uno. then i ve tried to upgrade it using BT shield but things got messy during the process.
my problem is that the receiver started so well but am still having a problem with the transmitter. it turns on and keeps on since i connect the power without transmitting anything.
1 other thing the when i disconnect the the arduino then reconnect it again. sometimes the code doesn't work. or acts weird? is that normal ?
/*
* IRremote: IRsendDemo - demonstrates sending IR codes with IRsend
* An IR LED must be connected to Arduino PWM pin 3.
* Version 0.1 July, 2009
* Copyright 2009 Ken Shirriff
* http://arcfn.com
*/
//16455911
#include <IRremote.h>
#include <SoftwareSerial.h> //Software Serial Port
IRsend irsend;
#define RxD 2
#define TxD 3
SoftwareSerial Bt(RxD,TxD);
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
String readString;
long unsigned value;
void setup()
{
Serial.begin(9600);
pinMode(RxD, INPUT);
pinMode(TxD, OUTPUT);
irrecv.enableIRIn(); // Start the receiver
bluetoothInitiate();
}
void bluetoothInitiate(){
// this part is copied from the Seeeduino example*
Bt.begin(38400); // this sets the the module to run at the default bound rate
Bt.print("\r\n+STWMOD = 0\r\n"); //set the bluetooth work in slave mode
Bt.print("\r\n+STNA=Spartan\r\n"); //set the bluetooth name as "SeeedBTSlave"
Bt.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
Bt.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
delay(50); // This delay is required.
Bt.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable
delay(50); // This delay is required.
Bt.flush();
Bt.println("Bluetooth connection established correctly!"); // if connection is successful then print to the master device
}
String Buffer;
void loop() {
//delay(50);
while(Bt.available() && Serial.read() == '0') {//Serial
//Serial.print("Transmitting");
while (Serial.available() == 0) {//Serial
}
delay(50);
while (Serial.available() > 0 ) {//Serial
}
Buffer = (String)Bt.read();//Serial
//value = Buffer.toInt();
Serial.println(value);
Bt.println(value); //Serial.println
//for (int i = 0; i < 3; i++) {
// irsend.sendNEC(value,32);
// delay(40);
//}
Buffer = "";
irrecv.enableIRIn(); // Start the receiver
}
if (irrecv.decode(&results)) {
Bt.println("Receiving");//Serial
Serial.println(results.value);
Bt.println(results.value);
irrecv.resume();
}
}
Why are you using while loops and why do you have while loops that do absolutely nothing? What updates "value" now that you commented out the line that is supposed to update it? And don't use Strings, there is no need to be using them. If you need to change the incoming chars to an int then use this:
HazardsMind:
Why are you using while loops and why do you have while loops that do absolutely nothing? What updates "value" now that you commented out the line that is supposed to update it? And don't use Strings, there is no need to be using them. If you need to change the incoming chars to an int then use this:
value = value * 10 + (Buffer - '0' );
When you're done with it, set value back to zero.
can u please show me what u meant in code? cause am kinda got lost and i think amn't getting u right
void loop() {
//delay(50);
if(Bt.available() && Serial.read() == '0') //Serial
{ //Serial.print("Transmitting");
Buffer = Bt.read();//Serial
value = value *10 +(Buffer - '0');
Serial.println(value);
Bt.println(value); //Serial.println
value = 0;
irrecv.enableIRIn(); // Start the receiver
}
if (irrecv.decode(&results))
{
Bt.println("Receiving");//Serial
Serial.println(results.value);
Bt.println(results.value);
irrecv.resume();
}
}
but u didn't declare the type of value? also will the serial.read take what is written from the serial monitor by BT? does the BT shield send the whole string at one or character by character?
No. You should read up on the differences between Serial and Software Serial, and how they work. You are not going to see anything from the BT module unless you say Serial.println( Bt.read() );
HazardsMind:
No. You should read up on the differences between Serial and Software Serial, and how they work. You are not going to see anything from the BT module unless you say Serial.println( Bt.read() );
Dear Sir. what am trying to do is transmitting the code through IR LED which is being send by B.T shield using SSCOM3.2
while(Bt.available() && Bt.read() == 0 ) {
Bt.print("Transmitting");
while (Bt.available() == 0) {
}
delay(50);
while (Bt.available() > 0 ) {
readString += (char)Bt.read();
}
value = readString.toInt();
Serial.println(value);
Bt.println(value); //Serial.println
for (int i = 0; i < 3; i++) {
irsend.sendNEC(value,32);
delay(40);
}
readString = "";
My condition is simple. if the first character the shield receive is being 0 then enter the transmitting mode, go in a while loop till u finish reading the whole string "bt.available> 0" save it to variable "value" then transmit "value". if the 1st character isn't 0 then go to the receiving mode and start detecting what is being send. ( the receiving works perfectly "
my problem now is that SCOM3.2 doesn't allow me to send and the IDE 1.0.5 lags when trying to connect to the Bluetooth port. so am n't sure if it's transmitting problem issue or SSCOM3.2?
any help is appreciated, also if u would like to modify it please do
It's most likely is the SSCOM3.2.
When you try to transmit, you should see on your screen a message " bluetooth connection was established", do you ever see this? From what I saw, a lot of people were having issues with that shield. Some were saying it wasn't compatible with their Arduino, another said he solved it by reversing the TX and RX in the code and for the rest, it still did not work.
I'm sure you played with the example codes to see if your IR is working, right? Start by getting one piece to work, at a time then combine them. Make sure everything works indepently first then begin to add more.