Google+

Saturday, 5 April 2014

A New life for dead console.

I have just completed a quick project to do something with a junk Ingersol Tennis TV game that has been laying about for a while.

It was purchased for £1 at a boot sale on the off chance that it would work. It was in a poor state, one controller was missing and the battery cover was absent. Cosmetically it was messed up by some old parcel tape residue that was used to hold the case together.

A while ago I have tried to fire it up, there was sound but no picture,The pcb was in very poor condition with many dry joints and flaky components.

I hate to give up and throw things away so I left it. I have previously made a pong game and wanted to do similar by refurbing the machine with a velleman kit, my previous project was digital up/down paddles so I did not bother as it would be a step down to add this to a analogue rotary game. However last year the kit had been superseded to a paddle type so I decided to go for it.


 I stripped the unit down and then soaked the case in a bath, it took an hour in the water to remove the residue left by the parcel tape, what awful stuff- never use it!





I assembled the Kit, I left some parts off that I knew were not to be used in the case, the battery connectors were replaced with wire that would run to a battery holder, the function switch that handles game mode and on/ off was replaced with wire as was the LED signal. I also fitted a switch over the PAL/NTSC mode so it could be toggled rather than fitting the link wire.
I tried to use the original matrix for the switch but it was unreliable so I mounted a tack switch to the board and cut away a little part of the push button that sits over it when assembled. There was no use for the other switches.

I wanted as much of the existing controller to be used as possible so I cut away a part of the kit paddle so that it could fit inside what was left of the original game.


I fitted a brighter LED and soldered it all together before re-assembly, I used hot glue to mount the board into the case. Two new holes had to be made to give access to the RCA sockets, this was done with a hacksaw and a file.


The cups for the controllers were cut to allow good grip to the new rotary controls they were turned the other way , it was a compromise that had to be made to allow the serve button to be operated by the player.
The controllers were sealed up with hot glue.

rear view

The new kit uses less batteries than the original! 

The whole project took a day, the cost of the kit was £15 
It was pleasing to make use of a kit for an application like this, it gives the kit a nice finish.

Its just a shame that things do not last forever, I would always prefer to use the original item in good working order.

Thanks for reading. :-)




Friday, 21 March 2014

A basic Arduino Solar PV Monitor.

submit to reddit

Hi, I have just completed my latest project.
I have just recently had solar pv installed, mainly to future proof my energy costs, I do not expect it to be like drilling for oil in my back garden, however the return looks to be encouraging.

The install gives you another single unit meter, from this you will see the total amount the panels produce, but that is about it.

I wanted to know how much the production was as it was happening, I discovered the light blinks on the front of the meter will flash 1000 times for each kWh of electricity which passes through. The rate of the flashing of the LED tells you how much power is currently passing through the meter.

Being a newbie to Arduino, I knew that this could be done, but did not know how!
After web searching I found many sketches that would have helped me, but they were for Data logging, a step that was too far for me at this time, but I did find the diagram on how to use AnalogRead.



I thought of just a row of LEDs that would illuminate in correlation to the amount of output the LDR was reading, like a VU meter.

So I thought about it another way, what was I doing?  I am measuring a pulse and then stopping the measurement when the pulse occurs again, with those results I could then find stuff out.

My eureka moment was looking on the net again, this time for lap counters and timers! there were plenty and very simple.

The most understandable one I found was Claudiu Cristian's Speed measurement with arduino with his code I began to set up my circuit and use a flashlight to experiment with some settings, changing when the LDR started to count was first, I n effect I needed to turn the  < and > inside out to count what I needed, as it would measure only when the light was on otherwise.

His sketch uses two LDRs on the premise that a car passes over LDR 1, starts a timer then passes over LDR 2 then grabs the timing and divides it by the distance to calculate speed.

Using the serial monitor and some breadboard I replicated his circuit and changed the code the not calculate distance, but to calculate seconds in one minute (3600) by the time counted.


While working on this code, I was also trying to find out how to reconcile LED output by using conditions so that if I was measuring 3600W I could perhaps illuminate four LEDs or if I was pulling in 1000W two LEDs would be lit and so on.

Meanwhile I posted a topic on the Arduino forum where I found extra insight. My thanks go to Rob Tillaart from the forum for giving me the conceptual code I needed to further the sketch from a lap counter to a meter reader he showed me how the IF statements work in C and work LEDs as a result.



In the mean time I was getting to grips with C and reduced the code to only require one LDR.


I managed to get the new code working the way I had intended, and I even managed to play with other types of output, I used the TV out library to display Watts and time on a standard screen, however the 7" TFT monitor was not very suitable to use when I wanted to site the completed module so I did not pursue this option.This was a blessing in disguise.



