Showing posts with label Raspberry Pi. Show all posts
Showing posts with label Raspberry Pi. Show all posts

Monday, 12 October 2015

Running MAME on a Raspberry Pi


Wocka-wocka....MAME on a Raspberry Pi

Introduction

The other weekend we stopped off for a pub lunch and my boys spotted a coin operated video game table. They'd been given a coin to play after their lunch and the food just couldn't arrive quick enough. But it wasn't that long before they got their first tastes of Pac Man, Galaxian and Centipede.... games of my youth were surprisingly just as amazing to my own kids.

The MAME table we found in the pub.
Right there I hatched an idea to look into running MAME on our Raspberry Pi and maybe even built a gaming table that was something like it. I've seen joystick/control kits on ebay, and read various blogs where impressive cabinets have been built around the diminutive computer, so I figured there'd be plenty of help out there. (I wasn't wrong)


I did some research this weekend; there's a few software projects providing more or less the same thing, with PiPlay (formerly PiMAME) being one of the common choices. I decided to look for something that needed the least amount of effort and I found a project called Raspicade which supports USB controllers or direct wired connections to the GPIO.

Installing Raspicade

Download the card image from the Files page (I chose raspicade-samba-gamepads-keyboard-pikeyd_ready-B-B B-GPIOready-ES-20150513.img.gz), unzip the file and then use DD to write the contents to an empty MicroSD card.

On my Mac the command would be something like..


sudo dd if=raspicade.img of=/dev/disk4

(nb. I shortened the img file name, and ensure you find out what disk number the card is mounted on - use "diskutil list" if you need to find out.)

I did try using diskutility to do this, but it can only handle a single partition. The image has two partitions, one dos and the other linux.

it's a 2.5Gb image, it took a long time!.. but after that it was a case of inserting the flash card into the Pi and booting. After the usual linux boot messages you are asked some questions about sound, input type and which front-end to use. Then you get an amazing looking start-up screen and a simple, easy to interface.

Update - 13/10/15
Before you go much further if you are using a card bigger than 4Gb it's a good idea to resize the linux partition to fill your card. I used gparted to do this. It has a nice easy to use GUI and only takes a few minutes.


My first issue was how do I install ROM files?... even though Samba and ftp should be included, it had failed to correctly set my wireless network up (which isn't surprising). I had to resort to shutting it down and mounting the file on a Linux system (I used my Raspbian install) and copy the ROMs over via USB.


The ROM files are NOT freely available, I guess the content owners (from 30 years ago) haven't released the copyright because there's been a lot of reboot type stuff available on android/ios. So you have no choice but to find a torrent.


I downloaded the MAME 0.37b11 mame4all ROMs and installed them in the following folder..

/home/pi/mame4all-pi/roms/

I also copied the artwork and samples to the following directory:-

/home/pi/mame4all-pi/

Interestingly there's a folder in roms for SCUMMVM too,.. something to look into, as the boys have been known to play Day of The Tentacle from time to time. But I couldn't see an option in the menus in which to load them.

After replacing the card into the Pi we powered on and found all of our old arcade games ready to play. Most seemed to work (the odd one refused to start) but it was apparent that we had no sound. There was no obvious setting (other than the questions on boot-up) so I searched the forums.

Fixing the Sound

Initially I checked to see if the sound was being routed to the 3.5mm jack socket, but nothing there either. There had to be a setting fix because it works fine in Raspbian.

So you can press escape to exit to the console, and the Raspicade forum suggests two things that might fix the sound:-

1) Set the output source on the sound mixer to 2 (HDMI)..
  

sudo amixer cset numid=3 2

2) Then enable HDMI sound..

sudo nano /boot/config.txt

Find and uncomment the line..

#hdmi_drive=2

After I'd saved and then rebooted, the splash screen burst into life with glorious sound, and moments later our selected game responded with glorious 8 bit retro tones.

Big Smiles All Round :o)

Tuesday, 10 February 2015

