Post topics, source code that relate to the Arduino Platform

User avatar
By NovaTag OFFICIAL
#47426 Hi everyone! ;)

Let me introduce myself: my name is Gabriele, I'm a student with a special passion for LaserTag. Recently, thanks to the support of 4 friends of mine, I've started a LaserTag project, involing Arduino, many sensors and components, LCDs and also the fabolous ESP8266 WiFi module.

Our goal is to provide an easy, not too much expensive, all-in-one solution for LaserTag players. Actually, our project is under beta test but works pretty good :D

We have to use the ESP-01 module since we would like to get the hit ACK and also be able to send and receive data from and to rifles, in order to control the match (banning cheaters, starting the game, pausing the game and so on, possibilities are endless!).

By looking on the internet, we discovered that many projects of this kind have been using the NRF24L01 module, instead of the ESP8266, this because ESP is actually more complicated to set up & use, since it requires a specific powering circuit and also a logic level shifter, plus obiouvsly, a very good Arduino programming.

Let me get in details a little bit more ;) when rifle is powered up, a menu will be prompted to the user, letting him decide to join or host a game, when joining a game, it means that a player has already chose the host game mode on his rifle, so a lobby has been created and the second player can join in it.

Problem is that we actually are total noobs with this module, we have been able to control it through our Arduino Mega but we don't know how to realize that kind of system we described earlier :(

So guys, to summarize, any sort of help is truly appreciated. Any code portion or idea could help :)

To prove that we're not joking, that the project is real and working, I've uploaded some images directly taken from our HUD screen ;)

Thanks to everyone, have a nice day!
You do not have the required permissions to view the files attached to this post.
User avatar
By NovaTag OFFICIAL
#47761 Hi again :)

I think we've made a little step forward: after several tries, we have been able to send and receive packets containing short sentences, with a maximum of 63 characters (otherwise they won't be received) between our Arduino Mega (which manually sends AT commands to the ESP module directly connected to it) and Telnet running on our Windows pc, using the following commands:

//SET MODULE IN RX MODE
1) Enable multiple TCP/UDP connections: AT+CIPMUX=1
2) Run a server: AT+CIPSERVER=1,PORT (must be the same, according to the transmitter)

//SET MODULE IN TX MODE
1) Enable multiple TCP/UDP connections: AT+CIPMUX=1
2) AT+CIPSTART=1,"TCP","DEST_IP",PORT (must be the same, according to the receiver)
3) AT+CIPSEND=ID,LENGTH (id goes from 0 to 4)

Here is the code we used to let the Arduino communicate with our module. Since the Arduino Mega comes with 4 hardware serial, just connect the module RX with the Arduino Serial 1, so TX1 (pin18) and the module TX with the Arduino RX1 (pin19). It will create a sort of bridge between the HW serial and the SOFT serial (Serial 0), letting you be able to send AT commands to the module, from Arduino, by simply opening the Serial Monitor of the board.

Code: Select allvoid setup()
{
    Serial.begin(9600);
    Serial1.begin(115200);
}
void loop()
{
    while (Serial1.available()) {
        Serial.write(Serial1.read());
    }
    while (Serial.available()) {
        Serial1.write(Serial.read());
    }
}


Now we're facing problems with the implementation of this thing in our project: since we would like each rifle to be able to send and receive data, we taught a router acting as an access point, connecting all the rifle's ESPs, could be a reasonable solution. The WiFi will give us many features like:

    Full control on a single rifle (block, pause, reset, change settings, view player informations
    Ability to control multiple rifles at the same time (e.g. ban 2 or 3 players at the same time)
    Send game packets to all rifles (like game start, game pause, game cancelled...)

So, here is the question: how could we do this? How can we send packets to a specific rifle, to some rifles and to the whole rifle's net (so that all rifles will receive the same thing, like a WiFi packet broadcast), without having to insert the rifle's ip on the send / receive function? Is there any way to do this?

Any suggestion is truly appreciated.
Thank you :|

Bye!
User avatar
By NovaTag OFFICIAL
#47858 Several tries later we finally have been able to send strings containing commands being executed from our rifles, directly from inside our code. The results is that by opening a server on a WiFi module, we are able to understand what is actually happening to our rifles (Player killed, new mag, entering a specific menu, joining a game, hosting a game and so on) since we receive a command like RIFLENUMBER_COMMAND, e.g: R1_KILLED means that player which is using the rifle 1 has been killed in game.

Next step is trying to read things being outputted from the WiFi module.

Since every time a command is sent (like AT) the module gives a response, we would like to check inside an "if function" if the command has been done correctly (so, the module will output "OK") or has gone wrong (in this case, the module usually writes "ERROR") in order to take actions in case of problems.

Also, reading the module's output is compulsory since by reading it we can listen to TCP packets being received by other rifles, like the "kill acknowledgement packet" which is being sent in case a player kills another player. The player which has been killed sends a specific packet to the killer, confirming the kill.

To summarize:
    we are experiencing problems while reading from the Serial of the WiFi module since on Arduino it works only by choosing "both NL & CR" mode on the serial monitor. Everytime a command is received, we have to pay attention also to these text characters.
    we don't know how to send data to a specific, multiple and all rifle/s without having to know the exact routing table. I mean, we would like to be able, for example, to send a "host game packet" from a rifle, to the net, and all the players connected to the net could join that game. After this, a "start game packet" is sent to all players at the same time.

Any suggestions? :)