Seeing how easy it was to include a module, I decided to import Liquidcrystal library and after a trip to Rapid electronics, set about improving the meter reader.

The pinouts were straight forward, I found the fact sheets easily on the web, and the Arduino pinout was described in the example sketches in the software.



I noted how the threshold on the LDR went from quite high (950) to 11 for the final build, this is because when I had just started with only a LDR connected to the Arduino there was more current as opposed to 4 LEDs or a LCD display plus relevant resistors.
As I had more space to display information, I included a 'High'est reading readout. It works the same as a hight-score register in a computer game.

When trying this system out, It work nicely however I had to make some extra refinements.
When my meter produces no power, at night the Meter LED is constant, my reader would just read the light and never compete its loop thus shows mega power being produced and messes up my nice display and called a stupid value to the High register, so If I came home in the dark I would never discover what the highest value was in the daytime.
Also if the light is constant for one minute, the display shuts down to increase battery life.

The original idea of two LEDs one operational and one to blink was a drain on a 9V battery, so I omitted the operation light, and left only a blink LED.

Then finally thanks to my Friend, Andy Ward who looked at my hacked up code decided it needed a good tidy up, and thanks to him I am able to give you the final code here.

I used some protoboard to make the build, the soldering was straight forward, although I had to employ some tricks to use both sides of the board, here is the board with the Arduino on one side and the LCD mounted to the front, like one big shield.

This project has taught me loads about C programming, and I am glad that I discovered things for myself so that when help came I knew why and how a solution would work, its tempting to go out and get an off the peg solution, but it's more satisfying to get the answers for yourself.

/*
RetroText Meter Pulse Reader 
inspired by  a Lap counter Written by Claudiu Cristian from his blog http://kumuya.blogspot.co.uk/2012/02/speed-measurement-with-arduino.html
Thanks to Rob Tilaart for valuable input.
Final Code and rewrite by Andy Ward. 
*/
#include <LiquidCrystal.h>

// Constants
const int mirrorLedPin = 13; // LED pin to mirror the monitored one
const int photocellPin = 0;  //  sensor is connected to a0
const int threshold = 11;    // value below sensors are trigerd

// Global variables
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // LCD
unsigned long highWatts;               // Highest watts recorded

void setup(void) 
{
  // Set up serial debugging
  Serial.begin(9600);

  // Set up the LCD number of columns and rows: 
  lcd.begin(16, 2);
  
  // Set up indicator LED
  pinMode(mirrorLedPin, OUTPUT);   // Set pin to output
  digitalWrite(mirrorLedPin, LOW); // Switch off
}

void loop(void) 
{
  unsigned long startMillis;
  unsigned long offStartMillis;
  unsigned long curMillis;
  unsigned long elapsedMillis;
  int generating;
  unsigned long watts;
  lcd.display();  //display on

  // Wait for the LED to go off
  startMillis = millis();
  generating = 1;
  while(analogRead(photocellPin) > threshold){
    // LED is still on
    if(generating){
      curMillis = millis();
      elapsedMillis = curMillis - startMillis;
      if(elapsedMillis > (60UL * 1000UL)){
        // Not gone off in 60 seconds Display off
        generating = 0;
        lcd.noDisplay();          // no display after a min
        Serial.println("NODISP"); // debug
      }
    }
  }

  // LED is now off
  offStartMillis = millis();
  digitalWrite(mirrorLedPin, LOW); // Switch on
  
  // Wait for LED to go on again
  while(analogRead(photocellPin) <= threshold){
    // Do nothing, just wait
  }

  // LED is now on again  
  curMillis = millis();
  digitalWrite(mirrorLedPin, HIGH); // Switch on

  // Display results
  elapsedMillis = curMillis - offStartMillis;
  watts = 36000 / elapsedMillis * 100;   // convert timing to watts
  if(watts > highWatts){ // is watts higher than top reading?
    highWatts = watts;   // remember for next time
  }

  // Output serial debug
  Serial.print("TIMING: "); 
  Serial.println(elapsedMillis);
  Serial.print("watts");
  Serial.println(watts);
  
  // LCD output
  lcd.begin(16, 2);
  lcd.print("Production Watts");  // catchy title
  lcd.setCursor(0, 1);            // Cursor
  lcd.print(watts);               // watts output
  lcd.setCursor(6,1);             // cursor
  lcd.print("High:");             // top reading
  lcd.print(highWatts);                // high output
}



thanks, as ever for reading!
























Monday, 3 March 2014

Arduino Colour Bursts.

Now that my Arduino is no longer used as a keyboard interface prototype, I decided to try and find a new use for it. I decided to utilise the GPIO kit for the raspberry pi that I have previously blogged about.

