Mikedowney.co.uk
What's New
Site Map

Diary
Astronomy
Bits N Bobs
Computing
Food And Drink
Links
Photography
Welcome


Recipe Collections
Recipe A Week 2013
Recipe A Week 2010
A-Z of Regional Cakes
Alphabet of Nations


Selected Entries
Pinhole Photography
Keeping Quail
Coventry
Recipes
A different recipe each week
Friends websites
Oven Temperatures and Measuring Cups


Most popular stories
A Hamster's Home is his C...
Hamster Peanuts
Simple HDR photography wi...
A Tangfastic Mess
Halloween Animal Beds
Decaffeinated Coffee
Garden Fountain
Pizza, Hamsters and Ballo...
Hamster Baby Update
More Squirrel Photos
Not Quite HDR photography


RSS Feeds:
RSS Feed Entire Site.
RSS Feed Diary only.



Powered by Blosxom


Pinhole Photography Ring
pinhole webring logo
powered by RingSurf
Next | Previous
Random Site | List Sites

Connecting an LCD screen to the NodeMCU

Story location: Home / computing / nodemcu /
14/Apr/2017

When I bought the electronics starter kit for the Raspberry Pi, it came with a small 16 character by 2 line LCD. I found instructions on the Adafruit website for wiring it up and controlling it. I thought it might also be a useful thing to use with the NodeMCU board so I had a look for any instructions for that.

Unfortunately everything I found was for the I2C version of the display and I've got the plain parallel bus version, so I decided to have a go at wiring it up and programming it myself.

The NodeMCU board with the LCD1602 display

See more ....

Wiring up the board

The wiring is quite straightforward, although a lot of wires are required. Six GPIO pins are needed at the NodeMCU end, along with power and ground.

Starting with the power pins, connect one of the ground pins from the NodeMCU to the ground rail of the breadboard. The 'Vin' pin supplies 5 volts (if used with a usb connection) so connect a wire from that to the '+' rail of the breadboard.

Four data lines are required: D4-D7 on the LCD. To make things easier I connected these to pins 4-7 on the NodeMCU board. The final two connections from the NodeMCU are 'Clock' (called 'E' on the display board) which went to pin 2, and 'RS' which went to pin 1. Data line D0-D3 from the display board are left unconnected.

The NodeMCU board with the LCD1602 display

