Showing posts with label Electronics. Show all posts
Showing posts with label Electronics. Show all posts

Saturday, 26 October 2024

Mega City Block Upgrade - Arduino Nano MAX7219 Display

A while ago I built a Mega City One Miniature Cary Case for my Judge Dredd miniatures and it was always my intention to have some sort of digital display which I could display random "in game" messages and to send instructions to the players such as ROLL FOR INITIATIVE.

The Components

Arduino Uno / Arduino Nano

I'd been itching to mess around with an Arduino microcontroller for years but never had the courage to just dive in.  However, there are so many people on ebay and Aliexpress selling ridiculously cheap arduino kits that there really is no barrier to entry. 

I plumped for an Arduino Uno Rev 3 Starter Kit which included a breadboard, jumpers and a whole pack of additional resistors and what nots.

The goal here is to make a small form factor self contained device so migrating from the large Uno dev board is essential.  I ordered a random Nano board from Aliexpress before realising that they come in 3 varieties with different board to PC connectors.  the cheap one I had picked came with an old style mini USB B connector and no lead.  Fortunately I had an lead from an old digital camera to use in the meantime, but I quickly ordered a bunch of nanos with USB C connectors for this and other projects I have in mind.  

MAX7219 8x32 Dot Matrix Display

The perfect lo-fi display for this project is a MAX7219 LED 8x32 dot matrix display.  It's small enough to work as a standalone unit and can take its power from the Arduino itself.  I bought one from AliExpress for only a couple of pounds. 

Wiring the MAX7219

I grabbed a bunch of dupont wires (these are the handy dandy push pin connectors which you get in your arduino kit.  I chopped one end off each wire and soldered them to the MAX7219 pins:

  • VCC - Purple - 5v
  • GND - White - GND
  • DIN - Black - Digital Pin 11
  • CS - Blue - Digital Pin 10
  • CLK - Grey - Digital Pin 13

Wiring the Button

The button is wired into:

  • VCC - Red - 5v
  • OUT - Orange - Digital Pin 7
  • GND - Yellow - GND

Entering the The Matrix Code

A bit of googling discovered the perfect code in the form of MAX7219 Message Selector on the Arduino Forums by user groundFungus.  Some tweaking later and I had a bunch of messages which I could toggle through with the addition of a button push on PIN7

// Program to demonstrate the MD_Parola library
// button select canned messages
// MD_MAX72XX library can be found at https://github.com/MajicDesigns/MD_MAX72XX
// by groundFungus AKA c. goulding

#include 
#include 
#include 

const byte  buttonPin = 7;    // the pin that the pushbutton is attached to

// Define the number of devices we have in the chain and the hardware interface
// NOTE: These pin numbers will probably not work with your hardware and may
// need to be adapted
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4

// Scrolling parameters
#define SPACE_IN      A5
#define DIRECTION_SET 8 // change the effect
#define INVERT_SET    9 // change the invert

#define CLK_PIN   13
#define DATA_PIN  11
#define CS_PIN    10

MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);

// individual messages in strings
const char msg_1[] = "<< WEATHER ALERT>> RAIN IN 10 MIN <> SECTOR 237 RIOT IN PROGRESS <> HOTTIE DAWGS ARE GOOD TO EAT <> BE GOOD CITIZENS LITTERING IS A CRIME>>  ";
const char msg_2[] = "<> ROLL FOR INITIATIVE>>";
const char msg_3[] = "<> GET UGLY GET OTTO SUMPS OIL OF UGLY TODAY!! >>";
const char msg_4[] = "<> HEAVY TRAFFIC ON THE BIG MEG CHOOSE ALTERNATE ROUTES >>";
const char msg_5[] = "<> THIS AREA IS IN LOCKDOWN >>";
const char msg_6[] = "<> CLEAN UP CREWS IN TRANSIT >>";

// an array of pointers to the strings
char *messages[] = {msg_1, msg_2, msg_3, msg_4, msg_5, msg_6};
byte messageNum = sizeof(messages) / sizeof(messages[0]);

int buttonPushCounter = 0;   // counter for the number of button presses
int buttonState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button

void setup(void)
{
   Serial.begin(115200);
   Serial.println("\nParola pick a message program\n");
   P.begin();
   pinMode(buttonPin, INPUT_PULLUP);
}

void loop(void)
{
   if (P.displayAnimate())  // time to show next frame?
   {
      P.displayText(messages[buttonPushCounter], PA_CENTER, 50, 3000, PA_SCROLL_LEFT, PA_SCROLL_UP);
   }
   checkButton();
}

