bluetooth with ATMEGA 16

Go To Last Post
19 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi all, I need help on receiving data from android to atmega16 through HC-05 bluetooth module... here is the code...

void takes()
{
  lcd_putsf("start");
  G =getchar();
  delay_ms(50);
  lcd_clear();
  sprintf(buf,"%d",G);
  lcd_puts(buf);
  delay_ms(50);
  takes();
}

it's a function that would be run continuous... both my android and atmega run in 9600 baud rate, no parity, 1 bit stop, 8 data

all data type brings no error so do the compiler

but when I send "a" (without quotation) from my android, i get 216 decimal in my LCD... I thought it should be 97 according to ASCII

how come is it?? why do i get 216 rather than 97??

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I may be able out of the ball park with this, but it sounds more like a general question you could ask the general AVR guys.

 

First off I would either echo back the byte or debug on the micro before it his the LCD to identify where the issue lies, whether its the bluetooth comms, some sort of component micro misassignment of a variable, or the LCD code/module.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks for your suggestion, but it's not about the LCD, because when i use data (216 decimal) to turn on the light it's working properly , so why i send "a" from androi to Atmega 16 and i got 216 decimal not 97 decimal ??

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So from my understanding you're sending a single character 'a' from an android device. The transmission goes:

Android (bluetooth transmitter) -> HC-05 (bluetooth receiver) (UART Transmitter) -> Atmega16 (UART Receiver) -> LCD

 

Despite your backlight illuminating with an original command of 216, you need to debug what happens with your 97. How do you know your 97 is not working?

 

Have you verified that your 97 has reached your Atmega16 correctly? Just beacuse you can see another transfer works, does not necessarily mean this one will.

 

How do you know it is not working? do you see the equivalent of 216 display on the LCD.

 

Have you tried sending something else as well? It seems both examples you're sending both result in 216. Perhaps you have not assigned this variabled correctly.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've tried this simple program

 

char G, buf[33];

G='a';

sprintf(buf,"%d",G);

lcd_puts(50);

delay_ms(50);

 

And the output to my LCD is 97, due to "a" ASCII

It means that my ATmega 16 is worked properly

I also tried to see "a" when sent through bluetooth and showed it to my LCD. It showed (seems like) Japanese character

I tried sending another character like "b","c","d" and showed it to my LCD. It showed 217,217,218.

Do I miss something??

Thanks for your reply anyway

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do you have any other interface to your atmega16 besides the LCD? Perhaps send the same letters from that interface to your LCD and see if it does the same thing?

 

Or even read the characters back through this interface?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thx for your reply, i think my LCD is alright , because i send a siimpel data without bluetooth and i get a fine data, but '216' decimal , what it's mean ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@dwi cahya m 

Sorry, but I didn't got your question in the first post. It will be help if you can post the functions used in the code u mentioned. 

Right now, I am also working on library for HC-05 Bluetooth Module. Once it gets complete I will post online. 

 

Happy Learning, 

ANKITKUMAR CHHEDA

MTech Scholar,

College of Engineering, Pune (COEP)

 

<Joined FORUM in 2009 to seek help, now back on FORUM to HELP>

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

dwi cahya m wrote:

hi all, I need help on receiving data from android to atmega16 through HC-05 bluetooth module... here is the code...

void takes()
{
  lcd_putsf("start");
  G =getchar();
  delay_ms(50);
  lcd_clear();
  sprintf(buf,"%d",G);
  lcd_puts(buf);
  delay_ms(50);
  takes();
}

it's a function that would be run continuous... both my android and atmega run in 9600 baud rate, no parity, 1 bit stop, 8 data

all data type brings no error so do the compiler

but when I send "a" (without quotation) from my android, i get 216 decimal in my LCD... I thought it should be 97 according to ASCII

how come is it?? why do i get 216 rather than 97??

Is this ALL your code?  It would help if you post all of it.  use the <> button in the upper right to post code.

 

