[SOLVED]Help Programming the PiZero

Having trouble with your GBZ build? Ask your questions here!
Post Reply
User avatar
Vineheart01
Posts: 55
Joined: Sat Aug 12, 2017 5:55 am
Location: Nebraska, USA
Has thanked: 8 times
Been thanked: 5 times

[SOLVED]Help Programming the PiZero

Post by Vineheart01 » Sun Oct 29, 2017 1:16 pm

So i just shut the case on my first GBZ and it turns on/screen works just fine. Only thing i need to do now is program the audio and gpio controls. Screen is a tad flicky but it works, i havnt turned a game on to see if thats just the menus not liking the tiny screen.

Problem is i am a complete dunce when it comes to how to program this thing. All the tutorials i find about how to program the PWM audio and/or controls sound like they are assuming i know how to enter the commands to begin with.

I am only using mono, so i wired the audio to GPIO13. (Tested the sound system already using my phone so i know the speaker works)

Controls are as follows:
GPIO4 = DPad Up
GPIO17 = DPad Down
GPIO27 = DPad Left
GPIO22 = DPad Right
GPIO23 = A button
GPIO5 = B button
GPIO6 = X button
GPIO12 = Y Button
GPIO16 = L Button
GPIO13 = R Button
GPIO20 = Start
GPIO26 = Select

This pi does not have wifi built in and i have no dongles. What i do have is a wireless usb keyboard.
Any help would be greatly appreciated.
(this thing reeks of first attempt woes lol...)
Last edited by Vineheart01 on Wed Nov 01, 2017 6:00 pm, edited 1 time in total.

User avatar
rodocop
Posts: 1723
Joined: Mon Aug 22, 2016 3:14 pm
Location: Saskatchewan
Has thanked: 606 times
Been thanked: 608 times

Re: Help Programming the PiZero

Post by rodocop » Mon Oct 30, 2017 12:53 pm

Vineheart01 wrote:
Sun Oct 29, 2017 1:16 pm
So i just shut the case on my first GBZ and it turns on/screen works just fine. Only thing i need to do now is program the audio and gpio controls. Screen is a tad flicky but it works, i havnt turned a game on to see if thats just the menus not liking the tiny screen.

Problem is i am a complete dunce when it comes to how to program this thing. All the tutorials i find about how to program the PWM audio and/or controls sound like they are assuming i know how to enter the commands to begin with.

I am only using mono, so i wired the audio to GPIO13. (Tested the sound system already using my phone so i know the speaker works)

Controls are as follows:
GPIO4 = DPad Up
GPIO17 = DPad Down
GPIO27 = DPad Left
GPIO22 = DPad Right
GPIO23 = A button
GPIO5 = B button
GPIO6 = X button
GPIO12 = Y Button
GPIO16 = L Button
GPIO13 = R Button
GPIO20 = Start
GPIO26 = Select

This pi does not have wifi built in and i have no dongles. What i do have is a wireless usb keyboard.
Any help would be greatly appreciated.
(this thing reeks of first attempt woes lol...)
For audio add this to the boot/config.txt.
dtoverlay=pwm,pin=13,func=2
disable_audio_dither=1

Since you do not have wifi, you can plug the SD card into your computer and see the config.txt, just edit it with notepad or something. or press f4 on the keyboard to enter the command prompt, and type:

sudo nano /boot/config.txt and add the lines, and then press control+x, then y to save.

GPIO button mapping without wifi...hmmm.

I always follow this guide: viewtopic.php?t=57

you have used different pins I think, so you could download the retrogame.c file (https://drive.google.com/open?id=0B9I5H ... EhKUFJOb2M), and place it in the boot directory of your memory card on your PC. then you edit it to use the same pins you have used by placing it in your pi, and typing:

sudo nano /boot/retrogame.c

Once you have the proper pins in that file, you should be able to follow all the other instructions in the guide I linked. The guide references putting the retrogame.c file in the /home/pi directory, you would just change that to the /boot directory.

also note, if you are doing this on the pi, the screen is tiny and the text is quite small, follow this guide to increase text size:
https://www.raspberrypi-spy.co.uk/2014/ ... font-size/

I change mine to 12X24 and it is pretty readable, you can adjust it how ever you prefer. But it's helpful if you plan to use the terminal.

User avatar
Vineheart01
Posts: 55
Joined: Sat Aug 12, 2017 5:55 am
Location: Nebraska, USA
Has thanked: 8 times
Been thanked: 5 times

Re: Help Programming the PiZero

Post by Vineheart01 » Mon Oct 30, 2017 2:49 pm

Wait really you can alter it in a notepad? Derp, expected it to have to be on the pi itself.
This all looks exactly what i needed. Course i need to crack my case open again and do some rewiring so i might not get to it today, go figure.
(Downside of having a multitasking mindset is sometimes i miss obvious mistakes, such as my ref sheet being mirrored when wiring the gpios. it dawned on me this morning it was mirrored and i went oh...crap... lol)
The pins i chose were basically just going down the line of "suggested pins for direct controls" chart i found. I just started at one end of the pin rows and started assigning dpads, abyx, lr, and start/select. Probably should just rewire them to reflect that guide you linked.

Thanks a lot! i'll post again once i rewire things and try these out (and probably just flatout remove that low LED light on my powerboost because i think i got one of the defective 1000c's where its always on. Full battery, low led is on...riiight...)

