Mintoris Forum

Author Topic: (ATMega16) how to send message over bluetooth?  (Read 5598 times)

jdi menya

  • Full Member
  • ***
  • Posts: 27
(ATMega16) how to send message over bluetooth?
« on: Sep 30, 2014, 07:14 AM »
Hello to everyone‼ Sorry if my english is not good. Can you please help me.
i am trying to send message with the program below to my micro ATmega16 with bluetooth module and lcd 16*2. It works ok but it sends no more then first two letters.
Help me please to solve this problem.
thank you all very mach‼

Code: [Select]
a$()=btgetpaired$()

list a$(), d$

print BTGetState(1)
print BTGetError$(1)
print

print "Connecting to: ";d$
 
name$ = ItemExtract$(d$, 0)
address$ = ItemExtract$(d$, 1)

BTConnect 1, address$

for i = 1 to 30
print BTGetState(1);" / ";
print BTGetError$(1)
if BTGetstate(1)=4 then exit for
wait 1000
next i



Top:
input c$
wait 1
BTWriteln 1, c$
goto Top
« Last Edit: Oct 01, 2014, 06:14 PM by Chuck »

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: (ATMega16) how to send message over bluetooth?
« Reply #1 on: Sep 30, 2014, 07:20 AM »
Could you post the micro ATmega16 code?

-Chuck

jdi menya

  • Full Member
  • ***
  • Posts: 27
Re: (ATMega16) how to send message over bluetooth?
« Reply #2 on: Sep 30, 2014, 07:26 AM »
Hello, Chuck‼ Thank you very much for such a good program Mintoris basic‼ I will post mega16 code in few minutes‼

jdi menya

  • Full Member
  • ***
  • Posts: 27
Re: (ATMega16) how to send message over bluetooth?
« Reply #3 on: Sep 30, 2014, 07:56 AM »
Code: [Select]
$regfile = "m16def.dat"

$crystal = 8000000

 $baud = 19200

Config Lcdpin = Pin , Rs = Portc.0 , E = Portc.1 , Db4 = Portc.2 , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5

Config Lcd = 16 * 2

 Const False = 0

Const True = 1

 

' Variables

 

  Dim Char As Byte

  Dim I As Byte

   Dim Message As String * 20

Dim Buffer As String * 20

Dim Received As Bit

Message = ""

Received = False

 

'program starts here

Cls

Cursor Off

Lcd "AVR Data"

 On Urxc Priem

  Enable Interrupts

  Enable Urxc

Do

 

Loop

 End

 Priem:

   Cls

Char = Inkey()                                          'see if there is a character

   If Char > 0 Then                                         'if there is

      If Char = 13 Then                                     'if its a Carriage return

         Nop                                                'ignore it

      Elseif Char = 10 Then                                 'if Linefeed (signals end of message)

         Message = Buffer                                   'copy to output

         Buffer = ""                                        'release the buffer

         Received = True                                    'signal we have the complete string

      Else

         Buffer = Buffer + Chr(char)

         Incr I                                             'add new char to buffer

      End If

   End If

 

   If Received = True Then

      'display the incoming message on the LCD

 

      Locate 1 , 1

      Lcd Message

      Locate 2 , 1

      Lcd I

  End If

 

  Return

« Last Edit: Sep 30, 2014, 06:45 PM by Chuck »

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: (ATMega16) how to send message over bluetooth?
« Reply #4 on: Sep 30, 2014, 08:15 AM »
     Locate 1 , 1

      Lcd Message

      Locate 2 , 1

      Lcd I

     Received = False


Try putting in the above Received = False after you display the lcd. And don't you need to put all the receive code inside the loop?

I'll check back in tomorrow.

-Chuck
« Last Edit: Sep 30, 2014, 08:16 AM by Chuck »

jdi menya

  • Full Member
  • ***
  • Posts: 27
Re: (ATMega16) how to send message over bluetooth?
« Reply #5 on: Sep 30, 2014, 08:56 AM »
Thank  you‼  I will try it in the evening after work.

jdi menya

  • Full Member
  • ***
  • Posts: 27
