13-SerialConnection example SOLVED

General discussion about anything related to Ultibo.
dieselnutjob
Posts: 15
Joined: Wed Jun 26, 2019 12:48 am

13-SerialConnection example SOLVED

Postby dieselnutjob » Mon Jul 08, 2019 5:52 pm

Hi
I am trying to communicate with an HC-05 bluetooth module using the example code in 13-SerialConnection
According to C:\Ultibo\Core\examples\13-SerialConnection\RPi\README.txt
it says "By default the serial (UART) device on the Raspberry Pi will be on pins 14 (Transmit) and 15 (Receive) plus you need to connect a Ground wire as well,"

I am using a Pi Zero W.
I have installed Ultibo-Core-2.0.029-Beetroot.exe

The default baud rate of the HC-05 is 38400 so the only thing that I changed is from 9600 to 38400 on line 81 of SerialConnection.lpr
also in project options I changed the target to RPIZERO

I can't get it to work.

I started searching around in the code and I cannot figure out what in the example code actually sets the default serial device to be a UART connected to pins 14 and 15 of the GPIO.

in serial.pas:-

in SerialInit I found this:-
SerialDeviceDefault:=nil;

In const I found this:-
{Serial Device Types}
SERIAL_TYPE_NONE = 0;
SERIAL_TYPE_UART = 1;
SERIAL_TYPE_USB = 2;

should I change it to SerialDeviceDefault:=SERIAL_TYPE_UART ?

Please can someone explain how this works?

Also I would like to change the pins to 10 and 12 as this would allow the HC-05 to be connected straight to the GPIO bus of the zero.

Can anyone help me with this please?

thanks, Philip
Last edited by dieselnutjob on Tue Jul 09, 2019 8:59 pm, edited 1 time in total.
User avatar
Ultibo
Site Admin
Posts: 2261
Joined: Sat Dec 19, 2015 3:49 am
Location: Australia

Re: 13-SerialConnection example help

Postby Ultibo » Tue Jul 09, 2019 12:34 am

dieselnutjob wrote:The default baud rate of the HC-05 is 38400 so the only thing that I changed is from 9600 to 38400 on line 81 of SerialConnection.lpr
also in project options I changed the target to RPIZERO

I can't get it to work.

I started searching around in the code and I cannot figure out what in the example code actually sets the default serial device to be a UART connected to pins 14 and 15 of the GPIO.

Hi Philip, welcome to Ultibo.

The actual driver for the UART on the Pi Zero can be found in the BCM2708 unit along with many of the other standard drivers for the SoC, the configuration of the GPIO pins is done in BCM2708UART0Open which is called when you call SerialDeviceOpen in your application.

dieselnutjob wrote:Also I would like to change the pins to 10 and 12 as this would allow the HC-05 to be connected straight to the GPIO bus of the zero.

If you have a look at the table on page 102 of the BCM2835 ARM Peripherals document it shows all of the available alternate functions for the GPIO pins.

From that you can see the UART0 (TXD0/RXD0) is only available on GPIO 14/15, GPIO 32/33 or GPIO 36/37 and of those only GPIO 14/15 are available on the 40 pin header, that means that you cannot use GPIO 10/12 for the UART.

I'm not sure if the reason you haven't been able to get the example to work is because you are trying to use pins 10 and 12 or because of another reason. The driver will be setting pins 14 and 15 when starting the UART so perhaps you could go back to the example and retest getting communications to work using a serial terminal program on a PC, one good way to test is to plug a USB to serial converter into the PC and connect the Pi to the other end of that.

If you still are not able to get any communication please let us know, provide as much information about your setup as you can and we'll try to help get it working.
Ultibo.org | Make something amazing
https://ultibo.org
dieselnutjob
Posts: 15
Joined: Wed Jun 26, 2019 12:48 am

Re: 13-SerialConnection example help

Postby dieselnutjob » Tue Jul 09, 2019 8:56 am

Thank you for the reply.
The explanation that I have to use GPIO 14/15 is noted.
I have been trying to use 14/15 and will continue to do so.

This is what I did:-

Connected GPIO pin14 to RXD on the HC-05 board
Connected GPIO pin15 to TXD on the HC-05 board
Connected GPIO pin4 to VCC on the HC-05 board
Connected GPIO pin6 to GND on the HC-05 board

opened C:\Ultibo\Core\examples\13-SerialConnection\RPi\SerialConnection.lpi

