News:

;) This forum is the property of Proton software developers

Main Menu

PIC 18F26K22, DS3231 and bluetooth

Started by GERARD, Jun 12, 2024, 07:06 PM

Previous topic - Next topic

GERARD

Hello,
For a future project, I would like to know how to communicate between my telephone and a HC05 or 06 module.
The aim is to be able to update an RTC by telephone.
Thank you in advance for your help.
I am the happy grandpa of twins

Pepe


GERARD

Thanks for your quick reply.
I would especially like to know how to manage the software side of the PIC.
I have Bluetooth Electronics on my phone.
https://www.keuwl.com/apps/bluetoothelectronics/
I am the happy grandpa of twins

Pepe

You have to connect it to the tx and rx of the pic, the hc connects to 5v but the rx and tx lines use 3.3v levels, therefore connect a resistive divider to the tx of the pic, the tx output of the hc06 can be connected directly to the pic, default communication is at 9600 baud.

GERARD

Thanks for the information.
And on the PIC side, which instruction should I use? I've never used a serial port.
I am the happy grandpa of twins

Pepe

this is an example

GERARD

It's downloaded.
I'll look into it.
Thank you so much for your time.
I am the happy grandpa of twins

GERARD

Hello,
I've tried several times and can't get anywhere.
What instruction should I use to turn on a LED if I send "1" and turn it off if I send "0"?
In the example you give, there's HRSOutLn.
 bVar1 = HRSIn, {1000, Timeout} ' Receive a byte serially into Var1
HRSOutLn Dec bVar1 ' Display the byte received
Where is bVar1 displayed?

Thanks for any help.
I am the happy grandpa of twins

Pepe

#8
Demo Proteus

Send by Bluetooth

ON + 13  to turn on Led
OFF + 13 to turn off Led

Device = 18F26K22
Declare Xtal = 64
Declare Optimiser_Level = 3
Declare Bootloader off
Declare Create_Coff On
Declare Reminders off
Declare Watchdog off
Declare Hserial_Baud = 9600 ' Set the Baud rate for HRsoutLn
Declare Hserial_Clear = On ' Clear the buffer before receiving
Symbol PLLEN = OSCTUNE.6 ' PLL enable
Symbol PLLRDY = OSCCON2.7 ' PLL run status

Symbol LED PORTB,0
Symbol enter = 13

Dim Var1 As Byte
Dim dato As String * 3

 OSCCON = $7c
 PLLEN = 1                                    ' Enable PLL 4x 16MHz = 64Mhz

 While PLLRDY = 0 : Wend

 TRISB = 0

Do
Var1 = HRSIn, {1, Continue}  ' Receive a byte serially into Var1

 Select Case Var1
 
    Case enter
      If dato = "ON" Then
                           LED = 1
                           HRSOutLn "Led on"
      ElseIf dato = "OFF" Then             
                           LED = 0
                           HRSOutLn "Led off"
      End If     
      dato =  ""
 
    Case Else
      dato = dato +  Var1
 
 End Select

Loop ' Loop forever


;-------------------------------------------------------------------------------
;**** Added by Fuse Configurator ****
; Use the Fuse Configurator plug-in to change these settings

;Device = 18F26K22

Declare Reminders Off
@ CONFIG_REQ = 0 ; Override Compiler's configuration settings
Asm-
Config FOSC = INTIO67 ;Internal oscillator block
Config PLLCFG = OFF ;Oscillator used directly
Config PRICLKEN = On ;Primary clock enabled
Config FCMEN = OFF ;Fail-Safe Clock Monitor disabled
Config IESO = OFF ;Oscillator Switchover mode disabled
Config PWRTEN = On ;Power up timer enabled
Config BOREN = OFF ;Brown-out Reset disabled in hardware and software
Config BORV = 190 ;VBOR set to 1.90 V nominal
Config WDTEN = OFF ;WDT is disabled
Config WDTPS = 256 ;1:256
Config CCP2MX = PORTC1 ;CCP2 input/output is multiplexed with RC1
Config PBADEN = OFF ;PORTB<5:0> pins are configured as digital I/O on Reset
Config CCP3MX = PORTB5 ;P3A/CCP3 input/output is multiplexed with RB5
Config HFOFST = OFF ;HFINTOSC output and ready status are not delayed by the oscillator stable status
Config T3CMX = PORTB5 ;T3CKI is on RB5
Config P2BMX = PORTB5 ;P2B is on RB5
Config MCLRE = INTMCLR ;RE3 input pin enabled; MCLR disabled
Config STVREN = OFF ;Stack full/underflow will not cause Reset
Config LVP = OFF ;Single-Supply ICSP disabled
Config XINST = OFF ;Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
Config Debug = OFF ;Disabled
Config Cp0 = On ;Block 0 (000800-003FFFh) code-protected
Config CP1 = On ;Block 1 (004000-007FFFh) code-protected
Config CP2 = On ;Block 2 (008000-00BFFFh) code-protected
Config CP3 = On ;Block 3 (00C000-00FFFFh) code-protected
Config CPB = On ;Boot block (000000-0007FFh) code-protected
Config CPD = OFF ;Data EEPROM not code-protected
Config WRT0 = On ;Block 0 (000800-003FFFh) write-protected
Config WRT1 = On ;Block 1 (004000-007FFFh) write-protected
Config WRT2 = On ;Block 2 (008000-00BFFFh) write-protected
Config WRT3 = On ;Block 3 (00C000-00FFFFh) write-protected
Config WRTC = On ;Configuration registers (300000-3000FFh) write-protected
Config WRTB = On ;Boot Block (000000-0007FFh) write-protected
Config WRTD = OFF ;Data EEPROM not write-protected
Config EBTR0 = OFF ;Block 0 (000800-003FFFh) not protected from table reads executed in other blocks
Config EBTR1 = OFF ;Block 1 (004000-007FFFh) not protected from table reads executed in other blocks
Config EBTR2 = OFF ;Block 2 (008000-00BFFFh) not protected from table reads executed in other blocks
Config EBTR3 = OFF ;Block 3 (00C000-00FFFFh) not protected from table reads executed in other blocks
Config EBTRB = OFF ;Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
Endasm-
Declare Reminders On

;**** End of Fuse Configurator Settings ****
;-------------------------------------------------------------------------------

GERARD

Hello,
Thank you for this code.
I have a busy weekend, the twins are at home.
I promise, next week I'll try your program.
Thanks again.
I am the happy grandpa of twins

Pepe

apk added

Pepe

video demo bluetooth

GERARD

Hello,
First of all, thank you for your help.
I'm sorry, I don't have the time, I haven't tried it yet. Hopefully next week I'll be able to give some good news.
Have a good weekend.
I am the happy grandpa of twins

GERARD

Hello,
I managed to turn on and off an LED with bluetooth electronic.
I'm going to try again to transmit more data.
Thanks again for your help.
I am the happy grandpa of twins