Comms Cabinet Controller/Monitor

This project was a real “Parts-bin Special”; made up from a load of stuff I’ve had hanging around at the bottom of boxes for years. What it does is pretty useful to me, though.

Last year I networked my entire house with a gigabit LAN. CAT6A cable runs from RJ45 sockets all over the house up to the loft where they are terminated at a patch-panel in a 6U 19 inch rack-mount cabinet. This cabinet houses a 24-port switch, router, cable-modem, and a server (an Intel i5 with 8GB of RAM in a 2U case, in case you’re interested). For a few days last year the sun did actually shine on my house, and subsequently the temperature in the loft rose alarmingly quickly. The power led on the cable-modem changed from blue to pink – a quick visit to Google confirmed that it was getting too hot. My quick fix consisted of running a couple of old CPU fans over the modem and router, and removing the door and side-panels of the cabinet. It worked, but was hardly a long-term solution.

There was nothing for it but to break-out the power-tools, and cut holes in the cabinet to permanently fit some fans.

Cabinet Fans
Cabinet Fans

All well-and-good, but how to control the fans? I was glad to finally find a use for the following stuff that I’d probably bought for various long-forgotten projects!:

Cabinet Controller/Monitor Circuit
Cabinet Controller/Monitor Circuit (it ain’t pretty, I know!)

When built, programmed, and mounted in the cabinet it give me the following functionality:

Fan Control

When the cabinet temperature (measured by the MCP9808) reaches 30°C the fans switch on. They will only switch off when the cabinet temperature falls below 26°C. If the server is running then the fans are switched on regardless of the cabinet temperature.

Cable Modem Control

Very occasionally the cable-modem needs rebooting. Being mounted in the loft used to mean that someone (that would be me, then) would have to climb up the ladder to pull the power from the back of the modem, wait 30 seconds, then reconnect it. Somewhat inconvenient. The modem power is now routed through one of the relays via its normally-closed connection which can be switched remotely.

Server & NAS Control

The server and NAS have their power switches connected in parallel with 2 of the relays, allowing a simulated button-push to turn them on and off.

Loft Temperature & Humidity Monitoring

The HTU21D-F is mounted outside the cabinet to provide monitoring functions (no reason for this, really – it was just easy to add!)

All the above is accessed via a mobile optimised web-page:

Cabinet Controller/Monitor Web Interface
Cabinet Controller/Monitor Web Interface

The take-away from this post is this:

You probably can build something cool from the long-forgotten components you already have – get to it!

ATmega328 Programming Cables

After using pre-built Arduinos the next step is to ‘roll your own’. It may not have the niceties of built in USB/debug-console, but it’s fully functional (and much cheaper!).

There are plenty of tutorials on DIY Arduino compatible circuits, so there’s no point duplicating that information here. As a reminder, however, here is what you need to make a minimal Arduino:

  • AVR ATmega328 Microcontroller
  • 16MHz Crystal
  • 22pF Capacitor (x2)
  • 10k Resistor
  • 10uF Capacitor
Minimal Arduino circuit
Minimal Arduino circuit

So far, so good – but with no built-in USB interface you’ll have to use either an FTDI interface (for ATmegas with a bootloader already installed), or an ICSP interface (for blank ATmegas).

FTDI Method:

To use this method you’ll need an ATmega328P that has had the Arduino bootloader pre-installed. This is a small piece of code that allows sketches to be uploaded via the microcontroller’s serial link. You’ll also need a USB to FTDI interface. I wholeheartedly recommend Adafruit’s FTDI Friend product.

The FTDI interface is connected to the ATmega328P thus:

ATmega328 FTDI Connections
ATmega328 FTDI Connections

 

Building in a programming header into your project that plugs directly into the FTDI interface can be a bit of a pain – routing the connections around the circuit takes time and space, and adds to the complexity. I prefer to simply put header pins next to the relevant ATmega pins, then use an adapter with flying leads. Another advantage is that the 0.1uF capacitor can be built into the adapter, as its only required when programming the device.

 

