Tuesday, 29 January 2019

Simple backup of a Raspberry Pi


Back up SD card data to USB drive

The Raspberry Pi generally uses an SD (or microSD) card as its main storage. This is a cheap and generally reliable storage medium, but it is vulnerable to problems if the power is interrupted while data is being written.

If the power is interrupted (by the cat pulling the power lead out or you thinking it is the mobile 'phone's charger etc.) there is always the possibility that the SD card may become corrupted and all the data is lost.

Of course, you should be running a backup process on any system.

Back up home directory


To back up your home directory to a mounted USB drive, use the following command lines. You will need to know the name of the USB drive (have a look in /media.pi for the USB drive), replace the "name_of_usbdrive" with the actual drive name. You might want to replace "mypi" with the network name of the machine if you have a number of different systems.

First change directory to the /home directory (off of root).

cd /home/
Note space between change directory and directory path.

sudo tar czf /media/pi/name_of_usbdrive/backups/mypi_$(date +%Y%m%dT%H%M)home.tar.gz pi

Once that is running, go off and make a beverage of choice, it will take a while, and using the machine will upset the backup (as any use may cause a file change).

Note

One thing to be aware of, this will back up the contents of the trash bin. 
This might cause issues as the zip process falls over at about 4GB, and deleting files just puts them in the bin.

It might be worth emptying the bin occasionally.

You might also not want some deleted items to be backed up ^___^.


Saturday, 15 December 2018

Raspbian Pixel desktop VNC Viewer

Since September 2016, all Raspberry Pi Raspbian distributions have included the RealVNC Virtual Network Computer server and viewer.

This allows the remote connection to the desktop on a Raspberry Pi machine. This is great if you want to to run your Raspberry Pi "headless" and do not want to use the Secure SHell (SSH).

