Jeremy W. Langston

Personal Website

Category: Electronics

Portable Console Emulator using a Raspberry Pi

Here’s a couple pictures from my last project:  tablet-based teleprompter with 15mm support rods and a quick disconnect camera system.  It turned out very well.  One of these days I’ll post up some more detail.

image image


But that project’s over and my shop is missing me.  This time I’m getting back to electronics.  Lately I’ve been playing the old NES games.  Well, when I say playing, I mean with my original NES.  I left a cartridge in the console the last time I played it and all of the pins got stressed, resulting in the blinking display.  This is typical when the pins connecting to the cartridge don’t make a good connection.  Bending them back was an easy fix, and didn’t even require the removal of the security chip.

Anyways, now I’m trying to make a portable system based on a Raspberry Pi.  Having installed the RetroPie distribution, running NES/SNES/Genesis/etc. emulators are a breeze.  I bought a few other components to make sure everything would work, and then started designing.

Portable Console v3 - 1Portable Console v3 - 2

Here’s what I’ve come up with.  I went through several revisions, trying to maximize space and portability.  At the same time, I tried to keep ergonomics in mind.  The size is a bit chunky, but feels good in the hand so far.  The enclosure is made of two pieces of polypropylene.  Originally I wanted it all milled out of solid aluminum.  Not wanting to spend 500 hrs making billions of passes milling, I chickened out for something much easier to machine (set RPMs low and make heavy cuts).

The parts I’m using are, mostly, shown below:  a Raspberry Pi, a 12V-5V switching regulator from eBay, a 4.3″ TFT car monitor from Amazon, a 12V LiPo battery with integrated charging and power switch components from eBay, and the little silicon pads from a Logitech Gravis Gamepad Pro that doesn’t work.  Oh, and a Teensy v3 to make the gamepad portion.



Since I’m splitting up the buttons from a traditional gamepad with the monitor in the middle, I needed some custom PCBs.  Gamepads work by closing circuits to ground via silicon pads with bits of carbon in it.  I could use some pushbuttons, but wanted to retain the nice action of a gamepad button.  Once I got the dimensions and button positions from Inventor, I made the PCB layout in DipTrace.  Then I used the tried and true laser toner, copper clad PC board, and ferric chloride PCB solution.  It took a few tries, but I like the results.

image  image

The 4.3″ TFT monitor is a great deal for $18.  I just need to make some changes to get it how I wanted.  First was to remove the case and hardwire the power to the battery and to the regulator.  Next I needed to remove the pushbuttons on the back of the monitor.  Eventually I’d like to control them via my Teensy microcontroller because they bring up the menu for setting things like brightness, etc.

image  image

When I first got the regulator I was a bit suspicious since it looked like there was a big glob of solder bridging a couple nodes.  Metering it all out it appears OK.

image  image


I then hardwired power and NTSC video directly to the Raspberry Pi.  The main regulator pads were the best place to supply 5V and bypass the USB port.

image  image

Lastly I started fabricating the front of the enclosure.  I’ve got about 8 hrs into it now and haven’t made any mistakes – yay!  Unfortunately I ran out of polypropylene and had to put in a new order.  In the meantime, I am going to make the buttons.  Well, that’s all for now…


Sawbot Update 2

So, I wrote a bit of code to control brushed DC motors from a Logitech USB Gamepad -> Custom VC++ Software -> Custom Arduino Software -> Motor Driver -> Brushed DC motor.  This is mostly just temporary code to test things.  Ultimately there will be three modes of operation:   remote via RC transmitter, remote via PC, and autonomous.  Depending on how I decide to control this thing, the RC transmitter/receiver will be pretty much plug-n-play.  Autonomous control will come much later.  This is something I’ve done before and know how much work goes into it.  Remote via PC is fairly straight-forward, as I mentioned.

Here’s my code, including the Arduino sketch and the code for VC++:


The DCMotor class talks with the Arduino via the USB using RS232 communications.  I had to make my own protocol for passing commands to the Arduino to control the motors.  Right now each message is composed of the following:

<STX> <Forward> <Speed[7-0]> <Speed[15-8]><Speed[23-16]><Speed[31-24]> <ETX>

Each are bytes, where:

STX = start of text = 0x02

Forward = 1-forward, 0-back