User avatar
Vineheart01
Posts: 55
Joined: Sat Aug 12, 2017 5:55 am
Location: Nebraska, USA
Has thanked: 8 times
Been thanked: 5 times

Re: Help Programming the PiZero

Post by Vineheart01 » Mon Oct 30, 2017 6:06 pm

Ok i rewired everything (including cutting off that power LED, i'll just have to suffer w/o a battery indicator until i get my "fancy" 10cent battery monitor boards in lol)

Plugged the SD card into my computer before closing it up and configured the config.txt file to have the PWM stuff you said. Wasnt sure if i had to add it to the end of the massively long text line or make a new line so i made a new line. Should i have instead added it to the end of the long text because im not getting any audio. Checked it in the pi itself and im positive i got the same text. Possible i fudged something with the soldering but i hope not :P

Also for some reason when i try to "make retrogame" i just get a permission denied error?
I didnt rename the retrogame file or put it in a folder, its just in the root file. I typed "cd /boot" (success) and i got that permission issue when i tried to make it.

User avatar
rodocop
Posts: 1723
Joined: Mon Aug 22, 2016 3:14 pm
Location: Saskatchewan
Has thanked: 606 times
Been thanked: 608 times

Re: Help Programming the PiZero

Post by rodocop » Mon Oct 30, 2017 9:05 pm

Vineheart01 wrote:
Mon Oct 30, 2017 6:06 pm
Ok i rewired everything (including cutting off that power LED, i'll just have to suffer w/o a battery indicator until i get my "fancy" 10cent battery monitor boards in lol)

Plugged the SD card into my computer before closing it up and configured the config.txt file to have the PWM stuff you said. Wasnt sure if i had to add it to the end of the massively long text line or make a new line so i made a new line. Should i have instead added it to the end of the long text because im not getting any audio. Checked it in the pi itself and im positive i got the same text. Possible i fudged something with the soldering but i hope not :P

Also for some reason when i try to "make retrogame" i just get a permission denied error?
I didnt rename the retrogame file or put it in a folder, its just in the root file. I typed "cd /boot" (success) and i got that permission issue when i tried to make it.
If you opened it it notepad and it was one long string I would have added it to the end. With one space between.

That may not make a difference. But can't hurt to try. Also do you have any pics of audio wiring? To double check. Also that line I provided can also be changed to 18 (instead of 13).

Not sure why you don't have permission...ill have to look into that.

Try putting the retrogame.c file in a Adafruit-Retrogame folder that's what the guide shows.

Also you can try to move the file to the home/pi directory. I can't remember the command to move files but you can Google it. Might be an permission issue because it's in the boot directory.

User avatar
Vineheart01
Posts: 55
Joined: Sat Aug 12, 2017 5:55 am
Location: Nebraska, USA
Has thanked: 8 times
Been thanked: 5 times

Re: Help Programming the PiZero

Post by Vineheart01 » Wed Nov 01, 2017 9:23 am

Evidently it does have to deal with root. Apparently when it boots it doesnt default for the Root user so thats why i was getting permission denied errors. Talked to one of the engineers at work that happens to know something about pi's. He threw this at me over our internal chat system: https://www.tutorialspoint.com/unix/uni ... ission.htm i'll drop it here for any future users.
Was busy yesterday so i didnt get a chance to try anything else. Will try again today after work. I'm going to focus on getting the sound done first because that involves cracking the case open. Probably as simple as the wire i have between the pi and the lowpass filter has a break in it since its salvaged wire from an old USB.
i really should buy some spools of thin wires if im going to start doing pi stuff.

edit: i work at a multisite radio company (the radios police, firefighters, and transportation use). I'm not an engineer, i just test their code for bugs. The extent of my electrical skills at this job are solder a wire jumper now and then and i dont ever touch code lol.

User avatar
Vineheart01
Posts: 55
Joined: Sat Aug 12, 2017 5:55 am
Location: Nebraska, USA
Has thanked: 8 times
Been thanked: 5 times

Re: Help Programming the PiZero

Post by Vineheart01 » Wed Nov 01, 2017 5:51 pm

Yeah i didnt do the picture thing. You really cant see the audio wires since its under EVERYTHING lol. I pulled the wire off the Pi and tested it with my phone again - it worked just fine. Either you cant use PWM1 as your only audio out or i busted my GPIO13 somehow, i swapped to use PWM0 (GPIO18), changed the code accordingly, and bam it works. Kinda cackly for some reason when its "silent" but i probably know why its doing that (sloppy wiring at the phone jack)

I just moved the retrogame file to follow that guide directly. For some reason when i logged in as the superuser it just told me to f off even though i entered the correct password (default user pi default password raspberry).

It...WORKS!!! Did my usual emulator test run of beating Snake Man in MM3 no damage (obviously i failed but i didnt die), and only control quark is i think the GB buttons are spaced out sliiightly more than older controllers. I didnt play on a gameboy brick that much, the pocket was the thing when i was 6 so i had that.

Thank you so much for your help!

....now to plan for another one thats actually cleanly put together and doesnt have a cheap ass screen....

User avatar
rodocop
Posts: 1723
Joined: Mon Aug 22, 2016 3:14 pm
Location: Saskatchewan
Has thanked: 606 times
Been thanked: 608 times

Re: [SOLVED]Help Programming the PiZero

Post by rodocop » Wed Nov 01, 2017 7:08 pm

Glad you got it working. As for crackly sound. That'll always Happen with PWM. It's never
Crystal clear.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest