TF2 Sentry - Page Work in Progress


Bluetooth System

Part of the engineer's tools in the game is his PDA. It let's him know the status of his buildings. For the sentry, that's the current level of the sentry, the health, it's ammo, and whether it's being sapped or not. I decided to make the PDA an app for a smartphone, so I can have a project to work on for a smartphone as well. This is the reason for the bluetooth. The bluetooth will be used for the STM and the smartphone to communicate with each other. The bluetooth device I will use for the STM is the HC05 by HiLetGo.

HC05 - Why this device?
Why did I use this bluetooth device? Well, I originally started with the expansion board from STM for my nucleo board from STM. It was called the X-NUCLEO-IDB05A2. I had huge problems with this expansion board. It just never would transmmit anything. I followed every tutorial for it, read the limited documentations, endless videos, posted on many forums for help, and debugged it myself in the STM debugger. I was stuck. Even people online were stuck on how to help. What I ended up finding out was the HAL libraries for bluetooth are not that well, and tons of people seem to have issues with it. Bugs here, incorrect spelling here that affects the code, etc. The time I realized this though, I already ordered the HC05 as I found much more documentation on it, and I decided to program the registers directly instead of the HAL libraries, which was much more straightforward and easier. It has six pins, and I will be using 4 of them. Transmit, receive, VDD, and GND.
sentry front
Bluetooth on the STM
To use the HC05, I will use the USART on the STM. Specifically USART3. I set the baud rate to the recommended 9600 Bit/s, with the word length being 8 bits (including parity bits). The data direction is both transmit and receive. The reason the smartphone app will send data is because when the sentry is "out of ammo", I will press a button on the phone to reset the variable. I also chose to use interrupt mode instead of polling so I don't consume the CPU time. Plus the bluetooth isn't used often. Only upon firing or sapped. Most of the time the sentry would be scanning.
Code on the STM
In interrupt file, under the USART3 interrupt handler I put the code to handle received data. First I check the ISR register if the interrupt was because we are receiving data. Once I do, I declare a 8 bit character and set it to the data in the received data register. Then I can do whatever I like with it. For example, if it's the value '1', then do X. The receiver enable bit is set and cleared by me. Now for sending data, I made a transferchar function. It takes an input. The transmitter enable bit is set and cleared by me. I simply set the transmit data register to the input, then have a while loop waiting for the tranmission to complete. That's it! I also have a transferstring function which will just use the transferchar function on a loop, depending on the length of the string and loops through it.
Oscilloscope Image
Here is a photo on my oscilloscope. This was actually one of the first reasons I bought the scope since I was having such issues with the original bluetooth module. Anyways, below is a transmission shown in hex. In english text it reads "hello" without the paranthesis. sentry front
Back to Audio System