My "Ultimate" 3A+ Build - With Temp-Controlled Fan

Show off your completed Game Boy Zero, or post your build logs here!
Post Reply
User avatar
infinitLoop
Posts: 383
Joined: Mon Dec 24, 2018 11:46 am
Has thanked: 164 times
Been thanked: 131 times
Contact:

My "Ultimate" 3A+ Build - With Temp-Controlled Fan

Post by infinitLoop » Wed Jul 03, 2019 1:59 pm

This one was in the works for a long time, but I think I'm finally "done" (or as done as reasonably possible). i've had it in working condition before, but I was never totally happy with it, and now I think I am (mostly, anyway).
IMG_5541.jpg
IMG_5541.jpg (684.99 KiB) Viewed 1496 times
Highlights:
  • Pi 3 A+
  • Temperature-controlled rear fan
  • LED backlit buttons, with H/W switch
  • Dual analog controllers
  • "Wide Angle" SPI Screen (Looks amazing! :D :o )
  • Digital Volume and Hotkey
  • HDMI Connectivity
Originally, I was trying to fit HoolyHoo's Bracket in here, but my insistence on keeping the HDMI Out in the build conflicted with that, and I just couldn't make that work.

So, next I reworked a 3d model and made use of four tactile buttons on the sides in the rear, since the pi and the BW Screen variant I had in there took up most of the main area... but I wasn't very happy with the buttons, and that screen seemed to be a huge power drain for whatever reason, so I pulled that out and put a Gearbest in, and that was.. ok... a little better life, but it would get really hot, and I couldn't fit a fan in there with the control board for the screen and all.

And so, I thought an SPI screen would be ideal. Low power, (almost) no control board, good picture quality, and pretty cheap... but since I had no experience with doing SPI, I first opted to build some GBZs to get my feet wet. That went well, so I was able to come back to this one, pull out the GB screen, and start figuring out how to get the fan back in there.

I designed a holder that could fit in the rear, if you cut out the two spots where stickers normally went.. the models are here which fit really well above a Pocket Adventures rear bracket prototype that I had (I designed some buttons and wells for a four button layout). That worked ok but the buttons are pretty close together and not the most comfortable to use.

Using this guide as a starting point, and ab NPN transistor, I was able to control the fan turning on and off with software, based on the CPU temp.
Temp-controlled fan InstructionsShow
First, create the file:

Code: Select all

sudo nano fan.py
You should have a blank text file. Paste the content in - Settings for the control Pin and temperature to trigger the fan are near the top:

Code: Select all

from os import popen
from time import sleep
import RPi.GPIO as GPIO

debug = False
GPIO_pin = 4
trigger_temp = 42

def setupGPIO():
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(GPIO_pin, GPIO.OUT)
    GPIO.setwarnings(False)
    return()

def getCPUTemp():
    cmd = popen('vcgencmd measure_temp').readline()
    temp = (cmd.replace("temp=","").replace("'C\n",""))
    if debug:
        print("CPU temp: {0}".format(temp))
    return temp

def checkTemp():
    CPU_temp = float(getCPUTemp())
    if CPU_temp>trigger_temp:
        enableFan(True)
        if debug:
            print("Fan is enabled")
    else:
        enableFan(False)
        if debug:
            print("Fan is disabled")
    return()

def enableFan(isActive):
    GPIO.output(GPIO_pin, isActive)
    return()

# do it
setupGPIO()
while True:
    checkTemp()
    sleep(5)

finally, you need to set it up to run the script at boot time:

Code: Select all

sudo nano /etc/rc.local
Add a line above "exit 0" with this text:

Code: Select all

sudo python /home/pi/fan.py &
I also opted for digital controls, so that I could use this Nav Toggle as a hotkey for the battery monitor and shutdown. I had to tweak the volume script that I wrote for my GBCZ build a little to get it working with USB audio...
Digital Volume InstructionsShow
First, create the file:

Code: Select all

sudo nano volume.py
You should have a blank text file. Paste the content in - Settings for the control Pins, Volume speed (increment and timing) are near the top:

Code: Select all

from os import system
from gpiozero import Button
from signal import pause
from time import sleep

# Location of perisitant state file
statePath = "/home/pi/volume.txt"

# Initial volume setting
vState = 80
# Minimum/maximum volume and how much each press adjusts
sType = "Speaker"  # PCM or Speaker (USB audio)
vStep = 10
vMin = 0
vMax = 100
vSpeed = 0.5

# GPIO pin configuration
volumeUpBtn = Button(23)
volumeDownBtn = Button(22)