on line 81 of SerialConnection.lpr I changed it from:-
if SerialOpen(9600,SERIAL_DATA_8BIT,SERIAL_STOP_1BIT,SERIAL_PARITY_NONE,SERIAL_FLOW_NONE,0,0) = ERROR_SUCCESS then

to:-
if SerialOpen(38400,SERIAL_DATA_8BIT,SERIAL_STOP_1BIT,SERIAL_PARITY_NONE,SERIAL_FLOW_NONE,0,0) = ERROR_SUCCESS then

In compiler options I changed Target Controller to RPIZERO

Then I compiled the program, and onto a MicroSD card copied the following:-
C:\Ultibo\Core\examples\13-SerialConnection\RPi\kernel.img
C:\Ultibo\Core\firmware\RPi\bootcode.bin
C:\Ultibo\Core\firmware\RPi\start.elf
C:\Ultibo\Core\firmware\RPi\fixup.dat

Then I booted up the Pi Zero

I paired my phone with the HC-05 using the default pin 1234
I installed android app Serial Bluetooth and connected it to the HC-05 and started typing characters.

Nothing happened.

Please can you clarify that GPIO pin 14 is TXD on the Pi Zero and so should be connected to RXD on the HC-05 and that GPIO pin 15 is RXD on the Pi Zero and so should be connected to TXD on the HC-05?
Maybe I got them the wrong way around?

thanks, Philip
dieselnutjob
Posts: 15
Joined: Wed Jun 26, 2019 12:48 am

Re: 13-SerialConnection example help

Postby dieselnutjob » Tue Jul 09, 2019 9:42 am

I made a mistake.
GPIO 14 is actually pin 8 on the header
GPIO 15 is actually pin 10 on the header

I have now connected header pin 8 (TXD) to RXD on the HC-05
and header pin 10 (RXD) to TXD on the HC-05

It still doesn't work though
dieselnutjob
Posts: 15
Joined: Wed Jun 26, 2019 12:48 am

Re: 13-SerialConnection example help

Postby dieselnutjob » Tue Jul 09, 2019 9:55 am

I tried connected TXD to RXD on the HC-05 so that what I send to it is simply echoed back
This also doesn't work so it's probably nothing to do with Ultibo
dieselnutjob
Posts: 15
Joined: Wed Jun 26, 2019 12:48 am

Re: 13-SerialConnection example SOLVED

Postby dieselnutjob » Tue Jul 09, 2019 9:07 pm

After trying two different HC-05 modules it seems that despite what the documentation says, the default baud rate is 9600.

I can confirm that the example code given by 13-SerialConnection does by default transmit on header pin 8 and receive on header pin 10.

It seems that the warnings in the README.txt which give links of where to look up the pins, this might not be enough for a newbie to realise that a GPIO pin number is different to a header pin number :roll:

The next challenge is to write a program that can talk to the GPIO pins and to a USB OTG connected FTDI chip at the same time. My project is essentially a protocol converter to go between two serial devices which talk different protocols. One of the devices is bluetooth and the other has an FTDI chip inside it, but it's more that a bridge between the two as "languages" that the two devices talk are different.
User avatar
Ultibo
Site Admin
Posts: 2261
Joined: Sat Dec 19, 2015 3:49 am
Location: Australia

Re: 13-SerialConnection example SOLVED

Postby Ultibo » Wed Jul 10, 2019 12:27 am

dieselnutjob wrote:After trying two different HC-05 modules it seems that despite what the documentation says, the default baud rate is 9600.

I can confirm that the example code given by 13-SerialConnection does by default transmit on header pin 8 and receive on header pin 10.

Excellent, that's great that you got it working.

dieselnutjob wrote:The next challenge is to write a program that can talk to the GPIO pins and to a USB OTG connected FTDI chip at the same time. My project is essentially a protocol converter to go between two serial devices which talk different protocols. One of the devices is bluetooth and the other has an FTDI chip inside it, but it's more that a bridge between the two as "languages" that the two devices talk are different.

That shouldn't be too hard, Ultibo has support for many of the FTDI USB serial devices, there is a thread here that includes example code showing how to locate the FTDI serial device.

Combine that with reading and writing to and from the UART device as per the serial example and you have a lot of the elements needed already.

Of course if you run into any questions feel free to ask.
Ultibo.org | Make something amazing
https://ultibo.org

Return to “Discussion”

Who is online

Users browsing this forum: No registered users and 0 guests