void checkButton()
{

   static unsigned long timer = 0;
   unsigned long interval = 25;
   if (millis() - timer >= interval)
   {
      timer = millis();
      buttonState = digitalRead(buttonPin);
      // compare the buttonState to its previous state
      if (buttonState != lastButtonState)
      {
         if (buttonState == LOW)
         {
            // if the current state is LOW then the button
            // went from off to on:
            buttonPushCounter++;  // add one to counter
            // if counter over number of messages, reset the counter to message 0
            if (buttonPushCounter >= messageNum)
            {
               buttonPushCounter = 0;
            }
            //Serial.println(buttonPushCounter);
         }
      }
      lastButtonState = buttonState;
   }
}

Debugging the Code

Unfortunately this particular code only reads the button state at the end of each scroll.  This is where an interrupt is going to be necessary.  The arduino Uno and Nano boards that I have access to are only enabled for interrupts on digital pin 2s and 3 and will necessitate a bit of a rethink in the code 

MAX7219 Case - Thingiverse: Thing 6809712

No one wants to live in a run down cyberpunk world with exposed wires everywhere, so I needed a case for the display with enough depth to house the nano and the button which would switch modes.

I found a simple MAX7219 8x32 case on Thingiverse which I could easily embed magnets into to affix to the top or side of my Mega City Block Storage Case.  Sadly this did not fit my particular MAX7219 board as the pins came out sideways.  

This was easily fixed with a bit of modelling in Sketchup and if you need a case and have side exit pins feel free to download this from Thingiverse using the link above.


Thursday, 17 October 2024

Mega City Block Upgrade - The Okey Dokey Chef

Once you start pimping out your Mega City One Block Storage Case it's hard to know when to stop...

The Okey Dokey Chef Animated Sign

I wanted my sign to be an advertising hoarding and one of the most famous signs in Mega City One is the Okey Dokey Chef as featured in the Supersurf 7 race story Midnight Surfer (progs 424-429).  I was also inspired by the famous Vegas Vic neon sign whose arm waving welcomed gamblers from all around the globe since 1951.

He wold make an excellent starting point to learn about how to control low voltage RC servos with Arduino.

The Chef

I found a nice piece of clipart online which had the vibe I was going for and imported this into GIMP for editing.  

I cut out the "Chef's Kiss" hand using the lasso tool and moved this over into  a seperate file.  This is going to be the sweeping hand which we will animate later using a servo.

I added a speech bubble with some appropriate text coming out of the side of the chef's head. 

Okey Dokey Chef Sign

Preparing for Tinkercad

I have learned that Tinkercad is a pretty simplistic modelling tool and it does not particular like creating complex curved or polygonal shapes.  The easiest way to solve this conundrum is to simply create a solid black mask version of your line drawn artwork.  This can be used as a background and because both shapes are exactly the same image size, they will register perfectly together when you import them into Tinkercad.

When I was happy with both files, I and exported them (and their solid black mask counterparts) as a PNG then converted into an SVG using convertio.com.  Each line drawn SVG is imported into Tinkercad for extrusion into a 3D object using the same technique I used to create my badges and Index Card RPG Card Back Stamps. I use an extrusion height of 30mm.

The black mask variant is then imported and the combined shapes exported as a single STL.  This gives me an STL file for the chef and a file for the arm which can be printed on the Anycubic Photon M5.

Okey-dokey-sign-002

The Electronics

The core of this project is an Arduino nano.  These little boards are stupidly cheap and really easy to start your coding adventure.  Seriously, if an idiot like me can do it then anyone can.

The bit doing all of the moving is a 9g 5v 180 degree hobby servo which I bought in a twinpack from Ali Express for £1.79.

Okey Dokey Chef with servo hand
This was superglued across the gap between the Speech bubble and the chef's arm.

The Wiring and Code

I used the excellent How to Control Servo Motors tutorial on the makerguides website.  The servo has 3 wires Red (5v Power) goes to the 5v pin,  Brown (Ground) goes to the GND pin and the Yellow (Signal) goes to Pin 9.

The code example given is perfect for my purposes, but I did need to customise the start and end positions for the hand as it does not need to run the full 180 that the servo is capable of.  I also added a 500 millisecond delay at the end of each travel.


#include 

Servo myServo;  // Create a Servo object

void setup() {
  myServo.attach(9);  // Attach the servo to pin D9
}

void loop() {
  // Move from 30 to 135 degrees
  for (int pos = 30; pos <= 135; pos += 1) {
    myServo.write(pos);  // Tell servo to go to position in variable 'pos'
    delay(45);           // Wait 15 milliseconds for the servo to reach the position
  }
  delay (500);
  // Move from 135 to 30 degrees
  for (int pos = 135; pos >= 30; pos -= 1) {
    myServo.write(pos);  // Tell servo to go to position in variable 'pos'
    delay(45);           // Wait 15 milliseconds for the servo to reach the position
  }
   delay (500);
}