takes();

NEVER call the function you are already in!  If you want this function to run forever then do this:

while(1)
{
  lcd_putsf("start");
  G =getchar();
  delay_ms(50);
  lcd_clear();
  sprintf(buf,"%d",G);
  lcd_puts(buf);
  delay_ms(50);
 
}

I get the feeling there is more at issue here, but without seeing the whole program there is little that anyone can effectively do.

 

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jgmdesign wrote:
NEVER call the function you are already in!

It's called recursion.

 

"NEVER" is a long time; recursion can be appropriate in some circumstances - but you should certainly never do it without some limit on the recursion!

 

surprise

 

The trouble with recursion is that it's a great way to use up a huge amount of stack very quickly and crash any machine - even more so a little 8-bit microcontroller with very limited RAM!!

 

I get the feeling there is more at issue here, but without seeing the whole program there is little that anyone can effectively do.

Indeed. 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It's called recursion.

Yeah, I know.  I could not think of it at the time.  Thanks.

 

But as you know we have had this discussion elsewhere and as you noted recursion is an easy way to take out an 8bit micro with limited resources.

 

 

recursion - it's like deja-vu all over again....

 

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes: recursion is the classic textbook solution to things like factorials & directory tree searches - but quickly fails in the Real World when the student fails to understand the implications!

 

But, in this case, I think the recursion is entirely accidental...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes: recursion is the classic textbook solution to things like factorials & directory tree searches - but quickly fails in the Real World when the student fails to understand the implications!

 

But, in this case, I think the recursion is entirely accidental...

 

Truly said when students fails to understand the recursion. 

 

1   void takes()
2   {
3    lcd_putsf("start");
4    G =getchar();
5    delay_ms(50);
6    lcd_clear();
7    sprintf(buf,"%d",G);
8    lcd_puts(buf);
9    delay_ms(50);
10   takes();
11   }

" takes()" on 10th line of the code will fill the stack very soon, instead, in my personal opinion, you should consider using "do-while" or simply "while" loop. 

 

Another thing which I am unable to get is, in line 7, variable 'buf'.. what data it holds. its really unfortunate to see that you seeking help without disclosing any of your code details even after asking by many members on the forum. This way no-one will understand what you are doing in your codes. All I can suggest is search (google) for 'ABLAB' article of "HC-05 interfacing with Atmega16 <CLICK HERE>" and find the libraries and codes given on the website. 

 

Disclaimer : 

I am in no-way associated with ABLABs. 

Happy Learning, 

ANKITKUMAR CHHEDA

MTech Scholar,

College of Engineering, Pune (COEP)

 

<Joined FORUM in 2009 to seek help, now back on FORUM to HELP>

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thx for your replys, i just want to know why "a " in ASCI code is 216 decimal rather than 97?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

recently even I had my hands on the HC-05. 

Make sure in your are coding your microcontroller (MCU) for 8-bit, EVEN Parity, 2 Stop bits. 

Check with this UART mode/method and let me know it works or not. 

Happy Learning, 

ANKITKUMAR CHHEDA

MTech Scholar,

College of Engineering, Pune (COEP)

 

<Joined FORUM in 2009 to seek help, now back on FORUM to HELP>

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dwi cahya m wrote:

thx for your replys, i just want to know why "a " in ASCI code is 216 decimal rather than 97?

WE do not know why because you are not posting your ENTIRE code.  If it is so large then post the .c file.

 

We are not mind readers.

 

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dwi cahya m wrote:

thx for your replys, i just want to know why "a " in ASCI code is 216 decimal rather than 97?

This is happening because you are not sending /r /n from the hc05 module. The ablab tutorial has it all.

Happy Learning, 

ANKITKUMAR CHHEDA

MTech Scholar,

College of Engineering, Pune (COEP)

 

<Joined FORUM in 2009 to seek help, now back on FORUM to HELP>

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I wonder if (s)he's really still waiting for that reply after 14 months ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...