<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:series="https://publishpress.com/"
	>

<channel>
	<title>Raspberry Pi Archives - Krystof.IO</title>
	<atom:link href="https://krystof.io/tags/raspberry-pi/feed/" rel="self" type="application/rss+xml" />
	<link>https://krystof.io/tags/raspberry-pi/</link>
	<description>Numerous hobbies, various ramblings.</description>
	<lastBuildDate>Fri, 17 Mar 2023 15:34:52 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.2.9</generator>

<image>
	<url>https://krystof.io/wp-content/uploads/2019/10/cropped-site-icon-low-32x32.jpg</url>
	<title>Raspberry Pi Archives - Krystof.IO</title>
	<link>https://krystof.io/tags/raspberry-pi/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>MJPG-Streamer on a Raspberry Pi Zero W with a USB Webcam Streaming Setup</title>
		<link>https://krystof.io/mjpg-streamer-on-a-raspberry-pi-zero-w-with-a-usb-webcam-streaming-setup/</link>
					<comments>https://krystof.io/mjpg-streamer-on-a-raspberry-pi-zero-w-with-a-usb-webcam-streaming-setup/#comments</comments>
		
		<dc:creator><![CDATA[Eric R. Krystof]]></dc:creator>
		<pubDate>Thu, 14 May 2020 16:58:46 +0000</pubDate>
				<category><![CDATA[Raspberry Pi]]></category>
		<category><![CDATA[Featured]]></category>
		<guid isPermaLink="false">https://krystof.io/?p=1467</guid>

					<description><![CDATA[<p>After my recent move, the streaming and &#8216;workshop/den/laboratory&#8217; setup has been a lot of work from the ground up on the computer system side. I used to have a Raspberry&#8230;</p>
<p>The post <a rel="nofollow" href="https://krystof.io/mjpg-streamer-on-a-raspberry-pi-zero-w-with-a-usb-webcam-streaming-setup/">MJPG-Streamer on a Raspberry Pi Zero W with a USB Webcam Streaming Setup</a> appeared first on <a rel="nofollow" href="https://krystof.io">Krystof.IO</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>After my recent move, the streaming and &#8216;workshop/den/laboratory&#8217; setup has been a lot of work from the ground up on the computer system side.  I used to have a Raspberry PI 4 used as a remote webcam that covered my old place&#8217;s 3D printing area.  While that worked, I never liked the idea of dedicating a whole Raspberry Pi 4 to that &#8211; I wanted to try a Raspberry Pi Zero W and see if it could handle the load.  Utilizing the popular MJPG-Streamer package, I was able to get that installed and running, though I had a few hiccups which I&#8217;ll reference at the bottom.</p>



<p>The article is a combination of various articles I found on the web, referencing older versions of one part or another, and this is a reference for my setup should I need to rebuild it.</p>



<div data-padding="10" class="wp-block-simple-blocks-info-block" style="background-color:#000000;color:#ffffff;padding:10px"><div data-iconsize="20" data-iconspace="20" class="icon" style="margin-right:20px"><span class="dashicon dashicons dashicons-info"></span></div><div>This article targets Raspberry PI Bullseye, Version dated 10-30-2021.</div></div>



<h2 class="wp-block-heading" id="h-hardware">Hardware</h2>



<ul><li>Raspberry Pi Zero W &#8211; Purchased one of those <a rel="noreferrer noopener" href="https://www.amazon.com/Vilros-Raspberry-Starter-Power-Premium/dp/B0748MPQT4" target="_blank">kits </a>on Amazon and it came with various cases and cables I needed, so I was happy with it.</li><li>Logitech USB Webcam</li><li>Power/HDMI/USB</li><li>Keyboard/Mouse</li></ul>



<h2 class="wp-block-heading" id="h-fresh-raspbian-install">Fresh Raspbian Install</h2>



<p>I&#8217;m utilizing the latest version of Raspbian as of this writing, which was released around February, 2020.  Flashing that to a simple 16 GB Micro SD Card for a blank slate:</p>



<figure class="wp-block-image size-large"><img decoding="async" width="796" height="478" src="https://krystof.io/wp-content/uploads/2020/05/2020-05-14_8-20-47.png" alt="" class="wp-image-1472" srcset="https://krystof.io/wp-content/uploads/2020/05/2020-05-14_8-20-47.png 796w, https://krystof.io/wp-content/uploads/2020/05/2020-05-14_8-20-47-300x180.png 300w, https://krystof.io/wp-content/uploads/2020/05/2020-05-14_8-20-47-768x461.png 768w, https://krystof.io/wp-content/uploads/2020/05/2020-05-14_8-20-47-585x351.png 585w" sizes="(max-width: 796px) 100vw, 796px" /><figcaption>Always fresh, never frozen</figcaption></figure>



<p>Assuming you&#8217;re relatively familiar with the Pi, here&#8217;s the minimum I&#8217;m generally doing as post boot up task work:</p>



<ul><li>Changing default password</li><li>Setting Up Wifi</li><li>Enabling SSH</li><li>Setting Hostname</li><li>Setting Locale/Internationalization Options</li><li>Rebooting</li></ul>



<p>After that, the obligatory &#8216;update&#8217; install:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
sudo apt update
sudo apt upgrade
</pre></div>


<p>I can now SSH into the Pi Zero W, disconnect the keyboard, and move along with the install.</p>



<h2 class="wp-block-heading" id="h-build-dependencies">Build Dependencies</h2>



<p>We need to download some things first before we can build mjpg-streamer.  I found some references to articles that pulled from the SVN repo to retrieve and compile, but I ended up getting a large amount of compile errors that look like some library was swapped but the source wasn&#8217;t updated.  It&#8217;s the <code>'redefinition of ‘struct statx_timestamp’'</code> error.</p>



<p>Instead of pulling the SVN version, I&#8217;m going to be pulling the Git repo of mjpg-streamer that was created by <a rel="noreferrer noopener" href="https://github.com/jacksonliam" target="_blank">jacksonliam</a>.  This (<a href="https://github.com/jacksonliam/mjpg-streamer" target="_blank" rel="noreferrer noopener">https://github.com/jacksonliam/mjpg-streamer</a>) is the &#8216;official&#8217; successor to the now abandoned SVN version at <a href="https://sourceforge.net/projects/mjpg-streamer/" target="_blank" rel="noreferrer noopener" class="broken_link">https://sourceforge.net/projects/mjpg-streamer/</a>.</p>



<p>We&#8217;ll now install our dependencies before we download and compile mjpg-streamer code:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
sudo apt-get install build-essential libjpeg9-dev imagemagick libv4l-dev cmake git -y
</pre></div>


<h2 class="wp-block-heading" id="h-git-make-install">Git, Make, Install</h2>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
mkdir ~/mjpg-streamer
cd ~/mjpg-streamer

git clone https://github.com/jacksonliam/mjpg-streamer.git
cd mjpg-streamer/mjpg-streamer-experimental

make
sudo make install
</pre></div>


<p>The make install will copy binaries, libraries and the www pages to the /usr/local/ directory structure:</p>



<ul><li><code>/usr/local/bin/mjpg_streamer</code> &#8211; The primary binary</li><li><code>/usr/local/lib/mjpg-streamer/</code> &#8211; The directory of input/output modules</li><li><code>/usr/local/share/mjpg-streamer/www</code> &#8211; The www server interface</li></ul>



<h2 class="wp-block-heading" id="h-test-the-build">Test The Build</h2>



<p>I&#8217;m going to test the build by plugging in a webcam into the Pi Zero W&#8217;s lone USB port.  Executing dmesg shows that it was loaded properly:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
&#91; 1275.662775] usb 1-1: New USB device found, idVendor=046d, idProduct=082d, bcdDevice= 0.11
&#91; 1275.662796] usb 1-1: New USB device strings: Mfr=0, Product=2, SerialNumber=1
&#91; 1275.662806] usb 1-1: Product: HD Pro Webcam C920
</pre></div>


<p>Let&#8217;s test by trying to run mjpg-streamer against the input_uvc.so plugin, since I&#8221;m not using a Raspi-Camera, but a USB one instead.  (<strong>See notes at the bottom about Raspberry Pi Bullseye and Raspi-Cameras</strong>).  I&#8217;ll also output using the http plugin.  So my testing command line looks like this:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
/usr/local/bin/mjpg_streamer -i &quot;input_uvc.so -f 15 -r 640x480&quot; \
 -o &quot;output_http.so -w /usr/local/share/mjpg-streamer/www&quot;
</pre></div>


<p>Executing that line gives us a dump of data &#8211; here&#8217;s the relevant info:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
MJPG Streamer Version: git rev: 5a6e0a2db163e6ae9461552b59079870d0959340
 i: Using V4L2 device.: /dev/video0
 i: Desired Resolution: 640 x 480
 i: Frames Per Second.: 15
 i: Format............: JPEG
 i: TV-Norm...........: DEFAULT
 o: www-folder-path......: /usr/local/share/mjpg-streamer/www/
 o: HTTP TCP port........: 8080
 o: HTTP Listen Address..: (null)
 o: username:password....: disabled
 o: commands.............: enabled
</pre></div>


<p>Our key variables to tweak are <strong>-f for frame rate</strong>, and <strong>-r for resolution</strong>. I&#8217;ll change those later, but for a quick test I head on out to my browser and point it at the www server at http://cam-pi-zero.local:8080/</p>



<figure class="wp-block-image size-large"><img decoding="async" loading="lazy" width="801" height="706" src="https://krystof.io/wp-content/uploads/2020/05/2020-05-14_11-08-40.png" alt="" class="wp-image-1477" srcset="https://krystof.io/wp-content/uploads/2020/05/2020-05-14_11-08-40.png 801w, https://krystof.io/wp-content/uploads/2020/05/2020-05-14_11-08-40-300x264.png 300w, https://krystof.io/wp-content/uploads/2020/05/2020-05-14_11-08-40-768x677.png 768w, https://krystof.io/wp-content/uploads/2020/05/2020-05-14_11-08-40-585x516.png 585w" sizes="(max-width: 801px) 100vw, 801px" /><figcaption>I always feel like&#8230; somebody&#8217;s watching me&#8230;</figcaption></figure>



<p>Not only do we see the web interface, but a snapshot of the web cam, which was, clearly, laying down on a workbench behind me while I tried this out.</p>



<p>Validating the stream worked (by clicking &#8216;Stream&#8217;) and turning around, I could see myself moving:</p>



<figure class="wp-block-image size-large"><img decoding="async" loading="lazy" width="734" height="706" src="https://krystof.io/wp-content/uploads/2020/05/2020-05-14_11-09-38.png" alt="" class="wp-image-1478" srcset="https://krystof.io/wp-content/uploads/2020/05/2020-05-14_11-09-38.png 734w, https://krystof.io/wp-content/uploads/2020/05/2020-05-14_11-09-38-300x289.png 300w, https://krystof.io/wp-content/uploads/2020/05/2020-05-14_11-09-38-585x563.png 585w" sizes="(max-width: 734px) 100vw, 734px" /><figcaption>Hello you&#8230; come here often?</figcaption></figure>



<p>You can now hit CTRL-C in your SSH window (or terminal) and quit the stream.  After this point, I could delete the build files I downloaded.</p>



<h2 class="wp-block-heading" id="h-tweaking-configuration">Tweaking configuration</h2>



<p>I wanted to run my camera at its intended resolution and at least a frame rate of 30fps.  To do that I modified my command line:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
#30fps, 1080 HD
/usr/local/bin/mjpg_streamer -i &quot;input_uvc.so -f 30 -r 1920x1080&quot; \
 -o &quot;output_http.so -w /usr/local/share/mjpg-streamer/www&quot;
</pre></div>


<p>I then loaded my own stream up in VLC by opening the direct network path to the stream:</p>



<p>http://cam-pi-zero.local:8080?action=stream</p>



<p>That worked, and I get about a 1-2 second delay from Pi to VLC.  So I wouldn&#8217;t use this with audio feeds unless I was planning on creating a sync delay.  I&#8217;m using this to monitor 3D prints, or watch birds outside, so my use case does <strong>not</strong> demand low latency.  Is it exactly 30 frames per second?  No&#8230;. NO it&#8217;s not.</p>



<p>At 1280&#215;720, it seemed closer, but at 1920&#215;1080, when set at 30fps, it definitely wasn&#8217;t even close.  I&#8217;d guess more like 15.</p>



<p>The PI wasn&#8217;t maxed out on CPU, but it could just be the nature of USB 2.0 at this point.  I&#8217;m not sure how I can tell if it&#8217;s overloaded there or not, but, once again, this is a light monitoring video stream, I don&#8217;t care too much about latency.  It could be WiFi as well.  Someday I may dig in a bit more and find out where the bottleneck is.</p>



<p>I think you could probably choose either 1920&#215;1080 15fps or 1280&#215;720 30fps routes and be okay.</p>



<div data-padding="10" class="wp-block-simple-blocks-info-block" style="background-color:#000000;color:#ffffff;padding:10px"><div data-iconsize="20" data-iconspace="20" class="icon" style="margin-right:20px"><span class="dashicon dashicons dashicons-info"></span></div><div>Be careful about frames and resolution &#8211; Watch your CPU, but also make sure you don&#8217;t see messages about fps being &#8216;coerced&#8217; down or up.  Your mileage may vary, and you may have to tweak format, fps, and resolution settings further, check out the mjpg-streamer headquarters on their git hub page (see references down below).  You can also see the different modes available to your camera by using this command:</div></div>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
v4l2-ctl --list-formats-ext
</pre></div>


<h2 class="wp-block-heading" id="h-running-on-startup">Running On Startup</h2>



<p>I liked<a rel="noreferrer noopener" href="https://jacobsalmela.com/2014/05/31/raspberry-pi-webcam-using-mjpg-streamer-over-internet/" target="_blank" class="broken_link"> Jacob Salmela</a>&#8216;s script &#8211; all I did was change it for my command line on the stop and restart section for my resolution and frame-rate.  Save the following script by doing a sudo vi:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
sudo vi /etc/init.d/livestream.sh
</pre></div>

<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
#!/bin/sh
# /etc/init.d/livestream.sh
### BEGIN INIT INFO
# Provides:          livestream.sh
# Required-Start:    $network
# Required-Stop:     $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: mjpg_streamer for webcam
# Description:       Streams /dev/video0 to http://IP/?action=stream
### END INIT INFO
f_message(){
        echo &quot;&#91;+] $1&quot;
}

# Carry out specific functions when asked to by the system
case &quot;$1&quot; in
        start)
                f_message &quot;Starting mjpg_streamer&quot;
                /usr/local/bin/mjpg_streamer -b -i &quot;input_uvc.so -f 15 -r 1920x1080&quot; -o &quot;output_http.so -w /usr/local/share/mjpg-streamer/www&quot;
                sleep 2
                f_message &quot;mjpg_streamer started&quot;
                ;;
        stop)
                f_message &quot;Stopping mjpg_streamer…&quot;
                killall mjpg_streamer
                f_message &quot;mjpg_streamer stopped&quot;
                ;;
        restart)
                f_message &quot;Restarting daemon: mjpg_streamer&quot;
                killall mjpg_streamer
                /usr/local/bin/mjpg_streamer -b -i &quot;input_uvc.so -f 15 -r 1920x1080&quot; -o &quot;output_http.so -w /usr/local/share/mjpg-streamer/www&quot;
                sleep 2
                f_message &quot;Restarted daemon: mjpg_streamer&quot;
                ;;
        status)
                pid=`ps -A | grep mjpg_streamer | grep -v &quot;grep&quot; | grep -v mjpg_streamer. | awk ‘{print $1}’ | head -n 1`
                if &#91; -n &quot;$pid&quot; ];
                then
                        f_message &quot;mjpg_streamer is running with pid ${pid}&quot;
                        f_message &quot;mjpg_streamer was started with the following command line&quot;
                        cat /proc/${pid}/cmdline ; echo &quot;&quot;
                else
                        f_message &quot;Could not find mjpg_streamer running&quot;
                fi
                ;;
        *)
                f_message &quot;Usage: $0 {start|stop|status|restart}&quot;
                exit 1
                ;;
esac
exit 0
</pre></div>


<p>Then we enable this on startup by performing:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
sudo chmod 755 /etc/init.d/livestream.sh
sudo update-rc.d livestream.sh defaults
</pre></div>


<p>Now you can reboot your pi, or use commands like &#8216;sudo service livestream start&#8217;   I rebooted my pi, and my fed was running, and running a status command on my service yields:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
pi@cam-pi-zero:~ $ sudo service livestream status
● livestream.service - LSB: mjpg_streamer for webcam
   Loaded: loaded (/etc/init.d/livestream.sh; generated)
   Active: active (running) since Thu 2020-05-14 11:46:09 CDT; 2min 51s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 411 ExecStart=/etc/init.d/livestream.sh start (code=exited, status=0/SUCCESS)
   Memory: 2.2M
   CGroup: /system.slice/livestream.service
           └─416 /usr/local/bin/mjpg_streamer -b -i input_uvc.so -f 15 -r 1920x1080 -o output_http.so

May 14 11:46:07 cam-pi-zero.local mjpg_streamer&#91;416]: MJPG-streamer &#91;416]: TV-Norm...........: DEFAUL
May 14 11:46:08 cam-pi-zero.local mjpg_streamer&#91;416]: MJPG-streamer &#91;416]: www-folder-path......: /us
May 14 11:46:08 cam-pi-zero.local mjpg_streamer&#91;416]: MJPG-streamer &#91;416]: HTTP TCP port........: 808
May 14 11:46:08 cam-pi-zero.local mjpg_streamer&#91;416]: MJPG-streamer &#91;416]: HTTP Listen Address..: (nu
May 14 11:46:08 cam-pi-zero.local mjpg_streamer&#91;416]: MJPG-streamer &#91;416]: username:password....: dis
May 14 11:46:08 cam-pi-zero.local mjpg_streamer&#91;416]: MJPG-streamer &#91;416]: commands.............: ena
May 14 11:46:08 cam-pi-zero.local mjpg_streamer&#91;416]: MJPG-streamer &#91;416]: starting input plugin inpu
May 14 11:46:08 cam-pi-zero.local mjpg_streamer&#91;416]: MJPG-streamer &#91;416]: starting output plugin: ou
May 14 11:46:09 cam-pi-zero.local livestream.sh&#91;411]: &#91;+] mjpg_streamer started
May 14 11:46:09 cam-pi-zero.local systemd&#91;1]: Started LSB: mjpg_streamer for webcam.

</pre></div>


<h2 class="wp-block-heading" id="h-conclusion">Conclusion</h2>



<p>Using the Raspberry Pi for video streams is good enough if we&#8217;re looking for low frame rate monitoring without audio.  I&#8217;ve yet to find anything that really gives me the frame rate and audio (regardless of latency) that a standard USB webcam directly into my OBS machine would give.  Maybe if NDI ever makes it on to the raspberry Pi, or if there is ever SLDP support.</p>



<p>Have you tried streaming across the network on a Raspberry Pi with a USB webcam?  Did you fare better than I?  Let me know!</p>



<p>Nevertheless, with that, I&#8217;m done!  I can now embed this into OBS via the VLC media source or anything that can handle an HTTP Motion JPEG video stream.  I won&#8217;t have audio, but that&#8217;s okay for what I&#8217;m using this for.</p>



<h2 class="wp-block-heading" id="h-raspi-cameras-libcamera-is-in-raspivid-is-out-in-bullseye">Raspi-Cameras (libcamera is in, raspivid is out in Bullseye)</h2>



<p>Mjpg-Streamer won&#8217;t have the raspicam input module anymore if you compile on Bullseye, because I believe the headers don&#8217;t exist as the Bullseye version is going the way of libcamera.  While I was able to hack around that and build it, I got HORRIBLE artifacts using a raspberry pi camera with the h264 codec and libcamera.  I tried switching codecs to MJPEG instead of H264 and had less artifacts, but worse frame rate.  So for now I decided to go with gstreamer instead of mjpg-streamer at 1280&#215;720 for a nice 30fps solution.</p>



