Introduction: Nextion Arduino Project: Whac-A-Mole Crazy Cony Game
Nextion display is a seamless HMI solution that can make your interface talking to a process, machine, application or appliance. It uses just one serial port to do communicating. It can be applied to various projects. And I can see unlimited potential in it. Today I am going to show you my recent Nextion project- a funny Whac-A-Mole game called Crazy Cony.
So my idea is to make a crazy hamster like Whac-A-Mole game. In this game, the little rabbit called Cony will show
up with smiling face in random position. Once you beat it right, it will show a crying face and you’ll get 1 score. The time will reduce itself during the game. I use Iteaduino Uno to control with nextion. So another necessary part is the codes.
What you’ll need?
Iteaduino Uno (or Arduino )*1
Foca (FTDI module)*1
4 pin Glove cable*1
Files to be downloaded:
Crazy Cony game HMI project file
Step 1: Step to Step Building Project File
To make Nextion display display the game, the first thing we should do is to design an HMI file in the related software called Nextion Editor. This editor allows you to design your desired interfaces, with which you can add pictures, fonts, components for different functions. And you can design as more interfaces as you like. Those components include: progress bar, crop, hotspot, gauge, waveform, slider, variable, text, number, pictures, etc. You can set codes and properties for each component.
Now let’s get started. Open the editor. Because my nextion size is 3.5’’, I create a new HMI project file(related solution 480*320, and choose display direction horizontal). This is a simple game. So just one interface is enough, so I create one page, I change the name to “game”. The pictures must be PS beforehand, and we must consider the size of each picture, just in case they are too large or too small. After that, add them in the picture library. We also need to create a font, there are many many fonts for you to choose, here I choose 24’ viner hand. Two reminders for you , the font should not be too large, in case your component size not that big enough. And the font name should not have spaces.
Then add the components one by one. Different components have different properties to set. There are many properties, if you download a nextion editor and open my HMI file, you can view them clearly. Of course, there are codes for some components. Touch press event is executed when you press the screen, touch release event is executed when you release your fingernail from the screen. If you are interested to learn more about the data you can visit the wiki page here.
After finish editing the HMI project, we can compile and debug it in the simulator to view effect. This simulator will help us troubleshooting problems. If everything is ok, then save this HMI file and upload it to Nextion display. Connect Foca (FTDI module) to PC with a USB cable. And connect Nextion display with Foca via a 4 pin grove cable. One more reminder, be careful, not to get wrong connections. As you can find the connections below:
Foca (USB--TTL)--- Nextion Display
Step 2: Arduino Code
Next, what we need is the codes for the game. Copy the codes below to Arduino software, and upload them to
Iteaduino Uno. Clicke here to view the codes.
Now connect Nextion display with Iteaduino Uno, power them up. We can get the game playing immediately. Tap START, Cony will show up randomly, just quickly hit its head right to get scores. Your time to play, have fun! More projects will come... You can also search"nextion" on Youtube to watch more projects.
We have a be nice policy.
Please be positive and constructive.