Snake game on an ARM microcontroller

I’m starting to get accustomed to using an ARM chip and wanted to do a small project. I’ve always enjoyed playing the game of Snake, but never programmed it myself. I present to you Snake on an ARM Cortex-M0 microcontroller.

I’m using the STM32 F0 Discovery board along with a Nokia 3595 cellphone screen. The hardware SPI on the ARM chip makes it pretty easy to address the display. But I’ve written the program to be display agnostic. Keep reading for more details on the programming choices I made.

Continue reading

My first ARM project

I’ve been trying off and on for years to get into ARM development. But my insistence on using FOSS for development has proven a difficult hurdle to overcome. But recently I acquire an STM32F0-Discovery board when they were offering samples. I’m proud to say I managed to get to a point where prototyping for the hardware on a Linux box is easy. I’ve written a bit about it here, and have posted a basic template (including Makefiles) in a github repository.

Above you can see my first working project. I ported it over from an AVR project, it’s the discovery board driving a Nokia 3595 LCD screen. It’s nice to have a microcontroller which is already at the 3V levels this display expects. Right now I’m addressing it via software, but I plan to migrate to hardware SPI and look into generating video. We’ll see.

One of my other near-term plans is to put up a quick post about how to use my template to compile the STM example code. I found that the image shipping on the boards is just a bit different from the source they provided in the firmware package.

Breakout Board for 3595 LCD

2008-11-20-lcd-breakout-boardI have manufactured a breakout board for the nokia 3595 lcd screen. As you can see this facilitates both interface with the screen itself as well as a backlight.

For the backlight I salvaged two LEDs from the phone board itself. I carefully measured and laid out the location for the copper to interface with the “spring” connection for the screen as well as the holes for the LEDs. The LEDs are SMD devices that are soldered to the bottom of the board and stick through a hole to the top of the board. I then cut the keypad area off of the plastic housing for the LCD and used that in conjunction with the metal frame from the phone to mount the unit to my home built PCB.

This is my first double-sided PCB. It doesn’t have the cleanest lines but it works and that’s good enough for me. I found it a bit more difficult to iron on the toner to both sides without smearing it (due to too much heat or from moving the paper while I worked).

Character Set for 3595


Here you can see the full ASCII character set displayed on the 3595 lcd. It was actually amazingly simple to get to this point from the previous “helloworld” firmware.

The most important change that was made is that I upgraded to an ATmega168 to solve my programming space problem. This chip will still operate at 3.3v which is the operating voltage of the LCD. The additional 14kb of programming space should give me plenty of room to grow. I would also like to dabble with SD card compatibility and this chip should allow me to do so (I’ve never looked into it so I may be wrong).

For the character set I borrowed the array and the function to read the characters from memory from a past project. I then wrote a function to handle advancing a “virtual cursor” after each character is written. This function handles wrapping to the next row when about to overflow as well as wrapping from the bottom to the top. The last thing was a function to parse the character information and write it on the screen.

I’ll provide more details in my next update.

3595 LCD – Hello World


I have made quite a bit of progress. Here you see my “Hello World” on the nokia 3595 lcd screen. I have been pouring over the datasheet as well as examining code from two different projects to get to this point. It seems that I am having no problems addressing the display and writing to it. I do still have some work to do with the initialization sequence.
Continue reading