Thursday, 31 December 2020

LED Firelight for Harry Potter

It's Lego Harry Potter, but I thought it would be fun to light up the great hall with LEDs setup to flicker like firelight 

I took three LEDs, one red and two yellow and wired them up on a breadboard as below


I used a 1KΩ resistor for each LED, connecting to Digital Pins 9, 10 and 11 on the Arduino.

Here's the Arduino script:

int LED_1 = 9;
int LED_2 = 10;
int LED_3 = 11;
void setup() {
pinMode(LED_1, OUTPUT);
pinMode(LED_2, OUTPUT);
pinMode(LED_3, OUTPUT);
}
void loop() {
analogWrite(LED_1, random(200)+55);
analogWrite(LED_2, random(200)+55);
analogWrite(LED_3, random(200)+55);
delay(random(100));
}
view raw Hogwarts.ino hosted with ❤ by GitHub

The analogWrite() call sets up Pulse Width Modulation (PWM). This is a square wave with a varying duration of "on" time, known as the pulse width or duty cycle. PWM can be used to simulate a range of voltages between 0 and 5V.

The value of the duty cycle is given to the analogWrite call. 0 is always off, 255 is always on. In this example, the minimum is set to at least 55 (about 20%) and a random amount up to the maximum is overlaid. 

The value is changed every 100ms to give a flicker-like effect.

Next, I replaced the breadboard by soldering the components onto 30-40cm long wires. Covered the bare wire with electrical tape and put the LEDs into the fireplace of the Lego Harry Potter Hogwarts Great Hall.

Here it is after dark...  Lego Harry Potter LED Great Hall Fireplace - YouTube



Tuesday, 3 November 2020

Setting up a Raspberry Pi (2020 Edition)

It's been a while since I setup a new Raspberry Pi from scratch. My Raspberry Pi 2 was running an old version of Raspbian Jessie which was no longer getting updates. In particular the version of Chromium was old. So I decided to update to the latest version.

It's now called Raspberry Pi OS and after downloading from here I tried to reflash the old SD card.

This is where it got a bit tricky...

First, Windows didn't recognise the SD, to the extent that I couldn't even reformat. I switched to Linux. I used DiskUtil to reformat it. At this point I thought it would be quick to use the Raspberry Pi Image Utility to install the OS but when I tried it failed with: Unspecified Libcurl Error 

So back to Windows which was able to open the SD but required another (quick) format and finally I was able to use Etcher to flash the card.

Phew. That was more work than it should have been. 

At this point I popped the SD card back in the Raspberry Pi, plugged it into the TV and started up

The process is a bit more streamlined than before. Connecting the Wifi and changing the password is covered by a Wizard.

The Wizard finally asked if I wanted to update the software on the Pi. I answered yes to this but the process ended up crashing. I resorted to the old method of running sudo apt-get update followed by sudo apt-get upgrade from a terminal

Next, from the terminal, enter sudo raspi-config. Select the Advanced Options and Expand Filesystem. This ensures the whole of the SD card is available to the Pi.

In the same tool, enable SSH and VNC. This is because I want to remotely logon to the machine from elsewhere on my network.

The next step was to give the machine a Static IP address on the home network. This just makes things easier for me to manage.

To do this edit /etc/dhcpcd.conf and add the following lines to the bottom, assuming the router IP is 192.168.0.1 and we want to setup our static IP to 129.168.0.200

   interface wlan0

   static ip_address=192.168.0.200/24

   static routers=192.168.0.1

   static domain_name_servers=192.168.0.1

Oh no this didn't work at all. I rebooted and was still allocated the dynamic IP address from the router. I went round a lot of circles and visited a lot of websites trying to resolve this, including disabling IPV6.

These proved useful:

  • ip a  : To see your IP Address
  • systemctl status dhcpcd.service : To see the status of dhcpcd

But in the end the solution was to open raspi-config and disable Predicable Network Interface Names

I also added noipv6rs after interface wlan0 in dhcpcd.conf but I don't think that is required. 

Network Share

Connect to the network share automatically on start up. Add the following to the end of /etc/fstab

  //ip.of.nas/Public /home/pi/NAS cifs guest 0 0

TouchScreen

The 7 inch touch screen was setup with the following commands

  git clone https://github.com/goodtft/LCD-show.git

  chmod -R 755 LCD-show

  cd LCD-show/

  sudo ./LCD5-show

Then reboot. No additional calibration was required 

Chromium

The default chromium is taken from the chromium-browser package. This has special optimisations for the Raspberry Pi but is not updated frequently. However the latest Debian chromium package can be installed which is perfect for my use case.

Monday, 12 October 2020

Eclipse and Windows 8.1 family accounts

OK this is a bit niche, but I think worth recording. 

I have a Windows 8.1 account setup with Family Security. What I wanted to do was install Eclipse on this account so the children could play with writing Java code, for Minecraft Mods.

This proved to be tricky. The Eclipse installer uses Oomph which didn't work too well in this use case:

1. Install on family account normally. This failed because underlying processes asked for access one at a time. When a process asks for access, even if it is provided, it then terminates. You can end up repeating this a lot of times but in this case even that didn't work.