Speed[#-#] = individual bytes of the unsigned int speed

ETX = end of text = 0x03

Inside the DCMotor zip are the DCMotorTestDlg .cpp/.h files I’ve used.  They can’t be directly built because there are several other files needed.  Really all you need to know are how to use the DCMotor class and how to talk to gamepads.  In the OnInitDialog() method of DCMotorTestDlg I make the following three calls:

m_DCMotor.Create(“DC Motor”, WS_CHILD|SS_NOTIFY, CRect(0,0,0,0), this, 6666);


SetTimer(m_pTimer, 20, NULL);

Create() is used for making a window.  The window is used for sending messages internally and externally. Internal messages go to/from the internal thread which does the communications to the Arduino.  External messages aren’t really used for much right now, but I’ll eventually rewrite all of this to be a Sawbot controller which will give status updates.  Open() does exactly what you think.  For now, I’m running at 9600, 8, n, 1.  SetTimer() is used for polling the gamepad for button presses.  I won’t get into the details of why I do polling instead of interrupts, except to say that polling allows for more use of the gamepad.  Feel free to let me know I’m wrong.

As you will see in OnTimer() method of DCMotorTestDlg, I issue move commands to the DCMotor class based on the analog X position of the gamepad.  Sorry about the massive lack of commenting.  I wrote it fast, but what isn’t obvious can be Google’d.  Just in case, here’s a quick explanation of what I’m doing.
if (bJoyPresent){
if ((joyInfoEx.dwXpos < 28672) || (joyInfoEx.dwXpos > 36864)){
if (joyInfoEx.dwXpos > 32767)
m_DCMotor.IssueCommand(true, (joyInfoEx.dwXpos – 32768)/128);
m_DCMotor.IssueCommand(false, (32767 – joyInfoEx.dwXpos)/128);
else {
m_nLastXpos = 32768;
m_DCMotor.IssueCommand(false, 0);

First, I’ve retrieved the gamepad/joystick info (refer to lines 104-109 of DCMotorTestDlg.cpp, not shown here).  If a gamepad is connected, then I check to see if I should command the motor to move.  I’ve put a dead-zone of 8192 (between 28672 and 36864).  This is to prevent the motor from always wanting to turn unless the value is exactly 32767.  Then I noticed a mistake.

The Arduino is an 8-bit microcontroller, and the pseudo-analog (read:  PWM) output I use to control the DC motor is 8-bit.  That’s a range of 0-255.  Much less than 0-32767.  So I divide by 128 to get in the appropriate range.  Not a big deal though as I doubt I will ever need to do anything more refined.

If you don’t quite follow my mental defection logic, feel free to leave a comment and I’ll explain.  Also, this code is very very basic and unfinished.  The Arduino code is easy to follow and uses the same protocol I stated above.  I’ll post up a demo when I get a chance.


Having no money after buying tools and tooling, I’ve had plenty of time to plan out a robot platform.  There are several ideas rolling around in my head.  They range from independently-driven, independently-suspension-ed (?) 4WD drivetrains, to Ackerman-steering platforms with front, rear, and center differentials.  Yeah, overly complex, at least for now.  I’m instead going for a simple skid-steer drivetrain with no suspension other than the tires.  The left-side two wheels will be driven by one motor, as is the right side.  The difference in speeds causes the platform to turn.  I also want to be able to get this thing up to a pretty good speed so I can run around with it like an RC car:  ~20mph.  I can already see it busted on a wall.  It’s going to be great.

Now the question is where can I find motors?  Ideally the shaft speed of the motor would be the same as the wheel speed.  I found that to be impossible within a reasonable budget (<$50 ea).  Typically the motors you find on RC trucks run at about 4,000 kv.  For those that don’t know, a 4,000 kv motor runs at 4,000 rpm PER VOLT.  Don’t get me wrong.  A robot rolling down the road at 476mph would be cool.  Maybe later.  So, I’ll need to go with a gear reduction.  It turns out that it can get expensive.  Making a custom gearbox is an option.  However it takes some careful design work to ensure proper meshing.  I don’t think my master metalworking skills are quite up to that just yet.

I came across several people repurposing a cordless drill motor.  Now there’s an idea!  At Harbor Freight, you can get cheap Chinese junk like cordless drills.  The batteries are horrible and the clutch be worn out fast.  However, the motor and gearbox are pretty decent – and the output shaft speed is around 500 RPM, unloaded.  Not bad for $20.  I picked up a couple.

IMAG0178 IMAG0145 IMAG0183

Bringing back the drills, I torn one apart and looked to see how I would mount it.  The plastic housing and extended shaft would take up too much space in my robot. The plastic housing is part of the clutch assembly, as it allows the ring gear to spin if the clutch isn’t tightened all the way (the drill setting).  Also, proper mounting is non-trivial.  I came across another site showing a custom gearbox enclosure for a drill.  This is definitely the way to go as it gives you a better fit and mounting options.

Then I came across this:

It’s the Harbor Freight 18V 5-1/2″ Cordless Circular Saw, part # 67026, and was on sale for $25.  The no-load speed is 3800 RPM, uses a larger 750-sized motor, and has a mounting bracket already!  As far as I know, no one else has tried this.  That’s usually a bad sign, but it’s worth a shot.

Here are some pictures from the break-down process.

Random Youtube video of the motor?  Sure, here you go:

Battery-powered USB Phone Charger

I was getting ready for a long train ride from KY to DC and found out there aren’t any AC outlets for coach seats!  A 15hr ride isn’t too bad when you have a smart-phone; then again, the stock battery on an HTC Incredible will last only about 3hrs of heavy usage.  Not good.  I wanted a way to be able to use it for, well, 15hrs.  So, using some easy-to-find parts I made an extended battery that will charge the phone via USB.  I also wanted the extended battery to be rechargeable.  So, I need to be able to have access to the battery contacts; maybe later I will add something fancier, but for now the battery disconnects from the USB circuitry.  Here’s my finished product, and how to make it.


I bought a battery from the local Home Depot for $20 (look in the outdoor lighting aisle).  It is 6V and provides 6.5AH.  You can get it cheaper at places like, but I was in a hurry and the shipping on seal-lead acid batteries is not cheap.  The higher the amp-hours (6.5AH in this case), the longer you will be able to run your USB device.


Now for the voltage – USB uses 5V DC.  I needed to drop the voltage from 6V to 5V, preferably without too much loss.  There are three main options:  voltage divider using resistors, non-switching regulator, and a switching regulator.  In the case of the voltage divider, the resistors basically turn the extra voltage into heat, and they would need to be rated for higher power than the typical $0.01 resistors.  Switching regulators, or DC-to-DC converters, are much higher efficiency, but are more costly.  Also, I couldn’t find one that would work at Radio Shack, so I went with a non-switching regulator:  the 7805.


The 7805 regulator will take voltages higher than 5V and hold them at 5V, also allowing up to 1A of current.  While that’s much more than is needed, it gives a nice buffer.  A regulator has three legs:  1) input, 2) ground,  and 3) output, where the ground leg is shared between the input and output.  The input comes from the positive side of the battery, the output goes to the 5V pin on a USB connector, and the negative side of the battery along with the GND pin on a USB connector both connect to the ground.  Since the 7805 drops the difference in voltage by heat, adding a heatsink to the regulator might be needed, depending on how much power your device will draw.


To connect USB devices, I need an adapter that would allow me to plug in a standard USB cable, like the one in your computer.  I happened to have an old PS2/USB adapter from an old mouse.  It hasn’t been used, ever, so I cut it up (the green thing above).  You could use something else, like a USB extension cable which already has wires to solder to.  USB connectors have 4 pins:  1) 5V, 2) Data+, 3) Data-, and 4) GND.  Use some wire to solder the connections (USB 5V -> 7805 Output), (USB GND  and Battery negative -> 7805 Ground), and (Battery positive -> 7805 Input).  Make sure to protect the solder points with some heatshrink or risk shorting, melting, and other bad things.  To connect the wires to the battery terminals, I used spade connectors.  Also, leave the terminals pointing up for reasons I’ll point out soon.


Once the soldering is done, connect the battery and use a multimeter to check the output on the USB connector (voltage across pin 1 and pin 4 should be +5VDC).  Then you can freely connect a USB device and you’re set.  You could stop here and be done.  Since I wanted this for travel and didn’t want exposed wires, I took it a step further:  enter hot glue.

Clean the top of the battery and add a layer of lubricant (e.g. WD-40) to keep the glue from sticking to the battery.  We want the circuitry to be detachable so that we can recharge the 6V battery using a trickle charger/car charger.  This is why I left the battery terminals sticking up – so that I can freely pull the circuit away from the battery.  I used about 10 – 15 sticks of hot glue used on a mini gun, just to make sure that everything would hold together.  This is the most time-consuming part.  It doesn’t take a lot of thought to do this.  Just fill in all the holes, keeping the USB port accessible.  You also want to keep the heatsink partially uncovered so that it passing air can pull away the heat given off by the 7805 regulator.  You could spend a lot of time getting this pretty by squaring up the sides and making it colored, but this was a last minute project for me.  Hopefully you will get some good use out of this – I know I will.  I hope they don’t kick me off the train thinking it’s a bomb.




© 2024 Jeremy W. Langston

Theme by Anders NorenUp ↑