# Functions
def volumeDown():
    global vState
    vState = max(vMin, vState - vStep)
    system("amixer sset -q '" + sType  + "' " + str(vState) + "%")

def volumeUp():
    global vState
    vState = min(vMax, vState + vStep)
    system("amixer sset -q '" + sType +  "' " + str(vState) + "%")

def readData(filepath):
    with open(filepath, 'rb') as file:
        return file.read()

def writeData(filepath):
    with open(filepath, 'wb') as file:
        file.write(str(vState))

def doVolume():
    while True:
        if volumeUpBtn.is_pressed:
            volumeUp()
            writeData(statePath)
            sleep(vSpeed)
        elif volumeDownBtn.is_pressed:
            volumeDown()
            writeData(statePath)
            sleep(vSpeed)

# Initial File Setup
try:
    vState = int(readData(statePath))
    system("amixer sset -q '" + sType + "' " + str(vState) + "%")
except:
    writeData(statePath)
    system("amixer sset -q '" + sType + "' " + str(vState) + "%")

# Doin its thing
volumeUpBtn.when_pressed = doVolume
volumeDownBtn.when_pressed = doVolume
pause()
that will also create a file to store the current volume setting (to persist when you reboot) named volume.txt in the pi root.

finally, you need to set it up to run the script at boot time:

Code: Select all

sudo nano /etc/rc.local
Add a line above "exit 0" with this text:

Code: Select all

sudo python /home/pi/volume.py &
For some reason, I could not get the on-board audio to work on the Tinkerboy board, which was very frustrating. Luckily there was still a free USB port on there to use, so I hooked in this tiny audio adapter and an audio amp for the speaker, which I got working pretty quickly, but I'm still bummed about having to stick those extra components in there, not to mention the extra power draw from them... but, oh well, "working" is better than not.

For the screen, I am using the JUJ ILI9341 Driver and I am also using Sixteenbit's fork of HoolyHoo's MintyBatteryMonitor but it took a little tweaking to get those two things to work together. Essentially, in MintyBatteryMonitor.py, "changeicon" method, I had to change the X/Y coordinates in the PngView call to be x=570, y=10.
config.txt settings for SPI screenShow

Code: Select all

framebuffer_width=320
framebuffer_height=240

## No Overscan needed
disable_overscan=1
overscan_scale=1
overscan_left=0
overscan_right=0
overscan_top=0
overscan_bottom=0

### Set custom view mode
## 320x240 60hz 4:3, no margins, progressive
hdmi_cvt=320 240 60 1
hdmi_mode=1
hdmi_group=1

### Just assume hdmi is on (for spi display)
hdmi_force_hotplug=1

### disable edid check
hdmi_ignore_edid=0xa5000080
ok, more pics...
IMG_5519.jpg
IMG_5519.jpg (519.96 KiB) Viewed 1496 times
IMG_5522.jpg
IMG_5522.jpg (542.53 KiB) Viewed 1496 times
IMG_5518.jpg
IMG_5518.jpg (471.99 KiB) Viewed 1496 times
IMG_5523.jpg
IMG_5523.jpg (504.6 KiB) Viewed 1496 times
IMG_5524.jpg
IMG_5524.jpg (490.24 KiB) Viewed 1496 times
IMG_5525.jpg
IMG_5525.jpg (529.76 KiB) Viewed 1496 times
IMG_5526.jpg
IMG_5526.jpg (463.17 KiB) Viewed 1496 times
IMG_5516.jpg
IMG_5516.jpg (984.61 KiB) Viewed 1495 times
IMG_5539.jpg
IMG_5539.jpg (782.69 KiB) Viewed 1496 times
IMG_5532.jpg
IMG_5532.jpg (684.54 KiB) Viewed 1496 times
IMG_5540.jpg
IMG_5540.jpg (622.41 KiB) Viewed 1496 times
Last edited by infinitLoop on Wed Jul 03, 2019 2:23 pm, edited 2 times in total.


User avatar
nexus23k
Posts: 62
Joined: Sat Sep 30, 2017 11:06 am
Has thanked: 23 times
Been thanked: 19 times

Re: My "Ultimate" 3A+ Build - With Temp-Controlled Fan

Post by nexus23k » Thu Jul 04, 2019 4:41 pm

Nice job! Does SPI screen work without tearing? 3,5" Waveshare?
greetings!

lightpixel
Posts: 47
Joined: Tue Nov 21, 2017 4:50 am
Has thanked: 8 times
Been thanked: 31 times

