Nick_Pyner:
For starters, you are using software serial on the hardware serial pins 0,1, which is a prettty sure way to disaster. Either get rid of the software serial and use the hardware serial, which seems otherwise unemployed, or move the software serial to another pair of pins.
No comment on Appinventor, except to leave it out of the game for the moment. Use a standard terminal.
You might find the following background notes useful.
Dropbox - GUIDE_2BT.pdf - Simplify your life
Dropbox - BT_2_WAY.ino - Simplify your life
Which pins would be the appropriate pins for software serial? I thought since serial pins were used for communication 0, 1 could have been used. I guess I switched over to 18 and 19?
jubukraa:
It should already be on.... is it?
I'd debug that by losing Bluetooth to start, and checking the led turns off and on by sending a 0 or 1 over Serial from the monitor. Does the led actually come on to start, since it should with the high in setup()? No point checking BT if the led's not working in the first place, and not switching over Serial.
Then if that works, use a simple BT terminal to send the 0 and 1, rather than AppInventor as suggested.
Only then if it's working so far, throw AppInventor into the mix.
Ah, I forgot that I uploaded a different version. Yes, the LED is on with that particular sketch, I was just messing with the HIGH and LOW states and forgot to adjust properly.
What do you mean by a BT terminal? I looked it up and it seemed to a bluetooth app, but nothing is really clear as to how to use it?
EDIT: So I removed the quotation marks from if (dataIn==0), and now the LED won't turn on. I am guessing there wasn't supposed to be any quotation marks to begin with since that would be associated with a char?
HillmanImp:
Hello nongateways.
I think the test your sketch uses does not align with the data type being sent by the app.
The app block responding to a press of the LEDON button sends a one byte integer of value 1. That would be the bit pattern of 00000001. This is not the ASCII character "1", which is bit pattern 0011 0001 (decimal 49).
The sketch test is:
else if (dataIn== '1'){
digitalWrite(ledPin, HIGH);
}
I think this is testing if the value of dataIn is equal to that of the character '1' which is not the same as the numerical value of 1.
Try:
if (dataIn == 1)
Also, since you are sending just one byte, how about defining dataIn as type byte?
Alternatively, you could change the block to send the text "1" and modify the sketch to expect an incoming character, or send "LEDON" and have the sketch receive a string.
Nick knows Bluetooth and serial. Software serial should not use pins 0 & 1.
John.
Hmm so several interesting things happen here. When I do what you suggested (changed "int dataIn" to "byte dataIn", and removed the quotation marks, it still doesn't work, and the LED does not turn on. In the sketch, I have the LED turned on in my setup, but once I make those changes the LED isn't on. I'm currently working on using characters like you said now.
Thanks