Loading web-font TeX/Main/Regular

Thursday, 29 November 2018

Distance Sensor


Another online purchase saw me get a set of HC-SR04 Ultrasonic sensors. These sensors contain an ultrasonic transmitter and receivers. Sound waves sent from the transmitter reflect off a distant surface and are sensed by the receiver. The time taken for the round trip can be used to calculate the distance. Details how it works are on the datasheet.
The company that sold the sensor, www.elegoo.com provided an download for Arduino, this consisted of a library and sample sketch.
The .cpp and .h files needed to be setup as an Arduino Library. To do this i needed to copy the files to ~/Arduino/Libraries/SR04/  The SR04 folder must match the library name.
The simple sketch below could then be created:
#include "SR04.h"
#define ECHO_PIN 11
#define TRIG_PIN 12

SR04 sr04 = SR04(ECHO_PIN, TRIG_PIN);
long distance;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  delay(1000);
}

void loop() {
  // put your main code here, to run repeatedly:
  distance = sr04.Distance();
  Serial.print(distance);
  Serial.println("cm");
  delay(1000);
}

Unfortunately, when I tried to upload to the Arduino I got this error:

/home/jonathan/Development/Arduino/arduino-1.6.7/hardware/tools/avr/bin/avrdude: error while loading shared libraries: libreadline.so.6: cannot open shared object file: No such file or directory

Looking in the /lib/x86_64-linux-gnu folder I discovered I only had libreadline.so.7.
An upgrade to Ubuntu 18.04 meant the installed version of the Arduino IDE, 1.6.7 was no longer compatible. However, simply installing the latest version 1.8.7 resolved the problem and I was able to upload the sketch.
Finally I added a piezoelectric buzzer configured to beep more rapidly the closer something got to the sensor.


The speaker was plugged into pin 8 and ground, with the code changed as below:
#define SPEAKER 8
void loop() {
  // put your main code here, to run repeatedly:
  distance = sr04.Distance();
  Serial.print(distance);
  Serial.println("cm");


  tone(SPEAKER, 550, 100);
  int delayTime = distance * 10;
  delay(delayTime);
}


This is what the setup looked like:


In practice the maximum distance reported by the sensor was around 1.25m.

Tuesday, 27 November 2018

Why everyone should keep a Soldering iron (and wire stripper)


The children have a toy guitar which they played with for quite a lot, with plenty of dropping and banging before it disappeared in a cupboard for a few months. Here it is, plenty of buttons for playing tunes, LEDs and the like.

But horror, when it was found in the back of the cupboard and new batteries inserted absolutely nothing happened. Horror for the children I have to add, I didn't really miss the sound it made!

But given my geeky nature I had to see what was the problem.  Opening it proved to be tricky. Although not glued it was held together by 18 screws, some of which were very tight. Eventually the inside was revealed:


Fortunately, the reason nothing worked was immediately obvious.

The wire to the positive battery terminal had snapped off. So the fix was a quick strip of the insulation and soldering the wire back onto the terminal.

Finally, replacing 18 screws turned out to be a lot quicker and the guitar lit up and played as soon as it was turned back on!

I'm looking forward to years more play out of it !!

Tuesday, 13 November 2018

Bird Box Camera Failure

After 2 years of continuous filming. The BirdBox camera has finally failed.

The Raspberry Pi itself is fine, I could still log onto it but unfortunately, when I tried to start up the motion detector python it complained it couldn't find the camera and that I should try enabling the camera. Now, clearly I'd already done this so some more investigation was required.

I then tried to take a still picture with raspistill, but this returned the following:

mmal: Camera is not detected. Please check carefully the camera module is installed correctly

This didn't look good.

I decided to take the Birdbox down to investigate. Being November there are no issues around disturbing nesting birds and the box itself can be taken down and cleaned between September and January.

The Birdbox was showing signs of age but the Raspberry Pi and Power over Ethernet box both looked as good as new.


As for the camera, this was looking a bit worse for wear. It turns out a large spider had made a home under the camera and had made meals of a number of woodlice.



After getting the Camera IC indoors I could certainly now see some quite significant corrosion. This is clear in the image below taken with a microscope. In particular the C8 capacitor looks to have corroded completely. Notice also the droppings.


I have a spare camera so I'll be setting up a new installation. Next time I'll look at to seal it more thoroughly.

Some links I discovered while looking for what the corroded capacitor was for

Thursday, 30 August 2018

Quirky Old Technology


I'm sure most people who at into technology and gadgets have a whole heap of old stuff lurking around in the back of cupboards, in lofts or garages. Well here is one of mine, still with box:

Yes, a Casio PB-100

Pop in a couple of CR-2032 batteries and it still works, albeit with a very faint screen
So I fired it up and entered in the first program in the manual (yes, still in the box)

10 INPUT "N= ", N
20 S=0
30 FOR I=1 TO N
40 S=S+1
50 NEXT I
60 PRINT S
70 GOTO 10