Re: (ATMega16) how to send message over bluetooth?
« Reply #6 on: Sep 30, 2014, 03:50 PM »
I try to change the ATmega code in different ways and nothing changes. :(

jdi menya

  • Full Member
  • ***
  • Posts: 27
Re: (ATMega16) how to send message over bluetooth?
« Reply #7 on: Sep 30, 2014, 04:02 PM »
By i found next thing‼ If i send "q", i get "q" on  lcd. If i send "qw", i get "qw" on lcd. If i send "qwe" or "qwer" or "qwert" and so on, i get "qw" on lcd. BUT if i send "qwertyuiopas", i get "qws" on my lcd. And if i send about 50 simbols  i get four simbols on lcd…‥   thank you for any comments.

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: (ATMega16) how to send message over bluetooth?
« Reply #8 on: Sep 30, 2014, 05:01 PM »
Try reducing the baud rate. I think the problem is on the ATmega side.

jdi menya

  • Full Member
  • ***
  • Posts: 27
Re: (ATMega16) how to send message over bluetooth?
« Reply #9 on: Sep 30, 2014, 05:58 PM »
Thank you, Chuck‼  I was thinking about it and change it, but i got nothing at all on lcd. But 5 min ago i did it‼ I get all simbols on lcd. But if its too much of them, the lcd gets blink. But i think for what i want to do, its not a problem.

jdi menya

  • Full Member
  • ***
  • Posts: 27
Re: (ATMega16) how to send message over bluetooth?
« Reply #10 on: Sep 30, 2014, 06:28 PM »
Code: [Select]
$regfile = "m16def.dat"

$crystal = 8000000

 $baud = 19200

Config Lcdpin = Pin , Rs = Portc.0 , E = Portc.1 , Db4 = Portc.2 , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5

Config Lcd = 16 * 2

Config Serialin = Buffered , Size = 100

Const False = 0

Const True = 1

  Dim Char As Byte

  Dim I As Byte

   Dim Message As String * 100

Dim Buffer As String * 100

Dim Received As Bit

Message = ""

Received = False

Cls

Cursor Off

Lcd "AVR Data"

Enable Interrupts

   Do

  Char = Inkey()                                          'see if there is a character

   If Char > 0 Then                                         'if there is

      If Char = 13 Then                                     'if its a Carriage return

         Nop                                                'ignore it

      Elseif Char = 10 Then                                 'if Linefeed (signals end of message)

         Message = Buffer                                   'copy to output

         Buffer = ""                                        'release the buffer

         Received = True                                    'signal we have the complete string

      Else

         Buffer = Buffer + Chr(char)

         Incr I                                             'add new char to buffer

      End If

   End If

     If Received = True Then

      'display the incoming message on the LCD

         Cls

      Locate 1 , 1

      Lcd Message

      Locate 2 , 1

      Lcd I

 

  End If

  Waitms 50

 Loop

 End
i want to make a rgb running string with bluetooth, so i can send some text to it from a phone. Why rgb running string ? Because i get a lot of rgb smd leds for free  :D and now i am making rgb moduls 8*8 rgb leds + 74hc595. Already made one and wil try to get message on it from a phone. Why with bluetooth? Because i like mintoris basic program. It is easyest program to learn and understand basic programming

« Last Edit: Sep 30, 2014, 06:45 PM by Chuck »

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: (ATMega16) how to send message over bluetooth?
« Reply #11 on: Sep 30, 2014, 06:43 PM »
Ah, I see. You took out the interrupt and just received the bluetooth data in the main loop. That means you were getting characters faster than the interrupt could be triggered. You still need to put in the Received = False.

I think the interrupt method would work if you read all the chars that are waiting instead of just one char at a time. When the interrupt is triggered, there may be more than one character waiting to be read. If, when the interrupt triggers you only read one character, then you will loose characters.

-Chuck.

jdi menya

  • Full Member
  • ***
  • Posts: 27
Re: (ATMega16) how to send message over bluetooth?
« Reply #12 on: Sep 30, 2014, 07:05 PM »
Config Serialin = Buffered , Size = 100
i find this in BASCOM help. I think it uses interrapt for UART buffer or something. So i had to put all code to main.

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: (ATMega16) how to send message over bluetooth?
« Reply #13 on: Sep 30, 2014, 07:08 PM »
I think the interrupt should work in a loop like I have below. Loop once for each character available.

Code: [Select]
Priem:

  Cls

  Char = Inkey()                                   ' See if there is a character
  ' You may have to fix the while loop.
  ' I wasn't sure about syntax.
  Do While Char > 0                              ' Loop while there are characters to be read.

    If Char = 13 Then                             ' if its a Carriage return
      Nop                                               ' ignore it
    Elseif Char = 10 Then                        ' if Linefeed (signals end of message)
      Message = Buffer                            ' copy to output
      Buffer = ""                                      ' release the buffer
      Received = True                              ' signal we have the complete string
    Else
      Buffer = Buffer + Chr(char)
      Incr I                                              ' add new char to buffer
    End If

    If Received = True Then

      'display the incoming message on the LCD
      Locate 1 , 1
      Lcd Message
      Locate 2 , 1
      Lcd I
      Received = False

    End If

    Char = Inkey()                                          'see if there is a character
  Loop

Return

jdi menya

  • Full Member
  • ***
  • Posts: 27
Re: (ATMega16) how to send message over bluetooth?
« Reply #14 on: Sep 30, 2014, 07:10 PM »
While i was thinking how to write in english, you wrote a new post. I am too slow :(  i will try your code now. Thank you‼

jdi menya

  • Full Member
  • ***
  • Posts: 27
Re: (ATMega16) how to send message over bluetooth?
« Reply #15 on: Sep 30, 2014, 07:51 PM »
Code: [Select]
Priem:

  Cls

  Char = Inkey()                                   ' See if there is a character
  ' You may have to fix the while loop.
  ' I wasn't sure about syntax.
   While Char > 0                              ' Loop while there are characters to be read.

    If Char = 13 Then                             ' if its a Carriage return
      Nop                                               ' ignore it
    Elseif Char = 10 Then                        ' if Linefeed (signals end of message)
      Message = Buffer                            ' copy to output
      Buffer = ""                                      ' release the buffer
      Received = True                              ' signal we have the complete string
    Else
      Buffer = Buffer + Chr(char)
      Incr I                                              ' add new char to buffer
    End If

    If Received = True Then

      'display the incoming message on the LCD
      Locate 1 , 1
      Lcd Message
      Locate 2 , 1
      Lcd I
      Received = False

    End If

    Char = Inkey()                                          'see if there is a character
  wend

Return
« Last Edit: Oct 01, 2014, 06:25 PM by Chuck »

jdi menya

  • Full Member
  • ***
  • Posts: 27
Re: (ATMega16) how to send message over bluetooth?
« Reply #16 on: Sep 30, 2014, 07:55 PM »
Thank you, Chuck‼ Your code warking best‼ I just delete DO and write WEND instead of LOOP.  And its not blinking now.

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: (ATMega16) how to send message over bluetooth?
« Reply #17 on: Sep 30, 2014, 08:38 PM »
If that Cls command clears the LCD, then you want to move it down inside the If Received = True Then like I did below.


    If Received = True Then

      Cls
      'display the incoming message on the LCD
      Locate 1 , 1
      Lcd Message
      Locate 2 , 1
      Lcd I
      Received = False

    End If

jdi menya

  • Full Member
  • ***
  • Posts: 27
Re: (ATMega16) how to send message over bluetooth?
« Reply #18 on: Sep 30, 2014, 09:20 PM »
Sorry‼ I copied an old code and forgot to change that. In my mega16 i have code with all your notes. Thank you‼
I took a code from one bascom teaching book and change it to be suitable for my 8*8 rgb matrix +74hc595.  And i dont no how, but it works  ;D but in that code to see message on running string i have to change variable and reprogramm chip.
in code i just have:
A="hello"
So i will be trying to put two codes together. I dont no how, but i will do it…

kistakalindra

  • Newbie
  • *
  • Posts: 1
Re: (ATMega16) how to send message over bluetooth?
« Reply #19 on: Feb 12, 2015, 07:37 AM »
@jdi menya…thanks for the code and the update  :)