Raspberry Pi Diary - Scratch GPIO and 7 Segment Displays

Installing Scratch GPIO

The standard version of scratch can't control the GPIO, so you need to install ScratchGPIO7 before you can play with LED's and switches. I googled the install instructions but here they are if you need them:-

wget http://bit.ly/1wxrqdp -O isgh7.sh

sudo bash isgh7.sh

If you need to add the desktop icons to other users you can specify user name on that last command:-

sudo bash isgh7.sh fred

(nb. make sure you have an internet connection first!)

Use the new desktop icons to start scratch and it will ensure a background python task is running that enables the GPIO control.

There's a simple code example that toggles pin 11 between low and high. We attached an LED to this pin, (using a 470R resistor) and connected the other end to one of the ground pins. (doesn't matter which)

Success - a flashing LED!


Moving on from Basics

The plan was that I'd set my 8 year old a task of driving one of his 7 segment displays using the Raspberry Pi, and maybe get it counting 0 to 9.

It seemed like a suitable jump of of complexity both in software and breadboard wiring. (perhaps it was a jump too far) Here's what happened!


Circuit Debugging

My son disappeared for half an hour and returned with breadboard, 7 segment display, and T-Cobbler carefully connected with jumper wires. He plugged it in to the RPi, loaded up the pin 11 demo program and clicked the green flag icon to run the program. The scratch variable was clearly cycling on and off on the screen, but none of the segments lit. We ended up tearing the circuit down trying to get it to work and along the way discovered a few problems..

1. The T-Cobbler board has 40 pins that need to be inserted into the breadboard. That takes more insertion force than you'd think.

2. The LED display was of the common anode variety. This means that all the anodes are connected together and the segments lit by pulling the individual cathodes down to ground.

(So he had connected the LED segments the wrong way round.)

A quick flick through the Maplin catalog confirmed you can get common cathode versions.

Driving Common Anode Displays

My initial thought was we'd have to use a transistor inverter to drive each segment, but that's a fair bit of extra complexity and not strictly necessary.

A simple inverter circuit is not necessary.

Each GPIO output actively pulls high or low, so if you connect the common anode to 3.3v then any low pins connected to the cathodes will turn the display segment on.

Connecting a common anode display to a Raspberry Pi

The only hitch is the logic is the other way around! (pin low = segment on)

But it's only just occurred to me that we could do this after reading the Raspberry Pi GPIO Documentation and seeing an LED connected this way. (Must try this tonight!!)

Wednesday, 4 February 2015

Raspberry Pi Diary - Breakout Boards

Interfacing 101

One of the main reasons why I bought the Raspberry Pi was to bring together the two worlds of electronics and computing for my two youngest sons. The oldest of the two already has various components and breadboard to play about with, and he's already been experimenting with scratch for a while now.

The great thing about the Raspberry Pi is that it has those GPIO pins just waiting to connected to LEDs, switches, sensors or the wide variety of add-ons that you can buy these days. I thought I'd start by getting a simple breakout board from Maplin.

GPIO Breakout Board
I got one, but lets just say I made a few mistakes!

Mistake #1

It comes in kit form, requiring the ribbon socket and header pins to be soldered together before you can use it. There's a simple diagram that suggests how the ribbon connector should connect to the GPIO pins and which way it should fasten into the breakout board. Seemed simple enough but it wasn't obvious which way up the board should go.

One end of the breakout board
One end was labelled 'GPIO HEADER' (see diagram), so I concluded that it belongs this way up and started soldering the socket. After I'd done about eight I started to get the niggling feeling that it wasn't correct. I stopped and traced the wiring only to find I actually had the board upside down!!!

Now unsoldering a double-sided board is a nightmare, and my desoldering pump just wasn't doing the job. In the end, I levered the socket away from the board leaving the soldered pins still attached. These were then individually removed with a hot soldering iron and a pair of pliers.

Botched breakout board with removed socket pins.
Now I'll have to drill out the remaining solder before I can start again. (This wasn't going well!)

