Go Down

Topic: Is this feasible / possible? Simple snake game w/ arduino uno from terminal (Read 132 times) previous topic - next topic

grindv1k

Hi forum!

I want to consider a project where I make a simple snake-like game, to get some more experience.

I thougth that if I made a matrix, say a 5x5 matrix of zeros, I could make a snake like game if the snake was displayed by the number 1 in the matrix.

I would move the "snake" by joystick or buttons, which should be fine.

Questions:

1) I am guessing the serial monitor is a poor choice for this?

2) Could I rather use the terminal (linux) and refresh the matrix from my computer, and only use the arduino for controls?

3) Say I make a program in C, and I'm currently in the while(1) part of my program, and waiting for input on the arduino. The matrix is constantly being "refreshed". If I'm communicating with the arduino and using it for control inputs, how does this work in terms of data transfer? The arduino works at 16 Mhz, and my computer far more. Or is the baud rate what determines the speed (bottleneck)? This is maybe a basic hardware question, would love to understand how it works.

4) I haven't compiled any projects from the terminal before. Do you have any guides or help on how to get started with this? I'd rather use VIM or gedit than the IDE. Do you perhaps have a never makefile? I saw there were makefiles when I googled but they seem to be a bit dated.

Hope to get som help!

jurs

I want to consider a project where I make a simple snake-like game, to get some more experience.

I thougth that if I made a matrix, say a 5x5 matrix of zeros, I could make a snake like game if the snake was displayed by the number 1 in the matrix.
Should be possible. Even with much bigger matrices.

I would move the "snake" by joystick or buttons, which should be fine.
You could control either the Arduino directly by connecting something on the Arduino
- buttons
- IR receiver
- joystick
so the input is given directly to the Arduino, and Serial is only used for sending the output to the terminal screen.

Or you could control the Arduino with keyboard input over Serial and the Arduino sends back output to the terminal screen as well over Serial.

Questions:

1) I am guessing the serial monitor is a poor choice for this?
You are right. Arduinos serial monitor is limited for keyboard input which always must be finished hitting the ENTER key. And Arduinos serial monitor is a 'dumb terminal'. But you would need something like a VT52, VT100 or ANSI terminal, so you will need to use a terminal program instead of the serial monitor to send nice terminal codes to the screen.

2) Could I rather use the terminal (linux) and refresh the matrix from my computer, and only use the arduino for controls?
I don't understand that question. The Arduino takes input from whereever (terminal or other) and sends output to the terminal to show what's going on.

3) Say I make a program in C, and I'm currently in the while(1) part of my program, and waiting for input on the arduino. The matrix is constantly being "refreshed". If I'm communicating with the arduino and using it for control inputs, how does this work in terms of data transfer? The arduino works at 16 Mhz, and my computer far more. Or is the baud rate what determines the speed (bottleneck)? This is maybe a basic hardware question, would love to understand how it works.
If your programming is done "the matrix constantly being refreshed", then the Serial baudrate will be the bottleneck. Max. Serial baudrate for Arduino is 500000 baud when communicating with a terminal over Serial-USB. But you need not "the matrix constantly being refreshed" for a snake-like game. For a snake-like game you need:
- clear the screen when the game begins
- send one char (and possibly one position) to the screen at each move of the snake

4) I haven't compiled any projects from the terminal before. Do you have any guides or help on how to get started with this? I'd rather use VIM or gedit than the IDE. Do you perhaps have a never makefile? I saw there were makefiles when I googled but they seem to be a bit dated.
REAL programmers use Emacs.
For what reason you want to use an Arduino?

If you just want to write a program that takes input from the keyboard and sends output to a terminal screen, you really need no Arduino. It can be done with a PC alone, without any Arduino for nothing.

The Arduino IDE is JAVA based and provides a complete and easy to use toolchain for editing, compiling, linking and uploading to the Arduino controller. You'd really need to have good internal knowledge about everything (compiler, linker, programmer) to set up your own toolchain not based on the Arduino IDE.

grindv1k

Should be possible. Even with much bigger matrices.

You could control either the Arduino directly by connecting something on the Arduino
- buttons
- IR receiver
- joystick
so the input is given directly to the Arduino, and Serial is only used for sending the output to the terminal screen.

Or you could control the Arduino with keyboard input over Serial and the Arduino sends back output to the terminal screen as well over Serial.

You are right. Arduinos serial monitor is limited for keyboard input which always must be finished hitting the ENTER key. And Arduinos serial monitor is a 'dumb terminal'. But you would need something like a VT52, VT100 or ANSI terminal, so you will need to use a terminal program instead of the serial monitor to send nice terminal codes to the screen.

I don't understand that question. The Arduino takes input from whereever (terminal or other) and sends output to the terminal to show what's going on.

If your programming is done "the matrix constantly being refreshed", then the Serial baudrate will be the bottleneck. Max. Serial baudrate for Arduino is 500000 baud when communicating with a terminal over Serial-USB. But you need not "the matrix constantly being refreshed" for a snake-like game. For a snake-like game you need:
- clear the screen when the game begins
- send one char (and possibly one position) to the screen at each move of the snake

REAL programmers use Emacs.
For what reason you want to use an Arduino?

If you just want to write a program that takes input from the keyboard and sends output to a terminal screen, you really need no Arduino. It can be done with a PC alone, without any Arduino for nothing.

The Arduino IDE is JAVA based and provides a complete and easy to use toolchain for editing, compiling, linking and uploading to the Arduino controller. You'd really need to have good internal knowledge about everything (compiler, linker, programmer) to set up your own toolchain not based on the Arduino IDE.

Thanks for the thorough response!!

I think I might have poorly worded my original post.

What I want is to use the arduino for the snake control. When I said buttons or joystick I meant using the arduino for either of those.

So the final setup would be:

* Use arduino for controls, joystick/buttons/pots of some kind
* Write code in C, using linux.
* Have the matrix output on the terminal in linux

The main problem is knowing how to use any editor (VIM/gedit) to do the same as the IDE. However I can bypass this, IF it is possible to get output to a terminal from the IDE? Do you or anyone else reading this konw how?

jurs

So the final setup would be:

* Use arduino for controls, joystick/buttons/pots of some kind
* Write code in C, using linux.
* Have the matrix output on the terminal in linux
No, normally it would be:
* Use arduino for controls, joystick/buttons/pots of some kind
* Write code in the Arduino IDE, using linux.
* Have the matrix output on the terminal in linux

The main problem is knowing how to use any editor (VIM/gedit) to do the same as the IDE. However I can bypass this, IF it is possible to get output to a terminal from the IDE? Do you or anyone else reading this konw how?
In an Arduino program you do Serial putput by the commands:
- Serial.print()
- Serial.write()

If you print letters and digits, your Linux terminal will receive letters and digits.
If you send ANSI-ESC control sequences for controlling position and color of output, your terminal will execute commands like setting the write position or color on the terminal screen.

This is how a snake like game might look in VT100/ANSI text terminal emulation:
https://www.youtube.com/watch?v=Jk5nRQOI7Os

Go Up