<p>For me, what worked was to enable the legacy raspi-camera support (so we&#8217;re not using libcamera, we&#8217;re using v4l2).</p>



<p>Here are the rough steps:</p>



<ul><li>Started out with Bullseye, latest install with sudo apt update/sudo apt upgrade executed.</li><li>Edit /boot/config.txt and change the following:<ul><li>start_x=1 //add this line</li><li>gpu_mem=128  //probably no higher</li><li>#camera_auto_detect=1 //Comment this line out</li></ul></li><li>Restart</li><li>Installs:</li></ul>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
sudo apt-get install gstreamer1.0-tools gstreamer1.0-plugins-base \
     gstreamer1.0-plugins-good gstreamer1.0-plugins-bad
</pre></div>


<p>Then execute this on the command line:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
/usr/bin/gst-launch-1.0 v4l2src ! video/x-h264,width=1280,height=720,framerate=30/1 ! h264parse config-interval=1 ! matroskamux streamable=true ! tcpserversink host=::0 port=9000 sync=false sync-method=2
</pre></div>


<p>Once that&#8217;s up and running, I ran VLC against it using :network-caching=250 and a URL of tcp://&lt;yourhostname&gt;:9000 and was able to get a decent stream.  That&#8217;s about the extent I&#8217;ve been pushing the raspi-cameras as I typically use the USB side.  I did notice it was nice and fluid, along with less power consumption by a 100 milliamps or so, so I think I&#8217;ll use this as a portable battery powered wireless camera to use around the house on streams.  Hmmm, I may need to look at getting a microphone on here somehow and streaming audio with gstreamer as well.</p>



<h2 class="wp-block-heading" id="h-references">References</h2>



<ul><li><a href="https://einar.slaskete.net/2018/08/16/using-a-raspberry-pi-as-a-surveillance-camera-in-home-assistant/" target="_blank" rel="noreferrer noopener">https://einar.slaskete.net/2018/08/16/using-a-raspberry-pi-as-a-surveillance-camera-in-home-assistant/</a></li><li><a href="https://picamera.readthedocs.io/en/release-1.12/fov.html" target="_blank" rel="noreferrer noopener" class="broken_link">https://picamera.readthedocs.io/en/release-1.12/fov.html</a></li><li><a href="https://qengineering.eu/install-gstreamer-1.18-on-raspberry-pi-4.html" target="_blank" rel="noreferrer noopener">https://qengineering.eu/install-gstreamer-1.18-on-raspberry-pi-4.html</a></li><li><a rel="noreferrer noopener" href="https://www.raspberrypi.org/documentation/configuration/wireless/wireless-cli.md" target="_blank" class="broken_link">https://www.raspberrypi.org/documentation/configuration/wireless/wireless-cli.md</a> &#8211; Raspberry Pi Document on WIFI Setup</li><li><a rel="noreferrer noopener" href="https://www.amazon.com/Vilros-Raspberry-Starter-Power-Premium/dp/B0748MPQT4" target="_blank">https://www.amazon.com/Vilros-Raspberry-Starter-Power-Premium/dp/B0748MPQT4</a> &#8211; The Raspberry Pi Zero W kit I purchased</li><li><a href="https://sourceforge.net/projects/mjpg-streamer" rel="noreferrer noopener" target="_blank" class="broken_link">https://sourceforge.net/projects/mjpg-streamer </a>&#8211; The original source forge project.</li><li><a href="https://github.com/jacksonliam/mjpg-streamer" rel="noreferrer noopener" target="_blank">https://github.com/jacksonliam/mjpg-streamer</a> &#8211; The successor to the abandoned Sourceforge project.</li><li><a href="https://jacobsalmela.com/2014/05/31/raspberry-pi-webcam-using-mjpg-streamer-over-internet/" class="broken_link">https://jacobsalmela.com/2014/05/31/raspberry-pi-webcam-using-mjpg-streamer-over-internet/</a> &#8211; Reference for build information</li><li><a href="https://www.acmesystems.it/video_streaming">https://www.acmesystems.it/video_streaming</a> &#8211; Another build reference</li><li><a href="https://qiita.com/xeno14/items/e32e52c688d969d182e2">https://qiita.com/xeno14/items/e32e52c688d969d182e2</a> &#8211; Another build reference</li></ul>



<p></p>
<p>The post <a rel="nofollow" href="https://krystof.io/mjpg-streamer-on-a-raspberry-pi-zero-w-with-a-usb-webcam-streaming-setup/">MJPG-Streamer on a Raspberry Pi Zero W with a USB Webcam Streaming Setup</a> appeared first on <a rel="nofollow" href="https://krystof.io">Krystof.IO</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://krystof.io/mjpg-streamer-on-a-raspberry-pi-zero-w-with-a-usb-webcam-streaming-setup/feed/</wfw:commentRss>
			<slash:comments>41</slash:comments>
		
		
			</item>
		<item>
		<title>Patching the VICE emulator to light up floppy drive LEDs</title>
		<link>https://krystof.io/patching-the-vice-emulator-to-light-up-floppy-drive-leds/</link>
					<comments>https://krystof.io/patching-the-vice-emulator-to-light-up-floppy-drive-leds/#respond</comments>
		
		<dc:creator><![CDATA[Eric R. Krystof]]></dc:creator>
		<pubDate>Sat, 15 Feb 2020 17:03:24 +0000</pubDate>
				<category><![CDATA[Retro Gaming]]></category>
		<category><![CDATA[Raspberry Pi]]></category>
		<category><![CDATA[Commodore]]></category>
		<category><![CDATA[VICE]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[Emulation]]></category>
		<guid isPermaLink="false">https://krystof.io/?p=1379</guid>

					<description><![CDATA[<p>To make the miniature floppy drive LED light up when VICE is using the virtual disk image, we need to patch VICE source code and write some new code to pass instructions on to the PI and toggle the LED activity light.</p>
<p>The post <a rel="nofollow" href="https://krystof.io/patching-the-vice-emulator-to-light-up-floppy-drive-leds/">Patching the VICE emulator to light up floppy drive LEDs</a> appeared first on <a rel="nofollow" href="https://krystof.io">Krystof.IO</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>In a previous article of the <a href="https://krystof.io/series/diorama-64">Diorama 64</a> series, we <a href="https://krystof.io/installing-the-vice-commodore-emulator-for-console-mode-on-a-fresh-raspberry-pi-4/">installed VICE 3.4</a>, unmodified, on our Raspberry Pi 4.  I didn&#8217;t cover any customization of <a rel="noreferrer noopener" label="VICE  (opens in a new tab)" href="http://vice-emu.sourceforge.net/" target="_blank" class="broken_link">VICE </a>in that article because I wanted to &#8216;walk before I run&#8217;.  However, our goal is to take a miniature floppy drive model, shove a LED into it, and have our VICE emulator control when the LED blinks on or off, mirroring the Commodore 1541 disk drive activity LED.  This article won&#8217;t cover the circuit itself (that&#8217;s a later article), but it is focused on modifying the VICE source code, and using some Python to transfer data from VICE and drive the Raspberry PI&#8217;s GPIO pins, which would later drive an LED light.</p>



<p>While the circuit details will come in a later article, here&#8217;s a little visual of the circuit setup &#8211; a Raspberry Pi 4 with GPIO pins attached to a breakout board, attached to a breadboard.  The top breadboard is used to drive a separate power source for the LEDs, but you can see the green &#8216;power&#8217; LEDs and one of the red &#8216;activity&#8217; LEDs light up there, that&#8217;s all driven by the Raspberry PI and VICE.</p>



<figure class="wp-block-image size-large"><img decoding="async" loading="lazy" width="866" height="506" src="https://krystof.io/wp-content/uploads/2020/02/vice-python-test-circuit.jpg" alt="" class="wp-image-1385" srcset="https://krystof.io/wp-content/uploads/2020/02/vice-python-test-circuit.jpg 866w, https://krystof.io/wp-content/uploads/2020/02/vice-python-test-circuit-300x175.jpg 300w, https://krystof.io/wp-content/uploads/2020/02/vice-python-test-circuit-768x449.jpg 768w, https://krystof.io/wp-content/uploads/2020/02/vice-python-test-circuit-585x342.jpg 585w" sizes="(max-width: 866px) 100vw, 866px" /><figcaption class="wp-element-caption">Pretend those LEDs are inside tiny disk drive models. </figcaption></figure>



<h2 class="wp-block-heading" id="h-high-level-design">High Level Design</h2>



<p>Since VICE is an open source project (thank goodness!), I figured I&#8217;d need to get in that code and see if I can detect when the virtual floppy drives are being used.  If I could do that, I&#8217;d want to send that data to a different program that would be responsible for driving the Raspberry Pi GPIO pins, which then drive the LEDs.  I purposefully did not want to drive the LEDs directly from VICE itself &#8211; I wanted to affect the actual emulator process as little as possible.  Just enough to get the data out of VICE.  After that, some other process takes the data and controls the circuit.  The secondary program would be written in Python, primarily because it&#8217;s very easy to interface with the Raspberry PI with the Python GPIO libraries.  VICE, of course, is written in C.</p>



<p>So I&#8217;d have a C program that gathers data, and a Python program that does something with it.  We typically call that a <strong>Publisher/Subscriber</strong> scenario.  VICE is the <em><strong>Publisher</strong></em> as it is sourcing data, and making it available (publishing) for other processes to use, and VICE isn&#8217;t getting any data back &#8211; this is a one-sided conversation.  Our Python program will be one of the <strong><em>Subscribers</em></strong><em> </em>as it will poll for new &#8216;messages&#8217; or changes in state.  The Python program will then, in turn, send signals via the GPIO library and Raspberry PI GPIO pins to the Darlington Array, which controls individual LEDs, namely our Commodore 1541 Floppy Disk Drive Activity Lights.  Here&#8217;s a high level flow:</p>



<figure class="wp-block-image size-large"><img decoding="async" loading="lazy" width="1024" height="576" src="https://krystof.io/wp-content/uploads/2020/02/2020-02-06_15-28-45-1024x576.jpg" alt="" class="wp-image-1387" srcset="https://krystof.io/wp-content/uploads/2020/02/2020-02-06_15-28-45-1024x576.jpg 1024w, https://krystof.io/wp-content/uploads/2020/02/2020-02-06_15-28-45-300x169.jpg 300w, https://krystof.io/wp-content/uploads/2020/02/2020-02-06_15-28-45-768x432.jpg 768w, https://krystof.io/wp-content/uploads/2020/02/2020-02-06_15-28-45-1170x658.jpg 1170w, https://krystof.io/wp-content/uploads/2020/02/2020-02-06_15-28-45-585x329.jpg 585w, https://krystof.io/wp-content/uploads/2020/02/2020-02-06_15-28-45.jpg 1440w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">High level design flow &#8211; in this article we cover VICE and Python.</figcaption></figure>



<p>The first real question I pondered was how I&#8217;d get a C program and a Python program on a Raspberry PI to share data, even if the conversation is one-sided.  I figured I had four options off the top of my head:</p>



<ol>
<li><strong>Datafile access</strong> &#8211; Vice writes to a file that the Python program constantly reads from to determine drive status.  While this is definitely feasible, I wanted to avoid constant file-system access, OS caching or not.  The LED is meant to blink on and off rapidly, that&#8217;s a lot of file updates to apply on a SD card.</li>



<li><strong>Networking Channel</strong> &#8211; UDP or TCP, some sort of client/server or packet broadcast.  This would be necessary if the diorama was remote (an interesting idea), but ultimately the emulator and the consumer are on the same machine, so I wanted to keep the communications channel a little tighter.</li>



<li><strong>UNIX Sockets</strong> &#8211; Since the Raspberry Pi 4 is running Raspbian, it supports UNIX style sockets for a simple IPC (Inter-process Communication) channel between the VICE and Python processes.  However, it&#8217;s still a lot of code to inject into VICE.</li>



<li><strong><em>The Winner</em> &#8211; Shared Memory</strong> &#8211; I finally decided on a shared memory solution to avoid a lot of unnecessary and potentially harmful patching to VICE with any networking related code (the less I&#8217;m in VICE the less I affect its processing), along with Python recently getting support for shared memory between disparate processes with Python 3.8 and above.  </li>
</ol>



<p>While we are calling this a &#8216;Publisher/Subscriber&#8217; model, it&#8217;s a very loose fit &#8211; there&#8217;s no middle-ware here handling message flow &#8211; it&#8217;s a bit bucket we poll for state changes every few milliseconds.  Therefore, I hesitate to apply the terminology of &#8216;Publisher/Subscriber&#8217; without a few grains of salt.   Thy key point: VICE is decoupled from the consuming process(es).</p>



<h2 class="wp-block-heading" id="h-patching-vice">Patching VICE</h2>



<p>Remember where we compiled <a href="https://krystof.io/installing-the-vice-commodore-emulator-for-console-mode-on-a-fresh-raspberry-pi-4/">VICE on the command line</a>?  Even if a binary was available, the reason why I wanted to compile VICE was because I knew I&#8217;d be tinkering with the source code.  To that end, I downloaded their SVN source and started searching through the code for key strings like &#8216;1541&#8217;, &#8216;drive&#8217;, &#8216;floppy&#8217;, etc. until I found drive.c and drive.h.  I won&#8217;t include the whole pieces here, but this part is what I found particularly interesting &#8211; I wanted to find some place to initialize the shared memory, and some place to write to it so we can &#8216;publish&#8217; our floppy drive status updates.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: cpp; title: ; notranslate">
/* Initialize the hardware-level drive emulation (should be called at least
   once before anything else).  Return 0 on success, -1 on error.  */
int drive_init(void)
{
    unsigned int dnr;
    drive_t *drive;

    if (rom_loaded) {
        return 0;
    }

//..... More
}
</pre></div>


<p>Great!  <em>drive_init</em> sounds like a good hook method &#8211; we don&#8217;t want to constantly be creating shared memory segments, create it once, but write to it many times.  Here&#8217;s where I figured I&#8217;d place the &#8216;publishing&#8217; code:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: cpp; title: ; notranslate">
static void drive_led_update(drive_t *drive, drive_t *drive0)
{
    int my_led_status = 0;
    CLOCK led_period;
    unsigned int led_pwm;

    /* Actually update the LED status only if the `trap idle&#039;
       idling method is being used, as the LED status could be
       incorrect otherwise.  */

    if (drive0-&gt;idling_method != DRIVE_IDLE_SKIP_CYCLES) {
        my_led_status = drive-&gt;led_status;
    }

//More.....
}
</pre></div>


<p>So now, we know the two spots that sound like they&#8217;d be great for initialization and continuous updates of our shared memory with drive status.  Let&#8217;s look at the modifications necessary, then.   Our goal is to allocate some shared memory (just enough to hold drive status for drive devices 8 through 11), and when VICE is updating it&#8217;s UI LED, we want to update shared memory with that status, a simple 1 or 0 toggle will suffice.  That&#8217;s a pretty straightforward hook!</p>



<h3 class="wp-block-heading" id="h-modifications-for-drive-c"><strong>Modifications for drive.c</strong></h3>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: cpp; title: ; notranslate">
#include &lt;fcntl.h&gt;
#include &lt;sys/shm.h&gt;
#include &lt;sys/stat.h&gt;
#include &lt;sys/mman.h&gt;
#include &lt;unistd.h&gt;

const char *led_shm_name = &quot;vice-drive-led-shm&quot;;

void *viceDriveLedShmPointer;

void init_drive_led_shm(void) {

	int shm_fd;

	const int SIZE = 16;

	/* create the shared memory object */
	shm_fd = shm_open(led_shm_name, O_CREAT | O_RDWR, 0666);

	/* configure the size of the shared memory object */
	ftruncate(shm_fd, SIZE);

	/* memory map the shared memory object */
	viceDriveLedShmPointer = mmap(0, SIZE, PROT_WRITE, MAP_SHARED, shm_fd, 0);

	sprintf(viceDriveLedShmPointer, &quot;%s&quot;, &quot;80900010&quot;);
}

void update_shm_drive_status(unsigned int driveNumber,
		int driveLedStatus) {
//      Uncomment for some simple and extreme debugging
//	log_warning(drive_log, &quot;Hey! Drive %d Status : %d&quot;, driveNumber,
//			driveLedStatus);

	if (drive_init_was_called) {
		((char*) viceDriveLedShmPointer)&#91;(driveNumber * 2) + 1] = (
				driveLedStatus == 0 ? &#039;0&#039; : &#039;1&#039;);
	}
}

//  Call our initialization method from drive_init
init_drive_led_shm();

//  Add this to update our status in the existing function drive_led_update
update_shm_drive_status(drive-&gt;mynumber, my_led_status);
</pre></div>


<h3 class="wp-block-heading" id="h-modifications-to-drive-h"><strong>Modifications to drive.h</strong></h3>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: cpp; title: ; notranslate">
extern void init_drive_led_shm(void);
extern void update_shm_drive_status(unsigned int driveNumber, int driveLedStatus);
</pre></div>


<h3 class="wp-block-heading" id="h-modifications-for-compilation"><strong>Modifications for compilation</strong></h3>



<p>There&#8217;s not much else to this &#8211; all I needed to add  (and this was a quite a bit of stumbling around on my part as I&#8217;m not comfortable or familiar with automake/autoconf) was adding the system libraries to work with shared memory to the configuration file configure.proto, around line 3316, before references to GFXOUTPUT_DRIVERS</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
dnl Patch to add -lrt for shared memory IPC work
echo &quot;Patch to add -lrt for shared memory IPC work&quot;
old_LIBS=&quot;$LIBS&quot;
LIBS=&quot;$LIBS -lrt&quot;
</pre></div>


<h3 class="wp-block-heading" id="h-github-repo">Github repo</h3>



<p>Of course, you don&#8217;t have to copy these and paste them yourselves.  I put a GitHub repo for my modifications here:</p>



<p><a href="https://github.com/erkrystof/vice">https://github.com/erkrystof/vice</a></p>



<p>You&#8217;ll want to check the tags for &#8216;pure VICE&#8217; and tags for my modifications to see deltas or pull the version you desire.</p>



<p>When I wrote this &#8211; there was one tag that represented my modifications and VICE 3.4 combined:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
git clone --single-branch --branch 3.4-Modded-1.0 https://github.com/erkrystof/vice
</pre></div>


<h2 class="wp-block-heading" id="h-running-vice-with-our-patch">Running VICE with our patch</h2>



<p>After running the same build commands as I did when installing basic VICE, executing the binary should have no discernible difference (unless you un-comment that log statement) in the logs for the way VICE handles.</p>



<p>However, you should now notice there&#8217;s a piece of shared memory  you can see, and that you can read, given that everything in *nix is a file.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
pi@vice-pi:/dev/shm $ ls -l
total 4
-rw-r--r-- 1 pi pi 16 Feb  9 09:16 vice-drive-led-shm
pi@vice-pi:/dev/shm $ cat vice-drive-led-shm
80900010
pi@vice-pi:/dev/shm $

</pre></div>


<p>Excellent, we now know it&#8217;s working!  If I loop over that in an SSH console, just to see, and run VICE and load a floppy, you should see the second byte (0/1 &#8211; the drive 8 status LED) flip between 1 and 0.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
for i in {1..10000}; do cat vice-drive-led-shm; echo ... Counter: $i; done
#Sample output:
80900010... Counter: 43
80900010... Counter: 44
80900010... Counter: 45
81900010... Counter: 46  &lt;----- We have activity on drive 8
81900010... Counter: 47
81900010... Counter: 48
81900010... Counter: 49
</pre></div>


<p>Looking good so far.  So VICE is essentially done &#8211; it&#8217;s &#8216;publishing&#8217; drive status to an area in shared memory that we&#8217;ll now want to read from and drive the LEDs connected to the Raspberry Pi GPIO pins.</p>



<h2 class="wp-block-heading" id="h-reading-the-1541-drive-status-with-python">Reading the 1541 drive status with Python</h2>



<p>We&#8217;re halfway there &#8211; the next step is to work on a separate process &#8211; our subscriber that reads the VICE drive status and sends commands to the Raspberry Pi&#8217;s GPIO pins to drive our LEDs.  I could have done this in C, matching how we read shared memory that we&#8217;re writing to in VICE, but I wasn&#8217;t familiar with driving a Raspberry Pi&#8217;s GPIO pins from C.  I am a bit more comfortable with the GPIO libraries available in Python, however, though the question of reading shared memory needed an answer.</p>



<p>Granted, I could probably just read from <code>/dev/shm/vice-drive-led-shm</code>, but I really wanted to keep this semi-portable in the sense that I wanted to use the available shared-memory libraries instead of  a known *nix-specific file behavior.  After doing some research on Python and shared memory, it turns out we need a more recent version of Python than may come with your default Raspbian install &#8211; Python 3.8 or greater.</p>



<h3 class="wp-block-heading" id="h-python-3-8-or-greater-and-rpi-gpio-libraries">Python 3.8 or greater and RPi.GPIO libraries</h3>



<p>For that installation, I&#8217;m going to divert away from this article to a separate one that&#8217;s not necessarily part of the series as reference if you need it &#8211; <a href="https://krystof.io/installing-alternative-python-versions-on-raspberry-pi/">How to install Python 3.8 on the Raspberry Pi</a>. </p>



<p>If you already have Python 3.8 or greater, you&#8217;ll just need to make sure you have the RPi GPIO library installed:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
sudo python3.8 -m pip install RPi.GPIO
</pre></div>


<h3 class="wp-block-heading" id="h-a-simple-python-client">A simple Python client</h3>



<p>The latest source code for the Python piece is available on <a rel="noreferrer noopener" aria-label="GitHub (opens in a new tab)" href="https://github.com/erkrystof/diorama-64-1541-status-consumer-gpio-led-driver" target="_blank">GitHub</a>, although I&#8217;ll go over this roughly below.  </p>



<div data-padding="10" class="wp-block-simple-blocks-info-block" style="background-color:#000000;color:#ffffff;padding:10px"><div data-iconsize="20" data-iconspace="20" class="icon" style="margin-right:20px"><svg aria-hidden="true" role="img" focusable="false" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewbox="0 0 20 20" class="dashicon dashicons-info"><path d="M10 2c4.42 0 8 3.58 8 8s-3.58 8-8 8-8-3.58-8-8 3.58-8 8-8zm1 4c0-.55-.45-1-1-1s-1 .45-1 1 .45 1 1 1 1-.45 1-1zm0 9V9H9v6h2z"></path></svg></div><div>I&#8217;m not a Python programmer by trade &#8211; this was just enough to illustrate the point of reading shared memory and routing commands to the Raspberry Pi, not a gold standard of Python coding.</div></div>



<h4 class="wp-block-heading" id="h-initialization">Initialization</h4>



<p>Let&#8217;s look at the first chunk, primarily initialization and some structure:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: python; title: ; notranslate">
powerLedsPin = 23
drive8ActivityPin = 27
drive9ActivityPin = 22

DRIVE_8_ACTIVITY_INDEX = 1
DRIVE_9_ACTIVITY_INDEX = 3

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(&#91;powerLedsPin,drive8ActivityPin,drive9ActivityPin],
        GPIO.OUT, initial=GPIO.HIGH)
</pre></div>


<p>My diorama has four &#8216;devices&#8217; &#8211; two 1541 floppy drives, a Commodore keyboard, and a Commodore monitor.  We use one pin for all green &#8216;power&#8217; LEDs, since I didn&#8217;t feel like controlling power LEDs separately, it&#8217;s all the same output.  For the floppy drive activity LEDs, however, I needed them controlled separately, so I created a drive 8 and drive 9 pin and reserved them to pins 27 and 22, respectively.</p>



<p>After that I&#8217;m setting up the state to be HIGH &#8211; initialize all LEDs as on.</p>



<h4 class="wp-block-heading" id="h-load-the-shared-memory-reference">Load the shared memory reference</h4>



<p>Our primary code must first initialize the reference to shared memory:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: python; title: ; notranslate">
try:
    print (&quot;Consumix Python version starting up.&quot;)

    while (True):
        try:
            shm_vice = shared_memory.SharedMemory(name=&quot;vice-drive-led-shm&quot;, create=False, size=16)
            break;
        except Exception as e:
            print (e)
            print (&quot;Error Trying to Open Shared Memory... Trying again in a bit.&quot;)
            time.sleep(.5)
            continue

    print (&quot;Shared memory found, let&#039;s read it.&quot;)
</pre></div>


<p> We&#8217;re using the same shared memory name we used in VICE, and we say &#8216;create=False&#8217; since VICE is responsible for creating the shared memory object &#8211; we are just reading 16 bytes worth.  In the case that the Python program starts before VICE, we catch the exception and try again in a little bit.  I had to add that slightly fault tolerant try/catch loop as this Python client ends up staring <em>before</em> VICE when I startup my Raspberry Pi.</p>



<h4 class="wp-block-heading" id="h-read-shared-write-led">Read Shared, Write LED</h4>



<p>Now that we&#8217;ve loaded our shared memory reference, we read from the shared memory, place it into a character array, and update the LEDs with a loop and a function:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: python; title: ; notranslate">
while (True):
        driveData = array.array(&#039;b&#039;,shm_vice.buf&#91;:8])
        driveDataString = driveData.tostring().decode(&quot;utf-8&quot;)
        updateLEDLighting(driveDataString)
        time.sleep(0.025)

#... more stuff after....
#update function for reference:

def updateLEDLighting(driveDataString):
    if (driveDataString&#91;DRIVE_8_ACTIVITY_INDEX] == &#039;1&#039;):
        GPIO.output(drive8ActivityPin,GPIO.HIGH)
    else:
        GPIO.output(drive8ActivityPin,GPIO.LOW)

    if (driveDataString&#91;DRIVE_9_ACTIVITY_INDEX] == &#039;1&#039;):
        GPIO.output(drive9ActivityPin,GPIO.HIGH)
    else:
        GPIO.output(drive9ActivityPin,GPIO.LOW)
</pre></div>


<p>It&#8217;s a pretty simple program overall &#8211; but it does the job.  Since I only ended up wiring up two drives, I only read the drive 8 and 9 data, and ignore 10 and 11.</p>



<h3 class="wp-block-heading" id="h-a-note-on-python-shared-memory">A note on Python shared memory</h3>



<p>This isn&#8217;t as fault tolerant as I&#8217;d like though &#8211; if you quit your Python client, the shared memory reference seems to be <strong><em>destroyed</em></strong> &#8211; which completely baffles me.  The creator of a resource is in charge of closing it, not some other process.  So if VICE is creating the shared memory, I could understand if my Python client needs to open and close a <em>reference</em>, but not the shared memory itself.  </p>



<p>Regardless, when I close my Python client, it destroys the shared memory object completely, even if I try to &#8216;close&#8217; the reference ahead of time.  Perhaps I&#8217;ve wired something up wrong here &#8211; but i think, based on some of these links referencing the shared-memory usage in Python 3.8, that I&#8217;m not entirely crazy.</p>



<p><a rel="noreferrer noopener" aria-label=" (opens in a new tab)" href="https://bugs.python.org/issue38119" target="_blank">https://bugs.python.org/issue38119</a></p>



<p>Now, I&#8217;m not really worried about this myself &#8211; but it could be an interesting read for others &#8211; as far as my Python client goes, I don&#8217;t need to restart it, so it shouldn&#8217;t start closing the shared memory VICE created on me.  What I may need to do now and then is restart VICE, however, and this setup handles that just fine (my patched-VICE simply uses the existing shared-memory object and the Python client keeps reading happily).</p>



<h2 class="wp-block-heading" id="h-the-outcome">The outcome</h2>



<p>Load up VICE and the Python client, and watch your GPIO pins toggle high and low with drive activity.  You can debug by tailing the shared memory object as we did above, you could use an oscilloscope or multimeter to watch some voltage changes on the GPIO pins, or you could do what I did &#8211; have some LEDs on the pins and watch them blink on and off &#8211; which is exactly what I&#8217;m looking for.</p>



<figure class="wp-block-image size-large"><img decoding="async" loading="lazy" width="1024" height="576" src="https://krystof.io/wp-content/uploads/2020/02/20200105_141239-1024x576.jpg" alt="" class="wp-image-1417" srcset="https://krystof.io/wp-content/uploads/2020/02/20200105_141239-1024x576.jpg 1024w, https://krystof.io/wp-content/uploads/2020/02/20200105_141239-300x169.jpg 300w, https://krystof.io/wp-content/uploads/2020/02/20200105_141239-768x432.jpg 768w, https://krystof.io/wp-content/uploads/2020/02/20200105_141239-1536x864.jpg 1536w, https://krystof.io/wp-content/uploads/2020/02/20200105_141239-scaled.jpg 2048w, https://krystof.io/wp-content/uploads/2020/02/20200105_141239-1170x658.jpg 1170w, https://krystof.io/wp-content/uploads/2020/02/20200105_141239-1920x1080.jpg 1920w, https://krystof.io/wp-content/uploads/2020/02/20200105_141239-585x329.jpg 585w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">Green Power LEDs are go, and drive 8 is active (Red LED lit)</figcaption></figure>



<p></p>
<p>The post <a rel="nofollow" href="https://krystof.io/patching-the-vice-emulator-to-light-up-floppy-drive-leds/">Patching the VICE emulator to light up floppy drive LEDs</a> appeared first on <a rel="nofollow" href="https://krystof.io">Krystof.IO</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://krystof.io/patching-the-vice-emulator-to-light-up-floppy-drive-leds/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		
		<series:name><![CDATA[Diorama 64]]></series:name>
	</item>
		<item>
		<title>Mirroring Raspberry Pi HDMI Video to a ST7789 1.3 inch LCD Display</title>
		<link>https://krystof.io/mirroring-raspberry-pi-hdmi-video-to-a-st7789-1-3-inch-lcd-display/</link>
					<comments>https://krystof.io/mirroring-raspberry-pi-hdmi-video-to-a-st7789-1-3-inch-lcd-display/#comments</comments>
		
		<dc:creator><![CDATA[Eric R. Krystof]]></dc:creator>
		<pubDate>Wed, 15 Jan 2020 16:13:13 +0000</pubDate>
				<category><![CDATA[Raspberry Pi]]></category>
		<category><![CDATA[LCD Displays]]></category>
		<category><![CDATA[Featured]]></category>
		<guid isPermaLink="false">https://krystof.io/?p=1126</guid>

					<description><![CDATA[<p>I needed a small display for my Commodore diorama that mirrors the output of my Raspberry Pi - I found one with this 1.3 inch ST7789 driven LCD display.  Trouble was, mirroring this wasn't as straight forward as I would have liked.</p>
<p>The post <a rel="nofollow" href="https://krystof.io/mirroring-raspberry-pi-hdmi-video-to-a-st7789-1-3-inch-lcd-display/">Mirroring Raspberry Pi HDMI Video to a ST7789 1.3 inch LCD Display</a> appeared first on <a rel="nofollow" href="https://krystof.io">Krystof.IO</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>My Commodore 64 Diorama project was well underway.  After installing VICE on the console of a Raspberry Pi 4, the next step was to make sure I could get a tiny display that would fit some sort of &#8216;tiny monitor&#8217; I&#8217;d have to create further into the project.    I shopped around a few different places, but I ended up really liking two, both available from Adafruit.    Either way, we&#8217;re mirroring the Raspberry Pi to a ST7789 driven LCD display. </p>



<p><a href="https://krystof.io/installing-the-vice-commodore-emulator-for-console-mode-on-a-fresh-raspberry-pi-4/">Previously in the series</a>, we installed VICE on our Raspberry Pi and made sure it worked.  Now we want to mirror the HDMI output to our tiny LCD for the <a href="https://krystof.io/series/diorama-64/">diorama</a>.</p>



<p>Here&#8217;s our video that covers this article at a high level:</p>



<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe loading="lazy" title="Mirroring Raspberry Pi HDMI Video to a ST7789 1.3 inch LCD Display" width="1170" height="658" src="https://www.youtube.com/embed/1zTZgx9ilWU?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div></figure>



<h2 class="wp-block-heading" id="h-two-lcds-enter-one-lcd-leaves">Two LCDs enter, One LCD leaves</h2>



<p>The <a rel="noreferrer noopener" aria-label="OLED Breakout Board - 16-bit Color 0.96&quot; w/microSD holder (opens in a new tab)" href="https://www.adafruit.com/product/684" target="_blank">OLED Breakout Board &#8211; 16-bit Color 0.96&#8243; w/microSD holder</a> was a contender.  At about 1/12 scale this would have worked out nicely, though it felt a little &#8216;wide screen&#8217; compared to the monitors I knew of my youth.  I was also concerned with resolution, as it supports  96&#215;64, a far cry from the <a rel="noreferrer noopener" aria-label="Commodore 64's 320x200 (opens in a new tab)" href="http://www.studiostyle.sk/dmagic/gallery/gfxmodes.htm" target="_blank">Commodore 64&#8217;s 320&#215;200</a>.</p>



<figure class="wp-block-image size-large"><img decoding="async" loading="lazy" width="970" height="728" src="https://krystof.io/wp-content/uploads/2020/01/oled-.96inch.display.jpg" alt="" class="wp-image-1130" srcset="https://krystof.io/wp-content/uploads/2020/01/oled-.96inch.display.jpg 970w, https://krystof.io/wp-content/uploads/2020/01/oled-.96inch.display-300x225.jpg 300w, https://krystof.io/wp-content/uploads/2020/01/oled-.96inch.display-768x576.jpg 768w" sizes="(max-width: 970px) 100vw, 970px" /><figcaption>Image from Adafruit&#8217;s Product Page</figcaption></figure>



<p>The other, and my ultimate winner &#8211; the <a rel="noreferrer noopener" aria-label="Adafruit 1.3&quot; 240x240 Wide Angle TFT LCD Display with MicroSD - ST7789 (opens in a new tab)" href="https://www.adafruit.com/product/4313" target="_blank">Adafruit 1.3&#8243; 240&#215;240 Wide Angle TFT LCD Display with MicroSD &#8211; ST7789</a> at least got me closer with 240&#215;240, though it was a touch larger.  To that end, I&#8217;d try both with the Raspberry Pi and compare.  Once I plugged in the 240&#215;240 display and saw the Commodore 64 Ready screen, I was sold.  Even though you&#8217;d be able to make out what I was playing on the OLED display mirroring my HDMI output, with the 240&#215;240 you can actually read a good amount of text, as well.  <em>We have a winner.</em></p>



<figure class="wp-block-image size-large"><img decoding="async" loading="lazy" width="970" height="728" src="https://krystof.io/wp-content/uploads/2020/01/tftlcd-1.3inch.display.jpg" alt="" class="wp-image-1131" srcset="https://krystof.io/wp-content/uploads/2020/01/tftlcd-1.3inch.display.jpg 970w, https://krystof.io/wp-content/uploads/2020/01/tftlcd-1.3inch.display-300x225.jpg 300w, https://krystof.io/wp-content/uploads/2020/01/tftlcd-1.3inch.display-768x576.jpg 768w" sizes="(max-width: 970px) 100vw, 970px" /><figcaption>Image from Adafruit&#8217;s Product Page</figcaption></figure>



<h2 class="wp-block-heading" id="h-a-couple-of-quests-for-the-chosen-one">A Couple of Quests for the Chosen One</h2>



<p>Adafruit has a great page in terms of how to wire this up to an Arduino and Raspberry Pi located <a rel="noreferrer noopener" aria-label="here (opens in a new tab)" href="https://learn.adafruit.com/adafruit-1-3-and-1-54-240-x-240-wide-angle-tft-lcd-displays?view=all" target="_blank">here</a>. It&#8217;s where I learned that the ST7789 chip is used to drive two different LCD displays &#8211; 240&#215;240 and 320&#215;240.  This becomes important later as I struggle with getting that working on the Raspberry Pi.  Regardless of what display I chose &#8211; I knew I needed to have the following requirements satisfied:</p>



<ul><li>The LCD should mirror HDMI output &#8211; I didn&#8217;t want this to be the primary display, but a <em><strong>mirrored</strong></em> display.</li><li>The LCD screen needed to be in a specific orientation &#8211; <strong><em>pins on the bottom</em></strong> &#8211; so they could more easily hide inside the 3D printed monitor &#8216;bottom&#8217;</li></ul>



<h3 class="wp-block-heading" id="h-wire-before-you-fire">Wire Before You Fire</h3>



<p>The display doesn&#8217;t come with header pins pre-soldered, so after remembering which end of the soldering iron is the hot end, I was able to move forward by placing the display into my breadboard:</p>



<figure class="wp-block-image size-full"><img decoding="async" loading="lazy" width="804" height="226" src="https://krystof.io/wp-content/uploads/2020/01/2020-01-11_7-22-55.jpg" alt="" class="wp-image-1149" srcset="https://krystof.io/wp-content/uploads/2020/01/2020-01-11_7-22-55.jpg 804w, https://krystof.io/wp-content/uploads/2020/01/2020-01-11_7-22-55-300x84.jpg 300w, https://krystof.io/wp-content/uploads/2020/01/2020-01-11_7-22-55-768x216.jpg 768w" sizes="(max-width: 804px) 100vw, 804px" /></figure>



<p>I followed the basic Adafruit directions for wiring the ST7789 driven 240&#215;240 display into my Raspberry Pi.  Key points:</p>



<ul><li>This is an SPI mode device.  We&#8217;re using the Raspi&#8217;s SPI0 mode, so that some of the LCD pins need to wire up to specific Raspberry Pi Pins.  More on SPI here.</li><li>We have a choice on the LCD&#8217;s reset pin, we went with a loose default of 24 on the Pi.</li><li>We have a choice on the D/C pin, we went with a loose default of GPIO 25 on the Pi.</li></ul>



<p>Here&#8217;s from Adafruit&#8217;s page specific to our ST7789 driven LCD display: <em><strong>(Editors Note &#8211; If you compare this to Adafruit&#8217;s wiring page, you may notice I swapped my RST and D/C pins &#8211; Adafruit uses 24/25 and I&#8217;m using 25/24 &#8211; It&#8217;s fine as long as you&#8217;re consistent with your physical pins and the command line options you&#8217;ll use later.  Thanks, Thomas!)</strong></em></p>



<ul><li><strong>Vin</strong>&nbsp;connects to the Raspberry Pi&#8217;s&nbsp;<strong>3V</strong>&nbsp;pin</li><li><strong>GND</strong>&nbsp;connects to the Raspberry Pi&#8217;s&nbsp;<strong>ground</strong></li><li><strong>CLK</strong>&nbsp;connects to SPI clock. On the Raspberry Pi, thats&nbsp;<strong>SCLK</strong></li><li><strong>MOSI</strong>&nbsp;connects to SPI MOSI. On the Raspberry Pi, thats also&nbsp;<strong>MOSI</strong></li><li><strong>CS</strong>&nbsp;connects to our SPI Chip Select pin. We&#8217;ll be using&nbsp;<strong>CE0</strong></li><li><strong>RST</strong>&nbsp;connects to our Reset pin. We&#8217;ll be using&nbsp;<strong>GPIO 25</strong>&nbsp;but this can be changed later. </li><li><strong>D/C</strong>&nbsp;connects to our the data/command pin. We&#8217;ll be using&nbsp;<strong>GPIO 24</strong>, but this can be changed later as well.</li></ul>



<hr class="wp-block-separator"/>



<div data-padding="10" class="wp-block-simple-blocks-info-block" style="background-color:#000000;color:#ffffff;padding:10px"><div data-iconsize="20" data-iconspace="20" class="icon" style="margin-right:20px"><svg aria-hidden="true" role="img" focusable="false" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewbox="0 0 20 20" class="dashicon dashicons-info"><path d="M10 2c4.42 0 8 3.58 8 8s-3.58 8-8 8-8-3.58-8-8 3.58-8 8-8zm1 4c0-.55-.45-1-1-1s-1 .45-1 1 .45 1 1 1 1-.45 1-1zm0 9V9H9v6h2z"></path></svg></div><div><em>&#8220;But I looked at Adafruit&#8217;s page and they reference CS AND D/C as SPI Chip Select?&#8221;</em>  I noticed that too&#8230; and it was confusing to me.  It seems there are variations in how SPI works, and here&#8217;s a simple summary of the same question on Adafruit&#8217;s site:  <a rel="noreferrer noopener" label=" (opens in a new tab)" href="https://forums.adafruit.com/viewtopic.php?f=47&amp;t=51949" target="_blank" class="broken_link">https://forums.adafruit.com/viewtopic.php?f=47&amp;t=51949</a>.  Also, found a great summary here on <a rel="noreferrer noopener" aria-label="particle.io (opens in a new tab)" href="https://community.particle.io/t/ssd1306-via-hardware-spi/8448/4" target="_blank">particle.io</a>:<br><br><em>The DC or D/C pin is needed by some devices to distinguish between commands or data for the controler.<br>Since SPI only pushes out anonymous bitsreams the user code has to “tell” the controler if this will be a command (e.g. D/C LOW) or a data (e.g. D/C HIGH) bitstream. And so D/C is not actually an SPI pin, but this gives you freedom which Core pin to choose.</em><br></div></div>



<hr class="wp-block-separator"/>



<p>Remember that the Raspberry PI has numerous GPIO pins, but GPIO pin 24 doesn&#8217;t mean pin 24 on the pin-out diagram &#8211; always refer to some cheat sheet like this one from <a rel="noreferrer noopener" label="RaspberryPi.org (opens in a new tab)" href="https://www.raspberrypi.org/documentation/usage/gpio/" target="_blank" class="broken_link">RaspberryPi.org</a> shown below.  Also, another great Raspberry Pi pin-out page that&#8217;s interactive is made available by <a rel="noreferrer noopener" aria-label="Gadgetoid (opens in a new tab)" href="https://pinout.xyz/" target="_blank">Gadgetoid</a>.</p>



<div class="wp-block-envira-envira-gallery"><div class="envira-gallery-feed-output"><img class="envira-gallery-feed-image" tabindex="0" src="https://krystof.io/wp-content/uploads/2020/01/GPIO-Pinout-Diagram-2-1024x588.png" title="GPIO-Pinout-Diagram-2" alt="" /></div></div>



<p>Okay, so we&#8217;ve got it wired now, and there&#8217;s a promising backlight barely illuminating the LCD when we turn the PI on.  We&#8217;re one step closer to mirroring our Raspberry Pi to the ST7789 driven LCD Display.  Now what?</p>



<h2 class="wp-block-heading" id="h-lcd-driver-powers-activate-form-of-a-mirrored-display">LCD Driver Powers activate! Form of a mirrored display</h2>



<p>While I could have used Python to draw some Commodore images, screenshots, and other static media on the display, I want to actually mirror the display.  What shows on the HDMI output should show on the LCD, but I need the mirror scaled.  My monitor I&#8217;ll play games on doesn&#8217;t support 320&#215;240 as a resolution, the bare minimum is 800&#215;600 to make it work well enough.  So I searched around the internet and found a couple of solutions that did NOT turn the LCD into the only display or require me to overwrite with a new image.</p>



<p>This is where things might get a little confusing.  Both solutions I&#8217;m presenting here involve taking the HDMI display output and doing a little frame-buffer copy and manipulation magic.</p>



<hr class="wp-block-separator"/>



<div data-padding="10" class="wp-block-simple-blocks-info-block" style="background-color:#000000;color:#ffffff;padding:10px"><div data-iconsize="20" data-iconspace="20" class="icon" style="margin-right:20px"><svg aria-hidden="true" role="img" focusable="false" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewbox="0 0 20 20" class="dashicon dashicons-info"><path d="M10 2c4.42 0 8 3.58 8 8s-3.58 8-8 8-8-3.58-8-8 3.58-8 8-8zm1 4c0-.55-.45-1-1-1s-1 .45-1 1 .45 1 1 1 1-.45 1-1zm0 9V9H9v6h2z"></path></svg></div><div>Keep in mind that as the time of this writing, I&#8217;m using the Raspbian Buster Lite image on a Raspberry Pi 4.  Mileage may vary in the future.</div></div>



<hr class="wp-block-separator"/>



<ol><li>Notro&#8217;s <strong>fbtft</strong> LCD device drivers, which create an LCD frame buffer at /dev/fb1, then utilizing tasanakorn&#8217;s <strong>fbcp</strong> program which copies /dev/fb0 (HDMI output) to /dev/fb1 (LCD output), effectively mirroring the display.</li><li>juj&#8217;s <strong>fbcp-ili9341</strong> display driver that effectively does the same thing as #1, though it doesn&#8217;t technically create it&#8217;s own framebuffer, and it&#8217;s not just for ili9341 displays (it supports my ST7789!)</li></ol>



<p>Which one to use?  Well, if only one works for you, choose that one.  Otherwise, I found that  the second, <strong>fbcp-ili9341</strong> worked the best, but it does utilize a little more CPU, so you may very well want to test both (the Raspberry Pi 4 handled it fine)</p>



<p>The primary issues I had with both of these solutions involved rotation.  My requirements for either solution were to have the header pins aligned with the bottom of the display so I could more easily hide them in the mini-LCD monitor&#8217;s bottom piece.  </p>



<h3 class="wp-block-heading" id="h-option-1-fbtft-and-fbcp">Option 1 &#8211; fbtft and fbcp</h3>



<h4 class="wp-block-heading" id="h-the-journey-to-a-working-lcd-mirror">The Journey to a working LCD mirror</h4>



<p>Notro&#8217;s <a rel="noreferrer noopener" aria-label="fbtft driver (opens in a new tab)" href="https://github.com/notro/fbtft" target="_blank">fbtft driver</a> repo seems to be still a good reference point but may not be forever.  There&#8217;s a lot of discussion around the future of this project, as part of it has been brought into the Linux staging structure, and that it may stay there forever stagnating based on some discussions on the <a rel="noreferrer noopener" aria-label="development page (opens in a new tab)" href="https://github.com/notro/fbtft/wiki/Development" target="_blank">development page</a>.  Nevertheless, it did end up working.</p>



<p>There&#8217;s a lot of good information to sift through on that wiki, but I&#8217;ll keep this page more towards my journey in getting it working.</p>



<p>I saw some references in the staging code base to the ST7789 driver, so it felt promising:</p>



<p><a href="https://github.com/torvalds/linux/blob/master/drivers/staging/fbtft/fb_st7789v.c" target="_blank" rel="noreferrer noopener" aria-label=" (opens in a new tab)">https://github.com/torvalds/linux/blob/master/drivers/staging/fbtft/fb_st7789v.c</a></p>



<p>Now, the key here is that if these drivers are effectively already part of my Raspbian install, I should be able to use the Linux modprobe commands to load these modules in.  By looking at other sample modprobe commands I tried this against my Raspberry Pi with the LCD on the breadboard:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
#Screen mirrors but inverted colors and rotation
sudo modprobe --first-time fbtft_device name=fb_st7789v custom width=240 height=240 speed=32000000 gpios=reset:25,dc:24
</pre></div>


<p>The command above loads the <em>fbtft_device</em> module with a custom configuration based on the provided driver <em>fb_st7789v</em>.  Notice that we didn&#8217;t have to declare the standard SPI pins but we need to reference our two custom GPIO pins from the wiring section &#8211; reset and dc.</p>



<p><em>Remember that this command just creates a framebuffer for the LCD at /dev/fb1, it doesn&#8217;t actively mirror the display.  We need the fbcp program for that.</em>  I just run fbcp as a background process and voila.  The LCD came to life &#8230; but it&#8217;s a little off.  (Also, don&#8217;t worry, the full setup steps are at the end)</p>



<p>Here&#8217;s the result when I ran &#8216;htop&#8217;:</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" loading="lazy" width="1024" height="578" src="https://krystof.io/wp-content/uploads/2020/01/2020-01-11_20-50-06-1024x578.jpg" alt="" class="wp-image-1161" srcset="https://krystof.io/wp-content/uploads/2020/01/2020-01-11_20-50-06-1024x578.jpg 1024w, https://krystof.io/wp-content/uploads/2020/01/2020-01-11_20-50-06-300x169.jpg 300w, https://krystof.io/wp-content/uploads/2020/01/2020-01-11_20-50-06-768x434.jpg 768w, https://krystof.io/wp-content/uploads/2020/01/2020-01-11_20-50-06.jpg 1220w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>I want none of this.</figcaption></figure></div>



<p>If you don&#8217;t know what that <strong>should</strong> look like, I can tell you that display screen is rotated 180 degrees off my desired layout (pins on the bottom), and the screen color is &#8216;negative&#8217;.  It should be a black screen with white text.</p>



<p>Now I&#8217;m off to figure out how to rotate and how to invert the colors.  I dug around the issues page on the wiki and found this reference:</p>



<p><a href="https://github.com/notro/fbtft/issues/425">https://github.com/notro/fbtft/issues/425</a></p>



<p>Github user <a rel="noreferrer noopener" aria-label="tr1p1ea  (opens in a new tab)" href="https://github.com/tr1p1ea" target="_blank">tr1p1ea </a>references an init string argument you can also pass along in the modprobe argument, which probably was setting some ST7789 specific codes I needed to set.</p>



<pre class="wp-block-code"><code>init=-1,0x11,-2,120,-1,0x36,0x00,-1,0x3A,0x05,-1,0xB2,0x0C,0x0C,0x00,0x33,0x33,-1,0xB7,0x35,-1,0xBB,0x1A,-1,0xC0,0x2C,-1,0xC2,0x01,-1,0xC3,0x0B,-1,0xC4,0x20,-1,0xC6,0x0F,-1,0xD0,0xA4,0xA1,-1,0x21,-1,0xE0,0x00,0x19,0x1E,0x0A,0x09,0x15,0x3D,0x44,0x51,0x12,0x03,0x00,0x3F,0x3F,-1,0xE1,0x00,0x18,0x1E,0x0A,0x09,0x25,0x3F,0x43,0x52,0x33,0x03,0x00,0x3F,0x3F,-1,0x29,-3</code></pre>



<p>What is all this crap?  These are initialization parameters you can send directly to your LCD driver chipset.  Notro&#8217;s page has some information there, but understanding the specifics for your LCD require the datasheet.  Nevertheless, I tried it out and we got farther&#8230;</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" loading="lazy" width="1024" height="579" src="https://krystof.io/wp-content/uploads/2020/01/2020-01-12_7-21-49-1024x579.jpg" alt="" class="wp-image-1167" srcset="https://krystof.io/wp-content/uploads/2020/01/2020-01-12_7-21-49-1024x579.jpg 1024w, https://krystof.io/wp-content/uploads/2020/01/2020-01-12_7-21-49-300x170.jpg 300w, https://krystof.io/wp-content/uploads/2020/01/2020-01-12_7-21-49-768x434.jpg 768w, https://krystof.io/wp-content/uploads/2020/01/2020-01-12_7-21-49.jpg 1222w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>Okay, color looks good, now let&#8217;s rotate it.</figcaption></figure></div>



<p>The fbtft_device page on the wiki references other parameters &#8211; one of them being rotate:</p>



<pre class="wp-block-code"><code>rotate
Angle to rotate display counter clockwise: 0, 90, 180, 270 </code></pre>



<p>Okay, so we rotate with our updated command &#8211; I figured 180 degrees to start.</p>



<pre class="wp-block-code"><code>sudo modprobe --first-time fbtft_device name=fb_st7789v custom width=240 height=240 speed=32000000 rotate=180 gpios=reset:25,dc:24 init=-1,0x11,-2,120,-1,0x36,0x00,-1,0x3A,0x05,-1,0xB2,0x0C,0x0C,0x00,0x33,0x33,-1,0xB7,0x35,-1,0xBB,0x1A,-1,0xC0,0x2C,-1,0xC2,0x01,-1,0xC3,0x0B,-1,0xC4,0x20,-1,0xC6,0x0F,-1,0xD0,0xA4,0xA1,-1,0x21,-1,0xE0,0x00,0x19,0x1E,0x0A,0x09,0x15,0x3D,0x44,0x51,0x12,0x03,0x00,0x3F,0x3F,-1,0xE1,0x00,0x18,0x1E,0x0A,0x09,0x25,0x3F,0x43,0x52,0x33,0x03,0x00,0x3F,0x3F,-1,0x29,-3</code></pre>



<p>Which now leaves us with something completely different &#8211; I thought I saw rotation but couldn&#8217;t tell easily &#8211; so I ran VICE and saw it fill up only part of the screen!</p>



<figure class="wp-block-image size-large"><img decoding="async" loading="lazy" width="1024" height="580" src="https://krystof.io/wp-content/uploads/2020/01/2020-01-12_15-32-31-1024x580.jpg" alt="" class="wp-image-1173" srcset="https://krystof.io/wp-content/uploads/2020/01/2020-01-12_15-32-31-1024x580.jpg 1024w, https://krystof.io/wp-content/uploads/2020/01/2020-01-12_15-32-31-300x170.jpg 300w, https://krystof.io/wp-content/uploads/2020/01/2020-01-12_15-32-31-768x435.jpg 768w, https://krystof.io/wp-content/uploads/2020/01/2020-01-12_15-32-31.jpg 1220w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>What fresh hell is this?</figcaption></figure>



<p>During my research on fbtft and fbcp, I ran across that the ST7789 driver chip supported 320&#215;240 <strong><em>and</em></strong> 240&#215;240 displays.  So it looked like to me that my 240&#215;240 lcd was acting as a viewport into the &#8216;opposite end&#8217; of the video ram that stores the 240&#215;240 image as configured by our modprobe command.</p>



<p>I had a rough idea now of what I was looking for &#8211; I need to &#8216;scroll&#8217; up about 320-240 = 80 pixels.  How the **** am I supposed to do this?  At this point I started looking for the ST7789 data sheet so I could see if there was some &#8216;mode&#8217; or related setting.  After perusing this for a while, I found something quite interesting in the <a rel="noreferrer noopener" aria-label="PDF (opens in a new tab)" href="https://www.rhydolabz.com/documents/33/ST7789.pdf" target="_blank">PDF</a>:</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" loading="lazy" width="535" height="622" src="https://krystof.io/wp-content/uploads/2020/01/2020-01-12_15-39-58.jpg" alt="" class="wp-image-1174" srcset="https://krystof.io/wp-content/uploads/2020/01/2020-01-12_15-39-58.jpg 535w, https://krystof.io/wp-content/uploads/2020/01/2020-01-12_15-39-58-258x300.jpg 258w" sizes="(max-width: 535px) 100vw, 535px" /><figcaption>This looks promising!</figcaption></figure></div>



<p>At this point it looked like I wanted to add to our init string.  Something with instruction 37h, with 2 parameters.  I defaulted the first to zero and the second to the number of pixels I wanted to &#8216;scroll&#8217;.  I wasn&#8217;t sure if my rotation settings &#8216;inverted&#8217; the pixel count so I just started with the difference of 320-240 = 80.  Of course, we&#8217;re dealing with hex, so thats 0x50.  The full piece of the initialization string I inserted after the 0x36 instruction follows:</p>



<pre class="wp-block-preformatted">-1,0x37,0x00,0x50
<strong>-1</strong> (break for new instruction)
<strong>0x37</strong> Instruction for Vertical Scroll Start Address Of RAM
<strong>0x00</strong> First Parameter  (defaulted this to 0)
<strong>0x50</strong> Second Parameter (set this to 80 pixels, converted to hex)</pre>



<p>So now my init string, with the extra 37h instruction added, yielded this result:</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" loading="lazy" width="1024" height="577" src="https://krystof.io/wp-content/uploads/2020/01/2020-01-12_15-47-06-1024x577.jpg" alt="" class="wp-image-1175" srcset="https://krystof.io/wp-content/uploads/2020/01/2020-01-12_15-47-06-1024x577.jpg 1024w, https://krystof.io/wp-content/uploads/2020/01/2020-01-12_15-47-06-300x169.jpg 300w, https://krystof.io/wp-content/uploads/2020/01/2020-01-12_15-47-06-768x433.jpg 768w, https://krystof.io/wp-content/uploads/2020/01/2020-01-12_15-47-06.jpg 1226w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>Holy crap, it actually worked.</figcaption></figure></div>



<h4 class="wp-block-heading" id="h-install-instructions-for-option-1-fbtft-and-fbcp">Install Instructions for Option 1 &#8211; fbtft and fbcp</h4>



<p>So, we at least have something working.  That was the entire goal of this first stage &#8211; just get the LCD mirroring the HDMI output of my Raspberry Pi with VICE.  Good to go!  So let&#8217;s finish off option 1 by building the list of instructions.</p>



<p>Since fbtft drivers are already part of Raspbian Buster, all we really need to do is download and copy fbcp, and basing the instructions off that GitHub page: <a rel="noreferrer noopener" aria-label="https://github.com/tasanakorn/rpi-fbcp (opens in a new tab)" href="https://github.com/tasanakorn/rpi-fbcp" target="_blank">https://github.com/tasanakorn/rpi-fbcp</a></p>



<hr class="wp-block-separator"/>



<div data-padding="10" class="wp-block-simple-blocks-info-block" style="background-color:#000000;color:#ffffff;padding:10px"><div data-iconsize="20" data-iconspace="20" class="icon" style="margin-right:20px"><svg aria-hidden="true" role="img" focusable="false" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewbox="0 0 20 20" class="dashicon dashicons-info"><path d="M10 2c4.42 0 8 3.58 8 8s-3.58 8-8 8-8-3.58-8-8 3.58-8 8-8zm1 4c0-.55-.45-1-1-1s-1 .45-1 1 .45 1 1 1 1-.45 1-1zm0 9V9H9v6h2z"></path></svg></div><div>This option is here to best describe the journey &#8211; I ended up going with Option 2 &#8211; FBCP-ILI9341</div></div>



<hr class="wp-block-separator"/>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
mkdir ~/fbcp-src
cd ~/fbcp-src

git clone https://github.com/tasanakorn/rpi-fbcp.git
cd rpi-fbcp/

mkdir build
cd build
cmake ..
make
</pre></div>


<p>After that point, a new <em><strong>fbcp</strong></em> binary now exists in the build directory we just made.</p>



<p>To just test the general execution of these two, I&#8217;ll enter the commands into the shell.  Afterwards I&#8217;d see the LCD activate and mirror the screen properly.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
#start LCD Driver - create fb1 frame buffer
sudo modprobe --first-time fbtft_device name=fb_st7789v custom width=240 height=240 speed=32000000 rotate=180 gpios=reset:25,dc:24 init=-1,0x11,-2,120,-1,0x36,0x00,-1,0x37,0x00,0x50,-1,0x3A,0x05,-1,0xB2,0x0C,0x0C,0x00,0x33,0x33,-1,0xB7,0x35,-1,0xBB,0x1A,-1,0xC0,0x2C,-1,0xC2,0x01,-1,0xC3,0x0B,-1,0xC4,0x20,-1,0xC6,0x0F,-1,0xD0,0xA4,0xA1,-1,0x21,-1,0xE0,0x00,0x19,0x1E,0x0A,0x09,0x15,0x3D,0x44,0x51,0x12,0x03,0x00,0x3F,0x3F,-1,0xE1,0x00,0x18,0x1E,0x0A,0x09,0x25,0x3F,0x43,0x52,0x33,0x03,0x00,0x3F,0x3F,-1,0x29,-3
</pre></div>


<p>Then, we need to run fbcp so it can copy the framebuffer from HDMI (/dev/fb0) to the LCD (/dev/fb1) &#8211; run this from your fbcp&#8217;s build directory you created earlier:</p>



<pre class="wp-block-preformatted">./fbcp &amp;</pre>



<p>What if we want this to run on start up?  There are numerous ways to do that, here&#8217;s a simple one &#8211; pop it into rc.local.  We&#8217;ll cover alternate methods later in the series, this article is just about getting the LCD going.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
#Copy fbcp and start it up and the fbtft drivers  (run from your fbcp build dir)
sudo cp fbcp /usr/bin 
sudo chmod +x /usr/bin/fbcp

sudo nano /etc/rc.local
</pre></div>


<p>Add the following lines to rc.local before &#8216;exit 0&#8217;.  Remember the sudo modprobe is <em>all one single line</em>.</p>



<pre class="wp-block-code"><code>sudo modprobe --first-time fbtft_device name=fb_st7789v custom width=240 height=240 speed=32000000 rotate=180 gpios=reset:25,dc:24 init=-1,0x11,-2,120,-1,0x36,0x00,-1,0x37,0x00,0x50,-1,0x3A,0x05,-1,0xB2,0x0C,0x0C,0x00,0x33,0x33,-1,0xB7,0x35,-1,0xBB,0x1A,-1,0xC0,0x2C,-1,0xC2,0x01,-1,0xC3,0x0B,-1,0xC4,0x20,-1,0xC6,0x0F,-1,0xD0,0xA4,0xA1,-1,0x21,-1,0xE0,0x00,0x19,0x1E,0x0A,0x09,0x15,0x3D,0x44,0x51,0x12,0x03,0x00,0x3F,0x3F,-1,0xE1,0x00,0x18,0x1E,0x0A,0x09,0x25,0x3F,0x43,0x52,0x33,0x03,0x00,0x3F,0x3F,-1,0x29,-3

#
#Add a little sleep before starting fbcp to allow fbtft to initialize
#(your display might stay blank otherwise)
#
sleep 2

/usr/bin/fbcp &amp;</code></pre>



<p>Reboot and you should see the screen mirror after the boot process initializes some.  If you don&#8217;t have your HDMI output active, VICE may not load (it doesn&#8217;t get a good hook into /dev/fb0) &#8211; so you may need to edit your /boot/config.txt and add:</p>



<pre class="wp-block-code"><code>hdmi_force_hotplug=1</code></pre>



<h3 class="wp-block-heading" id="h-option-2-fbcp-ili9341">Option 2 &#8211; fbcp-ili9341</h3>



<h4 class="wp-block-heading" id="h-a-faster-alternative-to-fbtft-fbcp-that-uses-a-little-more-cpu">A faster alternative to fbtft/fbcp that uses a little more CPU</h4>



<p>I was initially happy with option 1 &#8211; I wasn&#8217;t planning on playing games using the tiny LCD, just mirror it so the diorama looked alive.  However, I still perused a few other search threads and found out about this other option called <strong>fbcp-ili9341</strong>, and while the name may be confusing (it doesn&#8217;t create a framebuffer, and it&#8217;s not just for the ili9341 driver), I was able to get it working with our ST7789 1.3&#8243; LCD display.  </p>



<p><strong>Why did I try it out?</strong> Turns out, SPI doesn&#8217;t have the inherent bandwidth as it stands with libtft and fbcp &#8211; and since I&#8217;m playing games, which inherently implies video as opposed to text, I noticed the refresh rate on the LCD was always a little stuttered while playing C64 games and demos.  Through some optimizations and shortcuts, the author juj has created an alternative that is faster than our option 1, all the way to 60fps.  Ohhhhh yeah.</p>



<p>So here&#8217;s the journey to making that work.  A little easier, and a bit nicer payoff.  This option, while using a little more CPU (Our Raspi has 4 cores, so it&#8217;s not a big deal), is <strong><em>fast</em></strong>.  In fact, it says so on it&#8217;s <a rel="noreferrer noopener" aria-label="GitHub page (opens in a new tab)" href="https://github.com/juj/fbcp-ili9341" target="_blank">GitHub page</a>, so you know it&#8217;s true!</p>



<p>Since the name is also confusing, here&#8217;s <em>why</em> it&#8217;s named the way it is:</p>



<p><em>The&nbsp;<code>fbcp</code>&nbsp;part in the name means&nbsp;framebuffer copy; specifically for the ILI9341 controller. fbcp-ili9341 is not actually a framebuffer copying driver, it does not create a secondary framebuffer that it would copy bytes across to from the primary framebuffer. It is also no longer a driver only for the ILI9341 controller. A more appropriate name might be&nbsp;userland-raspi-spi-display-driver&nbsp;or something like that, but the original name stuck. </em></p>



<p>So I downloaded the source and compiled it, and there&#8217;s effectively just one execution line since this takes the place of fbtft and fbcp &#8211; in fact, you can&#8217;t run both at the same time &#8211; test with Option 1 or Option 2 separately.</p>



<p>The <strong>cmake</strong> command to the build takes a few options in, and I chose these as my initial settings so I could see what it would do:</p>



<pre class="wp-block-preformatted"><strong>-DST7789=ON</strong> 
There's built in support for our chip set, so this was a natural choice.
<strong>-DGPIO_TFT_DATA_CONTROL=24</strong>
Same as option 1 - our custom pin we chose for data control.
<strong>-DGPIO_TFT_RESET_PIN=25</strong>
Same as option 1 - our custom pin for LCD display reset.
<strong>-DSPI_BUS_CLOCK_DIVISOR=30</strong>
My sensible default based on the GitHub page - lower is more responsive but may cause screen artifacts on LCDs.</pre>



<p>Compiling with those options successfully, I now had a fbcp-ili9341 binary to execute.  Survey says&#8230;</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" loading="lazy" width="1024" height="578" src="https://krystof.io/wp-content/uploads/2020/01/2020-01-13_15-25-04-1024x578.jpg" alt="" class="wp-image-1191" srcset="https://krystof.io/wp-content/uploads/2020/01/2020-01-13_15-25-04-1024x578.jpg 1024w, https://krystof.io/wp-content/uploads/2020/01/2020-01-13_15-25-04-300x169.jpg 300w, https://krystof.io/wp-content/uploads/2020/01/2020-01-13_15-25-04-768x433.jpg 768w, https://krystof.io/wp-content/uploads/2020/01/2020-01-13_15-25-04.jpg 1225w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>Rotated 90 degrees off, and looks like some debugging info at the &#8216;top&#8217;.</figcaption></figure></div>



<p>Okay, we can fix this.  Reading up on a reported issue in the project&#8217;s GitHub issues list, I found reference to a couple of items to change in the code:</p>



<pre class="wp-block-preformatted"><strong>define DISPLAY_OUTPUT_LANDSCAPE</strong> - If we comment this out, we'll rotate the display 90 degrees - which way though?  Let's try and find out what happens.</pre>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" loading="lazy" width="1024" height="491" src="https://krystof.io/wp-content/uploads/2020/01/2020-01-13_15-30-45-1024x491.jpg" alt="" class="wp-image-1192" srcset="https://krystof.io/wp-content/uploads/2020/01/2020-01-13_15-30-45-1024x491.jpg 1024w, https://krystof.io/wp-content/uploads/2020/01/2020-01-13_15-30-45-300x144.jpg 300w, https://krystof.io/wp-content/uploads/2020/01/2020-01-13_15-30-45-768x369.jpg 768w, https://krystof.io/wp-content/uploads/2020/01/2020-01-13_15-30-45.jpg 1440w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>Getting closer&#8230;</figcaption></figure></div>



<p>So we&#8217;re rotated properly, but we&#8217;re reversed.  The text should be on the left.  So we need to reverse the image, not just a simple rotation.  Here&#8217;s the next changes I tried:</p>



<pre class="wp-block-preformatted"><strong>madctl ^= MADCTL_COLUMN_ADDRESS_ORDER_SWAP;</strong>  - Adding this line into another file will mirror image the display - Sold!

<strong>-DSTATISTICS=0</strong> Remove that debug information</pre>



<p>So, we try this change and rebuild, and we now have&#8230;</p>



<figure class="wp-block-image size-large"><img decoding="async" loading="lazy" width="1024" height="578" src="https://krystof.io/wp-content/uploads/2020/01/2020-01-13_15-36-03-1024x578.jpg" alt="" class="wp-image-1195" srcset="https://krystof.io/wp-content/uploads/2020/01/2020-01-13_15-36-03-1024x578.jpg 1024w, https://krystof.io/wp-content/uploads/2020/01/2020-01-13_15-36-03-300x169.jpg 300w, https://krystof.io/wp-content/uploads/2020/01/2020-01-13_15-36-03-768x434.jpg 768w, https://krystof.io/wp-content/uploads/2020/01/2020-01-13_15-36-03.jpg 1224w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>The proper orientation, but &#8230; slightly squeezed.  Like an 8-bit orange.</figcaption></figure>



<p>Now we&#8217;re getting there!  We&#8217;re oriented in the right way, and the image reads left to right.  Only thing now is to change the scaling, which is how my research led to this option:</p>



<pre class="wp-block-preformatted"><strong>-DDISPLAY_BREAK_ASPECT_RATIO_WHEN_SCALING=ON</strong> - I expected something like this because our display is 240 wide, so it's scaling 180 on the vertical to maintain aspect ratio.  Let's just make it fill the whole thing so we don't have the black bars of doom.</pre>



<p>And now&#8230;.</p>



<figure class="wp-block-image size-large"><img decoding="async" loading="lazy" width="1024" height="491" src="https://krystof.io/wp-content/uploads/2020/01/2020-01-13_15-56-22-1024x491.jpg" alt="" class="wp-image-1196" srcset="https://krystof.io/wp-content/uploads/2020/01/2020-01-13_15-56-22-1024x491.jpg 1024w, https://krystof.io/wp-content/uploads/2020/01/2020-01-13_15-56-22-300x144.jpg 300w, https://krystof.io/wp-content/uploads/2020/01/2020-01-13_15-56-22-768x369.jpg 768w, https://krystof.io/wp-content/uploads/2020/01/2020-01-13_15-56-22.jpg 1440w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>We&#8217;re done!</figcaption></figure>



<p>So now I&#8217;ve got both options working in the same fashion.  There are differences though, and we&#8217;ll cover that in the next section below, after the &#8216;install instructions&#8217;</p>



<h4 class="wp-block-heading" id="h-install-instructions-for-option-2-fbcp-ili9341">Install Instructions for Option 2 &#8211; fbcp-ili9341</h4>



<p>Our goal is to download fbcp-ili9341, perform some quick modifications to the code, set our options, compile, and execute it.</p>



<div data-padding="10" class="wp-block-simple-blocks-info-block" style="background-color:#000000;color:#ffffff;padding:10px"><div data-iconsize="20" data-iconspace="20" class="icon" style="margin-right:20px"><svg aria-hidden="true" role="img" focusable="false" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewbox="0 0 20 20" class="dashicon dashicons-info"><path d="M10 2c4.42 0 8 3.58 8 8s-3.58 8-8 8-8-3.58-8-8 3.58-8 8-8zm1 4c0-.55-.45-1-1-1s-1 .45-1 1 .45 1 1 1 1-.45 1-1zm0 9V9H9v6h2z"></path></svg></div><div>If you are running Option 1 on start up of your PI, you should disable that first.  Option 1 and Option 2 are mutually exclusive.</div></div>



<p>If necessary, download the dependencies required:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
sudo apt-get install cmake
</pre></div>


<p>Then let&#8217;s download our source code:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
mkdir ~/fbcp-ili9341
cd ~/fbcp-ili9341
git clone https://github.com/juj/fbcp-ili9341.git
</pre></div>


<p>This creates and downloads the source to /home/pi/fbcp-ili9341/fbcp-ili9341  (Yeah, it&#8217;s a double directory, I always make my own root directories for compilation work)</p>



<p>Before we compile, we need to make the edits referenced in our previous section on figuring out how Option 2 was going to work.  </p>



<p>Edit your config.h file:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
nano ~/fbcp-ili9341/fbcp-ili9341/config.h
</pre></div>


<p>Comment out the line below (the example is already commented out)</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: cpp; title: ; notranslate">
//#define DISPLAY_OUTPUT_LANDSCAPE
</pre></div>


<p>Next, we&#8217;ll edit our ST7789 (actually it&#8217;s a file that handles a couple of ST-made chips) specific file to do the &#8216;mirroring&#8217; swap.  Edit the following:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
nano ~/fbcp-ili9341/fbcp-ili9341/st7735r.cpp
</pre></div>


<p>and add the following line:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: cpp; title: ; notranslate">
madctl ^= MADCTL_COLUMN_ADDRESS_ORDER_SWAP;
</pre></div>


<p>somewhere before this line:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: cpp; title: ; notranslate">
SPI_TRANSFER(0x36/MADCTL: Memory Access Control/, madctl);
</pre></div>


<p><strong>Optional Gamma Change: </strong>I&#8217;ve also, over time, discovered that I like the screen a little darker, primarily because I have a camera pointed at it at the Twitch stream and it causes some overexposure of the screen compared to the diorama itself.  So you can make the gamma 1.0 by changing this line in the same file:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: cpp; title: ; notranslate">
SPI_TRANSFER(0x26/Gamma Curve Select/, 0x04/Gamma curve 3 (2.5x if GS=1, 2.2x otherwise)/);
</pre></div>


<p>Change the 0x04 to 0x08:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: cpp; title: ; notranslate">
SPI_TRANSFER(0x26/Gamma Curve Select/, 0x08/Gamma curve 3 (2.5x if GS=1, 2.2x otherwise)/);
</pre></div>


<p>That&#8217;s it for file editing, let&#8217;s get back to the compile.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
cd ~/fbcp-ili9341/fbcp-ili9341
mkdir build
cd build
cmake -DST7789=ON -DGPIO_TFT_DATA_CONTROL=24 -DGPIO_TFT_RESET_PIN=25 -DSPI_BUS_CLOCK_DIVISOR=30 -DSTATISTICS=0 -DDISPLAY_BREAK_ASPECT_RATIO_WHEN_SCALING=ON ..
make -j
</pre></div>


<p>This will create the <strong>fbcp-ili9341</strong> binary in the build directory.  Try it out by running it and hitting CTRL-C when you&#8217;re done.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
sudo ./fbcp-ili9341
</pre></div>


<p>If that works nicely for you, you could also make a quick hack to your /etc/rc.local file and make it boot on startup.  (This is a quick hack)</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
#Copy fbcp-ili9341 and start it up on boot
sudo cp ./fbcp-ili9341 /usr/bin 
sudo chmod +x /usr/bin/fbcp-ili9341

sudo nano /etc/rc.local
</pre></div>


<p>Add the following line to rc.local before &#8216;exit 0&#8217;.  </p>



<pre class="wp-block-code"><code>sudo /usr/bin/fbcp-ili9341 &amp;</code></pre>



<h2 class="wp-block-heading" id="h-comparing-mirroring-options">Comparing Mirroring Options</h2>



<p>You may notice right off the bat that the default initialization of our option 1 vs option 2 have a stark difference in brightness.  I didn&#8217;t investigate further in making the first option brighter, because I was just so happy with option 2 as a whole I never looked back.</p>



<figure class="wp-block-image size-large"><img decoding="async" loading="lazy" width="1024" height="590" src="https://krystof.io/wp-content/uploads/2020/01/2020-01-13_19-27-03-1024x590.jpg" alt="" class="wp-image-1222" srcset="https://krystof.io/wp-content/uploads/2020/01/2020-01-13_19-27-03-1024x590.jpg 1024w, https://krystof.io/wp-content/uploads/2020/01/2020-01-13_19-27-03-300x173.jpg 300w, https://krystof.io/wp-content/uploads/2020/01/2020-01-13_19-27-03-768x443.jpg 768w, https://krystof.io/wp-content/uploads/2020/01/2020-01-13_19-27-03.jpg 1199w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>Option 2 may seem almost too bright from the photo, but it&#8217;s actually not bad for me in person.</figcaption></figure>



<p>Option 2, as you can see in the video segment at the beginning of this article, has a much higher frame rate as promised.  While I did try two different arguments to the <strong>SPI_BUS_CLOCK_DIVISOR</strong> option (30 and 8), I really didn&#8217;t see much of a difference in my eyes.  The big difference is between fbtft/fbcp being much slower than fbcp-ili9341.  </p>



<p>What&#8217;s the trade-off?  As you see in the video, there&#8217;s about a 20-40% spike in one of my Pi&#8217;s cores on FBCP-ILI9341 vs regular old FBCP.  Given I&#8217;m using a beefy Raspberry Pi, I detected no issues in game play.  Your mileage may vary.</p>



<p>So we&#8217;ve now got part of our diorama circuitry working &#8211; we successfully mirrored the Raspberry Pi HDMI output to the ST7789 driven LCD display, showing whatever we play on our VICE Commodore emulator&#8217;s HDMI output.  There&#8217;s more to come, though!  Remember those 1541 disk drives that Commodore computers utilized?  Well, we need to make sure that the LEDs we plan on putting in those floppy drives <strong>light up according to activity in VICE</strong>.  To do that, we&#8217;ll need to create a custom VICE build (we&#8217;ll be doing a small bit of C programming) so we can drive LED activity and power LEDs based on whatever VICE is doing.  That will be the next article in the series, coming soon.</p>



<h2 class="wp-block-heading" id="h-references-and-further-reading">References and Further Reading</h2>



<p><strong>SPI &#8211; Serial Peripheral Interface</strong></p>



<p><a rel="noreferrer noopener" aria-label="https://learn.sparkfun.com/tutorials/serial-peripheral-interface-spi/all (opens in a new tab)" href="https://learn.sparkfun.com/tutorials/serial-peripheral-interface-spi/all" target="_blank">https://learn.sparkfun.com/tutorials/serial-peripheral-interface-spi/all</a><br><a rel="noreferrer noopener" aria-label="https://en.wikipedia.org/wiki/Serial_Peripheral_Interface (opens in a new tab)" href="https://en.wikipedia.org/wiki/Serial_Peripheral_Interface" target="_blank">https://en.wikipedia.org/wiki/Serial_Peripheral_Interface</a><br><a href="https://www.raspberrypi.org/documentation/hardware/raspberrypi/spi/README.md" class="broken_link">https://www.raspberrypi.org/documentation/hardware/raspberrypi/spi/README.md</a><br><a rel="noreferrer noopener" aria-label="https://learn.adafruit.com/circuitpython-on-raspberrypi-linux/spi-sensors-devices (opens in a new tab)" href="https://learn.adafruit.com/circuitpython-on-raspberrypi-linux/spi-sensors-devices" target="_blank">https://learn.adafruit.com/circuitpython-on-raspberrypi-linux/spi-sensors-devices</a></p>



<p><strong>Option 1 &#8211; FBTFT/FBCP</strong></p>



<p><a href="https://github.com/notro/fbtft" target="_blank" rel="noreferrer noopener" aria-label=" (opens in a new tab)">https://github.com/notro/fbtft</a></p>



<p><a href="https://github.com/notro/fbtft/wiki/Development" target="_blank" rel="noreferrer noopener" aria-label=" (opens in a new tab)">https://github.com/notro/fbtft/wiki/Development</a></p>



<p><a href="https://github.com/torvalds/linux/blob/master/drivers/staging/fbtft/fb_st7789v.c" target="_blank" rel="noreferrer noopener" aria-label=" (opens in a new tab)">https://github.com/torvalds/linux/blob/master/drivers/staging/fbtft/fb_st7789v.c</a></p>



<p><a href="https://github.com/notro/fbtft/issues/425" target="_blank" rel="noreferrer noopener" aria-label=" (opens in a new tab)">https://github.com/notro/fbtft/issues/425</a></p>



<p><a href="https://www.rhydolabz.com/documents/33/ST7789.pdf" target="_blank" rel="noreferrer noopener" aria-label=" (opens in a new tab)">https://www.rhydolabz.com/documents/33/ST7789.pdf</a></p>



<p><a rel="noreferrer noopener" aria-label=" (opens in a new tab)" href="https://github.com/tasanakorn/rpi-fbcp" target="_blank">https://github.com/tasanakorn/rpi-fbcp</a></p>



<p><strong>Option 2 &#8211; FBCP-ILI9341</strong></p>



<p><a href="https://github.com/juj/fbcp-ili9341">https://github.com/juj/fbcp-ili9341</a></p>



<p><strong>Raspberry Pi GPIO Information</strong></p>



<p><a href="https://www.raspberrypi.org/documentation/usage/gpio/" target="_blank" rel="noreferrer noopener" label=" (opens in a new tab)" class="broken_link">https://www.raspberrypi.org/documentation/usage/gpio/</a></p>



<p><strong>Adafruit</strong></p>



<p><a rel="noreferrer noopener" aria-label=".96&quot; OLED Product Page (opens in a new tab)" href="https://www.adafruit.com/product/684" target="_blank">.96&#8243; OLED Product Page</a> (Not the display I ended up going with for resolution reasons, otherwise it&#8217;s very nice.)</p>



<p><a rel="noreferrer noopener" aria-label="1.3&quot; 240x240 TFT LCD Product Page (opens in a new tab)" href="https://www.adafruit.com/product/4313" target="_blank">1.3&#8243; 240&#215;240 TFT LCD Product Page</a> (My ultimate choice for this diorama)</p>



<p><a href="https://learn.adafruit.com/adafruit-1-3-and-1-54-240-x-240-wide-angle-tft-lcd-displays?view=all">Tutorial/Learning Page for the 1.3&#8243; display</a> (wiring, python, etc.)</p>



<p><strong>VICE</strong></p>



<p><a href="https://csdb.dk/release/?id=179123" target="_blank" rel="noreferrer noopener" aria-label="The Elder Scrollers Demo by Booze Design (opens in a new tab)">The Elder Scrollers Demo by Booze Design</a></p>
<p>The post <a rel="nofollow" href="https://krystof.io/mirroring-raspberry-pi-hdmi-video-to-a-st7789-1-3-inch-lcd-display/">Mirroring Raspberry Pi HDMI Video to a ST7789 1.3 inch LCD Display</a> appeared first on <a rel="nofollow" href="https://krystof.io">Krystof.IO</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://krystof.io/mirroring-raspberry-pi-hdmi-video-to-a-st7789-1-3-inch-lcd-display/feed/</wfw:commentRss>
			<slash:comments>23</slash:comments>
		
		
		
		<series:name><![CDATA[Diorama 64]]></series:name>
	</item>
		<item>
		<title>Installing the VICE Commodore Emulator for Console Mode on a fresh Raspberry Pi 4</title>
		<link>https://krystof.io/installing-the-vice-commodore-emulator-for-console-mode-on-a-fresh-raspberry-pi-4/</link>
					<comments>https://krystof.io/installing-the-vice-commodore-emulator-for-console-mode-on-a-fresh-raspberry-pi-4/#comments</comments>
		
		<dc:creator><![CDATA[Eric R. Krystof]]></dc:creator>
		<pubDate>Sun, 12 Jan 2020 19:46:25 +0000</pubDate>
				<category><![CDATA[Retro Gaming]]></category>
		<category><![CDATA[Commodore]]></category>
		<category><![CDATA[VICE]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Emulation]]></category>
		<category><![CDATA[Raspberry Pi]]></category>
		<guid isPermaLink="false">https://krystof.io/?p=999</guid>

					<description><![CDATA[<p>Let's download, compile, and install the VICE Commodore 64 emulator on a fresh Raspberry Pi 4 install. We'll make sure it works in a non windows console by running a Commodore demo program.</p>
<p>The post <a rel="nofollow" href="https://krystof.io/installing-the-vice-commodore-emulator-for-console-mode-on-a-fresh-raspberry-pi-4/">Installing the VICE Commodore Emulator for Console Mode on a fresh Raspberry Pi 4</a> appeared first on <a rel="nofollow" href="https://krystof.io">Krystof.IO</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>At the time of this writing, there&#8217;s no binary package ready to install on the Raspberry Pi 4.  Also, I need to make sure I can run the <a label=" (opens in a new tab)" rel="noreferrer noopener" href="http://vice-emu.sourceforge.net/" target="_blank" class="broken_link">VICE</a> emulator on the console and <strong>not</strong> in X-Windows for my diorama project.  That install isn&#8217;t difficult but isn&#8217;t a single line or two either, so we&#8217;ll start from scratch on a fresh Raspbian lite install.  This article assumes some familiarity with how VICE works.  Let&#8217;s install VICE on a Raspberry Pi 4! </p>



<h2 class="wp-block-heading" id="h-raspberry-pi-4-version-log">Raspberry Pi 4 Version Log</h2>



<div data-padding="10" class="wp-block-simple-blocks-info-block" style="background-color:#0010f4;color:#ffffff;padding:10px"><div data-iconsize="20" data-iconspace="20" class="icon" style="margin-right:20px"><span class="dashicon dashicons dashicons-info"></span></div><div>EVOLVING VERSIONS NOTE: <br>This document evolves over time &#8211; things change and old versions of Raspbian just stop being supported, and we try to make it work with the latest versions.  I&#8217;ve generally had better luck with Buster compared to Bullseye, but we try to get both up and running.</div></div>



<p>All of these in records in the table below imply the general settings changes to the VICE config presented later in the document (<em>VICE/PI General Settings I change regardless of version</em>).  Also, make sure to check out settings specific to the OS you&#8217;re using later in this document!</p>



<figure class="wp-block-table is-style-stripes"><table><tbody><tr><td>OK For Use</td><td>Raspberry PI OS Version</td><td>VICE Version</td><td>Raspi 4B Status PAL</td><td>Raspi 4B Status NTSC</td><td>Raspi 400 Status PAL</td><td>Raspi 400 Status NTSC</td><td>Install Script Links</td></tr><tr><td>Yes</td><td><a href="https://downloads.raspberrypi.org/raspios_lite_armhf/images/raspios_lite_armhf-2023-02-22/2023-02-21-raspios-bullseye-armhf-lite.img.xz">2023-02-21-raspios-bullseye-armhf-lite.img.xz</a></td><td>3.5 <a href="http://svn.code.sf.net/p/vice-emu/code/tags/v3.5/vice/" target="_blank" rel="noreferrer noopener">SVN</a>/ <a href="http://svn.code.sf.net/p/vice-emu/code/tags/v3.5/vice/NEWS" target="_blank" rel="noreferrer noopener">Changelog </a>/ <a href="https://sourceforge.net/projects/vice-emu/files/releases/vice-3.5.tar.gz/download" target="_blank" rel="noreferrer noopener" class="broken_link">Tarball</a></td><td>OK!</td><td>OK!</td><td>OK!</td><td>OK!</td><td><a href="https://github.com/erkrystof/vice/blob/master/install-vice-3.5-raspi-4-bullseye-2023-02-21.sh" target="_blank" rel="noreferrer noopener">GitHub </a>/ <a href="https://raw.githubusercontent.com/erkrystof/vice/master/install-vice-3.5-raspi-4-bullseye-2023-02-21.sh" target="_blank" rel="noreferrer noopener">Raw</a></td></tr><tr><td>Yes</td><td><a href="https://downloads.raspberrypi.org/raspios_oldstable_lite_armhf/images/raspios_oldstable_lite_armhf-2023-02-22/2023-02-21-raspios-buster-armhf-lite.img.xz">2023-02-21-raspios-buster-armhf-lite.img.xz</a></td><td>3.5 <a href="http://svn.code.sf.net/p/vice-emu/code/tags/v3.5/vice/" target="_blank" rel="noreferrer noopener">SVN</a>/ <a href="http://svn.code.sf.net/p/vice-emu/code/tags/v3.5/vice/NEWS" target="_blank" rel="noreferrer noopener">Changelog </a>/ <a href="https://sourceforge.net/projects/vice-emu/files/releases/vice-3.5.tar.gz/download" target="_blank" rel="noreferrer noopener" class="broken_link">Tarball</a></td><td>OK!</td><td>OK!</td><td>OK!</td><td>OK!</td><td><a href="https://github.com/erkrystof/vice/blob/master/install-vice-3.5-raspi-4-buster-2023-02-21.sh" target="_blank" rel="noreferrer noopener">GitHub </a>/ <a href="https://raw.githubusercontent.com/erkrystof/vice/master/install-vice-3.5-raspi-4-buster-2023-02-21.sh" target="_blank" rel="noreferrer noopener">Raw</a> </td></tr><tr><td>Yes</td><td><a href="https://downloads.raspberrypi.org/raspios_lite_armhf/images/raspios_lite_armhf-2023-02-22/2023-02-21-raspios-bullseye-armhf-lite.img.xz" rel="nofollow">2023-02-21-raspios-bullseye-armhf-lite.img.xz</a>  </td><td>3.7.1 <a href="http://svn.code.sf.net/p/vice-emu/code/tags/v3.7.1/vice/" target="_blank" rel="noreferrer noopener nofollow">SVN</a> / <a href="http://svn.code.sf.net/p/vice-emu/code/tags/v3.7.1/vice/NEWS" target="_blank" rel="noreferrer noopener nofollow">Changelog</a> / <a href="https://sourceforge.net/projects/vice-emu/files/releases/vice-3.7.1.tar.gz/download" rel="nofollow" class="broken_link">Tarball</a></td><td>OK!</td><td>OK!</td><td>OK!</td><td>OK!</td><td><a href="https://github.com/erkrystof/vice/blob/master/install-vice-3.7.1-raspi-4-bullseye-2023-02-21.sh" target="_blank" rel="noreferrer noopener">GitHub</a> / <a href="https://raw.githubusercontent.com/erkrystof/vice/master/install-vice-3.7.1-raspi-4-bullseye-2023-02-21.sh" target="_blank" rel="noreferrer noopener">Raw</a> </td></tr><tr><td>Yes</td><td><a href="https://downloads.raspberrypi.org/raspios_oldstable_lite_armhf/images/raspios_oldstable_lite_armhf-2023-02-22/2023-02-21-raspios-buster-armhf-lite.img.xz" rel="nofollow">2023-02-21-raspios-buster-armhf-lite.img.xz</a></td><td>3.7.1 <a href="http://svn.code.sf.net/p/vice-emu/code/tags/v3.7.1/vice/" target="_blank" rel="noreferrer noopener nofollow">SVN</a> / <a href="http://svn.code.sf.net/p/vice-emu/code/tags/v3.7.1/vice/NEWS" target="_blank" rel="noreferrer noopener nofollow">Changelog</a> / <a href="https://sourceforge.net/projects/vice-emu/files/releases/vice-3.7.1.tar.gz/download" class="broken_link">Tarball</a></td><td>OK!</td><td>OK!</td><td>OK!</td><td>OK!</td><td><a href="https://github.com/erkrystof/vice/blob/master/install-vice-3.7.1-raspi-4-buster-2023-02-21.sh" target="_blank" rel="noreferrer noopener">GitHub </a>/ <a href="https://raw.githubusercontent.com/erkrystof/vice/master/install-vice-3.7.1-raspi-4-buster-2023-02-21.sh" target="_blank" rel="noreferrer noopener">Raw</a> </td></tr></tbody></table><figcaption class="wp-element-caption">This is your VICE life now, and it&#8217;s changing every SVN tag at a time.</figcaption></figure>



<div data-padding="10" class="wp-block-simple-blocks-info-block" style="background-color:#3279dd;color:#ffffff;padding:10px"><div data-iconsize="20" data-iconspace="20" class="icon" style="margin-right:20px"><span class="dashicon dashicons dashicons-info"></span></div><div>Which binary to run? x64sc or x64?  The configure line from VICE in the script has &#8216;&#8211;enable-x64&#8217;.  By default VICE builds create an x64sc binary, but NOT an x64 binary anymore.  What&#8217;s the difference?  Seems the SC binary is preferred as it focuses on accuracy of emulation over speed.  That being said, I find I like to use x64 on the C64 Demo Scene that still lives on to this day &#8211; otherwise the demos were occasionally quite choppy.  For normal game play I use x64sc but fall back to x64 if I detect heavy lag.  Your mileage may vary.  I find a lot of C64 scene demos don&#8217;t work well with x64sc, and I often fall back to x64.</div></div>



<p>Simplest way to execute the scripts is to copy the Raw link and on your raspberry pi console /ssh, do this:</p>



<pre class="wp-block-code"><code>wget -O - &lt;raw script url> | bash</code></pre>



<h3 class="wp-block-heading" id="h-test-programs">Test Programs</h3>



<p>I&#8217;ve also added some <a href="https://github.com/erkrystof/vice/tree/master/testprograms" target="_blank" rel="noreferrer noopener nofollow">test programs</a> I can easily download from my VICE script github.  I use these to test very basic SID/graphics functionality.  Here are the credits to the great demo makers that made them:</p>



<p><strong>delaytest.d64</strong> &#8211; Written by the 8-bit guy &#8211; useful for testing lag, and also gives an audio ping each time you press a key. I start here for just the most basic &#8216;is this thing on?&#8217; approach.</p>



<p><strong>Booze Design &#8211; Remains (PAL)</strong> &#8211; Lovely haunting track.  <a href="https://csdb.dk/release/?id=187524" target="_blank" rel="noreferrer noopener">https://csdb.dk/release/?id=187524</a></p>



<p><strong>SHAPE &#8211; Disco Apocalypso</strong> <strong>(PAL)</strong>  &#8211; Up beat and great visuals. <a href="https://csdb.dk/release/?id=133935" target="_blank" rel="noreferrer noopener">https://csdb.dk/release/?id=133935</a></p>



<p><strong>Fairlight &#8211; 2600 (PAL) &#8211; </strong><a href="https://csdb.dk/release/?id=197187" target="_blank" rel="noreferrer noopener">https://csdb.dk/release/?id=197187</a></p>



<p><strong>Style &#8211; Shine On (NTSC)</strong> &#8211; <a href="https://style64.org/release/shine-style" target="_blank" rel="noreferrer noopener">https://style64.org/release/shine-style</a> &#8211; At least some graphics and smooth SID music for NTSC testing</p>



<p>Looking for more demos and such?</p>



<p><a href="https://csdb.dk" target="_blank" rel="noreferrer noopener">https://csdb.dk</a></p>



<p><a href="http://www.atlantis-prophecy.org/recollection/?load=home" target="_blank" rel="noreferrer noopener">http://www.atlantis-prophecy.org/recollection/?load=home</a></p>



<h3 class="wp-block-heading">VICE/PI General Settings I change regardless of version</h3>



<p><em>Unless noted here, I don&#8217;t change any system settings on my raspberry pi workbench setup, except for enabling Wifi and SSH, everything is is left as the default when Raspberry Pi OS installs.</em></p>



<p>These seem to be the best general settings for things to play smoothly on the PI.  They mostly involve removing the raster line filter and adjusting audio settings.</p>



<ul>
<li>Apply these settings in your VICE Config:
<ol>
<li>Machine Settings -&gt; Model Settings -&gt; SID Settings:
<ol>
<li>SID Model -&gt; 8580 + digi boost (ReSID)</li>



<li>reSID sampling method -&gt; Fast</li>
</ol>
</li>



<li>Video Settings -&gt; Size Settings
<ol>
<li>Disable double size</li>



<li>Disable double scan</li>



<li>Select Fullscreen</li>
</ol>
</li>



<li>Video Settings -&gt; Render filter
<ol>
<li>Select &#8216;None&#8217;</li>
</ol>
</li>



<li>Sound Settings
<ol>
<li>Buffer size 50msec</li>



<li>Frequency 22050 Hz</li>
</ol>
</li>
</ol>
</li>
</ul>



<p>In C64 VICE Config form (/home/pi/.config/vice/sdl-vicerc, this looks like this:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
&#91;C64]
MenuKey=293
MenuKeyUp=273
MenuKeyDown=274
MenuKeyLeft=276
MenuKeyRight=275
MenuKeyPageUp=280
MenuKeyPageDown=281
MenuKeyHome=278
MenuKeyEnd=279
SoundDeviceName="alsa"
SoundSampleRate=22050
SoundBufferSize=50
AspectRatio="1.000000"
VICIIVideoCache=0
VICIIDoubleScan=0
VICIIDoubleSize=0
VICIIFullscreen=1
VICIIFilter=0
SDLStatusbar=1
SidResidSampling=0
SidEngine=1
SidModel=2
ETHERNETCARTBase=56832
Acia1Base=56832
</pre></div>


<p>Sometimes, I mess with the sound sample rate when I&#8217;m capturing HDMI output and streaming <em>It seems I need to set audio sample rate to 44100 to get my HDMI capture device to grab audio into OBS, but as far as the VICE/PI goes, I heard audio fine through my speakers.</em> (<code>SoundSampleRate=44100</code>)</p>



<p><em>If you need to change your sample rate if you&#8217;re capturing output</em>, you can try the various options in here: (Menu or config file)</p>



<ul>
<li>Sound Settings -&gt; 
<ul>
<li>Frequency 44100 Hz</li>
</ul>
</li>
</ul>



<p>This generally sets a config file line:</p>



<p><code>SoundSampleRate=44100</code></p>



<h3 class="wp-block-heading">VICE/PI Version specific settings I&#8217;ve changed</h3>



<h4 class="wp-block-heading">2023-02-21-raspios-buster-armhf-lite.img.xz / VICE specifics</h4>



<p><strong>Synopsis: </strong>Apply general settings and you&#8217;re good to go.</p>



<p><strong>Raw Notes:</strong> After applying recommended generic settings, test programs ran fine (Before that, no so much).  I was locked in at 100%/50fps using x64 and PAL/NTSC using the <strong>x64 </strong>binary.  The <strong>x64sc </strong>binary still chews more CPU and runs slightly slower (naturally).  <strong>I still recommend applying the generic settings I use though, since I had issues with NTSC (read on&#8230;)</strong></p>



<p>However, on NTSC, I do notice the CPU/FPS drop from 100% to 80%, jump back up again.  <strong>This was before applying my general settings.  </strong>Once I applied those, everything worked well, no stutters or CPU drops.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h4 class="wp-block-heading">2023-02-21-raspios-bullseye-armhf-lite.img.xz / VICE specifics</h4>



<p><strong>Synopsis: </strong>Apply general settings and change to fkms video driver, and then choose HDMI output in raspi-config.</p>



<p><strong>Raw Notes: </strong>After executing the script and applying the generic settings, I noticed the strange 100% to 80% CPU drops go away.  This has to be something with the audio layer, imho.  Now, I just wasn&#8217;t getting audio (maybe on headphones on the 4B, but the 400 doesn&#8217;t have a headphone jack)</p>



<p>When I switched default audio to HDMI 0 in raspi-config, <strong>that broke ALSA in vice</strong> (error message), but I also noticed even when playing demos, the CPU was locked at 100%.  Something with the sound layers&#8230;  I&#8217;ve tried changing to SDL and I get no audio at all (I&#8217;m only in console mode, remember)</p>



<p>So, next, I tried the <strong>no longer supported but still available fkms overlay</strong> setting in <strong>/boot/config.txt</strong>.  After setting that and rebooting, I was able to select HDMI in raspi-config and I got audio.  So far, so good.  I&#8217;m not happy about having to use fkms still for bullseye, but it at least got it working.</p>



<p>So, for me to get this working on Bullseye, I make the following changes:</p>



<ol>
<li>Make the general settings changes to sound/display in my general settings section (this is a must)</li>



<li>Bring in fkms driver for HDMI audio:</li>
</ol>



<p>Edit your <strong>/boot/config.txt</strong> and change the following:</p>



<p>BEFORE:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
# Enable DRM VC4 V3D driver
dtoverlay=vc4-kms-v3d
</pre></div>


<p>AFTER:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
# Enable DRM VC4 V3D driver
dtoverlay=vc4-fkms-v3d
</pre></div>


<p>You must reboot after <strong>/boot/config.txt</strong> changes. <strong>You must also go into raspi-config and choose your audio device</strong> (this is how I was able to get VICE HDMI Audio on the 400) </p>



<p>Side note: I had <strong>flashing video artifacts on bullseye</strong>, but <strong>only when I was going through a USB HDMI capture device</strong>.  Direct HDMI worked fine.  Not sure why video is flashing so much when not going through the USB HDMI capture device on bullseye when it didn&#8217;t happen on buster at all.  I&#8217;ve got another HDMI capture device I might use to see if it&#8217;s something specific with the flasher.  Is there some refresh rate configuration difference between buster and bullseye? Same hardware, same firmware, just different OS versions and vice dependencies.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<p>The rest of the document is a bit of a ramble since these versions change all the time but it covers the high level.</p>



<p><strong><em>To that end, given all the changes that constantly happen in VICE, PI, and such, the video below is no longer 100% accurate.  It still covers the general setup tasks, but the script is the source of truth as versions and methods change over time.</em></strong></p>



<figure class="wp-block-embed aligncenter is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe loading="lazy" title="Installing the VICE Commodore Emulator for Console Mode on a Fresh Raspberry Pi 4" width="1170" height="658" src="https://www.youtube.com/embed/uRVTAgqs7pU?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
</div></figure>



<hr class="wp-block-separator has-css-opacity"/>



<div data-padding="10" class="wp-block-simple-blocks-info-block" style="background-color:#0010f4;color:#ffffff;padding:10px"><div data-iconsize="20" data-iconspace="20" class="icon" style="margin-right:20px"><span class="dashicon dashicons dashicons-info"></span></div><div>You may wonder why I am doing it this way vs RetroPie, Combian 64, or BMC64&#8230; I probably could have, but I knew I&#8217;d be in the VICE source code a bit in a later article so I wanted to start with the basics first and make sure I could compile VICE myself.  Plus, at this time , the packages referenced above aren&#8217;t completely ready for the Raspberry Pi 4. </div></div>



<hr class="wp-block-separator has-css-opacity"/>



<h2 class="wp-block-heading" id="h-hardware-before-the-software">Hardware before the Software</h2>



<p>This part is pretty simple &#8211; you&#8217;ll need:</p>



<ul>
<li>Raspberry Pi 4 Model B, or Raspberry Pi 3B+</li>



<li>Micro SD Card (we&#8217;re generally at the days of 16GB or higher)</li>



<li>Micro HDMI cable (or full HDMI if you&#8217;re using a Raspberry Pi 3B+)</li>



<li>Keyboard / Mouse for initial setup, Wifi connectivity for later SSH connectivity.</li>
</ul>



<div data-padding="10" class="wp-block-simple-blocks-info-block" style="background-color:#0010f4;color:#ffffff;padding:10px"><div data-iconsize="20" data-iconspace="20" class="icon" style="margin-right:20px"><span class="dashicon dashicons dashicons-info"></span></div><div>Got a Raspberry Pi 3B?  I&#8217;ve added notes on that at the very end of this document.</div></div>



<h2 class="wp-block-heading" id="h-write-the-raspberry-pi-4-image">Write The Raspberry Pi 4 Image</h2>



<p>We&#8217;ll start with a fresh SD Card and a <a aria-label=" (opens in a new tab)" href="https://www.raspberrypi.org" target="_blank" rel="noreferrer noopener">Raspberry Pi 4</a>.   We&#8217;re going to burn <a label=" (opens in a new tab)" href="https://www.raspberrypi.org/downloads/raspbian/" target="_blank" rel="noreferrer noopener" class="broken_link">Raspberry Pi OS L</a><a href="https://www.raspberrypi.org/downloads/raspbian/" class="broken_link">ite</a> (I&#8217;m not using a window environment) on to the SD Card using <a aria-label=" (opens in a new tab)" href="https://www.balena.io/etcher/" target="_blank" rel="noreferrer noopener">Balena Etcher</a>.</p>


<div class="wp-block-image is-style-default">
<figure class="aligncenter size-large"><img decoding="async" loading="lazy" width="515" height="309" src="https://krystof.io/wp-content/uploads/2019/12/balena-etcher.jpg" alt="" class="wp-image-1004" srcset="https://krystof.io/wp-content/uploads/2019/12/balena-etcher.jpg 515w, https://krystof.io/wp-content/uploads/2019/12/balena-etcher-300x180.jpg 300w" sizes="(max-width: 515px) 100vw, 515px" /></figure></div>


<h2 class="wp-block-heading" id="h-boot-the-raspberry-pi-and-get-connected"> Boot the Raspberry Pi and get connected.</h2>



<p>We know our default password is <em>raspberry</em> and our default user name is <em>pi</em>.  You should change these if you&#8217;re going to keep this install around.  Regardless, we need to set just a couple of things before we start with VICE &#8211; such as my desire for SSH access so I could copy/paste commands more easily.  Here are those steps after you give yourself a good old fashioned <code>sudo raspi-config</code>:</p>



<ol>
<li>Set hostname to vice-pi-install (This makes it unique and through <a href="https://www.howtogeek.com/167190/how-and-why-to-assign-the-.local-domain-to-your-raspberry-pi/" class="broken_link">bonjour </a>lets me access it from my Windows PC as <strong>vice-pi-install.local</strong>.)</li>



<li>Set WIFI up to my access point (Country Code and SSID)</li>



<li>Allow SPI interface access (my diorama is going to be controlling an LCD through SPI) &#8211; <strong>This is purely optional </strong>&#8211; I used it because I&#8217;m hooking up some custom circuits to my Pi.</li>



<li>Allow SSH interface access (so we can copy/paste from a Windows SSH client) &#8211; Optional if you just want to type all the commands directly to your Pi console.</li>



<li>Setup locale, keyboard, etc. </li>



<li>Verify Internet Connectivity (ping google.com)</li>



<li>Perform your normal <strong><code>apt update / apt upgrade</code></strong> commands to update your system.</li>
</ol>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
sudo apt update
sudo apt upgrade
</pre></div>


<h2 class="wp-block-heading" id="h-download-and-execute-the-install-script">Download and execute the install script</h2>



<p>I&#8217;ve created a few scripts for various versions to do all this work on a Pi Install.  Check the table at the very start of this document for matching scripts to install based on your PI or VICE or PI OS version  (Yeah, it can be that twitchy).  Download the script you want,  chmod +x the script, and run it.  Look it over yourself if you&#8217;re concerned about just running some guy&#8217;s script.</p>



<p>You can execute your script directly by doing this if you don&#8217;t feel like downloading it, chmod-ing it, and executing it manually:</p>



<pre class="wp-block-code"><code>wget -O - https://raw.githubusercontent.com/erkrystof/vice/master/&lt;insertscriptnamehere&gt;.sh | bash</code></pre>



<p id="block-6664aacb-64da-4b18-beca-9ec7d167a79c">What the script does at a high level:</p>



<ol>
<li>Performs the general sudo apt update/upgrade</li>



<li>Downloads SDL from libsdl.org</li>



<li>Compiles and installs SDL and other SDL libraries</li>



<li>Downloads VICE compilation dependencies</li>



<li>Downloads VICE source code from sourceforge.net</li>



<li>Configures VICE to enable fast-sid options and the x64 &#8216;old&#8217; binary build (as well as the new binary x64sc)</li>



<li>Installs VICE into your home directory (/home/pi/vice-&lt;version-number>) &#8211; Because I dislike /usr/local for vice.</li>



<li>Binaries will be in the bin directory of where we installed VICE.  You&#8217;d generally run x64 for the &#8216;older&#8217; but smoother for PAL Demos binary, or the x64sc (technically more accurate, but uses more CPU and causes PIs to stutter in demos)</li>
</ol>



<p>The latest version of the script will always be at the link above.  It&#8217;s configured so if it runs into any error, it aborts. </p>



<div data-padding="10" class="wp-block-simple-blocks-info-block" style="background-color:#0010f4;color:#ffffff;padding:10px"><div data-iconsize="20" data-iconspace="20" class="icon" style="margin-right:20px"><span class="dashicon dashicons dashicons-info"></span></div><div>This script takes about 45 minutes to execute.  You are free to examine the script ahead of time to make sure it seems safe for your system.  I promise I&#8217;m not doing anything untoward.  It&#8217;s downloading, compiling, and taking VICE straight from the source.</div></div>



<h3 class="wp-block-heading" id="h-why-compile-sdl-on-the-pi">Why compile SDL on the Pi?</h3>



<p>We used to have to do this from a fork from Retropie, and in previous cases before that I could just install the sdl libraries and use those.  However, I&#8217;ve found that every time I try to do that with the latest versions of Raspi-OS and VICE, I end up getting an SDL related error trying to draw the screen when launching from the console &#8211; so for now, I compile the SDL libraries on the Pi and things seem to work.  In previous versions of Buster, I couldn&#8217;t get this to work from SDL directly, I had to use RetroPie&#8217;s fork and manipulations on some videocore headers.  <em>I no longer need to do that for what I&#8217;m assuming are changes in the OS version over the past couple of years.</em></p>



<p><s><strong><em>We will build SDL2-2.0.14 from&nbsp;<a rel="noreferrer noopener" href="https://github.com/RetroPie/SDL-mirror" target="_blank">RetroPie’s fork</a>&nbsp;that has&nbsp;<a href="https://github.com/RetroPie/SDL-mirror/tree/retropie-2.0.14" target="_blank" rel="noreferrer noopener">Raspberry Pi specific modifications</a></em></strong>. Part of the compilation below is from RetroPie’s SDL 2.0 install script. To learn more about the excellent RetroPie project, head on over to their site&nbsp;<a rel="noreferrer noopener" href="https://retropie.org.uk/" target="_blank">here</a>.  I&#8217;ve made a fork off that repo and that&#8217;s where I&#8217;m pulling from in my script &#8211; it&#8217;s just in case I need to make any tweaks.</s></p>



<h2 class="wp-block-heading">Apply generic settings for sound/video options in VICE.</h2>



<p>See the <em>VICE/PI General Settings I change regardless of version</em> section for that.  Also, if you&#8217;re in Bullseye, there are some specific tweaks in the Bullseye section to apply.</p>



<h2 class="wp-block-heading" id="h-download-a-demo-and-see-it-perform-horribly-or-wonderfully">Download a demo and see it perform horribly or wonderfully?</h2>



<p>I downloaded a simple demo from csdb.dk by Booze Design known as &#8216;<a aria-label=" (opens in a new tab)" href="https://csdb.dk/release/?id=179123" target="_blank" rel="noreferrer noopener">The Elder Scrollers</a>&#8216;.  Downloaded the .D64 file and uploaded that to the VICE Pi.  Moving into the /home/pi/viceinstall/bin directory, I typed ./x64 and was greeted with an old blue friend:</p>



<figure class="wp-block-image size-large is-style-default"><img decoding="async" loading="lazy" width="1024" height="576" src="https://krystof.io/wp-content/uploads/2019/12/commodore-64-ready-1024x576.jpg" alt="" class="wp-image-1021" srcset="https://krystof.io/wp-content/uploads/2019/12/commodore-64-ready-1024x576.jpg 1024w, https://krystof.io/wp-content/uploads/2019/12/commodore-64-ready-300x169.jpg 300w, https://krystof.io/wp-content/uploads/2019/12/commodore-64-ready-768x432.jpg 768w, https://krystof.io/wp-content/uploads/2019/12/commodore-64-ready-1536x864.jpg 1536w, https://krystof.io/wp-content/uploads/2019/12/commodore-64-ready.jpg 1920w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">Hello, Retro my old friend&#8230;</figcaption></figure>



<p>Now, depending on how this all comes together, you might have a really tiny C64 screen in the corner of your big monitor.  Simply hit F12, scroll down to Video Settings -&gt; Screen Settings -&gt; Fullscreen.</p>



<p><strong>Noticing stuttering and other issues?  </strong>Look at the settings in the top part of the document that I apply generically as well as for certain OS/VICE combinations and try those.</p>



<h2 class="wp-block-heading" id="h-apply-settings-and-watch-a-demo-perform-smoothly">Apply settings and watch a demo perform smoothly</h2>



<p>Finally, after modifying my settings, restarting VICE, and after autostarting the demo image I downloaded, I was able to sit back and enjoy classic SID sound from the Elder Scrollers demo:</p>



<figure class="wp-block-image size-large"><img decoding="async" loading="lazy" width="1024" height="576" src="https://krystof.io/wp-content/uploads/2019/12/the-elder-scrollers-1024x576.jpg" alt="" class="wp-image-1020" srcset="https://krystof.io/wp-content/uploads/2019/12/the-elder-scrollers-1024x576.jpg 1024w, https://krystof.io/wp-content/uploads/2019/12/the-elder-scrollers-300x169.jpg 300w, https://krystof.io/wp-content/uploads/2019/12/the-elder-scrollers-768x432.jpg 768w, https://krystof.io/wp-content/uploads/2019/12/the-elder-scrollers-1536x864.jpg 1536w, https://krystof.io/wp-content/uploads/2019/12/the-elder-scrollers.jpg 1920w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">I&#8217;ve come to scroll with you again&#8230;</figcaption></figure>



<p>With that, we finish the install of VICE on a Raspberry Pi 4 in console mode as the foundation of my Diorama 64 project.  Any thoughts or concerns, things that didn&#8217;t work well for you with your install?  Leave a comment down below or join the discord at <a rel="noreferrer noopener" aria-label="https://discord.gg/wbngTy8 (opens in a new tab)" href="https://discord.gg/wbngTy8" target="_blank">https://discord.gg/wbngTy8</a> and we can chat.  Next up: the Raspberry Pi 4 and the LCD display turned monitor.</p>



<h2 class="wp-block-heading" id="h-raspberry-pi-3b-instructions">Raspberry Pi 3B+ Instructions</h2>



<p>** May not work, I have NOT updated this yet for VICE 3.6.1 **</p>



<p>Generally, the build is very similar.  I&#8217;m going to skip all the discussion points and run down what I think seems to work on a Raspberry Pi 3B.  The key differences are how we build SDL.  I didn&#8217;t seem to need to change any graphic related driver setting to get this to work.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
sudo apt update
sudo apt upgrade

#SDL for Raspi-3B dependencies
sudo apt-get install libfontconfig-dev qt5-default automake mercurial \
 libtool libfreeimage-dev libopenal-dev libpango1.0-dev libsndfile-dev \
 libudev-dev libtiff5-dev libwebp-dev libasound2-dev libaudio-dev \
 libxrandr-dev libxcursor-dev libxi-dev libxinerama-dev libxss-dev \
 libesd0-dev freeglut3-dev libmodplug-dev libsmpeg-dev libjpeg-dev

mkdir ~/sdlwork
cd ~/sdlwork

hg clone http://hg.libsdl.org/SDL
cd SDL

./autogen.sh
./configure --disable-pulseaudio --disable-esd --disable-video-mir --disable-video-wayland \
 --disable-video-opengl --host=arm-raspberry-linux-gnueabihf
make
sudo make install

cd ~/sdlwork

wget http://www.libsdl.org/projects/SDL_image/release/SDL2_image-2.0.5.tar.gz
wget http://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-2.0.4.tar.gz
wget http://www.libsdl.org/projects/SDL_net/release/SDL2_net-2.0.1.tar.gz
wget http://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-2.0.15.tar.gz

tar zxvf SDL2_image-2.0.5.tar.gz
tar zxvf SDL2_mixer-2.0.4.tar.gz
tar zxvf SDL2_net-2.0.1.tar.gz
tar zxvf SDL2_ttf-2.0.15.tar.gz

cd SDL2_image-2.0.5 
./autogen.sh 
./configure 
make 
sudo make install
cd ..

cd SDL2_mixer-2.0.4
./autogen.sh 
./configure 
make 
sudo make install
cd ..

cd SDL2_net-2.0.1 
./autogen.sh 
./configure 
make 
sudo make install
cd ..

#Interestingly enough TTF builds just fine on the 3B.

cd SDL2_ttf-2.0.15
./autogen.sh
./configure
make
sudo make install
cd ..

#Now, on to VICE for the Raspi 3B

sudo apt install libmpg123-dev libpng-dev zlib1g-dev libasound2-dev libvorbis-dev libflac-dev \
 libpcap-dev automake bison flex subversion libjpeg-dev portaudio19-dev texinfo xa65

mkdir ~/vicework
cd ~/vicework

#3.4 is the latest VICE release
svn checkout svn://svn.code.sf.net/p/vice-emu/code/tags/v3.4/

cd ./v3.4/vice
./autogen.sh 
./configure --prefix=/home/pi/viceinstall --enable-sdlui2 --without-oss --enable-ethernet \
 --disable-catweasel --without-pulse
make -j $(nproc)

# I got an error here for the running of make install - you may or may not need to do the sudo.
sudo make install

#after this point, I went directly to the vice install directory and ran it
cd ~/viceinstall/bin
./x64sc
</pre></div>


<h2 class="wp-block-heading" id="h-references">References:</h2>



<ul>
<li><a rel="noreferrer noopener" aria-label=" (opens in a new tab)" href="https://www.balena.io/etcher/" target="_blank">Balena Etcher</a></li>



<li><a rel="noreferrer noopener" label=" (opens in a new tab)" href="https://www.howtogeek.com/167190/how-and-why-to-assign-the-.local-domain-to-your-raspberry-pi/" target="_blank" class="broken_link">Enabling Bonjour for your Raspberry Pi</a></li>



<li><a rel="noreferrer noopener" label=" (opens in a new tab)" href="http://vice-emu.sourceforge.net/" target="_blank" class="broken_link">VICE Homepage</a></li>



<li><a rel="noreferrer noopener" aria-label=" (opens in a new tab)" href="https://www.lemon64.com/forum/viewtopic.php?t=69443&amp;sid=b254aba4aa2e196e85420ada952765e5" target="_blank">Lemon 64 Thread on Custom SDL Build</a> </li>



<li><a href="https://choccyhobnob.com/sdl2-2-0-8-on-raspberry-pi/" target="_blank" rel="noreferrer noopener" label="SDL on Raspi (for 3B compile) (opens in a new tab)" class="broken_link">SDL on Raspi (for 3B compile)</a></li>



<li><a rel="noreferrer noopener" aria-label=" (opens in a new tab)" href="https://github.com/midwan/amiberry/wiki/Compile-SDL2-from-source" target="_blank">Compiling SDL2 from source</a></li>



<li><a rel="noreferrer noopener" aria-label=" (opens in a new tab)" href="https://www.lemon64.com/forum/viewtopic.php?t=44766&amp;sid=390e12b2777730f68569acebafcbb945" target="_blank">x64 vs x64sc VICE binaries</a></li>



<li><a rel="noreferrer noopener" aria-label=" (opens in a new tab)" href="https://csdb.dk/release/?id=179123" target="_blank">The Elder Scrollers Demo</a></li>
</ul>
<p>The post <a rel="nofollow" href="https://krystof.io/installing-the-vice-commodore-emulator-for-console-mode-on-a-fresh-raspberry-pi-4/">Installing the VICE Commodore Emulator for Console Mode on a fresh Raspberry Pi 4</a> appeared first on <a rel="nofollow" href="https://krystof.io">Krystof.IO</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://krystof.io/installing-the-vice-commodore-emulator-for-console-mode-on-a-fresh-raspberry-pi-4/feed/</wfw:commentRss>
			<slash:comments>68</slash:comments>
		
		
		
		<series:name><![CDATA[Diorama 64]]></series:name>
	</item>
		<item>
		<title>The &#8216;Working&#8217; Commodore 64/128 Diorama and Raspberry Pi VICE Emulator</title>
		<link>https://krystof.io/diorama-64-part-1-overview/</link>
					<comments>https://krystof.io/diorama-64-part-1-overview/#comments</comments>
		
		<dc:creator><![CDATA[Eric R. Krystof]]></dc:creator>
		<pubDate>Sun, 05 Jan 2020 00:53:04 +0000</pubDate>
				<category><![CDATA[Arcade Building]]></category>
		<category><![CDATA[Raspberry Pi]]></category>
		<category><![CDATA[Commodore]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[VICE]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Emulation]]></category>
		<guid isPermaLink="false">https://krystof.io/?p=973</guid>

					<description><![CDATA[<p>A ‘working’ diorama of my 1980s Commodore 128/64 computer room, with mirrored LCD display monitor and working 1541 disk drive lights. Driven by a Raspberry PI, custom circuit board, and VICE C64 emulator. Additional flavor added in the form of miniature floppy disks, game boxes, and wall posters, advertisements, and game maps from my youth.</p>
<p>The post <a rel="nofollow" href="https://krystof.io/diorama-64-part-1-overview/">The &#8216;Working&#8217; Commodore 64/128 Diorama and Raspberry Pi VICE Emulator</a> appeared first on <a rel="nofollow" href="https://krystof.io">Krystof.IO</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>A little bit of backstory:  It&#8217;s 1985 and the Nintendo Entertainment System begins its assault on North American wallets in the late fall season.  As a child of the 1980&#8217;s, I was ready and willing to throw my parent&#8217;s savings towards the Nintendo firing lines.  The problem was, Dad was an unwilling partner.</p>



<p><strong>10 Year Old Me:</strong> <em>Dad, I want a Nintendo!</em></p>



<p><strong>Older, Wiser Father: </strong><em>Well, Son, I bought you this Commodore 128 Computer instead.</em></p>



<p> <strong>10 Year Old Me:</strong> <em>God damn it, Dad (internal dialogue).</em> </p>



<p>There went my hopes and dreams of having a Nintendo &#8211; replaced with this many keyed Commodore paperweight.  Dad&#8217;s goal, unbeknownst to me, was simple &#8211; get something that <em>could play games</em> but could also be used to <em>learn about computers</em>.  One day I was bored enough to pick up the manual&#8230;</p>



<div class="wp-block-image"><figure class="aligncenter size-medium"><img decoding="async" loading="lazy" width="300" height="300" src="https://krystof.io/wp-content/uploads/2019/12/Commodore-128-System-Guide-300x300.jpg" alt="" class="wp-image-981" srcset="https://krystof.io/wp-content/uploads/2019/12/Commodore-128-System-Guide-300x300.jpg 300w, https://krystof.io/wp-content/uploads/2019/12/Commodore-128-System-Guide-150x150.jpg 150w, https://krystof.io/wp-content/uploads/2019/12/Commodore-128-System-Guide.jpg 814w" sizes="(max-width: 300px) 100vw, 300px" /><figcaption>Hello, Mr. Krystof.  This is Fate knocking.<br>It&#8217;s time to open this up.</figcaption></figure></div>



<p>I don&#8217;t remember which exact program I first built &#8211; but I do recall it was making use of the Commodore&#8217;s sprite mechanisms &#8211; some extremely crude animations and graphics manipulation.  Of course, most of the time with the Commodore 128 was spent in it&#8217;s &#8217;64 mode&#8217;, where almost all of the software library resided.</p>



<p>Nevertheless, thanks to my Nintendo-dodging father, I knew exactly what field I was going to get into in some way, shape, or form, by the time I was eleven.  I never had a console beyond the Atari 2600 until I was in my late thirties.</p>



<p>Fast forward through the years and Dad&#8217;s &#8216;spare room&#8217; (or &#8216;pit of crap&#8217; according to my mother) became the &#8216;computer room&#8217; as far as I was concerned.  Now, in the present, I want to pay homage to that era with a diorama capturing the spirit of that back room.  I also wanted to <em>play some of those old games again</em>, along with games <em>I never knew existed</em> at the time.</p>



<h2 class="wp-block-heading" id="h-birth-of-a-diorama-emulator-combo">Birth of a diorama / emulator combo</h2>



<p>I&#8217;ve put together Raspberry Pi <a href="https://krystof.io/the-tardis-arcade-hardware-invasion/" target="_blank" rel="noreferrer noopener" aria-label=" (opens in a new tab)">emulator setups before</a>, and I wanted to create one for myself, and I wanted to use this to specifically target my Commodore days.  While you&#8217;ll see a model of a Commodore 128, anybody who really used one will tell you it spends most of it&#8217;s time in &#8217;64 mode&#8217; since it was backwards compatible.  So the first thought was a 3D printed case that looks like a Commodore computer to wrap around my Raspberry Pi.</p>



<p>I found a few models online on sites like Thingiverse, an example being this <a rel="noreferrer noopener" aria-label=" (opens in a new tab)" href="https://www.thingiverse.com/thing:1954782" target="_blank">one</a>.  </p>



<div class="wp-block-image"><figure class="aligncenter size-medium"><img decoding="async" loading="lazy" width="300" height="225" src="https://krystof.io/wp-content/uploads/2019/12/raspberrypi-c64-case-300x225.jpg" alt="" class="wp-image-990" srcset="https://krystof.io/wp-content/uploads/2019/12/raspberrypi-c64-case-300x225.jpg 300w, https://krystof.io/wp-content/uploads/2019/12/raspberrypi-c64-case.jpg 628w" sizes="(max-width: 300px) 100vw, 300px" /><figcaption>I loved this model by Freakadude, but I really needed the Commodore 128 look.</figcaption></figure></div>



<p>I liked the idea, but I thought maybe I could add something to it &#8211; like LEDs?  A monitor?  A 1541 disk drive to hold an SD Card?  This will run the popular <a rel="noreferrer noopener" label=" (opens in a new tab)" href="http://vice-emu.sourceforge.net/" target="_blank" class="broken_link">VICE</a> Commodore emulator, so I figured a retro case like this to display the <a rel="noreferrer noopener" label=" (opens in a new tab)" href="https://www.raspberrypi.org/products/raspberry-pi-4-model-b/" target="_blank" class="broken_link">Raspberry Pi 4</a> I was planning to use would be a cool little project to take on.   Unfortunately, my brain wasn&#8217;t going to let me get off that easily.</p>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading" id="h-my-brain-goes-down-a-creative-spiral">My brain goes down a creative spiral.</h3>



<p>If I&#8217;m going to print a case and a little disk drive, why not a monitor?  Instead of that, what about a little computer desk and smaller versions of those components?  My mother does 1/12th scale miniatures (1 inch = 1 foot) as a hobby, so I just naturally went with that scale.   The more I thought about it, the more I realized trying to rebuild the Commodore setup I had as a child was really the way to go.  We (sadly) sold those pieces long ago; I felt building a diorama that captured the spirit of that room was now my goal.</p>



<p>Now I know I&#8217;m building a &#8216;room&#8217;, what about those LEDs?  Could I incorporate some simple little power LEDs into each component &#8211; monitor, disk drives, and keyboard?</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" loading="lazy" width="1024" height="576" src="https://krystof.io/wp-content/uploads/2020/01/20191206_155205-1024x576.jpg" alt="" class="wp-image-1085" srcset="https://krystof.io/wp-content/uploads/2020/01/20191206_155205-1024x576.jpg 1024w, https://krystof.io/wp-content/uploads/2020/01/20191206_155205-300x169.jpg 300w, https://krystof.io/wp-content/uploads/2020/01/20191206_155205-768x432.jpg 768w, https://krystof.io/wp-content/uploads/2020/01/20191206_155205-1536x864.jpg 1536w, https://krystof.io/wp-content/uploads/2020/01/20191206_155205-scaled.jpg 2048w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>It&#8217;s 1 and 1/2 inches wide.</figcaption></figure></div>



<p>If I&#8217;m going to build and/or manipulate 3D models to house LEDs for power &#8211; what about disk drive activity?  Could I have the classic red activity light on a 1541 disk drive turn on when the VICE emulator loads &#8216;virtual&#8217; floppy disk data?</p>



<p>If I&#8217;m going to manipulate power and activity LEDs for the components&#8230; what about a tiny LCD screen inside the Commodore 1802 monitor?  Could I play animations?  Show the &#8216;READY&#8217; screen?  Could I even mirror the Raspberry Pi output?</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" loading="lazy" width="1024" height="576" src="https://krystof.io/wp-content/uploads/2020/01/20191110_165347-1024x576.jpg" alt="" class="wp-image-1086" srcset="https://krystof.io/wp-content/uploads/2020/01/20191110_165347-1024x576.jpg 1024w, https://krystof.io/wp-content/uploads/2020/01/20191110_165347-300x169.jpg 300w, https://krystof.io/wp-content/uploads/2020/01/20191110_165347-768x432.jpg 768w, https://krystof.io/wp-content/uploads/2020/01/20191110_165347-1536x864.jpg 1536w, https://krystof.io/wp-content/uploads/2020/01/20191110_165347-scaled.jpg 2048w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>Not quite 1/12 scale, but it&#8217;s actually legible and that&#8217;s what I wanted.</figcaption></figure></div>



<p>If I&#8217;m going to do all that, I should get some sort of Commodore styled keyboard of some sort to type with so I can use those special <a href="https://en.wikipedia.org/wiki/PETSCII">PETSCII</a> keys.  </p>



<p>The VICE emulator also had some special keys for those common emulator functions, like mounting a virtual floppy image, pausing the emulator, loading/saving emulator machine state, etc.  Maybe I could build a little &#8216;mini-macro&#8217; keyboard to shorten those keystrokes.</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" loading="lazy" width="1024" height="576" src="https://krystof.io/wp-content/uploads/2020/01/20191208_202526-1024x576.jpg" alt="" class="wp-image-1087" srcset="https://krystof.io/wp-content/uploads/2020/01/20191208_202526-1024x576.jpg 1024w, https://krystof.io/wp-content/uploads/2020/01/20191208_202526-300x169.jpg 300w, https://krystof.io/wp-content/uploads/2020/01/20191208_202526-768x432.jpg 768w, https://krystof.io/wp-content/uploads/2020/01/20191208_202526-1536x864.jpg 1536w, https://krystof.io/wp-content/uploads/2020/01/20191208_202526-scaled.jpg 2048w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>Never built a keyboard of any kind until now, this was a fun exercise.</figcaption></figure></div>



<p>I had a few other design ideas that went farther, but this is where I stopped.  If I went too far, I knew I&#8217;d never get it done.  Nevertheless, that was my thought process behind the diorama / emulator combo.  I wanted to pay homage to that era as well as have a working emulator.</p>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading" id="h-the-diorama-is-still-a-room">The Diorama is still a &#8216;room&#8217;</h2>



<p>My mother has been creating miniatures for years now &#8211; primarily 1/12 &#8216;dollhouse&#8217; scale.  Once I mentioned the idea of the diorama to her, her &#8216;miniature brain&#8217; (ahem, don&#8217;t read that literally) went to work and she built the structure for the room box, carpet, desk, shelves, and even the old rolling chair we had plus some family pets.  It really started to feel like this diorama would capture the spirit of the computer room of my youth.  What I wasn&#8217;t expecting was mixing some &#8216;old me&#8217; and &#8216;young me&#8217;, as she found a figure, and with some paint in the right spots, created&#8230; mini-me.</p>



<div data-padding="10" class="wp-block-simple-blocks-info-block" style="background-color:#000000;color:#ffffff;padding:10px"><div data-iconsize="20" data-iconspace="20" class="icon" style="margin-right:20px"><svg aria-hidden="true" role="img" focusable="false" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewbox="0 0 20 20" class="dashicon dashicons-info"><path d="M10 2c4.42 0 8 3.58 8 8s-3.58 8-8 8-8-3.58-8-8 3.58-8 8-8zm1 4c0-.55-.45-1-1-1s-1 .45-1 1 .45 1 1 1 1-.45 1-1zm0 9V9H9v6h2z"></path></svg></div><div>Yes, I know it&#8217;s a guy with a beard&#8230; It&#8217;s the old me in the young me&#8217;s room.  Man that sounds creepy.</div></div>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" loading="lazy" width="576" height="1024" src="https://krystof.io/wp-content/uploads/2020/01/IMG_20191015_192807795-576x1024.jpg" alt="" class="wp-image-1094" srcset="https://krystof.io/wp-content/uploads/2020/01/IMG_20191015_192807795-576x1024.jpg 576w, https://krystof.io/wp-content/uploads/2020/01/IMG_20191015_192807795-169x300.jpg 169w, https://krystof.io/wp-content/uploads/2020/01/IMG_20191015_192807795-768x1366.jpg 768w, https://krystof.io/wp-content/uploads/2020/01/IMG_20191015_192807795-864x1536.jpg 864w, https://krystof.io/wp-content/uploads/2020/01/IMG_20191015_192807795-scaled.jpg 1152w" sizes="(max-width: 576px) 100vw, 576px" /><figcaption>It&#8217;s not that far off, really.</figcaption></figure></div>



<p>She created her own prototype of the diorama with a domed room, with myself and my Siamese Luna enjoying what little air is left under this glass by playing some Pac-Man (which I&#8217;d be replacing with Commodore specifics).</p>



<div class="wp-block-image"><figure class="aligncenter size-large is-resized"><img decoding="async" loading="lazy" src="https://krystof.io/wp-content/uploads/2020/01/IMG_20191103_174350649-576x1024.jpg" alt="" class="wp-image-1098" width="288" height="512" srcset="https://krystof.io/wp-content/uploads/2020/01/IMG_20191103_174350649-576x1024.jpg 576w, https://krystof.io/wp-content/uploads/2020/01/IMG_20191103_174350649-169x300.jpg 169w, https://krystof.io/wp-content/uploads/2020/01/IMG_20191103_174350649-768x1366.jpg 768w, https://krystof.io/wp-content/uploads/2020/01/IMG_20191103_174350649-864x1536.jpg 864w, https://krystof.io/wp-content/uploads/2020/01/IMG_20191103_174350649-scaled.jpg 1152w" sizes="(max-width: 288px) 100vw, 288px" /></figure></div>



<h2 class="wp-block-heading" id="h-making-the-mini-commodore-parts">Making The Mini Commodore Parts </h2>



<figure class="wp-block-image size-large"><img decoding="async" loading="lazy" width="1024" height="496" src="https://krystof.io/wp-content/uploads/2020/01/Resized_20191017_202858-1024x496.jpeg" alt="" class="wp-image-1095" srcset="https://krystof.io/wp-content/uploads/2020/01/Resized_20191017_202858-1024x496.jpeg 1024w, https://krystof.io/wp-content/uploads/2020/01/Resized_20191017_202858-300x145.jpeg 300w, https://krystof.io/wp-content/uploads/2020/01/Resized_20191017_202858-768x372.jpeg 768w, https://krystof.io/wp-content/uploads/2020/01/Resized_20191017_202858-1536x744.jpeg 1536w, https://krystof.io/wp-content/uploads/2020/01/Resized_20191017_202858-scaled.jpeg 2048w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>Some resin, some filament&#8230; All Retro.</figcaption></figure>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p>Taking a few models from Thingiverse (the series article on the modeling will have the details), and modifying them for some future LED wiring, I went to work recreating the system we had &#8211; A Commodore 128, two 1541 drives, and a monitor.  I also went about creating some floppy disks which you can see below, though I ended up making them thinner later.</p>



<div class="wp-block-envira-envira-gallery"><div class="envira-gallery-feed-output"><img class="envira-gallery-feed-image" tabindex="0" src="https://krystof.io/wp-content/uploads/2020/01/Resized_20191103_095418.jpeg" title="" alt="" /></div></div>



<p>After slimming down those floppies I created envelopes resembling some of the makers I remembered from my youth &#8211; Commodore branded floppies, BONUS, Elephant, Maxell, and Verbatim.  You may also recognize an EA branded floppy envelope from the days where EA was ground breaking and universally adored.</p>



<figure class="wp-block-image size-large"><img decoding="async" loading="lazy" width="1024" height="496" src="https://krystof.io/wp-content/uploads/2020/01/Resized_20191103_153824-1024x496.jpeg" alt="" class="wp-image-1092" srcset="https://krystof.io/wp-content/uploads/2020/01/Resized_20191103_153824-1024x496.jpeg 1024w, https://krystof.io/wp-content/uploads/2020/01/Resized_20191103_153824-300x145.jpeg 300w, https://krystof.io/wp-content/uploads/2020/01/Resized_20191103_153824-768x372.jpeg 768w, https://krystof.io/wp-content/uploads/2020/01/Resized_20191103_153824-1536x744.jpeg 1536w, https://krystof.io/wp-content/uploads/2020/01/Resized_20191103_153824-scaled.jpeg 2048w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>3D printed floppies, write protection notches included.</figcaption></figure>



<figure class="wp-block-image size-large"><img decoding="async" loading="lazy" width="1024" height="576" src="https://krystof.io/wp-content/uploads/2020/01/20191223_141023-scaled-1024x576.jpg" alt="" class="wp-image-1101" srcset="https://krystof.io/wp-content/uploads/2020/01/20191223_141023-scaled-1024x576.jpg 1024w, https://krystof.io/wp-content/uploads/2020/01/20191223_141023-scaled-300x169.jpg 300w, https://krystof.io/wp-content/uploads/2020/01/20191223_141023-scaled-768x432.jpg 768w, https://krystof.io/wp-content/uploads/2020/01/20191223_141023-scaled-1536x864.jpg 1536w, https://krystof.io/wp-content/uploads/2020/01/20191223_141023-scaled.jpg 2048w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>Game Boxes &#8211; Those floppies and manuals have to go somewhere.  Also going to need some posters for the back wall of that diorama.</figcaption></figure>



<h2 class="wp-block-heading" id="h-a-living-breathing-commodore">A &#8216;living, breathing&#8217; Commodore.</h2>



<p>The LED related goals of the diorama: <strong>Power LEDs</strong> and <strong>drive activity LEDs</strong> that match our VICE emulator install.  When you load a virtual floppy in VICE, I want the drive 8 LED to light up.  That requires a customization we&#8217;ve made to VICE itself (details in the series article), but it all has to come together connecting to the Raspberry Pi, a custom circuit board, and power.  Needless to say, the breadboard came in mighty useful during this endeavor.</p>



<figure class="wp-block-image size-large"><img decoding="async" loading="lazy" width="768" height="1024" src="https://krystof.io/wp-content/uploads/2020/01/img_20191208_201211-768x1024.jpg" alt="" class="wp-image-1102" srcset="https://krystof.io/wp-content/uploads/2020/01/img_20191208_201211-768x1024.jpg 768w, https://krystof.io/wp-content/uploads/2020/01/img_20191208_201211-225x300.jpg 225w, https://krystof.io/wp-content/uploads/2020/01/img_20191208_201211-1152x1536.jpg 1152w, https://krystof.io/wp-content/uploads/2020/01/img_20191208_201211.jpg 1536w" sizes="(max-width: 768px) 100vw, 768px" /><figcaption>The &#8216;Sleep / Shutdown&#8217; button, and the drive LEDs in the background.</figcaption></figure>



<p>Also, I wanted the 3d printed monitor to work as an enclosure for a small LCD that mirrors the HDMI output of the Raspberry Pi &#8211; here&#8217;s the initial capture I took when it somehow didn&#8217;t melt upon plugging all of it together:</p>



<div class="wp-block-image"><figure class="aligncenter size-full"><img decoding="async" loading="lazy" width="320" height="165" src="https://krystof.io/wp-content/uploads/2020/01/Dual-Display.gif" alt="" class="wp-image-1091"/></figure></div>



<h2 class="wp-block-heading" id="h-twitching-the-progression">Twitching The Progression</h2>



<p>I decided to clean up the work space <em>a little bit</em> and get the <a rel="noreferrer noopener" aria-label="Twitch  (opens in a new tab)" href="https://www.twitch.tv/mrkrystof" target="_blank">Twitch </a>stream going.  Figured I&#8217;d work on this and if anyone decided to stop by and chat about it, they could.  In fact, they did.  So far I&#8217;ve met a few interested in the old Commodore retro scene, some more on the electronics side of the circuit, and some just curious as to what the hell I&#8217;m doing.</p>



<figure class="wp-block-image size-large"><img decoding="async" loading="lazy" width="1024" height="576" src="https://krystof.io/wp-content/uploads/2020/01/20191219_184626-1024x576.jpg" alt="" class="wp-image-1082" srcset="https://krystof.io/wp-content/uploads/2020/01/20191219_184626-1024x576.jpg 1024w, https://krystof.io/wp-content/uploads/2020/01/20191219_184626-300x169.jpg 300w, https://krystof.io/wp-content/uploads/2020/01/20191219_184626-768x432.jpg 768w, https://krystof.io/wp-content/uploads/2020/01/20191219_184626-1536x864.jpg 1536w, https://krystof.io/wp-content/uploads/2020/01/20191219_184626-scaled.jpg 2048w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>Testing the final circuit build and the dual display of the VICE screens.</figcaption></figure>



<h2 class="wp-block-heading" id="h-diorama-emulator-parts-breakdown">Diorama/Emulator Parts Breakdown</h2>



<p>This diorama / emulator combo breaks down into these major components, and thus the series articles for more detail follow this list.  As I wrap up each one I&#8217;ll post the links here for posterity.</p>



<ul><li><strong>Raspberry Pi 4</strong> &#8211; The heart of the electronics &#8211; this runs the emulator as well as drives the circuit controlling power and drive activity LED&#8217;s. <strong>You can now see more on the VICE and OS install here: </strong> <a href="https://krystof.io/installing-the-vice-commodore-emulator-for-console-mode-on-a-fresh-raspberry-pi-4/">https://krystof.io/installing-the-vice-commodore-emulator-for-console-mode-on-a-fresh-raspberry-pi-4/</a> </li><li><strong>LCD display</strong> &#8211; this mirrors the Raspberry PI&#8217;s HDMI output, so as the big-me plays games, the mini-me in the diorama is playing the same game &#8211; or is it the other way around?</li><li> <strong>LED circuit board</strong> &#8211; This reads GPIO pin inputs from the Raspberry Pi and switches on the power and drive activity LED&#8217;s.  I also decided to try out a simple &#8216;Power&#8217; button to ease the shutdown of the Raspberry Pi. </li><li> <strong>3D Printed Commodore Models</strong> &#8211; Modified and scaled accordingly, printed in resin or filament, and painted by hand (crap-fully)  </li><li><strong>Custom VICE build and LED driver software</strong> &#8211; I created a custom VICE build to get my hook into the floppy drive activity and get that state sent to the LED circuit &#8211; so when VICE considers a floppy drive active, my LED circuit turns the LED on or off accordingly.</li><li><strong>Diorama Room</strong> containing models of our old computer desk, floppy disk holders, game boxes, and wall art I would hang in the computer room or my bedroom over the years.</li><li><strong>Input Peripherals</strong> &#8211; I need a keyboard to type on and joysticks to &#8230; joy with.</li><li><strong>Custom Keyboard Deck</strong> &#8211; This keyboard of 10 keys controls common emulator functions (mount floppy image, pause, restart emulator machine, etc.)</li><li><strong>Diorama case &#8216;base&#8217;</strong> &#8211; where we&#8217;re going to store the electronics of this diorama/emulator combo &#8211; underneath in a 3 inch tall base for the diorama to rest on.</li></ul>



<p>There are some parallel threads in the series here &#8211; I worked on many pieces at the same time &#8211; and you could to if you were recreating it.  Nevertheless, here&#8217;s how the series is presented &#8211; and I&#8217;ll do my best to keep this cohesive.</p>



<h2 class="wp-block-heading" id="h-series-breakdown">Series Breakdown</h2>



<p>As I upload articles and videos, this list will be updated and links created.  Stay tuned!</p>



<ol><li>This entry &#8211; the overview and motivation &#8211; <em><strong>Released</strong> <strong>Jan 4 2020</strong> </em></li><li><a href="https://krystof.io/installing-the-vice-commodore-emulator-for-console-mode-on-a-fresh-raspberry-pi-4/">VICE on the Raspberry Pi 4 Install</a> &#8211; Raspberry Pi 4, VICE Compiling &#8211; <strong><em>Released Jan 12 2020</em></strong></li><li><a href="https://krystof.io/mirroring-raspberry-pi-hdmi-video-to-a-st7789-1-3-inch-lcd-display/">Raspberry Pi 4 and  ST7789 LCD Install</a> &#8211; How to get frame buffer copying and display rotation working. &#8211; <strong><em>Released Jan 19 2020</em></strong></li><li><a href="https://krystof.io/patching-the-vice-emulator-to-light-up-floppy-drive-leds/">Custom VICE build and Python Shared Memory</a> &#8211; Using Linux shared memory to communicate between VICE and Python to drive the proper drive activity LEDs<strong><em> &#8211; Released Feb 15 2020</em></strong></li><li>Controlling LEDs from a Raspberry Pi and a Darlington Array &#8211; Isolating the power driving LEDs  and building the LED circuit </li><li> 3D Modeling the Commodore Computer &#8211; Modifications to support LED housing and wiring, painting, and decals </li><li>Input Peripherals &#8211; Keyboard and Joysticks and some alternate considerations</li><li>VICE Custom Keyboard Deck &#8211; Using an Arduino compatible Teensy to act as a USB HID Keyboard</li><li> Diorama Room &#8211; It&#8217;s not a diorama without some background items and finishing touches. </li><li>Diorama Case Base &#8211; Final touches and assembly of the diorama.</li><li>Retrospective &#8211; Looking back as we moved forward through this series.</li></ol>
<p>The post <a rel="nofollow" href="https://krystof.io/diorama-64-part-1-overview/">The &#8216;Working&#8217; Commodore 64/128 Diorama and Raspberry Pi VICE Emulator</a> appeared first on <a rel="nofollow" href="https://krystof.io">Krystof.IO</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://krystof.io/diorama-64-part-1-overview/feed/</wfw:commentRss>
			<slash:comments>8</slash:comments>
		
		
		
		<series:name><![CDATA[Diorama 64]]></series:name>
	</item>
		<item>
		<title>Auto mounting a USB drive in a Raspberry Pi</title>
		<link>https://krystof.io/auto-mounting-a-usb-drive-in-a-raspberry-pi/</link>
					<comments>https://krystof.io/auto-mounting-a-usb-drive-in-a-raspberry-pi/#comments</comments>
		
		<dc:creator><![CDATA[Eric R. Krystof]]></dc:creator>
		<pubDate>Mon, 30 Dec 2019 03:16:58 +0000</pubDate>
				<category><![CDATA[Raspberry Pi]]></category>
		<guid isPermaLink="false">https://krystof.io/?p=1026</guid>

					<description><![CDATA[<p>This isn't de facto behavior out of the box for a Raspberry Pi - so how do we auto mount USB drives to make access and file copying easier?</p>
<p>The post <a rel="nofollow" href="https://krystof.io/auto-mounting-a-usb-drive-in-a-raspberry-pi/">Auto mounting a USB drive in a Raspberry Pi</a> appeared first on <a rel="nofollow" href="https://krystof.io">Krystof.IO</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>When I&#8217;m building some retro arcade setups on a Raspberry Pi I&#8217;m often copying over some set of disk images, media files, configuration, or ROMs.  They&#8217;re not always on the same network, and sometimes it&#8217;s just easier to take a keychain thumb drive and copy some files around.  I&#8217;m not always in a windows environment on these boxes, either.  I searched the web for a bit on how to do it and here&#8217;s the information I&#8217;ve compiled in a step by step format.</p>



<h2 class="wp-block-heading" id="h-step-1-install-pmount">Step 1 &#8211; Install pmount</h2>



<p><strong>pmount</strong> is a wrapper around the standard mount program which permits normal users to mount removable devices without a matching /etc/<a href="https://wiki.debian.org/fstab">fstab</a>&nbsp;entry.   This is how we&#8217;ll manage to auto mount our USB drives.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
sudo apt install pmount
</pre></div>


<h2 class="wp-block-heading" id="h-step-2-udev-rule">Step 2 &#8211; UDEV Rule</h2>



<p>Udev&nbsp;allows for&nbsp;<em>rules</em>&nbsp;that specify what name is given to a device, regardless of which port it is plugged into.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
sudo vi /etc/udev/rules.d/usbstick.rules
</pre></div>

<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
ACTION==&quot;add&quot;, KERNEL==&quot;sd&#91;a-z]&#91;0-9]&quot;, TAG+=&quot;systemd&quot;, ENV{SYSTEMD_WANTS}=&quot;usbstick-handler@%k&quot;
</pre></div>


<h2 class="wp-block-heading" id="h-step-3-create-systemd-service">Step 3 &#8211; Create Systemd service</h2>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
sudo vi /lib/systemd/system/usbstick-handler@.service
</pre></div>

<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
&#91;Unit]
Description=Mount USB sticks
BindsTo=dev-%i.device
After=dev-%i.device

&#91;Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/local/bin/automount %I
ExecStop=/usr/bin/pumount /dev/%I
</pre></div>


<h2 class="wp-block-heading" id="h-step-4-create-mount-script">Step 4 &#8211; Create Mount Script</h2>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
sudo vi /usr/local/bin/automount
</pre></div>

<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
#!/bin/bash

PART=$1
FS_LABEL=`lsblk -o name,label | grep ${PART} | awk &#039;{print $2}&#039;`

if &#91; -z ${FS_LABEL} ]
then
    /usr/bin/pmount --umask 000 --noatime -w --sync /dev/${PART} /media/${PART}
else
    /usr/bin/pmount --umask 000 --noatime -w --sync /dev/${PART} /media/${FS_LABEL}_${PART}
fi
</pre></div>

<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
sudo chmod +x /usr/local/bin/automount
</pre></div>


<div data-padding="10" class="wp-block-simple-blocks-info-block" style="background-color:#000000;color:#ffffff;padding:10px"><div data-iconsize="20" data-iconspace="20" class="icon" style="margin-right:20px"><span class="dashicon dashicons dashicons-info"></span></div><div>Note the &#8211;sync option &#8211; with that enabled above write operations will not utilize caching, so while the write is &#8216;safer&#8217; to prevent data loss, it&#8217;s also a lot slower.  Your mileage may vary.</div></div>



<h2 class="wp-block-heading" id="h-step-5-should-be-working-but-if-not">Step 5 &#8211; Should be working, but if not&#8230;</h2>



<p>You&#8217;ll see your USB drives mounted under /media</p>



<p>Per the comment from James:</p>



<blockquote class="wp-block-quote"><p>And rather than reboot, UDEV should automatically detect new rules[<a href="https://wiki.archlinux.org/title/Udev#Loading_new_rules" target="_blank" rel="noreferrer noopener">2</a>], but if it fails to:</p><p>udevadm control &#8211;reload</p></blockquote>



<p>If that doesn&#8217;t work&#8230; you can always try turning it off and on again 🙂</p>



<h4 class="wp-block-heading" id="h-references">References</h4>



<ul><li><a href="https://linux.die.net/man/1/pmount" class="broken_link">pmount</a></li><li><a href="https://raspberrypi.stackexchange.com/questions/66169/auto-mount-usb-stick-on-plug-in-without-uuid" class="broken_link">Stack Exchange Post</a></li></ul>
<p>The post <a rel="nofollow" href="https://krystof.io/auto-mounting-a-usb-drive-in-a-raspberry-pi/">Auto mounting a USB drive in a Raspberry Pi</a> appeared first on <a rel="nofollow" href="https://krystof.io">Krystof.IO</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://krystof.io/auto-mounting-a-usb-drive-in-a-raspberry-pi/feed/</wfw:commentRss>
			<slash:comments>9</slash:comments>
		
		
			</item>
		<item>
		<title>The Tardis Themed Arcade Comes Together</title>
		<link>https://krystof.io/the-tardis-themed-arcade-comes-together/</link>
					<comments>https://krystof.io/the-tardis-themed-arcade-comes-together/#respond</comments>
		
		<dc:creator><![CDATA[Eric R. Krystof]]></dc:creator>
		<pubDate>Wed, 16 Mar 2016 11:11:48 +0000</pubDate>
				<category><![CDATA[Arcade Building]]></category>
		<category><![CDATA[Tardis]]></category>
		<category><![CDATA[Raspberry Pi]]></category>
		<guid isPermaLink="false">https://static.krystof.io/?p=70</guid>

					<description><![CDATA[<p>Building the plywood shell, painting, assembly, and decorating the Tardis themed bartop arcade.</p>
<p>The post <a rel="nofollow" href="https://krystof.io/the-tardis-themed-arcade-comes-together/">The Tardis Themed Arcade Comes Together</a> appeared first on <a rel="nofollow" href="https://krystof.io">Krystof.IO</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In the <a href="https://krystof.io/the-tardis-arcade-hardware-invasion">last</a> post we covered the wood working and inner wiring of the control panel. I built most of it &#8216;naked&#8217; to make sure things fit well enough, and the VESA plate I attached to the monitor had a decent angle for viewing. I don&#8217;t think I could have done that as easily with MDF with my lack of experience.</p>
<p><img decoding="async" src="https://krystof.io/wp-content/uploads/2019/10/unpainted-1-1-1-1-1.jpg" alt="Unpainted arcade"></p>
<p>With the control panel layout finalized, I test fit everything together. I wish I took more pictures along this stage, but unfortunately I did not. Next project I will have to snap more photos. I was originally intending a flashing Tardis light up on top, then just went and cut a ventilation hole up there instead, totally forgetting about the light fixture. Ah well. I still wired up my Raspberry Pi with a script to drive two LED lights embedded in the speaker holes to pulsate with the Tardis &#8216;Whoosh!&#8217; sound when the machine boots up, so it all worked out well enough.</p>
<p>I designed and printed off the Marquee at home, overlaying the Doctor&#8217;s name in Gallifrey on top of the &#8216;Pop&#8217;s Arcade&#8217; in a Doctor Who style font. Behind the marquee is just a flat panel of wood with 2 soft white 12 volt LED strips from my old RC airplane days. I printed two copies of the marquee and laid them over each other, which not only fought off light washing out the print but also gave a slight effect of depth to the words which I really liked.</p>
<p>Unfortunately I only have a inkjet and not a huge plotter, therefore at certain angles you can see where joined the two marquee halves together. There are printing companies online that will do full pieces, and I&#8217;ll heavily consider it next time around.</p>
<p>The Control Panel piece is hinged so it lefts up and towards you to get access to any wiring necessary, and the original plans I found (see first post) were adjusted to add more height for a keyboard tray. The very back of the arcade opens up to reveal the monitor mounted on a horizontal length of wood, with the power supply, wiring, and raspberry pi secured inside.</p>
<h2>Now that it&#8217;s put together, tear it all down</h2>
<p>I assembled most of it at this point except for the raspberry Pi and controls. This way I knew the wood came together as it should before I took it into the garage for painting. I haven&#8217;t done a lot of routing in my life either, so I was opting for white edge banding compared to arcade T-Molding. While the T-Molding really looks great and smooths edges out nicely, I figured I&#8217;d save that wood working struggle for a later time.</p>
<p>So, taking each piece downstairs, it was time to sand and prime.<br />
<img decoding="async" src="https://krystof.io/wp-content/uploads/2019/10/primer-1-1-1-1-1.jpg" alt="Priming picture 1"><img decoding="async" src="https://krystof.io/wp-content/uploads/2019/10/primer2-1-1-1-1-1.jpg" alt="Priming picture 2"> Not having access to anything near a professional painting setup, just a garage with some Krylon Fusion and some sand paper, I got down to business. I was surprised and happy overall with how it turned out, and while I read that I <em>could</em> have just started painting, I&#8217;m really glad on how the primer helped the paint attach and how smooth 95% of the surfaces felt when I was done.</p>
<p>It was around this time between painting breaks that I worked on the acrylic control panel overlay. Measuring out the acrylic to match the control panel was easy. The cutting of the holes for the acrylic proved to be more of a challenge. I didn&#8217;t want to just use a spade or forstner bit. I tried to practice with scrap acrylic knowing it would be a struggle and it surely was. So when it came down to the actual cutting of the holes for the buttons and joystick to fit into, I opted for a step bit on the acrylic whereas I used the forstner bit on the control panel wood.</p>
<p><img decoding="async" src="https://krystof.io/wp-content/uploads/2019/10/step-bit-1-1-1-1-1.jpg" alt="Milwaukee Step Bit"></p>
<p>A Milwaukee #9 7/8 in. and 1-1/8 in. Step Drill Bit, to be exact. Taking it slow into the circles and spots I drew on the acrylic outer plastic wrap (leave that on while you drill!), I couldn&#8217;t have asked for an easier cutting experience with acrylic. Once the piloting hole was drilled through, this thing literally fell through the acrylic like butter, step by step. Take it slow, take it easy, and with the 1 1/8&#8243; maximum width of the bit matching my desired hole size, I didn&#8217;t have to worry about it sliding further and making a larger hole than intended. After I finished drilling all of the holes in the acrylic, I noticed only one small crack that was hidden by the button chrome anyhow. After drilling that many holes I was more than accepting of that outcome. Expensive as it may be, it&#8217;s my go-to for acrylic hole drilling from this point forward.</p>
<p>I found some Tardis schematics online and printed them out on a high gloss inkjet paper. Trimming those the control panel board, I was able to complete the acrylic/overlay/control panel sandwich. I manually traced the circles through with the paper and cut them out by hand, however. Drills and paper are extremely strange bedfellows, in my opinion.</p>
<h2>After the paint dries&#8230;</h2>
<p>It&#8217;s time to take it all back upstairs and put it all together.</p>
<p><img decoding="async" src="https://krystof.io/wp-content/uploads/2019/10/back-together-1-1-1-1-1.jpg" alt="Tardis Arcade Together"></p>
<p>While C slept one morning, I was edge banding my life away after finally getting the painted pieces re-assembled. While I&#8217;m glad I used a hot iron to affix the edge banding, it sure is a delicate process. Compared to T-Molding, however, I think it came out fairly well with only a few spots to touch up or re-cut afterward.</p>
<p>So at this point, it was really ready to go except for one last piece. The side art. An arcade machine should have something on the side, and I&#8217;ve got a ncie control panel, cool lit up Marquee, but nothing yet for the side art. I struggled with the idea of printing a large background on paper and having to line up each piece&#8230; Or something on adhesive ink jet vinyl&#8230; or a poster of some sort.</p>
<p>C had a great idea that left a lot of the nice &#8216;Tardis Blue&#8217; paint I found revealed but also gave her a creative outlet with that Silhouette cutter. She searched around for various members of the Dr. Who rogue&#8217;s gallery and started cutting outlines on adhesive backed vinyl. Here&#8217;s the spectacular result:</p>
<p><img decoding="async" src="https://krystof.io/wp-content/uploads/2019/10/left-side-1-1-1-1-1.jpg" alt="Left side vinyl"><img decoding="async" src="https://krystof.io/wp-content/uploads/2019/10/right-side-1-1-1-1-1.jpg" alt="Right side vinyl"></p>
<p>Even the piece above the keyboard tray got some K-9 action:</p>
<p><img decoding="async" src="https://krystof.io/wp-content/uploads/2019/10/k-9s-1-1-1-1-1.jpg" alt="K-9 Keyboard"></p>
<h2>When it&#8217;s all said and done&#8230;</h2>
<p>I love how it turned out. I love that it was challenging for me on numerous levels, from hardware, woodworking, painting, graphics, software, joystick controls, lighting, and even some electrical work, as a LED switch plug and cutting apart a surge protector was not something I&#8217;d ever thought I&#8217;d be doing. I love that I was going to be able to present this as a gift to my Dad, and we could relive gaming on three separate platforms all over again, from Atari 2600 to Commodore 64 to your standard IBM PC.</p>
<p>It may not be the perfect build, but it&#8217;s the all the effort that goes into a handmade gift that really makes it special. As much as this was for Dad, I give credit to Mom for holding a secret for so many months.</p>
<p>When we took it over to my parent&#8217;s house, it was underneath a sheet and sitting on the coffee room table. He had only one guess that he could come up with what was sitting underneath the cloth: <em>a gun rack</em>. His expression when I lifted up the sheet, however, was priceless. The first thing he asked after looking at it from various angles was &#8216;What is it?&#8217; &#8216;Well, Pop, it&#8217;s your very own arcade machine.&#8217; &#8216;Well yeah, but&#8230; it works?&#8217;</p>
<p>I powered it up into it&#8217;s start up sequence &#8211; a Tardis flying through space and the words &#8216;Welcome To Pop&#8217;s Arcade&#8217; flying right along with it, Dr. Who theme music and all. He was completely enamored and taken aback by the whole thing. When you hear the words &#8216;I don&#8217;t think you&#8217;ll ever be able to top this gift and what it means to me that you made this&#8217;, I felt overjoyed that we could relive a little of our gaming history together again and that he loved how it turned out.</p>
<p>In fact, that&#8217;s what we did for the next two or three hours. Playing Heretic on my laptop connected to his Tardis Arcade via LAN meant that once again, after 20 years, I could turn him into a chicken with the &#8216;Morph Ovum&#8217; spell, and he could, somehow, manage to figure out a way to peck me to death.</p>
<p><strong><a href="https://images.krystof.io/#5">Visit the Tardis Gallery for all images.</a></strong></p>
<p>The post <a rel="nofollow" href="https://krystof.io/the-tardis-themed-arcade-comes-together/">The Tardis Themed Arcade Comes Together</a> appeared first on <a rel="nofollow" href="https://krystof.io">Krystof.IO</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://krystof.io/the-tardis-themed-arcade-comes-together/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		
		<series:name><![CDATA[Tardis Bartop Arcade Project]]></series:name>
	</item>
		<item>
		<title>The Tardis Arcade Hardware Invasion</title>
		<link>https://krystof.io/the-tardis-arcade-hardware-invasion/</link>
					<comments>https://krystof.io/the-tardis-arcade-hardware-invasion/#respond</comments>
		
		<dc:creator><![CDATA[Eric R. Krystof]]></dc:creator>
		<pubDate>Tue, 15 Mar 2016 11:11:48 +0000</pubDate>
				<category><![CDATA[Arcade Building]]></category>
		<category><![CDATA[Raspberry Pi]]></category>
		<category><![CDATA[Tardis]]></category>
		<guid isPermaLink="false">https://static.krystof.io/?p=59</guid>

					<description><![CDATA[<p>In the last post, I mused over the main electronic guts of what would become a Tardis themed arcade build. All I knew is that I&#8217;d build something to enclose&#8230;</p>
<p>The post <a rel="nofollow" href="https://krystof.io/the-tardis-arcade-hardware-invasion/">The Tardis Arcade Hardware Invasion</a> appeared first on <a rel="nofollow" href="https://krystof.io">Krystof.IO</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In the <a href="https://krystof.io/how-a-tardis-themed-arcade-build-began-to-take-shape">last</a> post, I mused over the main electronic guts of what would become a Tardis themed arcade build. All I knew is that I&#8217;d build something to enclose said guts, just not what yet. My parents have been in the same house for three decades now, and over time you accumulate enough stuff that a stand up arcade probably would have been too much.<code></code></p>
<p>So I started browsing around for DIY arcade designs, as I wanted to make this myself, and hopefully not lose a limb in the process. The two people I would have asked for help, Salazar and Pops, I could <em>not</em> ask&#8230; As I was also building a retro PC for Salazar as well. So any woodworking would be my first and mine alone. Still have all my fingers, so I must have done something right.</p>
<h2>Ordering a game at the bar&#8230;top</h2>
<p>There are numerous designs for your own DIY arcade. Cocktail, Bartop, Standup, Showcase&#8230; Bartop ended up winning for my gift for Pops &#8211; I could put it on his bar downstairs (if I could convince him to stop using it as a storage area, but if Mom can&#8217;t do that, I doubt I&#8217;d be able to) or even a desk. I searched numerous designs, but found this <a href="http://www.instructables.com/id/2-Player-Bartop-Arcade-Machine-Powered-by-Pi/">instructable</a> by rolfebox that fit my bill for the most part:</p>
<p><img decoding="async" src="https://krystof.io/wp-content/uploads/2019/10/instructable-1-1-1-1-1.jpg" alt="Rolfebox"></p>
<p>The plans are great, and I followed them not to the letter, but more to the word. I knew I was using at least these components:</p>
<ul>
<li>Raspberry Pi Internals</li>
<li>Acer VS228 LCD Monitor</li>
<li>Joysticks and Buttons</li>
<li>Keyboard and Mouse accessible (we played a LOT of Heretic, Hexen, and Doom)</li>
<li>LED Lights for Marquee</li>
<li>LED lights for startup sequence (I wanted to add the Tardis Whoosh!)</li>
</ul>
<p>I wanted to make sure all of these would physically fit with the plans above. They wouldn&#8217;t right off the bat, you could see above there is no keyboard tray, and the monitor used is smaller than the one I wanted. There are two main conclusions to draw from this:</p>
<ul>
<li>Be ready to modify any plans you find for your own purposes. Print them off, tape them together, or take them to your local printer and print them at scale. <strong>Your</strong> hardware needs to fit, and if you don&#8217;t have exactly every single piece used in an example you find, you may need to adapt measurements.</li>
<li><strong>Make a cardboard mock-up of your final plans before you cut any wood.</strong> I can&#8217;t stress that enough, so I&#8217;ll probably say it again in either this sentence or the <strong>Make a cardboard mock-up of your final plans before you cut any wood.</strong> &#8212; well, there it is. You can measure the width and height of your display and make sure the cardboard mock-up fits, as you can see in the featured photo at the top and below:</li>
</ul>
<p><img decoding="async" src="https://krystof.io/wp-content/uploads/2019/10/cardboard_on_table-1-1-1-1-1.jpg" alt="Cardboard mock-up on table"></p>
<h2>No Guts, No Glory</h2>
<p>So now that I have the plans I wanted to base the arcade build upon, had a separate thread in my head of what was going to be inside. While I&#8217;m used to keyboard and mouse gaming on a PC, a DIY Arcade&#8217;s spirit <em>demands</em> joystick and button glory.</p>
<p>This was a difficult decision. You can make this as cheap or expensive as possible. You could buy your own joystick, your own buttons, your own controller, and wire each one yourself. I&#8217;ve been down that road, and was getting tired of the soldering iron. While it would have helped my soldering skills, there was a balance between exactly how much Y I wanted to put in the DIY. I was already building the cabinet, I figured I&#8217;d at least purchase some wiring harnesses instead of cutting, crimping, and soldering each connection individually.</p>
<p>So, a <em>pack</em> of hardware suited me best. I opted for this package from <a href="https://gameroomsolutions.com/shop/2-player-led-arcade-control-panel-bundle-kit/">Game Room Solutions</a><br />
<img decoding="async" src="https://krystof.io/wp-content/uploads/2019/10/gameroomsolutions-1-1-1-1-1.gif" alt="Game Room Solutions 2 Player Bundle Kit"></p>
<p>You get essentially everything you need to use arcade hardware in your RetroPie arcade setup. It&#8217;s also, due to the USB controller shown, not limited to the your Raspberry Pi.</p>
<h2>A shell of an arcade</h2>
<p>Off I go to Home Depot. Tools, Lumber, Glue, Brackets. I&#8217;ve measured out the cardboard prototype and just had to figure out the material I&#8217;d use to create this monstrosity. I searched for a few options available to me, and they came down to two in the end:</p>
<ul>
<li>Plywood &#8211; This is what I ended up going with. 3/4&#8243; thick Maple or Birch Plywood. It may be heavier, and I could have probably gone lighter, but I wanted stability and some room for error. I could still sand and paint this later as well. You&#8217;re looking for furniture grade in my opinion. Cheaper is not necessarily better, but your mileage may vary.</li>
<li>MDF &#8211; I felt it would be heavier than the plywood I chose (even though my plywood was heavier than thinner plywood by comparison), but there were two aspects of MDF that gave me pause. <strong>Toxicity</strong> and <strong>Screwing</strong>. (Oh man, I used &#8216;anal&#8217; in another post, now I&#8217;ve got screwing? It&#8217;s all downhill from here) MDF is quite toxic when you&#8217;re cutting it, as it&#8217;s formed by taking wood pulp and pressing it down with a generally formaldehyde based resin. That&#8217;s in the air when you&#8217;re sanding and cutting. Plywood itself can be bad enough, so toxicity was a big no for me as an amateur. Screwing is the next point &#8211; once you screw into MDF, it tears fibers apart to make room for the screw. You can screw into MDF once, where a wood screw in plywood can handle more room for error. You can use pilot holes and MDF screws to counteract this, but I wanted to get this project moving along.</li>
</ul>
<p><em>Once again, as a total novice in woodworking, I chose the option with more give and take and less chance for killing myself with. Both are very viable choices, it comes down with what you&#8217;re more comfortable with.</em></p>
<p><img decoding="async" src="https://krystof.io/wp-content/uploads/2019/10/plansandwood-1-1-1-1-1.jpg" alt="Plans and Workbench"></p>
<p>I started turning my garage into a wood working nightmare. At least if I ever do anything with wood again, I&#8217;ve got tools and sawhorses for it. I was so ready, can&#8217;t you tell?</p>
<p><img decoding="async" src="https://krystof.io/wp-content/uploads/2019/10/thewoodworker-1-1-1-1-1.jpg" alt="The "></p>
<blockquote><p>“One person&#8217;s craziness is another person&#8217;s reality.” <cite>Tim Burton</cite></p></blockquote>
<h2>Control? Come in, Control.</h2>
<p>While there was woodworking going on, there was also some wiring of the guts together before anything was actually placed inside. These DIY projects tend to have multiple threads going at once, and I wanted to make sure the parts would work together. I highly recommend <em>prototyping your control panel</em> just like we made a cardboard mockup of the shell for no other reason than seeing something come to fruition early to keep momentum going, and give you a break from one part of the project to work another. Wiring up a control panel let&#8217;s you gauge sizing issues, determine layout, and hook all your guts up while you spend time configuring the software side (i.e. your joystick controls and your system / emulator / game play)</p>
<p>You could use very thin project board, scrap plywood, whatever. The Control Panel is by far the most important component of the external interface to your arcade. Consider button layout <em>very</em> carefully. Once you drill holes in wood, you should already have a good idea of button placement. An excellent resource for layout styles and history is is <a href="http://www.slagcoin.com/joystick.html">Slagcoin</a>, and search DIY arcade forums as well like the <a href="http://forum.arcadecontrols.com/">Arcade Controls Forum</a></p>
<p>I opted to make mine out of spare foam poster-board. It was <em>just sturdy enough</em> to hold all the components together:</p>
<p><img decoding="async" src="https://krystof.io/wp-content/uploads/2019/10/control_panel_mockup_litup-1-1-1-1-1.jpg" alt="Control Panel Mock-up"></p>
<p><img decoding="async" src="https://krystof.io/wp-content/uploads/2019/10/controlpanel_bottom-1-1-1-1-1.jpg" alt="Control Panel Mock-up Underside"></p>
<p>You may notice the markings on the buttons. They weren&#8217;t there when I got them. Another piece of hardware I purchased for this endeavor, and has been used quite a lot by C and myself for other projects is a <a href="http://www.silhouetteamerica.com/" class="broken_link">Silhouette Portrait</a> cutter. Works like a printer, cuts paper and adhesive vinyl, and that&#8217;s what I used to create the button labels &#8211; the nice thing is that they&#8217;re underneath the top button casing, no fingers working against the vinyl over time:</p>
<p><img decoding="async" src="https://krystof.io/wp-content/uploads/2019/10/vinyl-cutting-1-1-1-1-1.jpg" alt="Vinyl cutting button labels"></p>
<p>Things were starting to come together &#8211; mock-ups created, wood and plans finalized, and control panel wiring designed and tested with the Raspberry Pi. Now to actually make the cuts and start putting this thing together.</p>
<p>The post <a rel="nofollow" href="https://krystof.io/the-tardis-arcade-hardware-invasion/">The Tardis Arcade Hardware Invasion</a> appeared first on <a rel="nofollow" href="https://krystof.io">Krystof.IO</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://krystof.io/the-tardis-arcade-hardware-invasion/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		
		<series:name><![CDATA[Tardis Bartop Arcade Project]]></series:name>
	</item>
		<item>
		<title>How A Tardis Themed Arcade Build Began To Take Shape</title>
		<link>https://krystof.io/how-a-tardis-themed-arcade-build-began-to-take-shape/</link>
					<comments>https://krystof.io/how-a-tardis-themed-arcade-build-began-to-take-shape/#respond</comments>
		
		<dc:creator><![CDATA[Eric R. Krystof]]></dc:creator>
		<pubDate>Mon, 14 Mar 2016 11:41:07 +0000</pubDate>
				<category><![CDATA[Arcade Building]]></category>
		<category><![CDATA[Tardis]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Raspberry Pi]]></category>
		<guid isPermaLink="false">https://static.krystof.io/?p=51</guid>

					<description><![CDATA[<p>I&#8217;ve always enjoyed tinkering with electronics. Nothing terribly serious, just a few notches beyond basic understanding of circuits, primarily to control servos and power/manipulate LEDs. I can at least say&#8230;</p>
<p>The post <a rel="nofollow" href="https://krystof.io/how-a-tardis-themed-arcade-build-began-to-take-shape/">How A Tardis Themed Arcade Build Began To Take Shape</a> appeared first on <a rel="nofollow" href="https://krystof.io">Krystof.IO</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>I&#8217;ve always enjoyed tinkering with electronics. Nothing terribly serious, just a few notches beyond basic understanding of circuits, primarily to control servos and power/manipulate LEDs. I can at least say I&#8217;ve never <a href="https://www.youtube.com/watch?v=3XVtUUtfjJE">&#8216;Electro-Boomed&#8217;</a> myself. Maybe I&#8217;m not really an amateur electronics enthusiast until I have? I also enjoyed gaming on an Atari 2600 (Actually, the Sears version) and a Commodore 64. This is how my recent and first real Pi project came to be. Think of this first post as you would the formation of a planet. Bits and pieces swirling around, not quite coming together yet to form the whole.</p>



<h2 class="wp-block-heading">A slice of retro</h2>



<p>Last year I was using a <a href="https://www.raspberrypi.org" target="_blank" rel="noreferrer noopener" aria-label=" (opens in a new tab)">Raspberry Pi</a> to measure <a href="http://atlas-scientific.com/product_pages/kits/ph-kit.html" target="_blank" rel="noreferrer noopener" aria-label=" (opens in a new tab)">pH shifts</a> in my aquariums that naturally occur from CO2 injection. I just received one of the newer <a href="https://www.raspberrypi.org/products/raspberry-pi-2-model-b/" target="_blank" rel="noreferrer noopener" label=" (opens in a new tab)" class="broken_link">Pi-2 Model B</a>&#8216;s and asked my self what next? What can I do with this thing? Searching on google for raspberry pi projects, I came across a wonderful little project called <a href="https://retropie.org.uk" target="_blank" rel="noreferrer noopener" label=" (opens in a new tab)">RetroPie</a>. Retro gaming on this little credit card sized computer? Consider me signed up. <em>As an aside, there&#8217;s numerous projects like this for the Pi, such as <a href="http://piplay.org/" target="_blank" rel="noreferrer noopener" aria-label=" (opens in a new tab)">PiPlay</a></em></p>



<p>What <em>is</em> RetroPie? It&#8217;s essentially a project that <em>integrates</em> required components to launch, emulate, and gather meta-data about any &#8216;retro&#8217; games you might install. It&#8217;s a large endeavor as it attempts to make the setup as simple as possible, and given that while it may only use one front end, there are <strong>many</strong> emulators necessary to make this happen, depending on what you want to support.</p>



<figure class="wp-block-image"><img decoding="async" src="https://krystof.io/wp-content/uploads/2019/10/retropiesetup2-1-1-1-1-1.png" alt="RetroPie Screen"/></figure>



<h2 class="wp-block-heading">The Front side</h2>



<p>Underneath the project wrapper itself, you&#8217;re looking at a simple yet elegant front end known as <a href="http://www.emulationstation.org/" target="_blank" rel="noreferrer noopener" aria-label=" (opens in a new tab)">Emulation Station</a>. Not just for your Linux Pi installs, Emulation Station works on Debian Linux and Windows. You don&#8217;t technically need a front end to play a game, but it surely helps. An emulation front end separates you from having to remember which emulator to play which game, how to launch it, how to configure it, etc. While there are as many front ends as there are emulators, Emulation Station is a good fit for the RetroPie project as it looks sleek but covers your basic needs of wiring menu to emulator to software. Even more important is the RetroPie script that just installs this all for you.</p>



<p>EmulationStation acts as your interface to select the game you want to play. As such, it supports various control mechanisms, from keyboards to joysticks, even your classic arcade controllers if you can wire them in yourself or they&#8217;re USB compatible.</p>



<figure class="wp-block-image"><img decoding="async" src="https://krystof.io/wp-content/uploads/2019/10/es_theming_list-1-1-1-1-1.png" alt="Emulation Station Screen"/></figure>



<p>Also included is a <em>scraper</em>. You&#8217;ve wired up a game you&#8217;ve saved onto your Pi, perhaps by taking that old floppy drive from your Commodore 64 and interfacing it with your Linux machine by writing your own drivers and wiring your own connection interface, right? No? Me neither. The task of collecting ROMs or Disk Images isn&#8217;t here, so move along. I&#8217;m assuming you&#8217;ve got some already. Ah yes, the scraper. Sure, you can add &#8216;Panzer&#8217;s East!&#8217; as a menu item in Emulation Station to use the <a href="http://vice-emu.sourceforge.net/" target="_blank" rel="noreferrer noopener" label=" (opens in a new tab)" class="broken_link">Vice</a> emulator. But what about at least a little flair? Some box art? Some text describing the game? That&#8217;s where the scraper comes in. Scanning open and internet based databases containing game information and pointers to images, scraping turns your emulation station front end into more eye candy than you had before. I like that idea, though when I played around with Emulation Station I ran some scrapers as scripts in the background, as the embedded scraper seemed to be slow and a bit clunky to use, but perhaps that has improved.</p>



<h2 class="wp-block-heading">The Back side(s)</h2>



<p>RetroPie takes best of breed emulators for various gaming platforms and installs them all with default configurations. These emulators cover a wide range from Apple to NES, from MAME to Commodore, from Sega to Atari. These emulators, through the power of the RetroPie script, are wired into Emulation Station for you, no explicit configuration required unless you feel like tinkering.</p>



<p>While there are experimental builds of some emulators, the defaults generally work well out of the box, and some emulators are patched with the Pi in mind, taking advantage of certain pieces of Pi hardware or patched to work with the limited power the Pi has <em>compared to</em> a full desktop system. It&#8217;s a little give and take. While most of the early console systems worked well for me, DOSBOX emulation started to struggle. Since I&#8217;m a child of the 80s, a lot of my stuff was covered, but I also gamed into the 90s, so a lot of my DOS and early Windows games would need emulation on something with more oomph than a Raspberry Pi 2 Model B. <em>(The first generation Pi does work with RetroPie, but it suffers on the console side a lot more than the Pi 2).</em></p>



<p>If you&#8217;re used to tinkering with Raspberry Pi&#8217;s, you already know about images. The RetroPie project has you covered there and if you follow along and are already comfortable with the basics of Raspberry Pi usage, you&#8217;ll be fine. I wouldn&#8217;t recommend it as your very first Pi Project if you&#8217;ve never used one and never touched a Linux/Unix OS before. That&#8217;s more akin to hitting the ground hurtling instead of running, in my opinion.</p>



<h2 class="wp-block-heading">Pi installed, let&#8217;s play!</h2>



<p>One of my <em>favorite</em> games from the days when I had a Commodore 64 was a strategy game by Avalon Hill called <a href="http://www.c64sets.com/set.html?id=55" target="_blank" rel="noreferrer noopener" aria-label=" (opens in a new tab)">&#8216;Panzers East!&#8217;</a>. You&#8217;re the Axis powers and you must take out Russia before winter sets in, and you must utilize your Luftwaffe and supply lines to keep the pressure on while maintaining your ground.</p>



<figure class="wp-block-image"><img decoding="async" src="https://krystof.io/wp-content/uploads/2019/10/panzers_east-1-1-1-1-1.jpg" alt="Panzer"/></figure>



<p>My father and I played the <em>crap</em> out of that game. I could open that old game box if I still had it and there would be <em>zero crap</em> in there. He was Panzers and infantry, I was Luftwaffe. My mother had access to a copy machine (Yeah, I&#8217;m old) so we blew up the 8 1/2&#8243; x 11&#8243; map to fill the wall behind the old Commodore 64. This map, to be precise:<br></p>



<figure class="wp-block-image"><img decoding="async" src="https://krystof.io/wp-content/uploads/2019/10/panzers_east_pi-1-1-1-1-1.jpg" alt="Panzer"/></figure>



<p>To this day, I still remember cringing every time I saw the phrase &#8216;Insufficient German troops, Russians retake Bessarabia&#8217;. God damn it, not again!<br> There it is, on a Raspberry Pi, running the Vice emulator launched by Emulation Station.</p>



<p>It was right about this point I knew I&#8217;d end up not only having a RetroPie emulator, but I&#8217;d actually try and build an arcade box out of this, because I knew I wanted Pops to have one. I couldn&#8217;t just hand him over a bunch of wires and an HDMI cable and say &#8216;Hey, let&#8217;s play a game!&#8217;.</p>



<p>So I knew I was going to make <em>something</em> to house a raspberry Pi in. I just didn&#8217;t know how far I&#8217;d go and what it would actually be. I just knew it was for Pops and it would be special. It wasn&#8217;t until I was past prototyping that I thought&#8230; &#8220;<strong>Tardis</strong>&#8220;.</p>
<p>The post <a rel="nofollow" href="https://krystof.io/how-a-tardis-themed-arcade-build-began-to-take-shape/">How A Tardis Themed Arcade Build Began To Take Shape</a> appeared first on <a rel="nofollow" href="https://krystof.io">Krystof.IO</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://krystof.io/how-a-tardis-themed-arcade-build-began-to-take-shape/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		
		<series:name><![CDATA[Tardis Bartop Arcade Project]]></series:name>
	</item>
	</channel>
</rss>
