Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC18F4553 and bluetooth

Status
Not open for further replies.

hayawana

Member level 1
Member level 1
Joined
Apr 10, 2013
Messages
35
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Visit site
Activity points
1,524
Good morning everyone,

I've already done an analog to digital conversion on my PIC18f4553, and try to transmit the digital signals over a Bluetooth module RN-42.
But before that i have to encode the following steps? Does anybody have any idea how do I write the coding (i use mikroelectronika) ?

1 - If you turn on the power, the buzzer sends a beep.
2 - the pin RC0 which copies what happens on pin GPIO2 bluetooth connection goes one the ledRD1 goes one and the RD0 relay goes one toor, otherwise 0 connection off then ledRD2 goes on, send 0 on relay

I join the design on proteus. while testing the transmission i used virtual terminal. This might be easy for some of them but I am completely disoriented

thanks
 

Attachments

  • queries.jpg
    queries.jpg
    187.9 KB · Views: 91

okay done. I sent you a part of the datasheet for the pin GPIO2 bluetooth, I connected with the pin RC0 peak to see the status of the Bluetooth connexion.
 

Attachments

  • forum.zip
    101.4 KB · Views: 60

Your connection is wrong if you want to send adc data through bt. As you are using UART to send data your bt's UART Rx pin should be connected to uC UART Tx pin. Make sure that both your uC and bt module works at the same voltage. See attached code. The lowbyte and highbyte of adc result is sent over UART Tx line to bt. If you want to send string then make necessary calculations on the raw adc value and then convert the final result to string using IntToStr() or FloatToStr() and then use UART1_Write_Text(str); to send the adc value to bt module.

If you have any other problem them mention it clearly.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
unsigned int conversion1;
unsigned char lowbyte;
unsigned char highbyte;
void main()
{
 int i= 0;
/////////Initialization//////////////////
  ADCON1=0x03;      //VSS,VDD, ALL ANi are analog except for AN12
  ADCON2=0xAD;      //Right justified,  12TAD, 16TOSC
  TRISA=0xFF;       // set trisA as inputs
  TRISE=0b1111;    // set trisE as inputs
 
  UART1_Init(9600);     // Initialize hardware UART1 and establish communication at 9600 bps
  Delay_ms(100);        // Wait for UART module to stabilize
 /////////ADC CONVERSION///////////////////
           while(1)
        {
            for( i=0 ;i<7;i++)
              {
                  conversion1 = ADC_Read(i);  // Read analog value from channel 0  to 6
                  
                  lowbyte =  conversion1;
                  highbyte= conversion1 >> 8;
                  UART1_Write(lowbyte);
                  UART1_Write(highbyte);
                  delay_100ms() ;
                  delay_100ms() ;
                  delay_100ms() ;
                  delay_100ms() ;
                  delay_100ms() ;
                  delay_100ms() ;
              }
        }
}

 

Okay i see. But i think its correct cause my TX pin of pic is connected to RXD of bluetooth . (the bluetooth runs on 3 TO 3.3v and pic from 0 to 5).
But my question is how can i add this steps to my code:
1 - If you turn on the power, the buzzer sends a beep.
2 - the pin RC0 which copies what happens on pin GPIO2 bluetooth connection goes one the ledRD1 goes one and the RD0 relay goes one toor, otherwise 0 connection off then ledRD2 goes on, send 0 on relay
 

If you want to send a beep for 2 or 3 seconds when uC is started then you can do like this


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#define LED1 RD1_bit        //LED1 connected to RD1
#define LED2 RD2_bit        //LED2 connected to RD2
#define Relay RD0_bit       //Relay connected to RD0
#define Buzzer RD6_bit      //Buzzer connected to RD6
#define BTSense RD5_bit //assuming GPIO2 of bt is connected to input pin RD5 of uC
 