2. Install on Admin account. I hoped it would then be available to all users. Unfortunately, the Eclipse installation saves files to the user area for the Administrator.

3. Install on family account as Administrator. Open a command prompt as administrator and run the setup. This fails because it still saves the files to the Administrator user area even though it's run from the family account

So my solution after attempt #3 was to copy all the files from the Administrator User folder to the Family account user folder. Most important was to copy the .p2 folder.

I then manually edited the following files from the .p2 folder to point to the new location:

  • eclipse.ini
  • configuration\config.ini
  • configuration\org.eclipse.equinox.simpleconfigurator\bundles.info
  • configuration\org.eclipse.update\platform.xml

After this I was able to open the IDE and run a simple Hello, World!

Monday, 10 August 2020

LCD Display and Arduino


This blog describes the steps taken to setup a 20 x 4 Character LCD Display. The one I'm using has a small add on board at the back of the display that requires only 4 connections to the Arduino.

The LiquidCrystal_I2C library needs to be downloaded and installed on the Arduino IDE. The source and zip can be downloaded from GitLab https://gitlab.com/tandembyte/LCD_I2C

Then in the Arduino IDE select Sketch -> Include Library -> Add .ZIP Library...

The pin assignments for the LCD to Arduino are:

LCD Arduino
GND GND
VCC 5V
SDA A4
SCL A5

The Arduino code is simple, first you need to #include <LiquidCrystal_I2C.h> and create the instance. The parameters are the address of the LCD (typically 0x27), the number of columns (20 for my model) and the number of rows (4).

#include <Wire.h> // Library for I2C Communication
#include <LiquidCrystal_I2C.h>
// 0x27 is the address of the LCD
LiquidCrystal_I2C lcd(0x27,20,4);
char *names[] = {" Scrolling ", " LCD ", " Testing ", " Changing Rows "};
void setup() {
lcd.init();
lcd.backlight();
lcd.setCursor(0,0);
lcd.print(names[0]);
lcd.setCursor(0,1);
lcd.print(names[1]);
lcd.setCursor(0,2);
lcd.print(names[2]);
lcd.setCursor(0,3);
lcd.print(names[3]);
}
int index0 = 0;
int index1 = 1;
int index2 = 2;
int index3 = 3;
void loop() {
// put your main code here, to run repeatedly:
delay(1000);
lcd.setCursor(0,0);
lcd.print(names[index0]);
lcd.setCursor(0,1);
lcd.print(names[index1]);
lcd.setCursor(0,2);
lcd.print(names[index2]);
lcd.setCursor(0,3);
lcd.print(names[index3]);
index0 = ++index0 % 4;
index1 = ++index1 % 4;
index2 = ++index2 % 4;
index3 = ++index3 % 4;
}
view raw lcd_test.ino hosted with ❤ by GitHub
The snippet below scrolls 4 rows vertically. Note the padding in the data to align and clear the previous value.

Of course the first time I uploaded this the backlight turned on but no characters were visible. This was because the contrast was set to its lowest value. After adjusting  this pot on the back of the LCD everything was perfectly visible.



Thursday, 9 April 2020

Growing Crystals


More lockdown science! This time we've been growing crystals!

First up plain old sodium chloride. We boiled up some water and managed to dissolve 25 teaspoons of salt into roughly 300ml of water. We then poured it into this jar and suspended some string on paperclips



Why hot water? This is because more salt can dissolve in water when it's hot than cold. We created a saturated solution while hot, and as the water cooled it became supersaturated causing the salt to start crystallizing. The string acted to provide good sites for the crystals to grow.

After a few days a good number of crystals have grown on the string. We'll keep it for longer to see how they grow.



We also got a crystal set at Christmas. This contained a packet of potassium dihydrogen phosphate, a card tree and a marker pen.

The pen was used to colour the ends of the tree branches and the solution was placed in the dish at the bottom. As the solution was raised up the card by capillary action it reached the marker ink where it started crystallizing. It also took up the colour of the ink as the powder was initially white.




And the crystals seen through the microscope. The delicate nature of these is readily apparent.


Tuesday, 31 March 2020

Static electricity and sticky balloons

With the country in lockdown due to the Covid-19 coronavirus we've been taking advantage of the time to try out some experiments.

My sons were taking great delight rubbing the balloon on their heads to get their hair to stand on end when they decided to throw it up onto the wooden ceiling beam. Where it promptly stuck.


I've often tried to stick balloons to the wall or ceiling with static electricity often with no success so this was a really good result! But, what's happening?!

When the balloon was rubbed against the hair, electrons were deposited from the hair onto the balloon. This gave it an overall slight negative charge.

Now, when the balloon touched the beam, although the beam was neutral the electrons in the balloon repelled those in the wood. This gave the surface of the wood a slight positive charge, which like a magnet will lead to positive and negative building a slight attractive force.







And what's more awesome is that the tiny amount of electric charge caused just by rubbing the balloon is enough to overcome the force of gravity from the whole Earth!