The rest of the pins on the board go to either 0V, 5V or a potentiometer set as a voltage divider (ignore the 3 LEDs in the pictures, they aren't needed here).

Connect the following pins to ground (0V):

  • 'RW' (set permanently to Write mode since we aren't reading from the board)
  • 'VSS' (the board's ground connection)
  • 'K' (the ground connection for the backlight)
  • One side of the two potentiometers.

Wiring up the LCD1602 display

Connect the 'VDD' pin to 5V and also the other side of the two 10K potentiometers. Finally, the 'V0' and 'A' pins can be connected to the centre of the two potentiometers to provied adjustable contrast and backlight.

Wiring up the LCD1602 display

Programming the board

I based my Lua code on the Python code downloaded from the Adafruit website. Since I was converting the code from one language to another, I read through it carefully to make sure I only converted the bare minimum to get it working.

My first version of the code was little more than a few subroutines to send bytes to the board. While I was reading the NodeMCU Lua FAQ, I noticed that they recommend that code is written to be event driven instead of the more traditional program flow used in scripting. They also state that routines called from an event can only take a maximum of 10 milliseconds to run before they affect background services. After reading that I changed my code to buffer the text and use a timer to check the buffer and send the bytes to the display.

The current version is probably too cautious and sends a byte at a time. It might be more efficient to send a line at a time but that should be easy to change.

The code can be found over on Github. I have decided to put it there since it is easier for me to keep it up to date and easier for anyone else to download.



Using the Raspberry Pi serial port from Java

Story location: Home / computing / raspberry_pi /
25/Feb/2017

A couple of days ago I wrote about connecting the Raspberry Pi to the NodeMCU microprocessor board. I originally used Python since I find that the easiest for testing ideas or simple prototyping. Since I use Java for most of my application programming, I thought I should work out how to do the same thing in Java too.

Luckily there is a Java serial comms library called RxTx which is available precompiled for Debian Linux and can be installed on the Raspberry Pi simply by typing

sudo apt-get install librxtx-java

The jar file is placed in /usr/share/java/RXTXcomm.jar (and doesn't seem to be added automatically to the classpath) so to compile any code, you'll need to use something like

javac -cp /usr/share/java/RXTXcomm.jar:. SerialTest.java

and to run the code you need to reference both the jar and the JNI library, using

java -cp /usr/share/java/RXTXcomm.jar:. -Djava.library.path=/usr/lib/jni SerialTest

The Code

import gnu.io.CommPort;
import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;

import java.io.*
import java.util.Scanner;

public class SerialTest{

    public static void main(String[] args) throws Exception{
        CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier("/dev/ttyS0");
        CommPort commPort = portIdentifier.open("Java Serial Test",1000);
        System.out.println("Opened Port");

        SerialPort serialPort = (SerialPort) commPort;
                serialPort.setSerialPortParams(115200,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);

        String[] leds = new String[]{"r","g","b","off"};

                try(BufferedInputStream in = new BufferedInputStream(serialPort.getInputStream());
                BufferedOutputStream out = new BufferedOutputStream(serialPort.getOutputStream());
        Scanner s = new Scanner(in)){

            for(String c : leds){
                out.write(c.getBytes());
                out.flush();
                System.out.println(s.next());
                Thread.sleep(1000);
            }
        }
    }
}

I saved the code as SerialTest.java and compiled it and ran it using the commands above. It expects the serial.lua file to already be running on the NodeMCU board, either by running the python script from last time or by executing

python nodemcu-uploader.py --port /dev/serial0 file do serial.lua

As you can see, the code is much more verbose than the Python version but it gets the job done.



The long awaited Raspberry Pi post: Interfacing with a NodeMCU

Story location: Home / computing / raspberry_pi /
22/Feb/2017

I first used a Raspberry Pi when I was working in Leicester and I bought one for home not long after that. I set it up as a file/media server and it has been sitting in the front room quietly doing its job since then.

Last year I bought a Pi 3 and an electronics starter kit (which consisted of a breadboard, LEDs, switches and various other components) so I could learn how to connect things to the Pi.

A few weeks ago I was given a NodeMCU development board (my friend Tim has already written about some of his experiments with his).

I followed the instructions on flashing the firmware and getting a script running. For some reason the ESPlorer software doesn't seem to behave well on my computer. It usually takes several rounds of restarting/resetting/reconnecting before it will agree to communicate with it. The command line tools have no problems, neither does CoolTerm. After a day when it felt like I was spending half of my time struggling to get ESPlorer to connect properly, I decided to ditch it and use the nodemcu-uploader command line instead.

The first thing I wrote was the Hello World of the microcontroller world: the flashing LEDs. The next stage was to use the serial ports to connect the Raspberry Pi and the NodeMCU together.

See more ....

Setting up the Raspberry Pi Serial Port

By default, the serial port on the Pi is configured to be used for a serial console , mainly for diagnostics. To use it for other things, you need to disable the console. There are lots of different instructions to do this but for the Pi 3 it boils down to editing the /boot/config.txt file and adding the line

enable_uart=1

followed by editing /boot/cmdline.txt and removing the

console=serial0,115200

entry. After rebooting the Pi, the GPIO pins 14 & 15 should be available for the serial port.

Writing the script for the NodeMCU

I took my flashing LED script and modified it to listen to the serial port. Sending 'r','g' or 'b' will light up the respective LEDs, any other character will turn them off. If the following script is saved as serial.lua, it can be uploaded to the NodeMCU using

python nodemcu-uploader.py -port /dev/serial0 upload serial.lua

as long as the NodeMCU Uploader has been installed first.

-- Listen on the serial port for a colour.
-- Toggle the colour of the LED.

green=2
blue=1
red=3
gpio.mode(red,gpio.OUTPUT)
gpio.mode(green,gpio.OUTPUT)
gpio.mode(blue,gpio.OUTPUT)

-- Start with the LEDs off
gpio.write(red,gpio.LOW)
gpio.write(green,gpio.LOW)
gpio.write(blue,gpio.LOW)

uart.setup(0,115200,8, uart.PARITY_NONE, uart.STOPBITS_1, 1)

uart.on("data",1,
    function(char)
        if char=="r" then
            print("red")
            gpio.write(red,gpio.HIGH)
            gpio.write(green,gpio.LOW)
            gpio.write(blue,gpio.LOW)
        elseif char=="g" then 
            print("green")
            gpio.write(red,gpio.LOW)
            gpio.write(green,gpio.HIGH)
            gpio.write(blue,gpio.LOW)
            lighton=2
        elseif char=="b" then
            print("blue")
            gpio.write(red,gpio.LOW)
            gpio.write(green,gpio.LOW)
            gpio.write(blue,gpio.HIGH)
        else
            print("Off")
            gpio.write(red,gpio.LOW)
            gpio.write(green,gpio.LOW)
            gpio.write(blue,gpio.LOW)
        end
    end,0)

The script can be run using

python nodemcu-uploader.py -port /dev/serial0 file do serial.lua

Getting the Pi to talk to the NodeMCU

I connected the RX GPIO pin on the Pi to the TX pin on the NodeMCU, and vice versa. The easiest way of powering the NodeMCU was to use the power out pins from the Pi. I found that connecting the 5V out to Vin on the NodeMCU worked reliably. If I had the Pi plugged into a good quality USB power adaptor then I could sometimes get it to work by connecting one of the 3.3V pins of the Pi to one of the 3.3V pins of the NodeMCU board, but this isn't guaranteed to work.

The script uses the serial port library, which can be installed using

sudo apt-get install python-serial

The Python script is fairly simple and just cycles through the LEDs a few times. The third line runs the lua script, in case it wasn't already running. There isn't a pause between cycling between the LEDs but the serial timeout is set to 1 second and the port.read(100) command attempts to read 100 bytes. Since there should only be the colour names being returned, this automatically adds a 1 second delay. This might not be very good programming practice but it was the easiest way of incorporating reading a variable length response and adding a pause all at once.

import serial

port = serial.Serial("/dev/serial0", baudrate=115200, parity=serial.PARITY_NONE, timeout=1.0)

port.write("dofile('serial.lua')\r\n")

for i in range(1,10):
    for c in ['r','g','b']:
    port.write(c)
        r = port.read(100)
        print(r)

Flashing LEDs

This first demonstration is pretty trivial, although it took a few days of trial and error to get everything working. In due course I'll experiment with connecting different sensors to the Pi and NodeMCU.

Flashing LEDs on the NodeMCU, controlled by the Raspberry Pi

I think my next step is to use Java on the Pi to do the same thing. I have had a quick look at Java serial port stuff and it isn't as straightforward as Python but since I do most of my programming in Java these days, it will be useful to know how to do that.



International A-Z: Bulgarian Holiday Bread

Story location: Home / food_and_drink / a_to_z /
01/Jan/2017

For the letter 'B' I decided to do a version of a traditional Bulgarian Christmas loaf. I had originally intended to make it over Christmas but I didn't find time to do any baking, and since we had lots of cakes and chocolates to eat, we didn't really need more bread.

Ingredients

(For the bread)

  • 2 cups of bread flour
  • 2 tsp yeast
  • 2 eggs
  • 50g softened butter
  • ½ cup water
  • 1 tsp salt
  • 1 tablespoon honey

(For the glaze)

  • 1 tsp of honey
  • a few drops of water

Mix the water and honey a few drops at a time until the honey is a pourable consistency.

Method

I put all the bread ingredients in our food mixer, with the dough hook, and let it mix for a few minutes. Since this a brioche type bread, the mix was very wet and a bit sticky, which made it difficult to handle and shape.

I broke the dough into equal weight pieces, rolled them into balls and put them in a round tin to prove.

After proving and brushing with honey

After they had risen, I carefully brushed them with the honey mixture. It was baked in a pre-heated oven (gas mark 5) for half an hour. I started it off covered in foil, but took the foil off after the first 15 minutes.

After baking

Verdict: a soft slightly sweet brioche with a honey flavoured crust. Definitely one to try again.

Bulgarian honey bread with butter



Lunchroulette at the German Market again

Story location: Home / Blog / food_and_drink /
20/Dec/2016

I went back to the German Market again and picked a random stall to buy my lunch. This time it was one of the Pretzel stalls. The salami pretzel sounded good so I bought one of those.

Salami Pretzel

The pretzel was pretty much what you expect: soft, chewy and very salty on top. I had change left so I thought I would try a dessert next. The choice of desserts was reasonably wide and included pancakes, sweets, cakes, marshmallows or chocolate coated fruit kebabs. The dice took me to a marshmallow stand.

Marshmallows

I chose an orange and a gingerbread one. The marshmallow is softer and stickier than the sort you get in bags, and sits on a small waffle or wafer-like disc.



Sausageroulette

Story location: Home / Blog / food_and_drink /
09/Dec/2016

The German Market is in full swing in Birmingham and I am still using the random number app to choose my lunch.

Chicken Schnitzel

The dice took me to a schnitzel stand which offered a choice of different meats. I let the dice decide and came away with a chicken schnitzel. I also got some chips to go with it.

Chicken Schnitzel

I had asked for the mushroom sauce and I think they gave me the curry sauce but it was still good, and went well with the schnitzel.

Half metre sausage

The choice was a bit easier this time. The dice chose the half-metre bratwurst stand so I didn't have any extra choices to make. I didn't let the dice choose my condiments, I added half ketchup and half mustard.

Half-metre sausage

The sausage was fine but the bread was a bit chewy. Although it looks a lot of food, I still felt hungry afterwards.



Banana Bread/Pumpkin Traybake

Story location: Home / Blog / food_and_drink /
23/Nov/2016

This was another 'make room in the freezer' baking session. I had more grated pumpkin in the freezer, along with some 'shop damaged' bananas (6p for a bag). I defrosted them and made two cake mixes. My idea was to pour them in opposite ends of a baking tray, giving the middle a swirl so the ends were one type of cake and the middle had both combined.

Recipe

The original recipe was based on the pumpkin cupcakes. I beat together 175ml of vegetable oil, 3 eggs and a teaspoon of vanilla extract, then divided the mixture in two.

In one half I added the pumpkin cake ingredients (but using cranberries instead of sultanas):

  • 85g golden caster sugar
  • 100g of grated pumpkin
  • 50g cranberries
  • 1 tsp cinnamon with ½ tsp of mixed spice

In the other half I added

  • 85g of drinking chocolate powder, with an extra tablespoon of sugar
  • 100g mashed banana
  • 50g sultanas

Both halves also had

  • 100g self raising flour
  • ½ tsp of bicarbonate of soda

I poured the two batters into a 10x6 inch tray. I expected the cakes to take about half an hour at gas mark 4 but it was well over ¾ hour before the middle stopped being liquid.

When the cake had cooled, I made a lemon juice icing, slightly runny so I could drizzle it over the top.

Banana Bread/Pumpkin Traybake

I took some of the cake to work to share (since that was where the hot chocolate powder came from, it was only fair to do that). People seemed to like it - I got favourable comments from people, someone even noticed that I had used an oil based recipe. Both cakes were definitely worth doing again.



Lunchroulette at the German Market

Story location: Home / Blog / food_and_drink /
22/Nov/2016

The German Christmas Market returned to Birmingham last week. We popped out for an inaugural pint or two when it opened but this week I decided to get some food. Instead of using the Wheeldecide website, I used a random number generator app on my phone to choose which of the many food outlets to choose.

I found myself in front of a chalet-style take-away which had a range of different menu items all based around burgers, potatoes and mushrooms. Instead of letting the dice choose how much I ate, I went for the full menu since I didn't want to end up hungry.

Burgers, mushrooms and potatoes

The garlic sauce was a bit too strong but the meal itself was good, as was the wheat beer.



International A-Z: A for Algeria

Story location: Home / food_and_drink / a_to_z /
15/Nov/2016

Earlier this year I was watching Saturday Kitchen and they were showing one of the many regular clips from Rick Stein. This was from a series he did in Eastern Europe and it gave me the idea to try to do another alphabetical cooking challenge. I intend to take each letter of the alphabet and cook something from a country or region beginning with each letter.

Originally my plan was to cook a meal but we were recently at a barbecue where the husband was Algerian and his family had provided most of the food. There was a yellow bread which went down really well. When I got home I looked it up and found some recipes.

Khobz El Dar: Algerian Semolina Bread

I took inspiration from a recipe from food.com but I reduced the quantities a bit. Since the bread we ate didn't have seeds on or in it, I left those out.

Algerian Semolina Bread

My bread took a long time to rise (I think there were problems with the yeast) and the bread had a slight sourdough taste to it. I had baked with semolina before but this was the first time I had done a bread which was mostly semolina flour. My version wasn't as good as the one we had at the barbecue but it was my first attempt. If I try again, with fresher yeast, it might come out better.



Pumpkin Cupcakes

Story location: Home / Blog / food_and_drink /
07/Nov/2016

When we scooped out the pumpkins to make Halloween lanterns, I grated and froze the flesh so I could try cooking something with it. The pumpkins which are sold for lanterns are usually a lower quality and aren't recommended for eating so I thought I would start with something where the pumpkin isn't the main flavour, so I could probably get away with a lower quality ingredient.

I found a recipe for cupcakes. It was pretty much a carrot cake but using pumpkin instead of grated carrot. The recipe called for grated orange zest but I didn't have an orange so I left that out.

Pumpkin Cupcakes

I tried one of the cakes last night, when they were still a bit warm. It tasted ok but that was before I had made the icing. Tonight's cake, with a generous layer of cream cheese frosting, was definitely an improvement.



Fruit Juice Porridges

Story location: Home / Blog / food_and_drink /
27/Oct/2016

I carried on trying out different porridge recipes this week. A couple of highlights are below.

Apple and Blackberry Porridge

When I made the apple puree a few weeks ago, I bottled and froze the juice which collected in the bottom of the pan. I used it to make an apple and blackberry porridge.

Tropical Fruit Porridge

I used coconut water instead of milk, and added some tropical fruit mix.

Tropical Fruit Porridge



Porridge Week 2

Story location: Home / Blog / food_and_drink /
20/Oct/2016

I only had time to try 4 different porridges this week. I'm going to be away on Friday so won't have chance to make anything.

Monday: Bacon and Syrup

Yes, you read that right. I don't like mixing sweet flavours with meat and consider pineapple with gammon or on a pizza to be a very poor choice. I decided to be adventurous and try a sweet bacon porridge. Mistake. I could still taste it even after a cup of tea and brushing my teeth.

Bacon and Syrup porridge

Tuesday: Apple and Blackberry

After last week's Apple and Cinnamon porridge, I decided to try an Apple, Blackberry and Cinnamon porridge, using extra cinnamon. This was better than the plain apple one, although the blackberry seeds added a bit of a crunchy texture.

Wednesday: Lemon Berry Porridge

This was inspired by a recipe from the World Porridge Making championships. I used a mixture of frozen berries (blueberries, blackberries, wild strawberries and red gooseberries) which were mostly picked in our garden, with about a tablespoon of added lemon juice. I cooked the porridge in water instead of milk then added the fruit.

I tried the porridge first, before adding any extra sugar. I don't think it needed any. The fruit were quite sweet and the lemon juice balanced it out with some added sharpness.

Lemon Berry Porridge

Thursday: Chocolate and Coconut

This was inspired by the flavours of the Bounty chocolate bar. Since dessicated coconut can be quite 'bitty', I microwaved some in water last night then added it to the porridge this morning, along with some drinking chocolate. The coconut still had a bit of bite to it. I have tried coconut in porridge several times before and there are always some hard bits so I probably need to boil or simmer it for quite a long time to stop that happening.



Porridge Week 1

Story location: Home / Blog / food_and_drink /
14/Oct/2016

I have porridge for breakfast fairly often but now that the weather is starting to get cold, it's probably time to make it my regular breakfast now. Most mornings I just add some dried fruit and sometimes some honey but this week I thought I would try a different flavour each day.

Monday: Peanut butter and Cranberry

Since it is World Porridge Day, I decided to do a different porridge each day this week. I only decided this after I had already left for work so this morning I used what I had available: a tub of dried cranberries and a small pot of peanut butter.

Tuesday: Dried raspberry

While I like raspberries, the taste didn't get into the porridge and they were very 'bitty' to eat.

Wednesday: Apple, cinnamon and brown sugar

I have mentioned before that most cake recipes don't use enough cinnamon. Unfortunately I made the same mistake myself and didn't add enough to the oats. Next time, I will add more and possibly use sweetened cooked apple instead of chopping a fresh apple into the porridge.

Apple and cinnamon porridge

Thursday: Strawberry Porridge

We have a bag of frozen strawberries so I put some in a tub to defrost in the fridge overnight and added them to the porridge after I had cooked it. I then gave it another 20 seconds in the microwave to make sure the strawberries weren't too cold.

Strawberry Porridge

Fresh strawberries don't always have much flavour and I could probably have added more but this was ok.

Friday: Nutella and Peanut Butter

This used to be a favourite of mine but I hadn't had it for a while. We recently bought a jar of nutella so I made it again today. This was possibly my favourite of the week.



Lunchroulette

Story location: Home / Blog / food_and_drink /
13/Oct/2016

A few weeks ago I decided to try somewhere different for lunch. I found a website called wheeldecide.com which can randomly choose from nearby restaurants or take-aways. I decided to use it to choose where to go for lunch.

Week 1: Full Stop Sandwich

This place was a bit of a walk. I didn't know where 'New Town Row' was and had to look it up on a map. When I got there it was almost empty but while I was paying for my sandwich it started to fill up. I chose their 'sandwich of the day' which was pork and stuffing. It came with a very thick gravy and a few pieces of crackling.

Week 2: Tuckers

I walk past this place, in the Minories, fairly regularly. It does sandwiches and hot food. I decided to try the all day breakfast for £5 which had bacon, egg, sausage, black pudding, beans, toast, hash brown and tomatoes. It also came with a cup of tea. It was good value and very filling.

Week 3: Wasabi

I needed to walk to the shops to pick up something I had ordered from PC World so I put the postcode for the High Street into Wheeldecide. It kept coming up with places in the Palisades, which is closed for refurbishment, so I decided to go to Wasabi, in New Street Station, instead.

I had been wanting to go there since it opened. I chose one of their salmon sushi boxes, which came with a couple of spicy chicken skewers.

Sushi

They have a wide range of sushi and bento boxes, with rice and noodles. I'll have to revisit to try something else.



Apple Sauce Hot Chocolate Brownies part 2

Story location: Home / Blog / food_and_drink /
03/Oct/2016

I made a second batch of the apple sauce and drinking chocolate brownies. This time I added a handful of dried cherries to the mix. I also used half apple pureé and half olive oil, since I only had half a cup of apple pureé in the fridge (the rest is in the freezer).

alt_text

When the brownies came out of the oven, I sprinkled 50g of plain chocolate over the top and waited for it to melt before spreading it over the top.

I took the cakes to work the share out and the everyone seemed to like them.