Time Multiplexing with the HC-12 Wireless Transceiver Module

hc-12 V0.98 wireless

I'm using the HC-12 wireless transceiver module to allow each laser tag device to communicate wirelessly. The idea is that when you are tagged by someone, you can communicate back to the device that tagged you. That way, when you tag someone, you can indicate on your device that you successfully tagged someone. I got some feedback from players that it was hard to tell if they were tagging other people. The LED's on your head blink when you tag someone, but adding an indicator on your device may help. Plus, it paves the way to adding all sorts of other features that I want to have in the future, like regaining health when you tag someone.

I chose the HC-12 instead of the nRF24L01+ for a few reasons:

  1. I am using just about every single pin on the arduino UNO, and I don't have enough pins to support the nRF24L01+, and I have enough pins for the HC-12
  2. I am using 90% of the program memory on the arduino UNO, and I don't want to add another library and potentially run out of program space for other features I want to add later

And yes, I could upgrade to a different microcontroller and get more pins, more program memory, etc. And, for the next version, I'm planning on using a Blue Pill, if it meets the requirements for version 2.0. But, if I want to release a completed version 1.0, then I need to stop giving in to feature creep. Plus, based on my experience, the arduino UNO is a much easier starting point for beginners. Getting the Blue Pill running was a minor headache, as the tutorials I followed did not spell out how to do everything, and I had to do a bit of Googling and talk to a friend who had used one before in order for me to get it running using the Arduino software. The ultimate goal for this project is to make this beginner friendly, so if I can use an UNO, which has a low barrier to entry, then I'm going to. 

After getting the radio set up (with the help of this tutorial) and reading the data sheet, I decided to have each device set to a different frequency. That way, I wouldn't have to worry about devices trying to send data at the same time, which would cause the radios to collide and potentially not send the correct data. And, then, after implementing it, I realized that it takes 40 ms to enter programming mode, and 80 ms to leave it. If you get tagged, change channels, send a message, and then change channels back, that's 240 ms, or about a quarter of a second. Which means that mostly, you aren't going to be listening for whether or not you have tagged someone else.

To fix this, I decided to use time multiplexing to keep the devices from sending radio transmissions at the same time. The way I set this up is as follows:

  1. A base, or "master" device, sends a command to enter time sync mode. In this mode, the arduino ignores everything except for sending and receiving radio commands
  2. The base, or "master" device, sends a command to synchronize all radios.
  3. Once synchronized (or, if it times out), each device picks a set time from the synchronize radio command to send any data that it needs to send.

For example, if there are three radios, and I want them to send data one time a second, then the first radio will send the data in the first third of a second, the second radio will send data in the second third of a second, and then the third radio will send data in the last third of a second. Every second, all three radios can send data, and they will always send in the order, 1,2,3 (if they have any data to send). I've set up the system to send data every 250 ms, with a 3 ms window for each device to send, and 2 ms of silence (for 25 total transmitting devices). That way (hopefully), during a 5-15 minute game of laser tag, none of the devices send data at the same time, even if they drift a bit from the correct time to send (each clock has up to 5% error with the resonators I'm using).

So far, when testing on the bench, the system works. I've ran into some weird quirks, where it takes about 40 seconds before I can tag multiple devices at the same time and have them both send data properly, or that when I have a device constantly outputting radio chatter, the devices can't communicate (there is a limit on the amount of radio chatter that can happen before the system breaks down), but, so far, it's working. Mostly. I'll have to check it in the field to see how well it works with 8-10 players, and five bases, but so far it looks promising.

I may need to play with the baud rates to get it to work reliably, but so far, so good.

I'll definitely upgrade this to using the nRF24L01+ and using their Multiceiver (TM) functionality, but so far, everything is working alright. 

If you want to check out the code or use it in your own project, the full code is shown below. The functions used are:

  • wireless_transceiver( int device_id, int message, int value) - used to send radio transmissions at a set time
  • receive_wireless(void)  - used to receive radio transmissions
  • telegraph_tags(int check_variable) - used to blink an LED for a set time if you've tagged someone

Note that I try to avoid using delays in my code. To avoid this, I call each of these functions in the main loop and use the milis() function to check whether or not it's time to send radio data or turn off an LED.


Older Post Newer Post


Leave a comment

Please note, comments must be approved before they are published