Lovely BASIC nostalgia feeling aside, this doesn't really do much but when I ran it I got some very strange behaviour:

ERR6 P0-20

(Incidentally, Change to MODE 0 and SHIFT 0 to run)

P0 is the program in slot 0 and -20 is line 20. Now, line 20 is the rather innocuous assignment of S=0 and ERR6 from the separate technical manual is :

Variable error
  • Attempt was made to use the same memory for a numerical variable and a character variable at the same time
  • Do not use the same memory for a numerical variable and a character variable at the same time
This is interesting, a character variable is assigned with a , for example A. So the assignment S=0 should be fine.

Then If I change to from S to P, say, it all works fine and then changing back to S it worked again. Very mysterious.

Yes, I did make sure I didn't enter S=O !

So no real idea what's happening, probably some path in the internal circuitry is failing but at least I managed to get it working in the end.


Sunday, 27 May 2018

Stormy


Last night (2018-05-26) starting around 11pm we had a thunderstorm over London.

Now, we get a few thunderstorms over London but this one was pretty spectacular.  From our location, there was about 40 minutes of almost constant thunder and impressive lightning every few seconds.

And the technical angle? I took a video of a few seconds of the storm and uploaded it to YouTube.
This is my first YouTube upload, and second video only to watching an old multimeter.
 

Monday, 21 May 2018

Starting with Docker

Until now, I've not done any work with containers so for a bit of fun I decided to setup my RESTful web server to run with Docker.

As a reminder, this is a simple python server built using web.py running on my Raspberry Pi Zero.

Step 1: Install Docker on Raspberry Pi
First up, install Docker. To do this, run these commands:

curl -sSL https://get.docker.com/sh

Set it up to start automatically on a reboot 

sudo systemctl enable docker:

Now add the pi user to the docker group, this means there'll be no need to use sudo in future:

sudo usermod -aG docker pi

Reboot, and then run:

docker run hello-world

pi@raspberrypi:~/Server $ docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.


Success!

Step 2: Build Web server Image
The directory where the Dockerfile and build files is contained is called the context. The Dockerfile is a simple text file that contains the commands necessary to build the customised image.

All files used to build the image must be in the directory tree with this folder at its root:

pi@raspberrypi:~/Server $ ls
data  Dockerfile  RestServer.py


The image used to build for the Web server was a based on raspbian for Raspberry pi loaded from the docker hub. So starting from this point, the Dockerfile can be created:

FROM resin/rpi-raspbian:latest
ENTRYPOINT []

RUN apt-get -q update && \
    apt-get -qy install \
    python python-pip

RUN pip install web.py

WORKDIR /app

COPY RestServer.py /app

COPY data /home/pi/data/

CMD ["python", "RestServer.py"]


The script updates and installs python & python-pip before then using that to install web-py. It then setups the necessary directories and copies the python file along with the data folder for local storage.
Finally the CMD starts up the script using python.

This was then built with:

docker build -t rest-server .

Step 4: Run the Web server Container

Now to run the rest-server use this command

docker run -p 8080:8080 rest-server 

The -p argument exposes the 8080 port to external clients

This will start the container in the foreground and attach to stdout.

To run in "Detached" mode, use the -d flag. When starting this will return the long id of the container

Useful commands
Docker documents can be found here


To list the running containers:
docker ps

Open a bash shell into the image:
docker run -t -u rest-server /bin/bash 

List local docker images:
docker image ls

Delete a docker image
docker rmi <image id>

Tuesday, 10 April 2018

The pain of hours long downloads ... failing

I have a TomTom SatNav with which I use the MyDrive Connect Application on Windows 10 to download and update maps.

A Western Europe map comes in at around 3GB but when I attempted to upload this last week the time to complete indicator unfortunately went rapidly up to 12 hours. (This with a 50Mbit broadband connection which was otherwise working perfectly)

So, with that in mind I started investigations. First, the Windows task manager showed the biggest hog of network was Delivery Optimisation Service. Now this was interesting, because I'd already disabled it using the options under:

Settings > Update & security > Windows Update > Advanced options

I've only got one Windows 10 machine so this is a service I don't need. However, there is another instance of the service running using the Microsoft Store. I disabled this by turning off automatic app updates in the Windows Store Settings. Now the downside is I'll have to manually update Store apps so this won't work for everyone. However, given the number of updates pending already, and for some apps I'd never use (Groove Music for example), I'm not too upset. One thing that might be useful though, instead of often vague "What's new in this version", it might also be nice to show exactly what version I've got installed.

Back to the download. This did eventually speed up and ended up taking around 3hours. But when it said complete I got a dreaded no-maps found on my TomTom device, which is an indication the install was corrupted.

For some reason, it came to my mind that the USB cable I'd been using had shown some strange behaviour when I'd been developing with my Android phone so I decided to replace it and try again and, as if by magic, the update completed successfully in minutes.

You never can tell where a bad USB cable takes you.