You can connect to your Raspberry Pi from another (non Raspberry PI) machine by downloading and installing the RealVNC viewer (make your selection from the operating systems shown here https://www.realvnc.com/en/connect/download/viewer/. The RealVNC viewer is available from the Google Play Store (and probably from the Apple store as well). For Raspbian on the Raspberry Pi, wou can just get it from the Raspbian repository using the normal apt-get install (instructions are available from the above link)

Now I have an elderly Samsung Windows Netbook which is having a second life as a Raspbian Pixel netbook. Now this would be really useful to see what is happening on any live Raspberry Pis. Unfortunately, the non Raspberry PI distribution of Raspbian does not contain the RealVNC viewer.

So going back to the RealVNC downloads page, select the Linux option:
https://www.realvnc.com/en/connect/download/viewer/linux/

You need to select DEB x86 from the drop down menu, then click on Download VNC Viewer.

The file will (by default) appear in your Downloads directory. The one I received was called VNC-Viewer-6.18.907-Linux-x86.deb.

In the File Manager, right click and select Package Install. This will request your password to give the installer permission to make changes to the operating system (in the same way that normally you use SUDO to give heightened permissions).

Once it has been installed, the RealVNC viewer can be found in the Internet options on the start menu.

You will need to know either the ip address of the Raspberry Pi, or the network name. A default Raspberry Pi is normally called "raspberrypi", so should appear on the local network under the name "raspberrypi.home".

References:




Sunday, 9 December 2018

PIMORONI Breakout Garden

The Pimoroni Breakout Garden HAT is a clever way of allowing the development of sophisticated sensor and display systems without having to do lots of soldering.

 As a HAT, it is fitted with a female 2x20 pin socket so it can be attached to any Raspberry Pi with 2x20 way expansion bus (Raspberry Pi Plus versions to date). Raspberry Pi Zero boards require the headers to be added (the Raspberry Pi Zero WH is supplied with the header already soldered/

This is going to be used with a Raspberry Pi Zero WH fitted into a Pibow Zero W case. To improve stability, a Pibow Breadboard Base was added to the bottom of the stack of laser cut acrylic slices that make up the case. The supplied bolts are long enough to take the additional slice.
Assembly was reasonably straightforward, I did need to ease a couple of the corners with a curved needle file to make the Zero board fit correctly.

To use a Zero with a keyboard and display, you do need to have an On The Go cable for the micro USB (top) and a Micro to HDMI adapter (bottom). I got mine as part of the Pimoroni OctoCam package.

The key feature of the Breakout Gatden HAT is the six large sockets on the top.

These are designed to take the special format breakout board from Pimoroni.

The first breakout board is the BME680 Air Quality Sensor.
Back
The front shows the five connectors. The power and ground connections are diode protected, so if you do plug them in the wrong way round, nothing bad (or indeed nothing at all) happens.

The breakout has temperature, pressure, humidity and air quality sensors built in.

The LSM303D is a combined accelerometer and magnetometer


It can provide X, Y, Z values for acceleration and magnetic field strength (making it suitable for use as a digital compass).

The third sensor is the BMP280 temperature, pressure and altitude sensor.

The last breakout board I have is the 1.12" 128x128 pixel OLED display board.


Next, putting them all to work.

Friday, 23 November 2018

FutureLearn Begin Programming Week 3 Android game video

This is for the Week 3 element of the FutureLearn course Begin Programming.

Because I am not very good with video games, I have left the one point for hitting the ball, and five points for hitting the target.

This was recorded with the emulator's built in screen recorder, hence the odd resolution. 

Thursday, 22 November 2018

Android SDK, Emulator and the Intel HAXM

Android SDK and the Intel HAXM

The Android SDK has an Android emulator that can emulate ARM and x86 based Android devices.
The build #AI-181.5540.7.32.5056338, built on October 9, 2018 dated October 2018 has an issue with ARM based emulation which prevents it from working.
The x86 emulation requires the availability of the Intel Hardware Accelerated Execution Manager.

This process will require you to go into the BIOS and make changes. It is possible to seriously break your computer if you make the wrong changes.

The Hardware Accelerated Execution Manager can be downloaded via the Android Studio SDK manager. It will say it has installed it, but it hides some installation issues.
Once you have "installed" it, on a Windows PC go to:
C:\Users\<user>\AppData\Local\Android\Sdk\extras\intel\Hardware_Accelerated_Execution_Manager

First you need to check that your hardware is suitable to run HAXM.
Start a command prompt (type cmd in the search box).
Copy the file path from File Explorer and in the command prompt type CD .
Then paste the file path and press return.
Type dir and return.

The command window will show something similar to this:
22/11/2018  16:37    <DIR>          .
22/11/2018  16:37    <DIR>          ..
30/10/2018  16:47           108,792 haxm_check.exe
22/11/2018  16:38               225 haxm_silent_run.log
30/10/2018  16:47         2,937,888 intelhaxm-android.exe
30/10/2018  16:47             2,907 package.xml
30/10/2018  16:47             4,483 Release Notes.txt
30/10/2018  16:47             8,675 silent_install.bat
30/10/2018  16:47             2,274 silent_install_readme.txt
               7 File(s)      3,065,244 bytes
Type haxm_check.exe and return.
Hopefully the response will be:
VT support - yes
NX support - yes
If it is, then you can proceed. If not, you will have to wait for the ARM emulator to be fixed.
If you run the intelhaxm-android.exe program (right click and run as administrator) it will probably tell you it is installed.

What you need to do is uninstall it (close Android Studio if it is open).

Once it has been uninstalled, run intelhaxm-android.exe again and install it. It will probably tell you that the VT support is not enabled and roll back the installation. If it works, well done - nothing more to do.

To enable the VT support, you need to go into your computer’s BIOS or equivalent.

You will need to know how to get into the BIOS, this normally requires the machine to be restarted and then various buttons pressed.

It is a good idea to find out the access method before shutting your computer down.

HP laptops post 2011 generally require the Escape key to be repeatedly pressed after starting. From there follow the instructions.

Close everything down and shut down your computer.

Enact the arcane gestures required and go into the BIOS manager. Enable the VT (Virtualisation technology). Save and restart the machine.

Once you are logged in, go back to C:\Users\<user>\AppData\Local\Android\Sdk\extras\intel\Hardware_Accelerated_Execution_Manager
And run the intelhaxm-android.exe program as administrator.




This should allow you to set up an X86 emulator in the Android Studio and start it.

Friday, 9 November 2018

SQL delimited string to table function

Sometimes data suppliers do not make their data easy to separate. Other times you might want to split some other data up.

This SQL Table function will take a string comprising a list of substrings with a specified specified delimiter and returns a table containing the substrings

-- =============================================
-- Author: Technology Is Not Dull
-- Create date: 19/01/2016
-- Description: Takes a delimited string list and returns a table
-- =============================================
CREATE FUNCTION [dbo].[stringToTable]
(
@string VARCHAR(200),
@delimiter char(1)
)
RETURNS
@rettable TABLE
(
stringbit varchar(50)
)
AS
BEGIN
--***# select * from dbo.stringToTable(POLYETHYLENE GLYCOL 3350; POTASSIUM CHLORIDE; SODIUM BICARBONATE; SODIUM CHLORIDE; SODIUM SULFATE ANHYDROUS',';')
DECLARE @start INT, @end INT
    SELECT @start = 1, @end = CHARINDEX(@delimiter, @string)
    WHILE @start < LEN(@string) + 1 BEGIN
        IF @end = 0
            SET @end = LEN(@string) + 1
     
        INSERT INTO @rettable (stringbit)
                  VALUES(SUBSTRING(@string, @start, @end - @start))
        SET @start = @end + 1
        SET @end = CHARINDEX(@delimiter, @string, @start)
     
    END
    RETURN
END
GO

Tuesday, 6 November 2018

Circuitverse - online digital logic simulator

Circuitverse is a free online digital logic simulator developed by students at IIIT Bangalore.

It allows the building of digital logic systems in the comfort of your own browser.

The user can select various input and output devices plus logic gates, wire them up and then test them.

The circuits can be saved, and images of the circuits produced. The circuits can be Public, which allows them to shared, useful for distance learning.

Previously saved circuits can be retrieved, but you need to click on the user name to get to the menu with the "My Circuits" option.

The developers say that though you could undertake a full CPU implementation, it is really designed for educational work.

It is certainly an interesting piece of software, and is happy running on a Raspberry Pi 3.