Translate

Tuesday 25 July 2017

Committed to Git.

Been meaning to do this for a while...

https://github.com/andydoswell

I think they're all there.....

Let me know if they're not!

Grief with I2C library on arduino LiquidCrystal_I2C library (No display or displaying 1 character)

Oh man. I hate it when things break.

I've used a couple of these displays recently, whilst developing my next project (watch this space ... it may be Mini related!)


These are a bog-standard 1602 with a Hitachi HD44780 driver or equivalent, and mounted with a PCF8574 Remote 8-Bit I/O Expander for I2C-Bus, thus enabling a 2 wire (+ power and ground) solution. Great. 

Now when I made the GPS master clock, I used one coupled up with a 20x4 display. All was well after I tested a few libraries, I finally found one that worked.

Now something broke in the IDE. I'm not sure when, but now the library I used no longer works :(
Be very careful here, as there appear to be more than one library named LiquidCrystal_I2C ... which makes matters VERY confusing in the IDE's library manager. 

The library originally came from https://playground.arduino.cc/Code/LCDi2c ...

Now if it doesn't work , open up the LiquidCrystal_I2C.cpp file in the Libraries/LiquidCrystal_I2C folder in your Arduino's default folder...

Scroll down until you see this bit:

/*********** mid level commands, for sending data/cmds */

inline void LiquidCrystal_I2C::command(uint8_t value) {
send(value, 0);
}

inline size_t LiquidCrystal_I2C::write(uint8_t value) {
send(value, Rs);
return 0;
}


Now... change return 0; to return 1; 

Like this :

/*********** mid level commands, for sending data/cmds */

inline void LiquidCrystal_I2C::command(uint8_t value) {
send(value, 0);
}

inline size_t LiquidCrystal_I2C::write(uint8_t value) {
send(value, Rs);
return 1;
}

Save the file, and try again....

Fixed. 

Took bloody hours to find that!!!

Tuesday 18 July 2017

Classic Mini LED indicator (turn signal) lamp replacement.


Still working on the Mini. It's coming along nicely, albeit slowly...

I did have a plan to reassemble things in a nice orderly manner. That's long gone out of the window! The best plan seems to be this:

1) Remove a part from the box.
2) Identify part
3) See if we can if the part, and if so
4) Clean/ paint the part and fit it.

With this in mind, it's recently come down to electrics.

Now the front indicator (turn signals if you're across the pond) / side lamps housings were made by lucas 39 years ago, from a sort of Mazak "monkey metal". Now this alloy doesn't age well, and mine were starting to crack up. Sadly there are long since obsolete, and good original ones now command a high price. Lenses are still available, however.

There are a couple of reproductions available. Some are quite expensive. Most seem to be made from ABS plastic of some description. Ideal. I chose these from Spyda designs, simply on price! (£31ea at the time of writing). Link Here . (Image stolen without permission from Spyda designs, sorry)

They rapidly turned up, nicely packaged.

They are quite a lightweight flexible construction, but this is no problem in use. They fit really well.

Nicely constructed, the PCB features three 1W yellow LEDs for the indicator section, and one 1W warm white, wide angle LED for the sidelight. The observant amongst you will notice there's a TO220 device in the top right hand corner, I suspect it's an LM317 or similar configured as a constant current source for the LEDs. Far better than a dropper resistor, and should ensure our LEDs have a good, long life. Great stuff!

The problem with fitting LED lamps is the dear old Lucas flasher unit buried under the dash. It's a thermal bi-metallic strip kind of thing, and relies on the current drawn by the lamps to operate. A normal flasher bulb is 21W ... these indicators are 3W .... the Lucas flasher unit just doesn't flash... it just stays lit up. This problem is exacerbated by the fact I've installed LED lamps in the rear too...

Because Mini didn't really change much with the times, there's another flasher unit by the windscreen wiper motor too! It's job is purely for the hazard warning lights (Four-ways if you're in the states!) This doesn't work either.

Now we could just shove in some 21W 6.8 Ohm resistors in the circuit in parallel with every indicator lamp (we would probably get away with 10W, as the duty cycle is about 50%), but that's a horrible bodge really.

OK, I thought about a simple 555 timer or discrete astable multivibrator driving a relay, until I looked on eBay. LED compatible flasher relays are no money ....
OK. So I ordered a couple to replace my two relays.... one turned up. Typical. (I've contacted the seller, the other is on it's way!!)

Now our dear old Lucas unit has two pins (actually some have three, but only two are connected), and doesn't give one iota about which way it's connected. This new unit has three pins, and I suspect it transistorised somewhere along the line, and is therefore going to get upset if we wire it up backwards.

The three connections are as follows....
L - Lamp - goes to the indicator lamps.
E - Earth - goes to chassis ground.
B - Battery - goes to the battery.

Only, of course it's not quite that straight forward. If we wired it up like that, our indicators would be permanently flashing, day in, day out....

So .... a quick consultation with the Haynes manual, and a poke round with the multimeter are required....

I will point out at this juncture that Mini had a long production run, from 1959 to 2000. Along the way some improvements were made to the electrics (and some of it wasn't!!). You may have a positive earth car if it's from the 50's or 60's ... you may or may not have hazard warning lights... and of course, Mini was exported all over the world, so local requirements would have changed the wiring...

Anyway... the original Lucas flasher was located hiding under the dash rail....












It's that round tin thing .....












... duly removed...












One side connects to a light green/ red wire. This is in accordance with the Haynes manual... good.











The other wire is blue with a red stripe. It *should* be a solid dark green. I can see further up the loom, that a repair has been made, and it does indeed join onto a green wire....








Now this is where things get a bit confusing. Having thought about this, I (mistakenly) thought this wire would simply supply 12V, via the indicator switch to the relevant lamp. Nope, there's a permanent 12 Volts there.... damn. This is why I have a hated for car electrics diagrams. None of the switches show a position. Scroll back up to the photo of the diagram, and have a look. 26 is the indicator direction switch. 25 is the flasher unit. 153 is the hazard warning light switch. 31 & 31 are the indicator lamps. There's obviously something missing. Some lucas magic going on in the hazard switch? There's no such thing as magic....

No, here's what happens. 12 volts gets to the original flasher unit. It's output goes to the lamps, via the indicator direction switch. Once the switch is made, current is drawn through the lucas flasher, which starts to warm a bi-metallic strip inside the unit. Once it's been on for a second or two, the bi-metallic strip opens the circuit, and starts to cool as no current is being drawn. Once it's cool, it closes the circuit again, and the process repeats.

Right, but what happens to my new flasher unit, if it's getting a supply (and earth) simultaneously? Is it going to sit there clicking away, annoying the hell out of me, even when my indicators aren't on?

As it turns out, no. It actually needs to see a load to operate, exactly like the old lucas unit. Just not much of a load!

So, the dark green wire goes to B, and a new earth wire goes to the chassis and pin E.

Works a treat....

The hazard warning flasher is wired up the same, and works flawlessly too..

Light green and brown goes to L, and the wire from the inline fuse holder, connects to B.

How, back to work.... ;)





Saturday 8 July 2017

Classic Mini 1275GT Electronic GPS Speedometer and multifunction display.

The Mini 1275GT is fitted with a mechanical speedo. It's driven from an output on the gearbox via a cable, which wings it's way across the back of the engine bay, through the bulkhead and into the speedometer itself. The cables always seem to get cooked by the heat from the exhaust manifold, and fail fairly often. I've got sick of changing them ....

The 1275GT's speedo reads (rather enthuiastically) to 120 MPH.....


..... and is expensive due to it's rarity


Surely there's a better way to drive it??


Plan A...

Get a broken speedo cable and harvest the speedo drive fitting, attach that to a small electric motor, and use that to spin the speedo drive to show the correct speed. Get the speed from a GPS module, PWM the motor to show the correct speed. Even the odometer will run correctly.

Brilliant... 

The speedo is marked 1248 TMP on the dial... this means it needs 1248 turns per mile.. So at 60MPH that's 1248 RPM, and at 120 MPH, 2496 RPM... so a 2,500 RPM motor would be excellent.

A small motor and gearbox was procured from eBay...

oh it IS small!

The end was removed from a speedo drive cable ....
... and attached to the shaft of the motor's gearbox...
Running some tests showed the motor would drive the speedo, but it was going to need some sort of feedback to stabilise the speed... and then it became very obvious that this tiny motor was not going to be man enough to drive the speedo for any length of time at any speed... it was VERY hot.

I looked in the junque box and found a few other motors....

This looked promising, but was too lumpy at low speeds... a similar motor was also tested with similar results. Shame as the torque provided by these motors was good enough that speed control would not be required.




I then found this beauty, with a tacho so I could create some feedback to accurately control speed...

During tests it seized up :(







What about a stepper motor? ... nah not at 2,500 RPM :(

It became apparent that this was going to be tricky...

Plan B .....

Strip the speedo down, and replace the mechanical drive with a model servo...

Advantages... Easy to drive.

Disadvantages ...
Odometer won't work (replace with an LCD or OLED display?)
Means gutting an expensive instrument.
Positional 270 (or greater) servos are expensive, and have questionable positional accuracy.

... at least an "ordinary" 90 MPH speedo will be required for practice!

The cheap 360 degree servo shown is no use, it's a "continuous rotation" servo, which has no positional feedback at all. It simply turns one way or the other ad infinitum. To implement a positional servo, we'd need an expensive "boat winch" servo.

I'm not keen on this idea....

Plan C....

A stepper motor to drive the needle.

Advantages...
Easy to drive (may need an H-bridge), inexpensive. Accurate (especially a geared down unit)

Disadvantages...
Will need to get a zero position, something like a leaf or microswitch to set zero. Will need a display for the odometer.

OK, this looks feasible....

I had a nice cup of tea, and a bit of a think .... how does the speedo and rev counter work in Mrs Doz' posh Audi?

When you switch the ignition on in her car, the speedo and rev counter move to the full scale position, and then to zero before settling down to the correct reading .. must be driven by some sort of motor ....

After some googling, it turns out that manufacturers use a special instrument stepper motor to do this!

Vauxhall have one that's VERY cheap!

It's called the X27.168, and I bought 6 (Yes 6!!) for change out of a tenner on eBay! ... and some blue LEDs (not sure what I'm going to do with those!)

Not only that, but there's an arduino library at https://github.com/clearwater/SwitecX25
which will drive the things, and without an H-bridge! Oh joy!

A few feelers were put out for a gash speedo I could use as a test bed, and Tim at MiniMail (a superb purveyor of classic Mini parts) turned up a bit of an oddball speedo.

Look carefully at the picture, the KM/H and MPH scales are the same! It's a continental 1275GT speedo with a UK bezel. An ideal candidate.





I also ordered a 0.91" I2C OLED display to replace the odometer.











The bezel was removed (normally there would be a piece of glass over this, but it was missing)....












... the two screws either side of the speedo drive fitting was removed ....








... followed by the mechanism.







The pointer was carefully eased off the shaft...















... and the two screws holding the face to the rest of the mechanism removed. Note the state of the screws. It would appear I'm not the first to have been here!










Face off....











Remove the two screws each side of the support bracket.











Unsolder and remove the return spring.













Remove the two top and bottom screws and separate the magnetic coupling. The spindle drive and plate can now be removed....










... leaving the odometer digits.












Separate the split washer from the end of the shaft and remove the gears....












... and push the shaft out. Note there will be some resistance here, as there's a nylon split washer between the end of the barrel and the bracket.

Remove the odometer barrel...








Leaving us with a disassembled back plate.












... and a nice blank canvas !













I made a small hole in a cardboard box, so the zero stop pin on the face would sink in leaving me with a nice flat surface to work on. The OLED display is a little short, but otherwise looks to fit superbly. I can make a bezel up to cover the shortfall...







The rear bracket will need the barrel support arms removing or shortening though...










I was hoping to get lucky with the spindle size, but alas no. The mini spindle is a little smaller than the new stepper motor.....


















Thankfully, there's enough meat on the pointer to bore it out slightly with a very fine drill...












Although it's a good fit, a spot of thread lock will stop it moving once final assembly is complete.











Next job is to mount the stepper motor to the bracket. I secured the faceplate to the box to prevent it from moving about.....










and punched a small hole in the dead centre of the display, to centre up the motor shaft...












As there are no mounting holes in the vicinity of the motor mounting holes, I opt to glue the motor to the bracket. Suitable adhesives were considered ... Super Glue (cyanoacrylate), UHU "universal glue", Araldite (Epoxy) ... all of these were rejected. Super glue would be too brittle, and it has a propensity to run where you don't want it. I don't think UHU will be strong enough, and Araldite seems to be a bit "runny" these days.... I looked about for an alternative.... Epoxy car body filler? Strong, not runny, sets quickly if mixed with a touch more hardener than really required... let's give it a go!

Place a small heat shrink sleeve over the stepper motor shaft to prevent it getting stuck in any excess filler. We can remove this afterwards...










Mix up a small amount of filler, and apply to the bracket ...











... and place the motor carefully, so the shaft (and sleeve) push down through the cardboard box.

Hold in place until the filer starts to set (If you make a little too much, you can see if it's set on your mixing board)







Remove the protective sleeve. A little filler has oozed up round the sleeve. I removed this with a sharp craft knife....











... and the pointer test fitted. Looks good (must clean the corrosion off the centre though!) . Don't push the pointer on too hard just yet, we need to make sure the stepper motor is set to zero first.








Next solder some wires to the rear of the motor...


Note the pins aren't numbered on the motor....
Sort of standard convention would make pin 1 blue, pin 2 grey, pin 3 white and pin 4 purple... the colours aren't important, but connecting them up to the correct ports on the Arduino is.







We'll use Digital pins 4,5,6 & 7 as they are default for the library.

Pin 1 of the motor to digital pin 7 of the Arduino.
Pin 2 to digital pin 6
Pin 3 to digital pin 5
Pin 4 to digital pin 4



OK. Now we need to calibrate our pointer.

First off, setting the zero position. I couldn't get the example sketch in the library to run. It would compile OK, but didn't work as expected. So load this into your Arduino:-



This will set the motor to zero, run it round to half way wait for a second, and then back to zero.

Now push your pointer on (after you've polished up the corroded bit!). Hit reset. You should have something like this ....



You'll notice as the motor is finding zero, it jitters about a bit. This is normal.

Now we need to calibrate the full scale deflection, in this case, 120 MPH.

Load up the following sketch ...




... and connect a 10K pot, with the ends of the pot on 5V and GND, and the wiper to A1. Open the serial monitor window.

When you run the sketch, the pointer will zero, move to the halfway point, and then move to a point determined by the position of the pot.

Again, don't worry about the pointer jittering a bit, the sketch and electronics are simple, and there's no averaging on our analogue input, so it moves around.



Turn the pot unit the Speedo indicates 120MPH.












Read the value displayed on the serial monitor, and write it down. We'll need it later. It's 784 in my case.










A little black spray paint hides the blue PCB on the display nicely. The display was wired up and tested...










..and carefully glued into place with a smear of UHU universal glue to the raised part of the faceplate. It was held there until the glue has set.

I briefly added some text into this sketch to write "THIS WAY UP!" to avoid a mistake!







Whilst the glue made a reasonable job of holding the display in place. It wasn't quite up to the job. Another gob of body filler sorted that ...










The speedo could now be reassembled.
















Great, now for some other hardware...


The hardware needs a little explanation. The Arduino is connected to the display and GPS in a normal manner, it's the power supply that's a little odd, and with good reason. 
When the unit is running, we don't want to keep updating the EEPROM with the mileage, as the EEPROM wears out a little every time we write to it, so we need on only write to it every time the car is switched off. Now I did contemplate using an interrupt, writing the data and putting the micro to sleep every time. I decided against this because of the nature of the vehicles supply. During cranking the voltage can be going anywhere ... spikes of 75V, voltage falling to 6 ... generally unpleasant. When the micro wakes up, things need to be steady so everything comes back up in an orderly manner. We can't guarantee this. 

Here's the plan. When the car is initially switched on, The IGN line supplies 12V briefly (for a split second, until the starter is engaged) it then disappears...there's  a 6-second delay at the start of our sketch waiting for the GPS to power up, so nothing happens. The micro will shut down again. Now the engine is running, our IGN line returns, and supplies power to the 7805 via D3. The micro starts up, and runs it's set up procedure. Once that's done, the micro sends D8 high, switching the relay K1 via T1, and the 7805 is now getting it's power from the permanent 12V line. Any nasty spikes on the supply are dealt with by R3, and the two zener diodes, D1 and D2.

So we drive about for a bit, the speedo doing what it should. We stop, and switch the car off. The IGN line goes low, and this is sensed by D9. This runs the shutdown routine, which writes our updated mileage to the EEPROM, and sends D8 low, switching off K1, which kills the power to the micro.

.... then I got to thinking. In the car there's an ashtray in the top dash rail. It did more for non-smoking in the UK during the 1970's than all of the government health warnings put together... What about a nice display there? We already have GPS available, so what about a digital speedo and a clock ? We could easily measure the battery voltage. Outside temperature would be nice to satisfy the love us British have for moaning about the weather... 

 


Battery voltage is read through A0, via a voltage divider formed by R2 and R6. R6 can be used to adjust calibration. Temperature is provided by a DS18B20 temperature sensor. Excellent. I used a separate micro to avoid clashes, and memory issues (and, to be honest, it was all a bit of an afterthought!!) I also added some links, so the serial interface could easily be disconnected when uploading new software during development.

The electronics was built up on a bit of perfboard, and connected to some din plugs to connect to the various components. One each for GPS receiver, speedo (both motor and display), the "multi-function ashtray display", and the temperature sensor.
If you just wanted to add the multifunction display, you could simplify the power supply (no relay or switch-over needed), and just use the second micro. You'd want add the auto-config part at the start of the speedo sketch, and send the arduino's Tx line to the Rx pin on the GPS receiver as well)

Testing shows the speedo to be very accurate against another calibrated unit, so I'm pleased with that. 

OK, so now I've got git, the software (and the required libraries) can be found  at https://github.com/andydoswell/GPS_Speedo It's still here in the little text box too, for all you copy'n'pasters...

Addendum 04-Sept-2017 - get the software from the git hub page above. I've made a few revisions to prevent EEPROM corruption. The latest software will always be available on the git.



Here's the sketch for the multifunction display (also available from  https://github.com/andydoswell/GPS_MFD_for_car )



Here's a wonderful video of it in action!





*** STOP PRESS!!!*** I've now revised the software slightly... check out https://andydoz.blogspot.co.uk/2017/11/classic-mini-1275gt-electronic-gps.html