void main(){
 
        
    Buzzer = 1;
    Delay_ms(3000);
        Buzzer = 0;
 
 
    while(1){
 
 
        if(BTSense){
 
            LED1 = 1;
            Relay = 1;
 
        }
        else if(!BTSense){
            
            LED1 = 0;
            Relay = 0;
            LED2 = 1;
        }
 
 
    }
 
 
}

 

thank you very much for helping me.
But it doesnt work on simulation in proteus i've just replaced RD6 by RD7 like on the image and GPIO2 to RC0 of pic.
#define Buzzer RD7_bit //Buzzer connected to RD7
#define BTSense RC0_bit //assuming GPIO2 of bt is connected to input pin RC0 of uC

i assign the value 0 or 1 to GPIO2
 

Thanks a lot sir. The relay and LED's are working but the buzzer makes a garbled and infinite sound.
Can you check if I connected correctly the buzzer to the pic?
 

okay there's 2 files one with the adc and uart(not finished yet) and the other the one you gave me. I dont understand why the buzzer does not beeps and stOPs?
 

Attachments

  • forum_pic.zip
    52.4 KB · Views: 56

great amazing !! thank you sir. ive seen sound library , can we make a beautiful tone with simulation?
 

im only talking about the sound library used in mikroC where you can find
// Initialize the pin RD7 for playing sound
Sound_Init(&PORTD, 7);
// Play sound of 1KHz in duration of 100ms
Sound_Play(1000, 100);
I tought that i could use it to make a great bip because with the simulation its a annoying . I dont know if its gonna be the same tonality in reality with a piezo buzzer

- - - Updated - - -

I think the coding for buzzer does not work because even when i comment it, the buzzer still give me a sound. 8-O
 

Good morning,

okay if you say so. But, as soon as I enable the simulation, the buzzer emitts an infinite sound for about 6 seconds, even if I commented that part of the code that controls the buzzer works.
 

it's the same one that you gave me :oops:. i simulate the one you gave me.

- - - Updated - - -

I've sent you a private message. Thnx again.
 


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#define LED1 RD1_bit        //LED1 connected to RD1
#define LED2 RD2_bit        //LED2 connected to RD2
#define Relay RD0_bit       //Relay connected to RD0
#define Buzzer PORTD.F7      //Buzzer connected to RD7
#define BTSense RC0_bit     //assuming GPIO2 of bluetooth is connected to input pin RC0 of uC
 
 
unsigned char lowbyte;
unsigned char highbyte;
]unsigned int result[7];
 
void main()
{
 int i= 0;
 
/////////Initialization//////////////////
  ADCON1=0x03;      //VSS,VDD, ALL ANi are analog except for AN12
  ADCON2=0xAD;      //Right justified,  12TAD, 16TOSC
  TRISA=0xFF;       // set trisA as inputs
  TRISE=0b1111;    // set trisE as inputs
  TRISD=0x00;
  TRISC=0b1011000;
  TRISE=0b111;
  TRISC = 0x81;
  PORTC = 0x00;
  TRISD = 0x00;
  PORTD = 0x00;
     
  Buzzer = 1;
  Delay_ms(3000);
  Buzzer = 0;
 
  
  UART1_Init(9600);     // Initialize hardware UART1 and establish communication at 9600 bps
  Delay_ms(100);        // Wait for UART module to stabilize
 
        while(1){
 
        if(BTSense)
        {
 
            LED1 = 1;
            Relay = 1;
 
        }
        else if(!BTSense)
        {
 
            LED1 = 0;
            Relay = 0;
            LED2 = 1;
        }
 
 
            for(i=0;i<7;i++)
            {
                 result[i] = ADC_Read(i);  // Read analog value from channel 0  to 6
                                  
                  
                  lowbyte = result[i] & 0x0F;
                  highbyte = result[i] >> 8;
                  UART1_Write(lowbyte);
                  UART1_Write(highbyte);
                  
                  
             }
        }
}

 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top