Mistake #2

It wasn't until my son came through to check how I was getting on that I realised my next mistake. I was explaining to him about how the ribbon plug would fit into the GPIO. When I went to demonstrate this I spotted my next mistake. (this one pretty fatal)

This was a 26 pin breakout board for the original Raspberry Pi, but I'd bought the newer RPi B+ model, which has a 40 pin GPIO. The ribbon plug won't fit and if you try to force it you'll end up bending some of the pins. (darn!)

Let's do it Right

All I can say is "Cobblers" - or to be more exact Adafruit's T-Cobbler Plus. As soon as I opened the bag I was immediately impressed by the improved quality and the neat screen printing showing (without doubt) which way the socket should be soldered.

You can bet I still checked it carefully before I started, but within about 10 minutes it was done.

The assembled Adafruit T-Cobbler Plus
My son quickly relieved me of it and started building a circuit to light his 7 segment LED display.

(More about that another day)

Thursday, 29 January 2015

Raspberry Pi Diary - Refuses To Boot

Getting Nowhere

I've wasted a lot of time over the last 24 hours trying to get my 32Gb SD card formatted correctly. Today I tried loading the raspbian image file (from http://raspberrypi.org/) to the card using the 'dd' command in a terminal window.

It all looks OK yet the Raspberry Pi fails to see the card when you power it on.


A Hint at What Was Wrong

I found a few web pages that stated some SD cards just didn't work, and set about reviewing the http://www.raspberry-pi.co.uk/2012/06/07/compatible-sd-cards/ list to see if mine was supported.

But my card is a cheapo unbranded card from ebay and I wasn't able to see a brand name. Though not really conclusive, I began to suspect that this was the problem.

I gave the card to a work colleague who promised to try it out on his Raspberry Pi tonight.


Lets Try Another

In the mean time I borrowed a Kingston 8Gb card from my son (who's also keen on getting this working), carefully backing up his contents before starting work. We did exactly the same as before:-

  1. Format the SD card using SDFormatter (just a quick format this time).
  2. Copy the contents of the NOOBS folder onto the root of the card.
  3. Clean out the dot files that the Mac OS insists on adding (using CleanDisk).
Then we removed the card from it's adapter, slid it into the Pi's microSD slot and powered it up..... It started booting (whoop!!)


The NOOBS Install Menu
It takes about 20 minutes while it alters the partitions and then installs your selected OS.


Install the OS
I'm amazed how slick the process is after that. It runs fine on my TV, and the sound even works via HDMI. Next step is to get my bluetooth dongle working. :-)

Wednesday, 28 January 2015

Raspberry Pi Diary - There's power but screen is dead

We are Noobs

I ordered a Raspberry Pi B+ from Maplin last week and it arrived the other day. All the other parts had already arrived, and we'd downloaded NOOBS (which we definately are!!) and copied the files onto the micro SD card ready.


Rashberry Pi B+ in it's Pibow Coupé case

Tonight we put everything together, plugged it into our TV, borrowed the USB keyboard from the kid's computer and plugged the Pi into 5v power supply.

We got lights, but the screen remained blank!

Tried it on the monitor in the other room, still nothing.


Why Won't it Work?

The thing we noticed was the green ACT light wasn't flashing, which indicates that the Pi isn't booting. The two main causes of this are:-
  • Power supply has insufficient current.
  • The card isn't readable.

First I switched to my iPad charger unit as a power supply,.. but still nothing! (both LEDs still on solid)

After a little bit of googling it seems that the card isn't readable. If you format the SD card using SDFormatter using a Mac (which I did) then make sure you use the Full Overwrite method. Damn, that's gonna take some time.


Full Format The SD Card
The screen grab shows attempt number two, the first time (after about an hour) I brushed against the card in the reader slot and it crashed the software. Had to fix the format in Disk Utility and start again.

In the mean time I've re-downloaded the NOOBS software for when the card is ready. I'd like to rule out bad files too while I'm at it.

Overall - a disappointing start!