Troubleshooting

In my naievete I thought that the Arduino nano would be able to power this whole project.  However, the little servo apparently draws too much power to run continuously causing the nano to reset itself and creates some erattic animation.

I tried to mitigate this by adding increasing the dealy to 45 thereby slowing down the move, but sadly this was not enough.  It would have been nice to know all this from the start as an alternative board such as an ESP32.  

Anyway that is another story.  In the meantime check out the final result


Download the Files

I have also uploaded the Okey Dokey Sign STL files to Thingiverse if you should want to make your own version of this iconic comic book sign.

Okey Dokey Chef Sign with Supports

Let me know if you found this useful or if you have made your own animated signs for your own games


Friday, 29 March 2024

1:30 Scale Nax Fishing Vessel - NTKJ MODEL - Part Two

In Part One we got the basic hull together 

Sanding and More Sanding

As I mentioned the hull is made of straight ply planks and there are a lot of gaps and seams which require filling with wood filler.  I bought a tub of 151 wood filler which I thought was going to do the trick and I was dissapointed that it was more like wall filler than anything else.  Still I persevered and ended up slapping on a ton of the stuff.  

Naxos Fishing Boat filling the plank gaps

In hindsight I would do this totally differently.  The filler oozed between the planks and ended up inside the boat hull trapped between the frames which then dried and fell off.  I have in effect created a boat shaped maraca.  

Nax Fishing Boat Opening up the hull

This necessitated opening up the deck under the wheelhouse in order to release the now rock hard filler.  This might sound like major surgery, but as the deck is so thin it was easily acomplished with a sharp craft knife and a steady hand.  I made sure to keep the offcut as I have plans for that later.

The way to tackle this is to use the old superglue and baking soda trick to fill up the gaps.  This of course only works if you are painting the hull.  If you are going for the natural wood finish then you are going to have to get better at laying the planks. 

Painting

Painting the boat in sections is unavoidable at this stage.  I carefully masked off the deck and gave the now smooth (ish) hull a spray coat of white primer followed by a couple of coats of white gloss.

The airbrush then came in handy for painting the decks with a Vallejo Burnt Umber wash.

NAX Fishing Boat - Painting the Deck

The remaining wooden pieces for the wheelhouse, deck covers and the gunwhales were then extracted from their boards and sprayed with the same Vallejo Burnt Umber wash. 

NAX Fishing Boat - Deck Painting

Adding Some Colour

I imagined the boat a sort of tri-tone with a red top stripe white hull and black or red hull bottom.  In the end I just gave it a stripe of red on the sheerstrake plank and continuing around the transom.  Masking this off was a tricky exercise as I only had some really nasty cheap painters masking tape.  I will have to come back and do some tidying up by hand later.

Trial fitting the wheel house accents and deck hatches really makes the boat come alive.

NAX Fishing Boat - Red

You might beable to see in the photo above that I managed to glaze all the windows with some clear acetate from some recycled packaging.  I glued this in using my now favourite hobby glue UV Resin which I picked up in my Wish Hobby Products 2024 experiment.  This stuff is amazing.

Adding the Lights

Last year I picked up some micro LED lights for another project (which I have yet to start).  These are incredibly tiny and come pre-soldered onto super thin magnet wire.  I quickly soldered a couple of these together with a CR2032 coin cell battery holder and a latching push button and stuffed it into the hole.

NAX Fishing Boat Lighting

I will probably tidy this up with a piece of perfboard at a later date as the circuit is tiddly. I am also undecided if I will add any navigation lights.  For the uninitiated this mean a RED LED for the left (Port) side of the boat and a GREEN LED for the right (Starboard) side.  I have some 3mm LEDs from another side project but these might be too large, we will have to see.  Adding them to the circuit should be no problem and might even add some much needed resistance to bring down the brightness.  

The LEDs were then routed up through the floor of the front wheelhouse and up one corner.  One LED illuminates the interior and is bonded to the roof with the UV Resin and the other goes outside in front of the cabin as an exterior deck light.  I will need to find an appropriately nautical shroud for this exterior light as they are suprisingly bright for their size.

NAX Fishing Boat - Lighting the Wheelhouse

Oh did I forget to mention that I added a salty seadog to steer this fine boat across the treacherous seas? 

He is one of the many 3D Printed accessories I covered in part one of this mini series.  A fine free model although he is now sealed in his cabin for all eternity as I have glued on the roof and floor.  

In the next, and final part of this mini series we will add all the accessories masts and rigging.