[PIC] Bluetooth PIC18F MAX232

Status
Not open for further replies.

clau

Newbie level 5
Joined
Nov 13, 2013
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
82
Hi,

I'm doing a project that consists in transfer information from the PIC to PC trough bluetooth.

I'm using bluetooth module JY-MCU and PIC18F4450, but i'm having struggles at sending information from PIC to PC...I also have implement a MAX232 but I don't know if that is correct.

Can someone help me with this? Is the use of MAX232 correct? Can someone tell me a example-code in c for this?

Thank you.
 

You implementation is correct. You need max232 for connecting pic to pc.

Google is your best friend. Search this forum first. You can find lot of information here.
 

Hi,

Are you talking about one or two projects ?

Is it just one project communicating with the PC with that bluetooth module ? if so you do not need a max232 chip, the bluetooth receiver plugs in to your PCs USB socket.
There are plenty of examples of using that bluetooth module here just one
https://www.instructables.com/id/Success-Using-the-JY-MCU-linvor-Bluetooth-Module/

If you are doing two projects and you also need to communicate with the PC to its Serial port then as Nandhu015 says you must use a max232 chip or a ready made ttl to pc serial converter available cheaply on ebay.

In both cases you send the data out via the Pics Usart module so the code is virtually the same for either device.

You can use windows hyperterminal for your receiving software but there are much better free programs like pUTTY
 

Hi wp100

Thank you for your reply.

I'm doing one project only, I need to send information from PIC to the PC using bluetooth module. I tried to send something to the PC with and without MAX232 but it wasn't right. In both cases, I used RCOM Serial.
Without the MAX232, nothing happens. With the MAX232, RCOM Serial receives characters randomly.

I have googled this theme so badly but nothing helped

Can you help me? With a simples code?

Thank you*
 

hello,

What compiler are you using ? C18 MPLAB or other ?
Post your code to get help..

With YC-MCU on PIC18F side, you don't need MAX232 or RS232 ...to dialogue with your PC
you need A bluetooth dongle and a software like bluesoleil..
this soft can handle virtual serial link port..
Open a terminal software on your PC
old Terminal Win31, or Vbray terminal or other, with the com port bluesoleil
and you get a direct virtual connection with your UART PIC....

but at first, you must be able to establish a UART RS232 link with your PC
before to work with Blue tooth..(in this case you need a MAX232)
Ideal solution is to use both links.. RS232 for debugging and BT.



i did many test on it , see my web page :
**broken link removed**
 

Hello paulfjujo

I'm using C18 MPLAB.
Here is my code...The objective is send the value of "save_signal" to the PC using bluetooth.

ps- How do you send AT commands to the bluetooth?


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
#include "18F4550.h"
#device ADC=10; 
#fuses INTRC_IO, NOWDT, PUT, NOBROWNOUT, NOLVP, NOPROTECT, XT, NODEBUG, NOCPD
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7, parity=N)
#use delay(clock=4000000) 
 
#include <math.h>
 
//---- definition of variables -------------
 
unsigned int16 signal; 
unsigned int16 save_signal; 
 
//-------------- initial parameters to start reading A/D ------
 
void init_signal()    //determines the initial values
{
    setup_oscillator(OSC_4MHZ);
    setup_adc_ports(an0); /
    setup_adc(adc_clock_internal);
    signal=0;
    save_signal=0;
}
 
//--------- Read A/D ----------
unsigned int16 read_signal()
{
    signal=read_adc();  // Reads the conversion A/D
    return signal;      // Returns the value 
}
 
//---------------------- Main function ---------------------
void main()
{
    init_signal();
 
    while(1)
    {
//--------------------CENTER----------------------------------------------
        save_signal=read_signal(); // Memorizes the value from ADC
        
        if (save_signal>420 && save_signal<578) 
        {   
            output_low(pin_d0);
            output_low(pin_d1);
            output_low(pin_d2);
            delay_ms(500); //100
        }
}
}

 
Last edited by a moderator:

hello,

You don't need to send AT commands to your YC-MCU bluetooth device
if you use the initial factory values because SSP mode by default.
Name: linvor
code : 1234
speed: 9600,8,1,N
Simply send data to YC-MCU

but in front of PIC , on the PC computer you need to do
Appairage , autorisation to establish the connection ...
...Device fund
...Connected device
..etc...


or use and adapt to your case following this example
you can remove all LCD commands..
Code:
UART of PIC is  connected to YC-MCU 
Divider on TX to change Level TTL 5V to 3,3V level
UART TX ---- R=1K ---|-- RX YC-MCU
                               |
                            R=2,2K
                               |
                             -|--GND (0V) 

UART RX ----------------TX YC-MCU

Code:
void  Init_BT_YC_MCU()
{ 
    
    LCD_putcmd(LCD_CLEAR,1);  // LCD Clear
     LCD_putcmd(LCD_HOME,1);   // LCD Home
 
     dummy=PutStrR_RS("AT");         // Enter command mode
    LCD_putcmd(LCD_LINE1,1);
    LCD_putsRom("AT> ");
    dialogue=Get_reponse(); 
    Delay10KTCYx(100); // 1 sec 
   
    dummy=PutStrR_RS("AT+NAMElinvor");// Name of device
    LCD_putcmd(LCD_LINE2,1);
    LCD_putsRom("NAME> ");
    dialogue=Get_reponse();
    Delay10KTCYx(100); 
 
    dummy=PutStrR_RS("AT+PIN1234");  // Security pin code (mikroe)
     LCD_putcmd(LCD_LINE3,1);
    LCD_putsRom("PIN> ");
    dialogue= Get_reponse(); 
     Delay10KTCYx(100); 
   
    dummy=PutStrR_RS("AT+BAUD4");    //9600 bauds

     LCD_putcmd(LCD_LINE4,1);
    LCD_putsRom("BAUD= ");
    dialogue=Get_reponse();
 
    Delay10KTCYx(1000); 
   }

unsigned int  Get_reponse()
{ unsigned int j=0;
   while((buffer[0]==0) && (j<5000))
   { Tempo(10); 
       j++;
   } 
   // si pas de caractere en retour apres timeout de 20.000x0,4x10=  > à 80mS
   // on sort sans rien ecrire sur le LCD
   if(j>= 50000)
   {    LCD_putsRom("??"); // pas de reponse ou YC-MCU deja appairé
        return;  
    }    
   // detection arrivee caractere OK
   // pas possible de detecter un caractere specifique 
   // pour la fin de transmision du YC-MCU vers UART PIC
   // donc on attend suffisament longtemps pour que le buffer soit remplis
   // completement   
  Delay10KTCYx(150);   // valeur 100 insuffisannte 
   if (buffer[0]>0)
    {
    buffer[i1]=0;    
    LCD_puts(buffer); 
    DataReady=0;
    c1=0;
    i1=0;
    buffer[0]=0;
  }      
  return j; 
 }

see the datasheet of YC-MCU for details of command .. change UART speed , change password 1234...

My recommandation:
At first, start by using UART + external MAX232 to debug your program
with a termianl on PC..
When terminal link is OK, you can continue with Blutooth...

and play with AT command

- - - Updated - - -

by the way...
you are NOT USING C18 Mplab !!!
because this declaration
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7, parity=N)

maybe CCS or HTC ?
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…