My good friend Andy Ward had wrote code to make a colour bursts and many other effects for his Kit and Raspberry Pi in C, and now has ported the code over to be compiled on the Arduino Uno.

I modified Meltwaters Kit to fit the other way around on my Arduino and used a 9v PSU I had laying about.
 The Original Raspi Connections remain, but a new set of Pins were soldered to the other side.


video

The setup runs really nicely, and I have found a new home for this Kit in my Arcade Cabinet at the coin slot.

The raspi header mates with a blank header that is glued to the back of the coin door. The surround sound is seen inside the chamber.

video



Here is the Light operating on the cab coin door, I hope you get get an idea on how loud the cab can be, this is at half way.Sega's Astro blaster is one of the loudest games I have played- very good it is too.
[the noises are from the camera itself, sorry about that!]


Here is Andy's Sketch for the Arduino.

// Sets LEDs to increasing intensity cycling through all colour combinations

// Defines
//#define DEBUG 1
#define offsetof(st, m) __builtin_offsetof(st, m)
//#define offsetof(st, m) ((size_t)(&((st *)0)->m))

// Constants
// Pins
const int led1 = 3;
const int led2 = 4;
const int led3 = 5;
const int led4 = 6;
const int led5 = 7;
const int red = 8;
const int green = 9;
const int blue = 10;
// Pin array
const int noleds = 5;
const int ledpins[noleds]= {
  led1, led2, led3, led4, led5
};
// Timing
const int quanta = 1000; // ms per led
const int noframes = 4; // number of frames to hold pattern for
// Intensities
const int intensities[] = {
  0, 1, 4, 25, 100
};
const int nointensity = (sizeof(intensities) / sizeof(int));
const int intensityvalslong[] = {
  0, 1, 1, 2, 2, 3, 3, 4, 4, 3, 3, 2, 2, 1, 1, 0
};
const int intensityvalsshort[] = {
  0, 1, 2, 3, 4, 3, 2, 1
};
const int nointensityvalslong = (sizeof(intensityvalslong) / sizeof(int));
const int nointensityvalsshort = (sizeof(intensityvalsshort) / sizeof(int));

// Variables
typedef struct
{
  int r;
  int g;
  int b;
} leddef;
leddef ledstruct[noleds];
leddef *leds[noleds];

// Prototypes
void setLed(int led, int r, int g, int b);

// Functions
void setup()
{              
  int i;
#ifdef DEBUG
  Serial.begin(9600);

  Serial.println("---=== Spectrum ===---");

  // Dump led pins
  Serial.print("ledpins["); Serial.print(noleds); Serial.print("] = {");
  for(i=0; i<noleds; i++){
     if(i > 0) Serial.print(", ");
     Serial.print(ledpins[i]);
  }
  Serial.println("}");

  // Dump RGB pins
  Serial.print("red = "); Serial.println(red);
  Serial.print("green = "); Serial.println(green);
  Serial.print("blue = "); Serial.println(blue);

  // Print timing details
  Serial.print("LED quanta = "); Serial.print(quanta); Serial.println(" microseconds");
  Serial.print("LED frame = "); Serial.print(quanta * noleds); Serial.println(" microseconds");
  Serial.print("pattern frames = "); Serial.println(noframes);
  Serial.print("LED pattern length = "); Serial.print(quanta * noleds * noframes); Serial.println(" microseconds");
  // Dump intensities
  Serial.print("intensities["); Serial.print(nointensity); Serial.print("] = {");
  for(i=0; i<nointensity; i++){
     if(i > 0) Serial.print(", ");
     Serial.print(intensities[i]);
     Serial.print("%");
  }
  Serial.println("}");
  Serial.print("intensityvalslong["); Serial.print(nointensityvalslong); Serial.print("] = {");
  for(i=0; i<nointensityvalslong; i++){
     if(i > 0) Serial.print(", ");
     Serial.print(intensityvalslong[i]);
  }
  Serial.println("}");
  Serial.print("intensityvalsshort["); Serial.print(nointensityvalsshort); Serial.print("] = {");
  for(i=0; i<nointensityvalsshort; i++){
     if(i > 0) Serial.print(", ");
     Serial.print(intensityvalsshort[i]);
  }
  Serial.println("}");
#endif
  // Set the LED pins as outputs, initialise the LED structs and pointers.
  for(i=0; i<noleds; i++){
    pinMode(ledpins[i], OUTPUT);
    digitalWrite(ledpins[i], HIGH);
    leds[i] = &ledstruct[i];
    ledstruct[i].r = 0;
    ledstruct[i].g = 0;
    ledstruct[i].b = 0;
  }
  // Set the colour pins as outputs
  pinMode(red, OUTPUT);  
  pinMode(green, OUTPUT);  
  pinMode(blue, OUTPUT);    
  // Initialise the colour pins
  digitalWrite(red, LOW);
  digitalWrite(green, LOW);
  digitalWrite(blue, LOW);
}

// Main loop
void loop()
{
  int stage;
  int p1;
  int p2;
  int p3;
  int l1;
  int l2;
  int l3;
  byte *statebase;
  int i;
  int l;
  leddef *tmpled;
  for(stage=0; stage<4; stage++){
#ifdef DEBUG
    Serial.print("stage="); Serial.print(stage); Serial.println();
#endif
    switch(stage){
    case 0:
      p1 = offsetof(leddef, b);
      p2 = offsetof(leddef, g);
      p3 = offsetof(leddef, r);
      break;
    case 1:
      p1 = offsetof(leddef, g);
      p2 = offsetof(leddef, r);
      p3 = offsetof(leddef, b);
      break;
    case 2:
      p1 = offsetof(leddef, r);
      p2 = offsetof(leddef, b);
      p3 = offsetof(leddef, g);
      break;
    }
#ifdef DEBUG
    Serial.print("p1="); Serial.print(p1); Serial.print(", ");
    Serial.print("p2="); Serial.print(p2); Serial.print(", ");
    Serial.print("p3="); Serial.print(p3); Serial.println();
#endif
    for(l1=0; l1<nointensityvalsshort; l1++){
#ifdef DEBUG
      Serial.print("l1="); Serial.print(l1); Serial.println();
#endif
      for(l2=0; l2<nointensityvalsshort; l2++){
        for(l3=0; l3<nointensityvalslong; l3++){
          statebase = (byte *) leds[noleds - 1];
          *((int *)(statebase + p1)) = intensities[intensityvalsshort[l1]];
          *((int *)(statebase + p2)) = intensities[intensityvalsshort[l2]];
          *((int *)(statebase + p3)) = intensities[intensityvalslong[l3]];
          for(i=0; i<noframes; i++){
            for(l=0; l<noleds; l++){
              setLed(l, leds[l]->r, leds[l]->g, leds[l]->b);
            }
          }
       
          // Move
          tmpled = leds[0];
          for (i = 0; i < noleds - 1; i++) {
            leds[i] = leds[i+1];
          }
          leds[noleds - 1] = tmpled;
        }
      }
    }
  }
}

void setLed(int led, int r, int g, int b)
{
  int i;
  int rc;
  int gc;
  int bc;
  // Initialise the rgb pins
  digitalWrite(red, LOW);
  digitalWrite(green, LOW);
  digitalWrite(blue, LOW);
  // Switch on the required led
  digitalWrite(ledpins[led], LOW);
  rc=0;
  gc=0;
  bc=0;
  for(i=0; i<100; i++){
    rc+=r;
    if(rc>=100){
      digitalWrite(red, HIGH);
      rc-=100;
    }
    else{
      digitalWrite(red, LOW);
    }
    gc+=g;
    if(gc>=100){
      digitalWrite(green, HIGH);
      gc-=100;
    }
    else{
      digitalWrite(green, LOW);
    }
    bc+=b;
    if(bc>=100){
      digitalWrite(blue, HIGH);
      bc-=100;
    }
    else{
      digitalWrite(blue, LOW);
    }
    // Wait
    delayMicroseconds(quanta / 100);
  }
  // Switch off the led
  digitalWrite(ledpins[led], HIGH);
}
Full details of the circuit you have to make are at Meltwaters Blog


Thursday, 20 February 2014

Raspberry Pi in Commodore 16 PSU

submit to reddit




Hi, yet again I can't leave the Pi alone! 
I managed to fit the Raspi into a junk C16 PSU by carefully removing the internal bosses and supports, the plastic was easy to work with.
I used a stanley knife,hacksaw and some fine files to keep the whole thing tidy.
Finally I added a power LED by attaching an LED and 480r resistor to pins 1 and 13.

I use the Pi by tightVNC server and also puTTY so my retronica case can work in the background, anywhere in the room/ house without leads or a keyboard.




Sunday, 2 February 2014

Surround sound on the Arcade Cabinet.

The surround sound system in the living room has become surplus to requirement, rather than storing it I thought of putting it in the cab to give me some awesome bass when playing space invaders!

The ideal area to install the woofer is in the coin door, however I needed to saw the chipboard inside the cabinet to do it as the speaker was far too big to fit through the door.

When I did this the speaker dropped in nicely.

Two of the small speakers fit perfectly in the Marquee either side of my low volt light.

The audio simply plugs into the output of the Xbox. I can't devise away of demonstrating how good the sound is, MP3 sounds quite linear, needless to say the mirror on the wall in the next room shakes to Space Invaders.




You can read more about my Cab on this blog.