FTDI Cable
FTDI Cable

 

Another good idea is to make a handy reference to remind you what goes where. Print this out (laminate it if you can) and keep it with the adapter:

ATmega328 FTDI Header Pins
ATmega328 FTDI Header Pins
ICSP Method:

For this method you’ll need an ICSP interface. You’ve got a lot of options when choosing one. I use the official ArduinoISP – although it is apparently no longer made.

One of the things I don’t like about the ArduinoISP is the lack of status LEDs showing activity. Adafruit’s FTDI Friend features blinking LEDs whenever data is transmitted or received, which is a great sanity check when things don’t quite work out the way you expect. I built an ICSP programming cable that flashes an LED every time the SCK pin goes high (as you can imaging, this pin is very active during programming). The LED is driven via a BS270 MOSFET as connecting an LED/resistor directly would interfere with the data transfer (why a BS270? – it’s what I had lying around in my parts collection!). As a bonus, programming the ATmega with the test ‘Blink’ sketch will flash the LED, as the ATmega’s SCK pin maps to the Arduino pin 13.

Here are the connections for ICSP programming:

ATmega328 ICSP Connections
ATmega328 ICSP Connections

 

Using a 3mm LED with built-in resistor saves space:

ICSP Cable
ICSP Cable

 

Once again, make a handy reference card, and keep it, err, handy:

ATmega328 ICSP Header Pins
ATmega328 ICSP Header Pins
** ICSP GOTCHA **

Here’s a tip that may save you a few headaches. If after programming a completely blank ATmega for the first time the sketch seems to run really slowly, then try burning the bootloader first, then reload your sketch afterwards. The bootloader will be erased, but when burning it the Arduino IDE also sets certain settings in the ATmega correctly for Arduino compatible operation (specifically, it sets the device to use the external 16MHz crystal oscillator rather than the 1MHZ internal one).

 

Retro Video Game Console

Hackvision Pong
Hackvision Pong

I always wanted to build my own games console, so I was pleased when I stumbled across the TVOut library for the Arduino. It enables many different types of Arduino to generate both video (PAL and NTSC) and audio signals using interrupts. One of the best things about the library is the minimal hardware that is required to implement it – just 2 resistors at its most basic.

Of course, I wasn’t surprised to find out that others had had the same idea, probably the best known of which is the Hackvision by nootropic design.

I wanted to build a system that allowed the external connection of 2 joystick or 2 paddle controllers, and the Hackvision *almost* meets these requirements; 2 paddles can be used, but it only allows for 1 joystick/d-pad. Now I could’ve just ignored the Hackvision, and built my own version, but the Hackvision has had some really good games written for it I wanted to be able to play. I needed a way to build something that could be used with 2 joysticks, but was still compatible with the Hackvision.

The Hackvision design does actually have unassigned IO pins, although not the 5 required to simply assign to the functions of a joystick. I found that I could *just* manage to connect everything if I reused pin D0 (which is used for the first paddle button) for a direction function on the second joystick, and used pin D1 for both the paddle button and joystick button on the second controllers (the first controllers use different pins for the paddle and joystick buttons).

Confused?! The circuit and pinout should make things clearer:

Console circuit - basically an Arduino and a hand-full of passive components.
Console circuit – basically an Arduino and a hand-full of passive components.
Controller ports labelled with functions and associated Arduino pins
Controller ports labelled with functions and associated Arduino pins

Sticking to the pinouts for Player A & B ports enables the use of classic joysticks with an “Atari” connector that were used throughout the 80s and 90s, and can still be sourced relatively easily on eBay, etc. If you really insist on making your own, then this is the circuit:

D-Pad circuit
Joystick/D-Pad circuit

 

I’m afraid you’ll have to make your own paddle controllers, but they’re pretty simple:

Paddle circuit
Paddle circuit
Paddle controller construction
Paddle controller construction

 

Housing a project in an enclosure is always more complicated and time consuming that you anticipate. I happened to have an aluminium project box in my parts-bin:

Prepared aluminium chassis
Prepared aluminium chassis

 

Sticky-backed plastic (Fablon) gives a good exterior finish, and is far-less hassle than painting:

Internal constrution
Internal construction

 

My grandfather used to work for Plessey back in the 70s – these LEDs found their way into his workshop…

Ancient LEDs
Ancient LEDs

 

Woodgrain Fablon for the authentic ‘retro’ look:

Finished console - Front
Finished console – Front

 

Finished console - Rear
Finished console – Rear

 

Hackvision Space Invaders
Hackvision Space Invaders

 

I intend to write a library for the console, however I’ll have to do that at a later date. Since upgrading my Mac to OSX ‘El Capitan’, the Arduino IDE is refusing to upload anything to any of my Arduinos. I’ll get around to it when I get it fixed.

Electronic Dice (Part 1)

This is about as simple an Arduino project as you can build that still has a real-world use. If you’re comfortable with getting the ‘Blink’ sketch running, then you should have no problem with constructing this electronic dice. If, however, you’re an Arduino master looking to learn about Arizona Microchip’s PIC microcontrollers, then read on, as in part 2 I’ll be implementing the same functionality with a circuit based around a PIC 12F629 coded in assembler.

The circuit is pretty simple; a simple push-button is pressed to “throw” the dice, and the result is displayed as a familiar dot-pattern for a few seconds before turning off to wait for the next throw. The “randomness” is in generated by having a counter that continuously loops through the values 1 to 6 very quickly until a button is pressed. The moment the button is pressed the counter is stopped and its value is displayed as a dice dot-pattern.

Hardware

In addition to an Arduino (I’ve used an UNO R3), you’ll need a push-button switch and seven LEDs with appropriate current limiting resistors (or you could do what I did and use LEDs with built in resistors to save some complication).

Arduino Dice Schematic
Arduino Dice Schematic
Software

Much like the hardware, the software sketch is nice and simple:

// Arduino Dice
// Simon Buckwell
// July 2015

// variables
int d = 0; // dice value

void setup()
{
  // set up GPIO pins
  pinMode(2, OUTPUT); // GPIO 2 - controls LED2 and LED6
  pinMode(3, OUTPUT); // GPIO 3 - controls LED3 and LED5
  pinMode(4, OUTPUT); // GPIO 4 - controls LED4
  pinMode(5, OUTPUT); // GPIO 5 - controls LED1 and LED7
  pinMode(6, INPUT_PULLUP); // GPIO 6 - detects push-button
}

void loop()
{
  // turn all LEDs off
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);

  // loop through values 1 to 6 until the push-button is pressed
  do
  {
    d = d % 6;
    d++;
  } while (digitalRead(6) == HIGH);

  // display value as dot-pattern
  if (d == 1)
  {
    // dot-pattern for 1 - turn on LED4
    digitalWrite(4, HIGH);
  }
  else if (d == 2)
  {
    // dot-pattern for 2 - turn on LED2 and LED6
    digitalWrite(2, HIGH);
  }
  else if (d == 3)
  {
    // dot-pattern for 3 - turn on LED2, LED4 and LED6
    digitalWrite(2, HIGH);
    digitalWrite(4, HIGH);
  }
  else if (d == 4)
  {
    // dot-pattern for 4 - turn on LED1, LED2, LED6 and LED7
    digitalWrite(2, HIGH);
    digitalWrite(5, HIGH);
  }
  else if (d == 5)
  {
    // dot pattern for 5 - turn on LED1, LED2, LED4, LED6 and LED7
    digitalWrite(2, HIGH);
    digitalWrite(4, HIGH);
    digitalWrite(5, HIGH);
  }
  else
  {
    // dot-pattern for 6 - turn on LED1, LED2, LED3, LED5, LED6 and LED7
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(5, HIGH);
  }

  // wait 3 seconds
  delay(3000);
}
dice_arduino_proto
Arduino dice on prototyping board