Re: My "Ultimate" 3A+ Build - With Temp-Controlled Fan

Post by lightpixel » Fri Jul 05, 2019 5:45 am

how did you get working the mintybatterymonitor together with tinkerboy´s pcb, which is arduino based controls...? The mintybattery monitor need gpio input with adafuit retrogame...

User avatar
infinitLoop
Posts: 383
Joined: Mon Dec 24, 2018 11:46 am
Has thanked: 164 times
Been thanked: 131 times
Contact:

Re: My "Ultimate" 3A+ Build - With Temp-Controlled Fan

Post by infinitLoop » Fri Jul 05, 2019 9:33 am

nexus23k wrote:
Thu Jul 04, 2019 4:41 pm
Nice job! Does SPI screen work without tearing? 3,5" Waveshare?
greetings!
thanks. it's a 3.2" ILI9341 screen, 18-pin flat cable (i used this adapter from Pocket Adventures to make hookup easier). i can't find the exact link. it was likely from aliexpress, i think.

i looked for one labelled "full angle" (aka "wide" angle) which looks a little better than other ones i've used. there isn't as much of an interlacing effect. (from what i understand, those screens were manufactured for vertical mounting, with the pixel alignment that way, which causes that interlacing when you are looking at them in horizontal mount)

I haven't seen any tearing at all using this setup. Some N64 games do not run at full speed, which is expected, but others run at around 55-60fps, and i haven't noticed any slowdown on other systems. PSX plays pretty great. :)

User avatar
infinitLoop
Posts: 383
Joined: Mon Dec 24, 2018 11:46 am
Has thanked: 164 times
Been thanked: 131 times
Contact:

Re: My "Ultimate" 3A+ Build - With Temp-Controlled Fan

Post by infinitLoop » Fri Jul 05, 2019 9:43 am

lightpixel wrote:
Fri Jul 05, 2019 5:45 am
how did you get working the mintybatterymonitor together with tinkerboy´s pcb, which is arduino based controls...? The mintybattery monitor need gpio input with adafuit retrogame...
the minty monitor wouldn't work with the v3 board, directly. i used Helder's Retro PSU and its built-in ADS-1015.

to use the atmega one on the tinkerboy board, you would have to use the GBZ Battery Monitor. I believe you just need to edit the HHBatterymonitor.py file, and change ser.write('1') to ser.write('9') before running the install, but i know other people have issues with getting that working, and i actually prefer the minty one, since it has the option already to hide the icon with a hotkey, and sixteenbit's icons look really nice on the build. (at some point soon, i might fork it myself to incorporate some improvements and adjustments i've been making too).

(you do not need retrogame though, for the minty option - retrograme is a different overlay that maps GPIO to keyboard inputs. the minty battery monitor uses the SDA and SCL pins to read it's voltage output off of the analog input on the ADS).

matt2mi
Posts: 21
Joined: Wed Sep 11, 2019 8:54 am
Has thanked: 5 times
Been thanked: 4 times

Re: My "Ultimate" 3A+ Build - With Temp-Controlled Fan

Post by matt2mi » Wed Sep 25, 2019 10:19 am

Hey,

Really nice job you did there !! I hope I can get close to it (i won't obviously...)
I just wanted to know how did you manage with the HDMI port to extend it ? I really want to have this feature on my build...

Thanks

User avatar
infinitLoop
Posts: 383
Joined: Mon Dec 24, 2018 11:46 am
Has thanked: 164 times
Been thanked: 131 times
Contact:

Re: My "Ultimate" 3A+ Build - With Temp-Controlled Fan

Post by infinitLoop » Wed Sep 25, 2019 10:42 am

matt2mi wrote:
Wed Sep 25, 2019 10:19 am
Hey,

Really nice job you did there !! I hope I can get close to it (i won't obviously...)
I just wanted to know how did you manage with the HDMI port to extend it ? I really want to have this feature on my build...

Thanks
i used this extender and just cracked apart the case of it.

look for one of these that can bend at a 90 degree angle and it should be similar to this, with the cables and not a circuit board.

there's also some flat cable stuff you can use if you need it longer. i've used these from adafruit but you can find them elsewhere too.

matt2mi
Posts: 21
Joined: Wed Sep 11, 2019 8:54 am
Has thanked: 5 times
Been thanked: 4 times

Re: My "Ultimate" 3A+ Build - With Temp-Controlled Fan

Post by matt2mi » Thu Sep 26, 2019 12:12 am

Hi, i'll definitely try this stuff !!

Thanks !

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest