All posts by admin

The Beaufort Wind Scale

The weather has been atypical since the beginning of the year, with an unusually long period of dry, frosty weather.  Yesterday this was broken by an unusually rough rainstorm, such that I was concerned about damage to young plants in the garden. Now the BBC RSS feed gives wind speeds in miles per hour (possibly you can choose other units too), but how do you interpret this in terms of damage risk?  The obvious answer is the Beaufort Wind Scale, which devised over 200 years ago for use by mariners, but there is a interpretation of wind effects for landlubbers too, as shown below.

So the weather forecast for yesterday showed a wind speed of 28 mph at my location.  This equates to Force 6 ‘Strong Breeze’ on the Beaufort Scale,  with ‘Larger tree branches moving, whistling in wires’.  Given that this is ‘average wind speed’, there will be stronger gusts, quite probably reaching Force 8, a full gale where twigs break off trees and it is difficult to walk against the wind.

Definitely time to ‘batten down the hatches’, or to us landlubbers, to ensure that delicate plants are properly staked and loose covers are properly fixed down.

Beaufort Wind Scale

Developed in 1805 by Sir Francis Beaufort, U.K. Royal Navy

Force Wind speed
(knots)
Wind speed
(mph)
Wind speed
(km/h)
Wind speed
(m/s)
WMO
Classification
Appearance of Wind Effects
On Land
0 0-1 0-1 0- 1 0-0.2 Calm Calm, smoke rises vertically
1 1-3 1-3 1-5 0.3-1.5 Light Air Smoke drift indicates wind direction, still wind vanes
2 4-6 4-7 6-11 1.6-3.3 Light Breeze Wind felt on face, leaves rustle, vanes begin to move
3 7-10 8-12 12-19 3.4-5.4 Gentle Breeze Leaves and small twigs constantly moving, light flags extended
4 11-16 13-18 20-28 5.5-7.9 Moderate Breeze Dust, leaves, and loose paper lifted, small tree branches move
5 17-21 19-24 29-38 8.0-10.7 Fresh Breeze Small trees in leaf begin to sway
6 22-27 25-31 39-49 10.8-13.8 Strong Breeze Larger tree branches moving, whistling in wires
7 28-33 32-38 50-61 13.9-17.1 Near Gale Whole trees moving, resistance felt walking against wind
8 34-40 39-46 62-75 17.2-20.7 Gale Twigs breaking off trees, generally impedes progress
9 41-47 47-54 75-88 20.8-24.4 Strong Gale Slight structural damage occurs, slate blows off roofs
10 48-55 55-63 89-102 24.5-28.4 Storm Seldom experienced on land, trees broken or uprooted, “considerable structural damage”
11 56-63 64-72 103-117 28.5-32.6 Violent Storm  
12 64+ 73+ 118+ 32.7+ Hurricane  

Adding an RSS feed to a WordPress site

An RSS feed lets people subscribe to the blogs on your website, without having to open their web browsers to see what’s new. They say that RSS stands for ‘Really Simple Syndication’.   I don’t understand that term, but it’s how to use it that matters.

WordPress automatically generates an RSS feed for every blog that you write.  It’s important to realise that an RSS feed is not an email generator – it does not send emails to subscribers.   You have to subscribe to the feed by entering its address into an RSS reader, including Microsoft Outlook, which has an RSS reader built in.

WordPress has a built-in RSS ‘widget’ that lets you put an RSS feed onto your website from either your own or any other website.  I have added a feed from my own website into the left-hand sidebar.

Not only does this give a quick summary of my latest blogs, but users can copy the URL of the feed from the sidebar and add it to their own RSS reader, so they’re always up to date. Quite neat.

My feed is at:

http://www.fivefarthings.org/wp/?feed=rss

It is worth mentioning that by default, WordPress only updates the RSS feed once every 12 hours by default, although I understand that when customising your Theme (not the Widget) you can usually change this.

Update on BT Digital Voice

I’ve previously noted that the existing PSTN copper-wire telephone network is due to be retired by the end of 2025.  Although this may seem impossibly ambitious, given that’s only 3½ years away, it seems that the intention is not to rip out the copper network – this will remain in place for years to come – but to provide the telephone service over the broadband signal, which might come via the existing copper network or via fibre to the premises if you have that fitted.

Openreach Retiring the copper network say that there are 221 locations where they will stop selling ‘copper’ products between now and the end of the year, and from September 2023, you’ll only be able to get a digital phone, although delivered via the copper network where full fibre isn’t available.

They’re planning to connect 20 million homes to full-fibre, including 3.2 million premises in ‘harder to reach’ areas.

Salisbury was the first ‘fully-fibred’ city in June 2020, taking a year to reach more than 20,000 premises. By ‘reaching’ premises, it means that there is a connector on the building, but it will not be until 2022 that everyone is switched over.

But the thing I just don’t get is the cost of the ‘landline’ service.  In fact, their website no longer has ‘landline’ as a headline service – it comes under ‘Broadband’.

‘Pay-As-You-Go’ is £21 a month ‘line rental’ plus 21 p a minute for calls.  You can get 700 minutes of calls for an extra £7 per month.  But I remember getting stung by this some years ago when our only use of the landline was my partner making a 2-hour call to a friend once per month.  After the first hour, the cost went up to 20p a minute, so cost an extra £12!  So 120 minutes once a month cost £19.  Their prices just aren’t competitive with a mobile phone deal – they’ve lost interest in their traditional business, and must be trying to price it out of existence.

 

Fake DHL message scam

I’ve just sent an item abroad using the DHL courier service, which is expensive but reliable – these days there are more hurdles than ever to sending items abroad, including customs tariffs, so it is essential to use a firm that will handle it properly.

Then I got a text purporting to be from DHL giving a tracking link.  Since I use DHL a lot, this didn’t look like their usual message, particularly as the URL looked odd.  And not long after I got another similar text with a different URL.

I’d already decided that the message was dodgy and I used my official order number and went directly to the DHL tracking site to check on the progress of my item.  Now I’ve read that there are thousands of these texts going out and if you log into the supplied URL, you are encouraged to install an app which contains a virus that replicates the message to everyone in your contact list. it is said to be effectively a ‘denial of service’ attack.  Sadly we are now at the stage where the bigger the company, the less you can be sure that messages are genuine.

I was even suspicious of an email from BT telling me that my phone line was going digital.  Since it is not asking me to do anything, I’m pretty sure it is genuine, especially as it is highly unlikely that a scammer could have correctly guessed some of the information in the email.

BT switches to ‘Digital Voice’ phone service

Today I received a letter from BT explaining that my phone would shortly be switching to ‘Digital Voice’.  Their letter says that the phone service will be delivered through my broadband connection rather than my old copper phone line (cheerio Dixon of Dock Green!).  I do have ‘full fibre to the premises’ so the copper wires are essentially redundant in my case.  There is a socket on the back of the ‘smart home hub’ for ‘Digital Voice’ which takes any standard phone plug, so anyone could do the changeover.  Obviously the smart hub can still be used for voice even if your broadband is delivered over the copper pair.  BT can disconnect the copper pair at the telephone exchange as the broadband signal is injected at a street cabinet.  What a change from the dozens of pairs of humming copper wires strung from pole to pole that I remember from my youth, although the thick, black, fibre cables are just as unsightly.

They warn you that if you have a burglar alarm or ‘pendant’ (personal safety) alarm, you shouldn’t change yet.  Presumably these might require power from the phone line.

There is one issue that they studiously ignore – if you have hard-wired extensions, or an extension bell, these will not work as they rely on wiring from your landline socket, which will be deactivated.

There is an acknowledgement of this hidden away on their help pages, suggesting that you don’t changeover yet.  It is clear that if you need phones in several rooms, they expect you to use cordless phones which will use the DECT wireless system.

They also acknowledge that if your power goes off, your smart hub and ‘digital voice’ connection will cease to work.  I’m assuming that given that the vast majority of people now have a mobile phone, BT feels that this is no longer the risk it used to be.  (I remember the instructions that accompanied the rotary dial telephones, explaining how to dial 999 when in a blackout or smoke-filled room!)

I suppose that preparing for the changeover will cost BT quite a bit, but there will be huge savings from not having to maintain all the digital switching equipment and all those unreliable copper wire connections, not to mention the huge amount of power needed to run the old system.

So it is looking like the time is coming to bid the PSTN to RIP.

Write/Read a file in Python

In this blog, I am simply wanting to write some data to file so that my program can read it during  a subsequent restart.

I’m running Python 3 under Raspbian on a Raspberry Pi computer, so I am only going to deal with that system.  I shall ignore the complexities of input/output as far as possible.

Python holds its variables in many different formats such as text, integer, floating point and binary.   I want to store some integer values from a list variable and then to read them back at some future time.

The first step is to tell the system the name of the file and the directory where I want to store it.   The directory can be on any resource that I can access from the Pi, but in this case I will store it in the Pi’s Downloads directory. I will store the full path and file name (motorPosition.text) in a variable called logfile, using the statement:

logfile='/home/pi/Downloads/motorPosition.text'

Now I need to open the file with the parameter ‘w+’ which means it is opened for writing, as shown below.  The file will be created if it does not already exist. If it does exist, any contents will be deleted when the file is opened.  (If I want the new contents to be added, then I need to use the ‘a’ (append)  parameter instead of w+.  Note that the open command can fail for a variety of reasons, but as we aren’t trapping  errors, this would make execution halt.

Next we create a string of text.  MotorPos is a list of integer values, so  the for loop takes each value from the list, converts it to a string and appends it to the string called text.  Each value is followed by a newline character (‘\n’).  This will mean that each value will be on a separate line in the file.

When all the values in the list have been added to the string, the for loop terminates and the next statement writes the text to the file.

The next line closes the file.  This is important as it ensures that the output buffer is flushed and the system resources are released.

file = open(logfile,'w+') # store motorPos on SD card
text=''
for line in motorPos:
  text = text+str(line) +'\n' #append values to string

file.write(text) # write string to file
file.close() # flush buffer and release resources

Next we are going to try to read the values back into the list, using a try structure to trap a FileNotFound error.  If the file is present, it is opened for reading and a for loop reads lines 0 to 6 into motorPos, converting each string value to an integer.  It prints the result and then closes the file. (For reasons best known to its authors, range loops stop when the parameter reaches the upper limit rather than when it exceeds the upper limit.)

However, if the file does not exist, the program takes the necessary action (in this case, it is simply to pass control to the next statement).  Without the try structure, execution would terminate if the file is not present.

try: # Use motorPos positions from file if present
   file = open(logfile,'r+')

   for line in range(0,7):
      input_text = file.readline() 
      motorPos[line] = int(input_text)
   print (motorPos)
   file.close()
except FileNotFoundError: # File not present
   pass

Input/output is error-prone on any computer system and it is important to trap errors, otherwise programs will often fail for reasons that are unfathomable to the ordinary user.

I’m sure that Python aficionados will point out more elegant ways of doing this, but this is the most obvious way that I could fathom.  The documentation is quite fragmented, so that many sophisticated features are quite obscure.

Editing the file

You can read the file using the Pi’s built-in text editor.  It will look something like this:

8
516
404
472
592
1824
180

You can then edit the file, which could be used to supply starting parameters to the program.  However, you will only be able to save the updated file if you have the necessary permissions, generally if you are the owner.  I have found that if I let the program create the file, then I can view and copy the file but cannot save an update.  However, if I create the file first using the text editor, then the program can write to it and I retain permissions to update it.  This is just one of the complexities of input/output that i mentioned previously.  Of course, file permissions can be changed by the superuser, but that is another ball game.

A very clever scam

Earlier this week I got a call from ‘BT Retention Team’ saying that  my contract had come to an end, but if I agreed to renew then I could continue to get a £5 discount that I’d been given.  I said that I would renew and he asked me to confirm how I would pay.  I said I would continue my present direct debit.  End of call.

The next day I got a call from ‘my bank’s security department’ saying that BT had cancelled my previous direct debit and were asking to set up a new one.  Was this OK? Yes, I said.  OK, we just need to confirm you are the account holder, please give us some information.  I won’t go into exactly what information I gave them, but the caller said he needed to send a ‘one-time-code’ to my mobile phone to confirm my identity.  When the code came, I recognised that it was the message that I get for ‘two-factor verification’ when I log into the account, which comes with the warning not to reveal the code to anyone, not even bank staff.  Anyway he asked me to tell him the code.  I refused, and thank goodness I did because in retrospect it seems that he would then have logged into my account and drained it!

Indeed I told him in no polite terms that I thought he was a scammer and I was going to contact the bank.  Fine, he said, just call the number on the back of your card.  Of course, he would have used the ‘open line scam’, whereby they don’t hang up and so the call doesn’t go through to the bank, but stays with the scammer so they can pretend to be bank security and get even more information from you.

As it was, I called on a different phone and the bank confirmed that they had not called me.  Even so I asked them to change my online banking details and cards, so the details I’d given the scammer wouldn’t help any future attack.  Likewise, BT confirmed that they hadn’t called me either.

So this is a clever two-part scam.  In the first part, they might be lucky enough to get details that would allow them to pose as the target and if not, to set you up as a patsy for the second part.  You are not surprised to get a call from your ‘bank security’ about a direct debit from BT and in the hoops that they get you to jump through deliberately to cause confusion, inadvertently reveal your access codes.  In the present case, they were trying to get my telephone banking codes, but fortunately I don’t use that system.

The fact is that if someone calls you, even if you are expecting the call, you need to verify their identity. It is shameful that large companies don’t already have such a system.

I am not a pushover for these scam calls – I get far too many and usually just hang up, occasionally after expressing my opinion of them.  I am very cross with myself for letting this one get as far as they did.

Believe me, they are very clever at what they do, so my warning is that EVEN IF YOU ARE EXPECTING A CALL FROM A LARGE COMPANY, DO NOT BELIEVE THAT THE CALL IS GENUINE.  Confirm it first.

How the stepper motor works

How does it work?  The pole pieces are arranged in a triangle, with the ‘bottom’ pole pieces being the ends of the driver coils and the top pole piece being formed from the top end of the coils bending back to the rotor.  This means that when the coils are driven with opposite polarity, the north and south poles cancel out and the top pole piece is magnetically neutral.

Let’s assume the coils are energised such that the left-hand coil becomes a north pole and the right hand coil becomes a south pole. This requires the left-hand coil to be energised in direction 10, and the right-hand coil to be energised in the direction 01.  Magnetic force attracts the opposite poles of the rotor causing it to turn so that its south pole faces the north pole of the stator and its north pole faces the south pole of the stator.  The top pole is neutral at this point.

Pulse 2 makes both pole pieces into north poles, at the same time making the top pole piece into a South. This attracts the N of the rotor and repels the S of the rotor, causing the rotor to turn anticlockwise ¼ of a turn.   On Pulse 3, the left-hand coil now becomes an S and attracts the N of the rotor, whilst the S of the rotor is attracted to the N of coil 2.  On Pulse 4, both pole pieces are S, attracting the N of the rotor, whilst the top pole piece becomes an N and attracts the S of the rotor.  The next pulse is the same as Pulse 1 and we are back to the starting position.

It is clear that if the rotor is left in, say, position 3, and the pulsing sequence starts at 1, the rotor could turn either way to get to position 1. In either case, this would cause a positioning error.  To avoid this, the driver either needs to remember its position in the pulse sequence or it should always be driven a multiple of 4 pulses (one revolution) so that it is always at the appropriate starting position.

Using an H-bridge driver

The stepping sequence shown in the diagram is that of a typical H-bridge driver. The setting 1001 indicates the polarity of the two coils, with coil 1 being energised with polarity 10 and coil 2 by polarity 01 (i.e. the opposite polarity).  The direction of rotation will be reversed by changing the pulse sequence.  Thus, starting from position 1001, if the next step is 0101 (rather than 1010) the direction will be anticlockwise.  Some H-bridge drivers, such as The DRV8834 Stepper Motor Driver have a ‘direction’ pin that alters the pulse sequence accordingly.  They also remember the last step as long as they remain energised and ‘awake’.

By altering the relative current through the coils, it is possible to achieve coil positions intermediate to the main steps shown above.  The motor shown in this example works well at quarter steps but may not have as much starting torque.  Moreover, it is necessary to keep the coils energised in order to maintain an intermediate position.  The data sheet advises that the driver should be designed to accelerate and decelerate the pulse rate at the start and end of travel to ensure accurate stepping.

Clearly, it is worth using a H-bridge driver for non-trivial implementations.

Investigating an X27 Dial stepper motor

I use the X27 168 stepper motor for driving the barometer dials.  These are intended for driving the dials on a car dashboard, but I had no technical specification for them.  You can see from the photo that it is a bipolar motor – i.e. it has two coils each around a steel core which is extended to form curved pole pieces. The top of each core turns downwards under the cogs and come together to make a third pole piece, such that the pole pieces are at 120 degrees to each other.

You can see at the bottom of the photo that between the pole pieces there is a very small rotor, which consists of a small circular ceramic 2-pole magnet with very fine bearings and a small cog no more than a two or three millimetres in diameter.  The cog engages with another reducing gear which drives the output shaft via another reducing gear.  Each full rotation of the rotor (4 full steps) turns the output shaft by 2 degrees.  The result is that it takes 640 steps of the rotor to turn the output shaft through 320 degrees.  An end stop prevents it from continuing to rotate. The cogs are made of quite slippery plastic and whilst there is no obvious lubricant,  some PTFE type lubricant might have been applied during assembly.   The motor is held in a circular plastic housing about 30 mm diameter and about 10 mm thick.  The two halves are held by spring clips moulded into the housing. I will describe how it works in a separate post.

I have managed to find a Data Sheet for this motor!

The important parameters are that the motor coils have a resistance of about 255 ohms and are intended to be driven from a 5 volt source (maximum 9 v). This gives a current of about 20 mA.

The data sheet states that one full step creates half a revolution of the rotor, which is one degree of rotation of the output shaft.  (Maybe this depends on the definition of a full step, which doesn’t really affect this analysis.)

The datasheet goes on to say that each full step can be divided into 3 partial steps, so that a 360 degree rotation needs 1080 partial steps.

Importantly, it states that full steps can be carried out at 600Hz , i.e. 1.7 ms per step, resulting in a 600 degrees per second angular speed.  However, allowance must be made for acceleration and deceleration.  To avoid losing steps at the start, or overrunning at the end, the angular speed should be 200 degrees per second, although this depends on the inertial mass of the pointer.  So to achieve the maximum speed requires the pulse rate to be gradually increased and conversely on stopping.

I am need to achieve the most accurate rotation rather than the fastest, so a speed of 200 degrees/s is fine.  What step rate does this equate to?

I’ve determined that 4 pulses are needed from the stepper chip to rotate by 2 degrees, so I would need 400 pulses to rotate by 200 degrees.  This equates to a period of 1/400 = 2.5 ms.

Up till now I have been using a pulse duration of 3 ms with a pause of 3 ms between pulses (during which the coils are energised).  So essentially each pulse was 6 ms long. This was giving a noisy and jerky movement, and I observed that sometimes there was overrun.  Basically I was over-driving the motors.

So I have reduced the pulse length to 2.5 ms with no pause between pulses.  This is giving a smooth and quieter movement, without the tendency to overrun at the ends.

Due to the fairly soft materials that the cogs are made from, and given that my long pointer will have a fair amount of inertia, I’m thinking that the jerkiness was causing springiness and over-run.

The quicker but smoother movement is better matched to the dynamic response of the motor system.  The result looks promising!

 

Testing the not ENABLE pin

I had one GPIO pin unused (on the 26-pin version of the pi B), so I used this to route  a signal to the ¬Enable pin of the drivers.  I altered the code to wake the driver, enable the output, step the required number of times, disable the output and sleep the driver.

2-phase (bipolar) stepper motor showing very fine cogs

This ensures that the motors are de-energised before the logic sleeps, and it does definitely reduce the number of phantom pulses.  I can run the dials back and forth hundreds of times without losing place.  However, the large ‘weather’ hand sometimes appears to stumble.  This could be due to dirt on the cogs, as the teeth are extremely fine, as can be seen in the photo. The motor is about 25 mm (one inch) across.

But also, I need to sort out why the voltage on one of the coils seems lower.  Is there a problem?