Introduction: Portal 2 Turret - Master Turret Control

This project is an extension or remix of my original Portal Turret on Instructables (Portal-2-Turret-Gun). It can also be used as a cheap controller to control anything that uses the nRF24L01 radio chip. The LCD screen is particularly useful when customizing.

(It turns out to be quite useful in checking when my radios establish and lose connections with other nRF24L01's on the "network". I can walk around and watch the display screen show the connection status of the radios! Quite helpful for adjusting settings and verifying range!)

After I had completed the Portal Turret, I saw a short video clip of the Cara Mia opera scene at the end of Portal 2. I thought, “hey, I’ve built a few turrets now. I can do that!” Well, I had the turrets, but to make it work, they would now need to communicate with each other, or with some other device. After giving it some thought, and thinking that manual control would also be cool, I ended up deciding that I would build a Master Turret Controller, or an MTC.

Ok, so how to go about this? Well, I didn’t feel like modifying the turrets too much, so that was a constraint. I had some nRF24L01 radio chips which I hadn't yet used, and thought that would keep in line with my goal of using inexpensive components and relying on mechanical design and code to make this work. I would have to build a controller and started mulling over what the controller would contain and what exactly I could do to the turrets. Cara Mia was already on the agenda, but what else?

Manual control: So once the wings are open, I would like to control the pitch and the pivot. 2 axes = a joystick, so joystick control and some push buttons. Push button 1 would fire the turret, and maybe push button 2 would make it say one of its sayings. Sounds good! Simple enough…

Chat: I recently saw the “Who’s on First” - Abbott and Costello routine again, and a light went off in my head! I would also make a sketch comedy routine using all of the sayings, using multiple turrets!! Ok, this one wasn’t fully figured out, but I’m sure I would get it sorted once my build was underway.

I also wanted this MTC to be wireless, so I opted for a simple 9V battery powered option and designed the controller to be powered by the mini-USB plug through the Nano at the back. Useful for updating too.

Step 1: Incorporating the Radio Into the Turrets

I first got the radio working with a few bare Nanos, to make sure I could make it work and send information between multiple devices. Once that was done, it was a matter of incorporating the radio into the existing turrets. Hmm, adding the physical PCB into the turret was pretty easy. I just modified the chip holder to include the nRF24L01, the Nano and the mp3 chip. Ok. One physical part modified, with some wiring.


The modified chip holder is already part of the turret printed parts now. I just deleted the non-radio option from the printed parts in that build. It won’t make a difference if someone wants to build the non-radio variant. Just don’t include the nRF24L01 radio chip.

Step 2: (Re)wiring of the Turrets

Uh oh...

This wasn’t looking good. I needed to add 5 connections to the Nano, and I was already low on available pins. After looking into this for a bit, I realized which connections took precedence, and recognized that to make this work, I would have to remap most of the existing Nano connections.

To those who want to make a “Radio Turret” and have already built the previous gen... Sorry…

Now, I’ve done this change a few times and it turns out that the process isn’t too bad. It does involve going back in, but I was able to undo the existing connections to the Nano and then reconnect to the appropriate pins without too much grief. I added the 7 wires for the radio chip to the nRF24L01 (5 comm wires, 3v and GND), then connected the other ends to the Nano.

More wires in there now though, so it makes that much more important to keep things tidy when routing the wires.

IMPORTANT: When assembling, make sure the wires don’t press on the Nano reset button on the board!! That happened to me on one and threw me for a needless loop!

So the turret build now has 2 wiring schematics: the old legacy “non-radio” option and the revised “radio Turret” option. If building a “non-radio” turret today, I would still use the radio schematic and code. Just delete or comment out the radio portions if that’s the chosen route, or not. The turret should still work on its own without the radio.

Step 3: MTC Electrical Components

Having the turrets sorted out, it was time to make an MTC.

The MTC uses the following components, all sourced through Amazon or Baggood or Ali Express, etc. I’m showing the Amazon part numbers that I referenced for reference, since these items are commonly available and reasonably priced (and I didn’t have to wait 2+ weeks to get my hands on what I needed before I could start the mechanical design!)

  • Arduino Nano 0.96” LCD, (SSD1306) I used the Blue/Yellow version
  • Small Joystick (HW-504) 5V PS joystick module
  • Toggle switch (dx-004) 22mm * 13mm
  • Radio - (nRF24L01)
  • 12mm pushbuttons (CLT1088 for coloured buttons, PBS-33B for black)
  • 2 mm screws (M2 Self Tapping Screws Set, Cross Drive Pan Head assortment)
  • 5mm LEDs of your choice for indicators. (Don’t use bright LEDs!!)
  • Generic 9V battery connector with pigtails
  • 9V battery (use a good one, not one of the dollar store varieties which can’t always supply enough power for these projects!)
  • I used silicone sheathed wire. I like using it for these projects.

I originally used some bright LEDs, but found they were too good. They were blinding me! I ended up using some old, weak LEDs, and that made more sense for this application.

Step 4: 3D Printed Parts

I designed the MTC using Fusion, similar to the way I did the turret design.

The printed assembly only requires 3 parts:

  • Top panel (version 1 or 2)
  • Bottom housing
  • LCD strap

The nRF chip, the Nano, the 9V battery, the toggle switch and the LEDs are installed in the top plate without fasteners. The LEDs just press in the plate and are held in place by tabs. They should just snap in, but don’t overdo it. The top plate is designed to snap-hold the Nano, and the nRF chip should go in gently. Careful with the nRF small tab; it is small and is bent back to open up and released to capture the chip. Even though its travel is limited, be gentle here.

The joystick and the LCD need 2mm screws (5mm long) to hold them to the top plate. The joystick PCB has large holes, so I felt I needed small washers to make sure the screws didn’t pull through.

I’ve found that the PCB’s the LCD’s come on vary slightly dimensionally from manufacturer to manufacturer, so I opted to use a simple strap to hold it in place instead of cleats or hooks.

Note that the LCD can be physically installed into the top plate either way, but the display only shows up fully through the opening in one orientation! For this reason, I’ve included a 2nd top plate option when using the split yellow/blue screen. One version has the yellow at the top, and the other will show the yellow at the bottom as shown in my photos.

For the single colour version LCD, it doesn’t matter which one is used as you can flip the display using software.

Since all the wiring is done on the top plate, the bottom is effectively just a cover held to the top plate with longer 2mm screws (qty:4).

Instead of a “battery door” option, I just incorporated the battery into the top plate. This means removing the 4 screws that hold the bottom to the top to change a battery, but since it can also be powered by USB cable, not the end of the world. The top plate is made with a 9V battery holder system that should be sturdy enough for repeated use, isn’t overly complicated but prevents the battery from moving around.

I printed the top plate in 2 colours as seen in the photos. I use a Prusa i3 Mk2 without the multi colour option, but use their colour print tool (https://www.prusaprinters.org/color-print/) to change colour partway through the process. Check the layer that the text stops and becomes solid, and make that the transition layer. Voila! Coloured text!

I printed the parts at 0.35mm layer height since there is no need for finer resolution on these flat parts. I also prefer the way it looks at this resolution. Oh, and it prints pretty quickly too!

Step 5: Electrical Assembly

The electrical components are all installed on the underside of the Top plate, and all wiring is done together. Push buttons and toggle have to be installed first, and the LCD, Nano, Joystick, nRF radio can all be pre-wired before being installed in the Top plate. I recommend this method of pre-wiring the individual components, then making the final connections to the Nano at the end. I also recommend uploading the sketch to a bare Nano first, before completing the wiring.

There is nothing more satisfying than switching the device on and watching it come to life as expected when finished!

The only electrical part prep required was to remove the header pins from the joystick to make it fit under the top plate. The LCD screen can be purchased with or without pins installed, and will work either way. The Nano should be selected without header pins.

Step 6: Code

Code for MTC, Red turret, White Turret and Blue Turret now up!

Well, this was an experience in coding! I had the turret working independently, but incorporating the radio was more difficult than I originally thought! I also had some fun getting the “Chat” section to work as desired (more on that later).

The MTC code, once fully figured out, started taxing memory limits of the Nano! I had to make adjustments and economize the code to be more memory efficient. Another good learning experience.

I’ve included the corresponding “Turret w radio option” code in this build, as they work together. Building the radio option turret per the Turret build page will make it ready for use with the MTC, or for your other nRF24L01 method of control.

Also, getting the sounds to work with this code took some time, and since the sounds were taken from other publicly accessible websites, I incorporated all sounds as I’ve used them in a couple of ZIP files; one for the regular turret, and one for Defective turret. The good thing for you, dear reader, is that you can use the sounds on your SD cards with the codes as written and you’ll be good to go!

Step 7: MTC Menu - Navigation

The MTC code starts up with a custom Splash screen, then checks on the status of the turrets. If no turrets are present, it will just sit there until turrets connect!

If at least one turret is connected, the main menu will display and the “Ready” LED will illuminate, unless the turrets are interrupted or are busy “dealing with someone”. If they are busy, a “Turrets are Busy screen” will be displayed, and the “Busy” LED will illuminate.

All actively connected turrets must be in “Ready Mode” before the MTC can control the turrets.

Use the joystick (up and down) to cycle through the menu choices:

  • Aria
  • Chat
  • Manual

Select the desired option using the ‘X’ button, or by pressing down on the joystick.

Aria Mode - selecting this option will display the “Aria Mode” screen and make the turrets perform the Aria scene at the end of the Portal 2 game. Once complete, the turrets will close up and wait for a command or someone to wake them up.

Chat Mode - Selecting this option will display the “Chat Mode” screen and start the Chat sequence. Once complete, the turrets will close up and wait for a command or someone to wake them up.

Manual Mode - Selecting this option will display the “Manual Mode” screen, illuminate the “Manual” LED and allow manual operation of the turrets. Joystick control of pitch and pivot. Pressing the ‘X’ button will activate the firing sequence. Pressing the ‘T’ button will make them “talk”, where the turrets speak a random saying from their library.

Pressing the ‘<’ or back button will cancel these three modes, close up the turrets and return to the main menu.

If you would like to see the connection status of your swarm of turrets (currently limited to 3), press the ‘T’ button when in the main menu. You will be taken to the “turret status” screen, where you can see the connection status of each turret.

When in the “turret status” screen, you will see the status of each turret.

  • Ready - ready for control
  • Busy - turret is busy “tending” to someone
  • Not available - MTC cannot connect with this turret

Press the ‘<’ button to return to the main menu.

Step 8: Customizing the Code

The screen shot shown here shows what I was staring at for far too long... 4 sketches at a time! Who said debugging isn't fun!

The code provides the control and options shown above, but what about customizing the code?

Of course! But there is a fair amount going on here, so here are some guidelines or tips.

Tip1 - Modifying “Chat” sequence. This modification takes place in the turret code.

I tried to come up with a way of making the code work for me wherever I could. Making the chat sequence more editable (Is that a word?) so that I could focus on the story took more work up front, but makes it easier to customize afterwards.

Changing the Chat sequence using the coding structure provided can be done in a pretty straightforward way, provided you follow the method used in the code. Using the sound files provided, from the Portal 2 game, you would only need to change the (chatSayings[]) table.

Select the saying for either the regular turret or defective turret. The saying is the mp3 file that is identified by “00XX -” followed by text describing the saying. It is the number that is the important part. Turret # 1 would use this XX value in the table. Turret # 2 would prefix the XX value with a ‘1’, and turret # 3 would prefix the XX value with a ‘2’. So, for example, if you were selecting the saying, “0040 - sorry” expression, and wanted turret # 3 to say it, you would insert “240” into the table in the correct sequence. If turret # 1 were to say it, you would insert “40” into the table.

Do the same for the next expression, and so on. It could be a few expressions between the turrets, or quite a few. (I’m not aware of the limitations of this method, other than memory).

You would not need to change the values of the other tables as they are the timings which correspond to the saying in the table. The only other line to change is around line 520.

if (i >= 43) { // end of sequence

The value of i here would have to be set to the number of sayings in the chatSayings[] table.

To make completely customized sayings, (where the real fun begins!), you would need to set up the expressions in numbered files, and know the length of time needed to play the file. Save the file into the “mp3” folder in the root directory of the SD card using the four digit method (“0001”, “0002”, etc.). Then log the time in milliseconds that it takes for that file to play. Insert these values in the appropriate table.

So for an expression saved as, “0037 - [your expression]”, which takes 5400 milliseconds to play, you would put ‘37’ in the chatSayings[] table at the appropriate location (and add the prefix depending on which turret is saying it), and 5400 in the NormaTimings[] table at the same location (such as 5th item in each table).

Now when the value of ‘i’ is incremented, the code will play 0037 for 5400 milliseconds.

Note that I've added a "timeadder" variable which adds a little extra time to each saying when playing. This gives a little distance between sayings so they don't appear to overlap.

The beauty of this method is that the completed tables are the exact same in each turret! No need to customize these tables for each turret. You only need to sort out one table, and the code figures out what each turret says based on the same table.

This means that you can focus on script writing instead of coding!

If someone has a better way of doing this, I'd love to hear it!!

Step 9: Summary

So this took more time than I thought, but I’m rather tickled by the result. Some of the Chat routines still make me laugh!


I would love to hear other methods of doing the things I did within my code. I’m sure there are sections that could be rewritten and use less memory, allowing for more features or options.

I would also love to see other ideas incorporated into the MTC and control of the turrets!

I hope I have provided a platform for other designers and coders to use / steal / learn from. I could see this being used to help people learn to code. Remove a section from the MTC and/or turret, like "Manual mode" for example, and get students to develop their own way to incorporate manual control!

I’ve learned a lot from this community and the broader web in general. I’m still amazed how many people spend gobs of time figuring things out and sharing them with the world. I figure I should take what I’ve learned, apply it, then share it with you as well!

Good luck and have fun building your own army of turrets!

Epilog X Contest

Participated in the
Epilog X Contest